1
|
|
|
package domain |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"gorm.io/gorm" |
5
|
|
|
) |
6
|
|
|
|
7
|
|
|
type Card struct { |
8
|
|
|
gorm.Model `swaggerignore:"true"` |
9
|
|
|
Question string `json:"question"` |
10
|
|
|
Answer string `json:"answer"` |
11
|
|
|
Mcq Mcq `json:"mcq" gorm:"foreignKey:McqID"` |
12
|
|
|
DeckID uint `json:"deck_id"` |
13
|
|
|
McqID uint `json:"mcq_id"` |
14
|
|
|
CardType CardType `json:"card_type"` |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
func (c *Card) TableName() string { |
18
|
|
|
return "cards" |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
// String returns the string representation of the card. |
22
|
|
|
func (c *Card) String() string { |
23
|
|
|
return c.Question + " " + c.Answer |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
// HasMcqType returns true if the card has a mcq type. |
27
|
|
|
// It returns true for both mcq and progressive types. |
28
|
|
|
func (c *Card) HasMcqType() bool { |
29
|
|
|
return c.IsMcqType() || c.IsProgressiveType() |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
// IsLinked returns true if the card is linked. |
33
|
|
|
// It returns true for both mcq and progressive types. |
34
|
|
|
func (c *Card) IsLinked() bool { |
35
|
|
|
return c.IsMcqType() && c.Mcq.IsLinked() |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
// IsMcqType returns true if the card is a mcq type. |
39
|
|
|
// It returns true only for mcq and blank mcq types. |
40
|
|
|
func (c *Card) IsMcqType() bool { |
41
|
|
|
return c.CardType == CardTypeMCQOnly || c.CardType == CardTypeBlankMCQ |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
// IsProgressiveType returns true if the card is a progressive type. |
45
|
|
|
func (c *Card) IsProgressiveType() bool { |
46
|
|
|
return c.CardType == CardTypeQAProgressive || c.CardType == CardTypeBlankProgressive |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
// IsBlankType returns true if the card is a blank type. |
50
|
|
|
func (c *Card) IsBlankType() bool { |
51
|
|
|
return c.CardType == CardTypeBlankOnly || c.CardType == CardTypeBlankProgressive || c.CardType == CardTypeBlankMCQ |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
// IsQAOnlyType returns true if the card is a qa only type. |
55
|
|
|
func (c *Card) IsQAOnlyType() bool { |
56
|
|
|
return c.CardType == CardTypeQAOnly |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
// CardType is the type of the card |
60
|
|
|
type CardType int32 |
61
|
|
|
|
62
|
|
|
const ( |
63
|
|
|
CardTypeQAOnly CardType = iota // CardTypeQAOnly is the qa only type of the card |
64
|
|
|
CardTypeMCQOnly // CardTypeMCQOnly is the mcq only type of the card |
65
|
|
|
CardTypeQAProgressive // CardTypeQAProgressive is the qa progressive type of the card |
66
|
|
|
CardTypeBlankOnly // CardTypeBlankOnly is the blank only type of the card |
67
|
|
|
CardTypeBlankProgressive // CardTypeBlankProgressive is the blank progressive type of the card |
68
|
|
|
CardTypeBlankMCQ // CardTypeBlankMCQ is the blank mcq type of the card |
69
|
|
|
) |
70
|
|
|
|
71
|
|
|
// String returns the string representation of the card type. |
72
|
|
|
func (c CardType) String() string { |
73
|
|
|
return [...]string{"QAOnly", "MCQOnly", "QAProgressive", "BlankOnly", "BlankProgressive", "BlankMCQ"}[c] |
74
|
|
|
} |
75
|
|
|
|