bill-server-go/internal/bill/domain.go

69 lines
1.7 KiB
Go
Raw Normal View History

2023-05-07 22:49:59 +08:00
package bill
2023-06-01 17:55:41 +08:00
import (
"context"
"gorm.io/gorm"
)
2023-05-07 22:49:59 +08:00
// Bill represents 'bills' object.
type Bill struct {
2023-06-01 17:55:41 +08:00
gorm.Model
2023-06-10 16:52:49 +08:00
Year int
Month int
Day int
2023-06-01 20:06:43 +08:00
Money float64
2023-06-10 16:52:49 +08:00
Label string
2023-06-01 20:06:43 +08:00
Options string
2023-06-10 16:52:49 +08:00
Type string
}
type BillDTO struct {
ID int `json:"id"`
Year int `json:"year"`
Month int `json:"month"`
Day int `json:"day"`
Money float64 `json:"money"`
Label string `json:"label"`
Options string `json:"options"`
Type string `json:"type"`
}
func (b *Bill) Dto() BillDTO {
return BillDTO{
ID: int(b.ID),
Year: b.Year,
Month: b.Month,
Day: b.Day,
Money: b.Money,
Label: b.Label,
Options: b.Options,
Type: b.Type,
}
2023-05-07 22:49:59 +08:00
}
2023-05-31 15:40:27 +08:00
// BDate 用于判断获取bill的时间范围
2023-05-07 22:49:59 +08:00
type BDate struct {
2023-06-10 17:31:16 +08:00
Year int `validate:"min=0"`
Month int `validate:"min=0,max=12"`
Day int `validate:"min=0,max=31"`
2023-05-07 22:49:59 +08:00
}
type BillRepository interface {
2023-06-10 15:19:31 +08:00
GetBills(ctx context.Context) ([]Bill, error)
GetBillByDay(ctx context.Context, year int, month int, day int) ([]Bill, error)
GetBillByMonth(ctx context.Context, year int, month int) ([]Bill, error)
GetBillByYear(ctx context.Context, year int) ([]Bill, error)
2023-05-07 22:49:59 +08:00
GetBillByID(ctx context.Context, id int) (*Bill, error)
CreateBill(ctx context.Context, bill *Bill) error
UpdateBill(ctx context.Context, bill *Bill) error
DeleteBill(ctx context.Context, id int) error
}
type BillService interface {
2023-06-10 16:52:49 +08:00
GetBills(ctx context.Context, date BDate) ([]interface{}, error)
GetBillByID(ctx context.Context, id int) (interface{}, error)
2023-05-11 21:00:29 +08:00
CreateBill(ctx context.Context, bill *Bill) error
UpdateBill(ctx context.Context, bill *Bill) error
DeleteBill(ctx context.Context, id int) error
2023-05-07 22:49:59 +08:00
}