diff options
author | rtz12 <koenig@fagott.pw> | 2016-10-11 19:02:59 (UTC) |
---|---|---|
committer | rtz12 <koenig@fagott.pw> | 2016-10-11 19:02:59 (UTC) |
commit | ce5973c4024f22a8f8c63818109a2ca4f3be7bc4 (patch) | |
tree | e7b6b5d5c6e73451b489e97f90206a96bf9ed2df /models | |
parent | fbd746aef8c78067593f901afb0f255574392499 (diff) | |
parent | b5051d2358e12f877e5c52053dcf1a16959e4ded (diff) |
Merge branch 'master' of projekte.fagott.pw:grilist
Diffstat (limited to 'models')
-rw-r--r-- | models/gril.go | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/models/gril.go b/models/gril.go new file mode 100644 index 0000000..f0b8f8f --- /dev/null +++ b/models/gril.go | |||
@@ -0,0 +1,61 @@ | |||
1 | package models | ||
2 | |||
3 | import ( | ||
4 | "database/sql" | ||
5 | "fmt" | ||
6 | "strconv" | ||
7 | "strings" | ||
8 | "time" | ||
9 | |||
10 | "fagott.pw/grilist/modules/series" | ||
11 | |||
12 | "github.com/lib/pq" | ||
13 | ) | ||
14 | |||
15 | type DataSource int | ||
16 | |||
17 | const ( | ||
18 | DataSourceACD DataSource = iota | ||
19 | DataSourceAniDB | ||
20 | DataSourceAnilist | ||
21 | ) | ||
22 | |||
23 | type Trait struct { | ||
24 | Name string | ||
25 | Value string | ||
26 | OfficialValue string | ||
27 | } | ||
28 | |||
29 | type Gril struct { | ||
30 | ID int | ||
31 | KanjiName string | ||
32 | RomajiName string | ||
33 | OtherNames []string | ||
34 | Age sql.NullInt64 | ||
35 | Birthday pq.NullTime | ||
36 | Tags []string | ||
37 | Traits []Trait | ||
38 | ForeignIDs map[DataSource]int | ||
39 | UpdatedAt time.Time | ||
40 | Lists []int | ||
41 | Series []series.Series | ||
42 | } | ||
43 | |||
44 | // Der kram hier sollte eigentlich auch eher wo anders hin als ins Model, oder?! | ||
45 | func (g *Gril) Slug() string { | ||
46 | if g.RomajiName == "" { | ||
47 | return strconv.Itoa(g.ID) | ||
48 | } | ||
49 | return fmt.Sprintf( | ||
50 | "%d/%s", | ||
51 | g.ID, | ||
52 | strings.Replace(g.RomajiName, " ", "", -1)) | ||
53 | } | ||
54 | |||
55 | // Das hier sollte auch irgendwo anders hin. | ||
56 | func (g *Gril) ImagePath(useThumbnail bool) string { | ||
57 | if useThumbnail { | ||
58 | return fmt.Sprintf("http://img.grilist.moe/gril/thumb/%d.jpg", g.ID) | ||
59 | } | ||
60 | return fmt.Sprintf("http://img.grilist.moe/gril/full/%d.jpg", g.ID) | ||
61 | } | ||