-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel_cart.go
65 lines (57 loc) · 1.56 KB
/
model_cart.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"time"
)
type CartFilter struct {
IDs []int64 `json:"ids,omitempty"`
UserIDs []int64 `json:"user_ids,omitempty"`
ShowtimeIDs []int64 `json:"showtime_ids,omitempty"`
SeatIDs []int64 `json:"seat_ids,omitempty"`
}
func (f *CartFilter) Validate() error {
return nil
}
type CartInput struct {
UserID int64 `json:"user_id,omitempty"`
ShowtimeID int64 `json:"showtime_id,omitempty"`
SeatID int64 `json:"seat_id,omitempty"`
}
func (i *CartInput) Validate() error {
if i.UserID <= 0 {
return NewErr(ErrInput, nil, "user id is invalid")
}
if i.ShowtimeID <= 0 {
return NewErr(ErrInput, nil, "showtime id is invalid")
}
if i.SeatID <= 0 {
return NewErr(ErrInput, nil, "seat id is invalid")
}
return nil
}
func NewCart(input CartInput) (*Cart, error) {
err := input.Validate()
if err != nil {
return nil, err
}
Cart := Cart{
UserID: input.UserID,
ShowtimeID: input.ShowtimeID,
SeatID: input.SeatID,
}
return &Cart, nil
}
type Cart struct {
ID int64 `json:"id,omitempty"`
UserID int64 `json:"user_id,omitempty"`
ShowtimeID int64 `json:"showtime_id,omitempty"`
SeatID int64 `json:"seat_id,omitempty"`
CreatedAt time.Time `json:"created_at,omitempty"`
UpdatedAt time.Time `json:"updated_at,omitempty"`
// relation
Movie string `json:"movie"`
ShowtimeStart time.Time `json:"showtime_start"`
ShowtimeEnd time.Time `json:"showtime_end"`
Room string `json:"room"`
Seat string `json:"seat"`
Price int64 `json:"price"`
}