aboutsummaryrefslogtreecommitdiff
path: root/models
diff options
context:
space:
mode:
authorjan <jan@ruken.pw>2016-10-11 15:44:12 (UTC)
committerjan <jan@ruken.pw>2016-10-11 15:44:12 (UTC)
commitb5051d2358e12f877e5c52053dcf1a16959e4ded (patch)
tree43c9edcd70facc9becd1d6de8c1a454625ac9762 /models
parente2d40c07c10ba46c7b32bbfbbf00493f40fe3c56 (diff)
irgendwie angefangen 'models' zu verwenden, wir muessen mal gucken wie wir das genau gestalten wollen
Diffstat (limited to 'models')
-rw-r--r--models/gril.go61
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 @@
1package models
2
3import (
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
15type DataSource int
16
17const (
18 DataSourceACD DataSource = iota
19 DataSourceAniDB
20 DataSourceAnilist
21)
22
23type Trait struct {
24 Name string
25 Value string
26 OfficialValue string
27}
28
29type 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?!
45func (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.
56func (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}