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