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
|
|
|
func (res *ResponseHTTP) GenerateError(message string) { |
22
|
|
|
res.Set(false, message, nil, 0) |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
func (res *ResponseHTTP) GenerateSuccess(message string, data interface{}, count int) { |
26
|
|
|
res.Set(true, message, data, count) |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
// CardResponse struct |
30
|
|
|
type CardResponse struct { |
31
|
|
|
CardID uint `json:"card_id" example:"1"` |
32
|
|
|
Card Card |
33
|
|
|
Response string `json:"response" example:"42"` |
34
|
|
|
Training bool `json:"training" example:"false"` |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
// CardResponseValidation struct |
38
|
|
|
type CardResponseValidation struct { |
39
|
|
|
Validate bool `json:"validate" example:"true"` |
40
|
|
|
Message string `json:"message" example:"Correct answer"` |
41
|
|
|
Answer string `json:"correct_answer" example:"42"` |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
// ResponseCard struct |
45
|
|
|
type ResponseCard struct { |
46
|
|
|
Card Card |
47
|
|
|
Answers []string |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
// Set ResponseCard values |
51
|
|
|
func (responseCard *ResponseCard) Set(card Card, answers []string) { |
52
|
|
|
responseCard.Answers = answers |
53
|
|
|
responseCard.Card = card |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// ResponseAuth struct |
57
|
|
|
type ResponseAuth struct { |
58
|
|
|
Success bool |
59
|
|
|
User User |
60
|
|
|
Message string |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// ResponseDeck struct |
64
|
|
|
type ResponseDeck struct { |
65
|
|
|
DeckID uint `json:"deck_id" example:"1"` |
66
|
|
|
Deck Deck |
67
|
|
|
Permission AccessPermission `json:"permission" example:"1"` |
68
|
|
|
CardCount int64 `json:"card_count" example:"42"` |
69
|
|
|
OwnerId uint `json:"owner_id" example:"6"` |
70
|
|
|
Owner User |
71
|
|
|
} |
72
|
|
|
|