Total Lines | 47 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | package models |
||
2 | |||
3 | import ( |
||
4 | "gorm.io/gorm" |
||
5 | "memnixrest/pkg/database" |
||
6 | ) |
||
7 | |||
8 | // Deck structure |
||
9 | type Deck struct { |
||
10 | gorm.Model `swaggerignore:"true"` |
||
11 | DeckName string `json:"deck_name" example:"First Deck"` |
||
12 | Description string `json:"deck_description" example:"A simple demo deck"` |
||
13 | Banner string `json:"deck_banner" example:"A banner url"` |
||
14 | Status DeckStatus `json:"deck_status" example:"2"` // 1: Draft - 2: Private - 3: Published |
||
15 | } |
||
16 | |||
17 | type DeckStatus int64 |
||
18 | |||
19 | const ( |
||
20 | DeckDraft DeckStatus = iota + 1 |
||
21 | DeckPrivate |
||
22 | DeckPublic |
||
23 | ) |
||
24 | |||
25 | func (s DeckStatus) ToString() string { |
||
26 | switch s { |
||
27 | case DeckDraft: |
||
28 | return "Deck Draft" |
||
29 | case DeckPrivate: |
||
30 | return "Deck Private" |
||
31 | case DeckPublic: |
||
32 | return "Deck Public" |
||
33 | default: |
||
34 | return "Unknown" |
||
35 | } |
||
36 | } |
||
37 | |||
38 | func (deck *Deck) GetOwner() User { |
||
39 | db := database.DBConn |
||
40 | |||
41 | access := new(Access) |
||
42 | |||
43 | if err := db.Joins("User").Joins("Deck").Where("accesses.deck_id =? AND accesses.permission >= ?", deck.ID, AccessOwner).Find(&access).Error; err != nil { |
||
44 | return access.User |
||
45 | } |
||
46 | |||
47 | return access.User |
||
48 | } |
||
49 |