Passed
Push — main ( 26be31...19cade )
by Yume
01:25
created

models.CardType.ToString   A

Complexity

Conditions 5

Size

Total Lines 10
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 10
nop 0
dl 0
loc 10
rs 9.3333
c 0
b 0
f 0
1
package models
2
3
import (
4
	"gorm.io/gorm"
5
)
6
7
// Card structure
8
type Card struct {
9
	gorm.Model  `swaggerignore:"true"`
10
	Question    string `json:"card_question" example:"What's the answer to life ?"`
11
	Answer      string `json:"card_answer" example:"42"`
12
	DeckID      uint   `json:"deck_id" example:"1"`
13
	Deck        Deck
14
	Tips        string   `json:"card_tips" example:"The answer is from a book"`
15
	Explication string   `json:"card_explication" example:"The number 42 is the answer to life has written in a very famous book"`
16
	Type        CardType `json:"card_type" example:"0" gorm:"type:Int"`
17
	Format      string   `json:"card_format" example:"Date / Name / Country"`
18
	Image       string   `json:"card_image"` // Should be an url
19
}
20
21
type CardType int64
22
23
const (
24
	CardString CardType = iota
25
	CardInt
26
	CardMCQ
27
)
28
29
func (s CardType) ToString() string {
30
	switch s {
31
	case CardString:
32
		return "Card String"
33
	case CardInt:
34
		return "Card Int"
35
	case CardMCQ:
36
		return "Card MCQ"
37
	default:
38
		return "Unknown"
39
	}
40
}
41