api for initial widgets

This commit is contained in:
Gabe Farrell 2023-04-10 22:39:51 -04:00
parent 36f751a69f
commit 4aa8a2f822
14 changed files with 864 additions and 11 deletions

8
money/currency.go Normal file
View file

@ -0,0 +1,8 @@
package money
type Currency string
const (
USD Currency = "USD"
CAD = "CAD"
)

31
money/money.go Normal file
View file

@ -0,0 +1,31 @@
package money
type Money struct {
Currency Currency `json:"currency" bson:"currency"`
Whole int `json:"whole" bson:"whole"`
Decimal int `json:"decimal" bson:"decimal"`
}
// add x to y
func Add(x, y Money) Money {
x.Decimal += y.Decimal
if x.Decimal >= 100 {
x.Whole++
x.Decimal -= 100
}
x.Whole += y.Whole
return x
}
// subtract x from y
func Subtract(x, y Money) Money {
x.Decimal = y.Decimal - x.Decimal
if x.Decimal < 0 {
x.Whole++
x.Decimal += 100
}
x.Whole = y.Whole - x.Whole
return x
}