1
|
|
|
package models |
2
|
|
|
|
3
|
|
|
// ResponseHTTP structure to format API answers |
4
|
|
|
type ResponseHTTP struct { |
5
|
|
|
Success bool `json:"success"` |
6
|
|
|
Data interface{} `json:"data"` |
7
|
|
|
Message string `json:"message"` |
8
|
|
|
Count int `json:"count"` |
9
|
|
|
} |
10
|
|
|
|
11
|
|
|
// Set ResponseHTTP values |
12
|
|
|
func (res *ResponseHTTP) Set(success bool, message string, data interface{}, count int) { |
13
|
|
|
*res = ResponseHTTP{ |
14
|
|
|
Success: success, |
15
|
|
|
Data: data, |
16
|
|
|
Message: message, |
17
|
|
|
Count: count, |
18
|
|
|
} |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
// GenerateError method |
22
|
|
|
func (res *ResponseHTTP) GenerateError(message string) { |
23
|
|
|
res.Set(false, message, nil, 0) |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
// GenerateSuccess method |
27
|
|
|
func (res *ResponseHTTP) GenerateSuccess(message string, data interface{}, count int) { |
28
|
|
|
res.Set(true, message, data, count) |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
// DeckConfig struct |
32
|
|
|
type DeckConfig struct { |
33
|
|
|
TodaySetting bool `json:"settings_today"` |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
// CardResponse struct |
37
|
|
|
type CardResponse struct { |
38
|
|
|
CardID uint `json:"card_id" example:"1"` |
39
|
|
|
Card Card `json:"-" swaggerignore:"true"` |
40
|
|
|
Response string `json:"response" example:"42"` |
41
|
|
|
Training bool `json:"training" example:"false"` |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
type CardSelfResponse struct { |
45
|
|
|
Training bool `json:"training" example:"false"` |
46
|
|
|
Quality uint `json:"quality" example:"3"` // Min 0 - Max 4 |
47
|
|
|
CardID uint `json:"card_id" example:"1"` |
48
|
|
|
Card Card |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
// CardResponseValidation struct |
52
|
|
|
type CardResponseValidation struct { |
53
|
|
|
Validate bool `json:"validate" example:"true"` |
54
|
|
|
Message string `json:"message" example:"Correct answer"` |
55
|
|
|
Answer string `json:"correct_answer" example:"42"` |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
func (validation *CardResponseValidation) SetCorrect() { |
59
|
|
|
validation.Validate = true |
60
|
|
|
validation.Message = "Correct answer" |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
func (validation *CardResponseValidation) SetIncorrect() { |
64
|
|
|
validation.Validate = false |
65
|
|
|
validation.Message = "Incorrect answer" |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
// ResponseCard struct |
69
|
|
|
type ResponseCard struct { |
70
|
|
|
Card Card |
71
|
|
|
Answers []string |
72
|
|
|
LearningStage LearningStage `json:"learning_stage"` |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
// Set ResponseCard values |
76
|
|
|
func (responseCard *ResponseCard) Set(memdate *MemDate, answers []string) { |
77
|
|
|
responseCard.Answers = answers |
78
|
|
|
responseCard.Card = memdate.Card |
79
|
|
|
responseCard.LearningStage = memdate.LearningStage |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
// ResponseAuth struct |
83
|
|
|
type ResponseAuth struct { |
84
|
|
|
Success bool `json:"success"` |
85
|
|
|
User User `json:"user"` |
86
|
|
|
Message string `json:"message"` |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
type ResponsePublicAuth struct { |
90
|
|
|
Success bool `json:"success"` |
91
|
|
|
User PublicUser `json:"user"` |
92
|
|
|
Message string `json:"message"` |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
// ResponseDeck struct |
96
|
|
|
type ResponseDeck struct { |
97
|
|
|
DeckID uint `json:"deck_id" example:"1"` |
98
|
|
|
Permission AccessPermission `json:"permission" example:"1"` |
99
|
|
|
CardCount uint16 `json:"card_count" example:"42"` |
100
|
|
|
ToggleToday bool `json:"settings_today" ` |
101
|
|
|
OwnerID uint `json:"owner_id" example:"6"` |
102
|
|
|
Owner PublicUser `swaggerignore:"true" json:"Owner,omitempty"` |
103
|
|
|
Deck Deck `json:"Deck,omitempty"` |
104
|
|
|
} |
105
|
|
|
|