aboutsummaryrefslogtreecommitdiff
path: root/modules/grils/gril.go
blob: 7b54ab16996ea200b57c10544daa3247050da503 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package grils

import (
	"database/sql"
	"fmt"
	"strconv"
	"strings"
	"time"

	"fagott.pw/grilist/modules/series"

	"github.com/lib/pq"
)

type DataSource int

const (
	DataSourceACD DataSource = iota
	DataSourceAniDB
	DataSourceAnilist
)

type Trait struct {
	Name          string
	Value         string
	OfficialValue string
}

type Gril struct {
	ID         int
	KanjiName  string
	RomajiName string
	OtherNames []string
	Age        sql.NullInt64
	Birthday   pq.NullTime
	Tags       []string
	Traits     []Trait
	ForeignIDs map[DataSource]int
	UpdatedAt  time.Time
	Lists      []int
	Series     []series.Series
}

func (g *Gril) Slug() string {
	if g.RomajiName == "" {
		return strconv.Itoa(g.ID)
	}
	return fmt.Sprintf(
		"%d/%s",
		g.ID,
		strings.Replace(g.RomajiName, " ", "", -1))
}

func ImagePath(id int, useThumbnail bool) string {
	if useThumbnail {
		return fmt.Sprintf("http://img.grilist.moe/gril/thumb/%d.jpg", id)
	}
	return fmt.Sprintf("http://img.grilist.moe/gril/full/%d.jpg", id)
}

func (g *Gril) ImagePath(prioritizeThumbnail bool) string {
	return ImagePath(g.ID, prioritizeThumbnail)
}