-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.go
51 lines (41 loc) · 972 Bytes
/
core.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package core
import (
"errors"
"time"
)
const (
// Debit is a transaction which is subtracted.
Debit = 1
// Credit is a transaction which is subtracted the next month.
Credit = 2
// Income is a transaction which is summed.
Income = 3
)
type (
// Category is the general class of a Transaction (eg: Health, Food).
Category struct {
Name string
}
// Transaction is money received or expended.
Transaction struct {
ID int
Amount int
Type int
Category Category
Date time.Time
Name string
}
)
// Validate whether a transaction has all it's required properties set.
func (t *Transaction) Validate() error {
if t.Amount <= 0 {
return errors.New("Transaction.Validate: invalid amount")
}
if t.Type != Debit && t.Type != Credit && t.Type != Income {
return errors.New("Transaction.Validate: invalid type")
}
if t.Category.Name == "" {
return errors.New("Transaction.Validate: invalid category")
}
return nil
}