Use AnimeID type
This commit is contained in:
parent
a3f04fbd2f
commit
18a7be18d2
@ -4,9 +4,9 @@ import "sort"
|
||||
|
||||
// ActivityConsumeAnime is a user activity that consumes anime.
|
||||
type ActivityConsumeAnime struct {
|
||||
AnimeID string `json:"animeId"`
|
||||
FromEpisode int `json:"fromEpisode"`
|
||||
ToEpisode int `json:"toEpisode"`
|
||||
AnimeID AnimeID `json:"animeId"`
|
||||
FromEpisode int `json:"fromEpisode"`
|
||||
ToEpisode int `json:"toEpisode"`
|
||||
|
||||
hasID
|
||||
hasCreator
|
||||
@ -14,7 +14,7 @@ type ActivityConsumeAnime struct {
|
||||
}
|
||||
|
||||
// NewActivityConsumeAnime creates a new activity.
|
||||
func NewActivityConsumeAnime(animeID string, fromEpisode int, toEpisode int, userID UserID) *ActivityConsumeAnime {
|
||||
func NewActivityConsumeAnime(animeID AnimeID, fromEpisode int, toEpisode int, userID UserID) *ActivityConsumeAnime {
|
||||
return &ActivityConsumeAnime{
|
||||
hasID: hasID{
|
||||
ID: GenerateID("ActivityConsumeAnime"),
|
||||
@ -46,7 +46,7 @@ func (activity *ActivityConsumeAnime) Self() Loggable {
|
||||
}
|
||||
|
||||
// LastActivityConsumeAnime returns the last activity for the given anime.
|
||||
func (user *User) LastActivityConsumeAnime(animeID string) *ActivityConsumeAnime {
|
||||
func (user *User) LastActivityConsumeAnime(animeID AnimeID) *ActivityConsumeAnime {
|
||||
activities := FilterActivitiesConsumeAnime(func(activity *ActivityConsumeAnime) bool {
|
||||
return activity.AnimeID == animeID && activity.CreatedBy == user.ID
|
||||
})
|
||||
|
@ -39,7 +39,7 @@ func NewAniListAnimeFinder() *AniListAnimeFinder {
|
||||
}
|
||||
|
||||
// GetAnime tries to find an AniList anime in our anime database.
|
||||
func (finder *AniListAnimeFinder) GetAnime(id string, malID string) *Anime {
|
||||
func (finder *AniListAnimeFinder) GetAnime(id AnimeID, malID string) *Anime {
|
||||
animeByID, existsByID := finder.idToAnime[id]
|
||||
animeByMALID, existsByMALID := finder.malIDToAnime[malID]
|
||||
|
||||
|
16
arn/Anime.go
16
arn/Anime.go
@ -62,8 +62,12 @@ func init() {
|
||||
}
|
||||
}
|
||||
|
||||
// AnimeID represents an anime ID.
|
||||
type AnimeID = string
|
||||
|
||||
// Anime represents an anime.
|
||||
type Anime struct {
|
||||
ID AnimeID `json:"id"`
|
||||
Type string `json:"type" editable:"true" datalist:"anime-types"`
|
||||
Title *MediaTitle `json:"title" editable:"true"`
|
||||
Summary string `json:"summary" editable:"true" type:"textarea"`
|
||||
@ -81,7 +85,6 @@ type Anime struct {
|
||||
Trailers []*ExternalMedia `json:"trailers" editable:"true"`
|
||||
|
||||
// Mixins
|
||||
hasID
|
||||
hasMappings
|
||||
hasPosts
|
||||
hasLikes
|
||||
@ -104,9 +107,7 @@ type Anime struct {
|
||||
// NewAnime creates a new anime.
|
||||
func NewAnime() *Anime {
|
||||
return &Anime{
|
||||
hasID: hasID{
|
||||
ID: GenerateID("Anime"),
|
||||
},
|
||||
ID: GenerateID("Anime"),
|
||||
Title: &MediaTitle{},
|
||||
Rating: &AnimeRating{},
|
||||
Popularity: &AnimePopularity{},
|
||||
@ -121,7 +122,7 @@ func NewAnime() *Anime {
|
||||
}
|
||||
|
||||
// GetAnime gets the anime with the given ID.
|
||||
func GetAnime(id string) (*Anime, error) {
|
||||
func GetAnime(id AnimeID) (*Anime, error) {
|
||||
obj, err := DB.Get("Anime", id)
|
||||
|
||||
if err != nil {
|
||||
@ -767,6 +768,11 @@ func (anime *Anime) String() string {
|
||||
return anime.Title.Canonical
|
||||
}
|
||||
|
||||
// GetID returns the ID.
|
||||
func (anime *Anime) GetID() string {
|
||||
return anime.ID
|
||||
}
|
||||
|
||||
// TypeName returns the type name.
|
||||
func (anime *Anime) TypeName() string {
|
||||
return "Anime"
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
|
||||
// AnimeCharacters is a list of characters for an anime.
|
||||
type AnimeCharacters struct {
|
||||
AnimeID string `json:"animeId" mainID:"true"`
|
||||
AnimeID AnimeID `json:"animeId" mainID:"true"`
|
||||
Items []*AnimeCharacter `json:"items" editable:"true"`
|
||||
|
||||
sync.Mutex
|
||||
@ -108,7 +108,7 @@ func (characters *AnimeCharacters) First(count int) []*AnimeCharacter {
|
||||
}
|
||||
|
||||
// GetAnimeCharacters ...
|
||||
func GetAnimeCharacters(animeID string) (*AnimeCharacters, error) {
|
||||
func GetAnimeCharacters(animeID AnimeID) (*AnimeCharacters, error) {
|
||||
obj, err := DB.Get("AnimeCharacters", animeID)
|
||||
|
||||
if err != nil {
|
||||
|
@ -11,7 +11,7 @@ import (
|
||||
|
||||
// AnimeEpisodes is a list of episodes for an anime.
|
||||
type AnimeEpisodes struct {
|
||||
AnimeID string `json:"animeId" mainID:"true"`
|
||||
AnimeID AnimeID `json:"animeId" mainID:"true"`
|
||||
Items []*AnimeEpisode `json:"items" editable:"true"`
|
||||
|
||||
sync.Mutex
|
||||
|
@ -18,7 +18,7 @@ type AnimeList struct {
|
||||
}
|
||||
|
||||
// Add adds an anime to the list if it hasn't been added yet.
|
||||
func (list *AnimeList) Add(animeID string) error {
|
||||
func (list *AnimeList) Add(animeID AnimeID) error {
|
||||
if list.Contains(animeID) {
|
||||
return errors.New("Anime " + animeID + " has already been added")
|
||||
}
|
||||
@ -45,7 +45,7 @@ func (list *AnimeList) Add(animeID string) error {
|
||||
}
|
||||
|
||||
// Remove removes the anime ID from the list.
|
||||
func (list *AnimeList) Remove(animeID string) bool {
|
||||
func (list *AnimeList) Remove(animeID AnimeID) bool {
|
||||
list.Lock()
|
||||
defer list.Unlock()
|
||||
|
||||
@ -60,7 +60,7 @@ func (list *AnimeList) Remove(animeID string) bool {
|
||||
}
|
||||
|
||||
// Contains checks if the list contains the anime ID already.
|
||||
func (list *AnimeList) Contains(animeID string) bool {
|
||||
func (list *AnimeList) Contains(animeID AnimeID) bool {
|
||||
list.Lock()
|
||||
defer list.Unlock()
|
||||
|
||||
@ -88,7 +88,7 @@ func (list *AnimeList) HasItemsWithStatus(status string) bool {
|
||||
}
|
||||
|
||||
// Find returns the list item with the specified anime ID, if available.
|
||||
func (list *AnimeList) Find(animeID string) *AnimeListItem {
|
||||
func (list *AnimeList) Find(animeID AnimeID) *AnimeListItem {
|
||||
list.Lock()
|
||||
defer list.Unlock()
|
||||
|
||||
|
@ -11,7 +11,7 @@ const (
|
||||
|
||||
// AnimeListItem ...
|
||||
type AnimeListItem struct {
|
||||
AnimeID string `json:"animeId"`
|
||||
AnimeID AnimeID `json:"animeId"`
|
||||
Status string `json:"status" editable:"true"`
|
||||
Episodes int `json:"episodes" editable:"true"`
|
||||
Rating AnimeListItemRating `json:"rating"`
|
||||
|
@ -18,7 +18,7 @@ func init() {
|
||||
|
||||
// AnimeRelation ...
|
||||
type AnimeRelation struct {
|
||||
AnimeID string `json:"animeId" editable:"true"`
|
||||
AnimeID AnimeID `json:"animeId" editable:"true"`
|
||||
Type string `json:"type" editable:"true" datalist:"anime-relation-types"`
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
|
||||
// AnimeRelations is a list of relations for an anime.
|
||||
type AnimeRelations struct {
|
||||
AnimeID string `json:"animeId" mainID:"true"`
|
||||
AnimeID AnimeID `json:"animeId" mainID:"true"`
|
||||
Items []*AnimeRelation `json:"items" editable:"true"`
|
||||
|
||||
sync.Mutex
|
||||
@ -72,7 +72,7 @@ func (relations *AnimeRelations) Self() Loggable {
|
||||
}
|
||||
|
||||
// Find returns the relation with the specified anime ID, if available.
|
||||
func (relations *AnimeRelations) Find(animeID string) *AnimeRelation {
|
||||
func (relations *AnimeRelations) Find(animeID AnimeID) *AnimeRelation {
|
||||
relations.Lock()
|
||||
defer relations.Unlock()
|
||||
|
||||
@ -86,7 +86,7 @@ func (relations *AnimeRelations) Find(animeID string) *AnimeRelation {
|
||||
}
|
||||
|
||||
// Remove removes the anime ID from the relations.
|
||||
func (relations *AnimeRelations) Remove(animeID string) bool {
|
||||
func (relations *AnimeRelations) Remove(animeID AnimeID) bool {
|
||||
relations.Lock()
|
||||
defer relations.Unlock()
|
||||
|
||||
@ -101,7 +101,7 @@ func (relations *AnimeRelations) Remove(animeID string) bool {
|
||||
}
|
||||
|
||||
// GetAnimeRelations ...
|
||||
func GetAnimeRelations(animeID string) (*AnimeRelations, error) {
|
||||
func GetAnimeRelations(animeID AnimeID) (*AnimeRelations, error) {
|
||||
obj, err := DB.Get("AnimeRelations", animeID)
|
||||
|
||||
if err != nil {
|
||||
|
@ -7,14 +7,14 @@ import (
|
||||
|
||||
// DraftIndex has references to unpublished drafts a user created.
|
||||
type DraftIndex struct {
|
||||
UserID string `json:"userId"`
|
||||
GroupID string `json:"groupId"`
|
||||
SoundTrackID string `json:"soundTrackId"`
|
||||
CompanyID string `json:"companyId"`
|
||||
QuoteID string `json:"quoteId"`
|
||||
CharacterID string `json:"characterId"`
|
||||
AnimeID string `json:"animeId"`
|
||||
AMVID string `json:"amvId"`
|
||||
UserID string `json:"userId"`
|
||||
GroupID string `json:"groupId"`
|
||||
SoundTrackID string `json:"soundTrackId"`
|
||||
CompanyID string `json:"companyId"`
|
||||
QuoteID string `json:"quoteId"`
|
||||
CharacterID string `json:"characterId"`
|
||||
AnimeID AnimeID `json:"animeId"`
|
||||
AMVID string `json:"amvId"`
|
||||
}
|
||||
|
||||
// NewDraftIndex ...
|
||||
|
@ -30,12 +30,12 @@ func GetIgnoreAnimeDifference(id string) (*IgnoreAnimeDifference, error) {
|
||||
}
|
||||
|
||||
// CreateDifferenceID ...
|
||||
func CreateDifferenceID(animeID string, dataProvider string, malAnimeID string, typeName string) string {
|
||||
func CreateDifferenceID(animeID AnimeID, dataProvider string, malAnimeID string, typeName string) string {
|
||||
return fmt.Sprintf("arn:%s|%s:%s|%s", animeID, dataProvider, malAnimeID, typeName)
|
||||
}
|
||||
|
||||
// IsAnimeDifferenceIgnored tells you whether the given difference is being ignored.
|
||||
func IsAnimeDifferenceIgnored(animeID string, dataProvider string, malAnimeID string, typeName string, hash uint64) bool {
|
||||
func IsAnimeDifferenceIgnored(animeID AnimeID, dataProvider string, malAnimeID string, typeName string, hash uint64) bool {
|
||||
key := CreateDifferenceID(animeID, dataProvider, malAnimeID, typeName)
|
||||
ignore, err := GetIgnoreAnimeDifference(key)
|
||||
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
type Quote struct {
|
||||
Text QuoteText `json:"text" editable:"true"`
|
||||
CharacterID string `json:"characterId" editable:"true"`
|
||||
AnimeID string `json:"animeId" editable:"true"`
|
||||
AnimeID AnimeID `json:"animeId" editable:"true"`
|
||||
EpisodeNumber int `json:"episode" editable:"true"`
|
||||
Time int `json:"time" editable:"true"`
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user