From 9e62774eb4c2157b92b28fd226c471f8afe2ffdd Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Mon, 18 Nov 2019 15:13:51 +0900 Subject: [PATCH] Cleanup --- arn/AMV.go | 2 +- arn/Anime.go | 64 +++------------------------ arn/Anime.init.go | 53 ++++++++++++++++++++++ arn/Character.go | 2 +- arn/CharacterFinder.go | 2 +- arn/Company.go | 2 +- arn/DraftIndex.go | 18 ++++---- arn/Episode.go | 2 +- arn/Group.go | 2 +- arn/IDCollection.go | 4 +- arn/IDList.go | 6 +-- arn/IgnoreAnimeDifference.go | 2 +- arn/Notification.go | 2 +- arn/Person.go | 2 +- arn/Post.go | 2 +- arn/Quote.go | 2 +- arn/ShopItem.go | 4 +- arn/SoundTrack.go | 2 +- arn/Thread.go | 2 +- pages/editor/filteranime/startdate.go | 3 +- 20 files changed, 89 insertions(+), 89 deletions(-) create mode 100644 arn/Anime.init.go diff --git a/arn/AMV.go b/arn/AMV.go index b9852108..f29c700c 100644 --- a/arn/AMV.go +++ b/arn/AMV.go @@ -237,7 +237,7 @@ func (amv *AMV) Self() Loggable { } // GetAMV returns the AMV with the given ID. -func GetAMV(id string) (*AMV, error) { +func GetAMV(id ID) (*AMV, error) { obj, err := DB.Get("AMV", id) if err != nil { diff --git a/arn/Anime.go b/arn/Anime.go index 77f074ca..6581475d 100644 --- a/arn/Anime.go +++ b/arn/Anime.go @@ -8,7 +8,6 @@ import ( "strings" "time" - "github.com/aerogo/api" "github.com/aerogo/nano" "github.com/akyoto/color" "github.com/animenotifier/kitsu" @@ -17,59 +16,6 @@ import ( "github.com/animenotifier/twist" ) -// AnimeDateFormat describes the anime date format for the date conversion. -const AnimeDateFormat = validate.DateFormat - -// AnimeSourceHumanReadable maps the anime source to a human readable version. -var AnimeSourceHumanReadable = map[string]string{} - -// Register a list of supported anime status and source types. -func init() { - DataLists["anime-types"] = []*Option{ - {"tv", "TV"}, - {"movie", "Movie"}, - {"ova", "OVA"}, - {"ona", "ONA"}, - {"special", "Special"}, - {"music", "Music"}, - } - - DataLists["anime-status"] = []*Option{ - {"current", "Current"}, - {"finished", "Finished"}, - {"upcoming", "Upcoming"}, - {"tba", "To be announced"}, - } - - DataLists["anime-sources"] = []*Option{ - {"", "Unknown"}, - {"original", "Original"}, - {"manga", "Manga"}, - {"novel", "Novel"}, - {"light novel", "Light novel"}, - {"visual novel", "Visual novel"}, - {"game", "Game"}, - {"book", "Book"}, - {"4-koma manga", "4-koma Manga"}, - {"music", "Music"}, - {"picture book", "Picture book"}, - {"web manga", "Web manga"}, - {"other", "Other"}, - } - - for _, option := range DataLists["anime-sources"] { - AnimeSourceHumanReadable[option.Value] = option.Label - } - - API.RegisterActions("Anime", []*api.Action{ - // Publish - PublishAction(), - - // Unpublish - UnpublishAction(), - }) -} - // AnimeID represents an anime ID. type AnimeID = ID @@ -112,7 +58,7 @@ type Anime struct { // NewAnime creates a new anime. func NewAnime() *Anime { - anime := Anime{} + anime := &Anime{} return anime.init() } @@ -355,10 +301,10 @@ func (anime *Anime) Link() string { // StartDateTime returns the start date as a time object. func (anime *Anime) StartDateTime() time.Time { - format := AnimeDateFormat + format := validate.DateFormat switch { - case len(anime.StartDate) >= len(AnimeDateFormat): + case len(anime.StartDate) >= len(validate.DateFormat): // ... case len(anime.StartDate) >= len("2006-01"): format = "2006-01" @@ -372,10 +318,10 @@ func (anime *Anime) StartDateTime() time.Time { // EndDateTime returns the end date as a time object. func (anime *Anime) EndDateTime() time.Time { - format := AnimeDateFormat + format := validate.DateFormat switch { - case len(anime.EndDate) >= len(AnimeDateFormat): + case len(anime.EndDate) >= len(validate.DateFormat): // ... case len(anime.EndDate) >= len("2006-01"): format = "2006-01" diff --git a/arn/Anime.init.go b/arn/Anime.init.go new file mode 100644 index 00000000..a59e12ae --- /dev/null +++ b/arn/Anime.init.go @@ -0,0 +1,53 @@ +package arn + +import "github.com/aerogo/api" + +// AnimeSourceHumanReadable maps the anime source to a human readable version. +var AnimeSourceHumanReadable = map[string]string{} + +// Register a list of supported anime status and source types. +func init() { + DataLists["anime-types"] = []*Option{ + {"tv", "TV"}, + {"movie", "Movie"}, + {"ova", "OVA"}, + {"ona", "ONA"}, + {"special", "Special"}, + {"music", "Music"}, + } + + DataLists["anime-status"] = []*Option{ + {"current", "Current"}, + {"finished", "Finished"}, + {"upcoming", "Upcoming"}, + {"tba", "To be announced"}, + } + + DataLists["anime-sources"] = []*Option{ + {"", "Unknown"}, + {"original", "Original"}, + {"manga", "Manga"}, + {"novel", "Novel"}, + {"light novel", "Light novel"}, + {"visual novel", "Visual novel"}, + {"game", "Game"}, + {"book", "Book"}, + {"4-koma manga", "4-koma Manga"}, + {"music", "Music"}, + {"picture book", "Picture book"}, + {"web manga", "Web manga"}, + {"other", "Other"}, + } + + for _, option := range DataLists["anime-sources"] { + AnimeSourceHumanReadable[option.Value] = option.Label + } + + API.RegisterActions("Anime", []*api.Action{ + // Publish + PublishAction(), + + // Unpublish + UnpublishAction(), + }) +} diff --git a/arn/Character.go b/arn/Character.go index fc189294..244dfa88 100644 --- a/arn/Character.go +++ b/arn/Character.go @@ -134,7 +134,7 @@ func (character *Character) Anime() []*Anime { } // GetCharacter ... -func GetCharacter(id string) (*Character, error) { +func GetCharacter(id CharacterID) (*Character, error) { obj, err := DB.Get("Character", id) if err != nil { diff --git a/arn/CharacterFinder.go b/arn/CharacterFinder.go index cda053e5..90ca34ce 100644 --- a/arn/CharacterFinder.go +++ b/arn/CharacterFinder.go @@ -32,6 +32,6 @@ func (finder *CharacterFinder) Add(character *Character) { } // GetCharacter tries to find an external anime in our anime database. -func (finder *CharacterFinder) GetCharacter(id string) *Character { +func (finder *CharacterFinder) GetCharacter(id CharacterID) *Character { return finder.idToCharacter[id] } diff --git a/arn/Company.go b/arn/Company.go index 9981862d..337b20d3 100644 --- a/arn/Company.go +++ b/arn/Company.go @@ -108,7 +108,7 @@ func (company *Company) Self() Loggable { } // GetCompany returns a single company. -func GetCompany(id string) (*Company, error) { +func GetCompany(id CompanyID) (*Company, error) { obj, err := DB.Get("Company", id) if err != nil { diff --git a/arn/DraftIndex.go b/arn/DraftIndex.go index 5c0c7528..f541e842 100644 --- a/arn/DraftIndex.go +++ b/arn/DraftIndex.go @@ -7,14 +7,14 @@ import ( // DraftIndex has references to unpublished drafts a user created. type DraftIndex struct { - UserID string `json:"userId" primary:"true"` - 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"` + UserID UserID `json:"userId" primary:"true"` + GroupID GroupID `json:"groupId"` + SoundTrackID ID `json:"soundTrackId"` + CompanyID CompanyID `json:"companyId"` + QuoteID QuoteID `json:"quoteId"` + CharacterID CharacterID `json:"characterId"` + AnimeID AnimeID `json:"animeId"` + AMVID ID `json:"amvId"` } // NewDraftIndex ... @@ -55,7 +55,7 @@ func (index *DraftIndex) GetID() string { } // GetDraftIndex ... -func GetDraftIndex(id string) (*DraftIndex, error) { +func GetDraftIndex(id ID) (*DraftIndex, error) { obj, err := DB.Get("DraftIndex", id) if err != nil { diff --git a/arn/Episode.go b/arn/Episode.go index 06abcca3..2ecde62e 100644 --- a/arn/Episode.go +++ b/arn/Episode.go @@ -159,7 +159,7 @@ func StreamEpisodes() <-chan *Episode { } // GetEpisode returns the episode with the given ID. -func GetEpisode(id string) (*Episode, error) { +func GetEpisode(id EpisodeID) (*Episode, error) { obj, err := DB.Get("Episode", id) if err != nil { diff --git a/arn/Group.go b/arn/Group.go index 2e3e5c3f..e166d2a7 100644 --- a/arn/Group.go +++ b/arn/Group.go @@ -262,7 +262,7 @@ func (group *Group) DeleteImages() { } // GetGroup ... -func GetGroup(id string) (*Group, error) { +func GetGroup(id GroupID) (*Group, error) { obj, err := DB.Get("Group", id) if err != nil { diff --git a/arn/IDCollection.go b/arn/IDCollection.go index d15f6301..3da7d595 100644 --- a/arn/IDCollection.go +++ b/arn/IDCollection.go @@ -9,8 +9,8 @@ import ( // IDCollection ... type IDCollection interface { - Add(id string) error - Remove(id string) bool + Add(id ID) error + Remove(id ID) bool Save() } diff --git a/arn/IDList.go b/arn/IDList.go index 18c594f2..c5a53b15 100644 --- a/arn/IDList.go +++ b/arn/IDList.go @@ -1,10 +1,10 @@ package arn // IDList stores lists of IDs that are retrievable by name. -type IDList []string +type IDList []ID // GetIDList ... -func GetIDList(id string) (IDList, error) { +func GetIDList(id ID) (IDList, error) { obj, err := DB.Get("IDList", id) if err != nil { @@ -15,6 +15,6 @@ func GetIDList(id string) (IDList, error) { } // Append appends the given ID to the end of the list and returns the new IDList. -func (idList IDList) Append(id string) IDList { +func (idList IDList) Append(id ID) IDList { return append(idList, id) } diff --git a/arn/IgnoreAnimeDifference.go b/arn/IgnoreAnimeDifference.go index 3fea42c3..99287e01 100644 --- a/arn/IgnoreAnimeDifference.go +++ b/arn/IgnoreAnimeDifference.go @@ -19,7 +19,7 @@ type IgnoreAnimeDifference struct { } // GetIgnoreAnimeDifference ... -func GetIgnoreAnimeDifference(id string) (*IgnoreAnimeDifference, error) { +func GetIgnoreAnimeDifference(id ID) (*IgnoreAnimeDifference, error) { obj, err := DB.Get("IgnoreAnimeDifference", id) if err != nil { diff --git a/arn/Notification.go b/arn/Notification.go index 58c477cf..3391fcd2 100644 --- a/arn/Notification.go +++ b/arn/Notification.go @@ -48,7 +48,7 @@ func NewNotification(userID UserID, pushNotification *PushNotification) *Notific } // GetNotification ... -func GetNotification(id string) (*Notification, error) { +func GetNotification(id ID) (*Notification, error) { obj, err := DB.Get("Notification", id) if err != nil { diff --git a/arn/Person.go b/arn/Person.go index 6ea25379..2f3f8aae 100644 --- a/arn/Person.go +++ b/arn/Person.go @@ -95,7 +95,7 @@ func (person *Person) HasImage() bool { } // GetPerson ... -func GetPerson(id string) (*Person, error) { +func GetPerson(id ID) (*Person, error) { obj, err := DB.Get("Person", id) if err != nil { diff --git a/arn/Post.go b/arn/Post.go index 37354a4d..d609ab79 100644 --- a/arn/Post.go +++ b/arn/Post.go @@ -154,7 +154,7 @@ func (post *Post) OnLike(likedBy *User) { } // GetPost ... -func GetPost(id string) (*Post, error) { +func GetPost(id PostID) (*Post, error) { obj, err := DB.Get("Post", id) if err != nil { diff --git a/arn/Quote.go b/arn/Quote.go index 49dbad53..bf7b93fa 100644 --- a/arn/Quote.go +++ b/arn/Quote.go @@ -153,7 +153,7 @@ func (quote *Quote) String() string { } // GetQuote returns a single quote. -func GetQuote(id string) (*Quote, error) { +func GetQuote(id QuoteID) (*Quote, error) { obj, err := DB.Get("Quote", id) if err != nil { diff --git a/arn/ShopItem.go b/arn/ShopItem.go index 4844db00..b629450f 100644 --- a/arn/ShopItem.go +++ b/arn/ShopItem.go @@ -21,7 +21,7 @@ const ( // ShopItem is a purchasable item in the shop. type ShopItem struct { - ID string `json:"id" primary:"true"` + ID ID `json:"id" primary:"true"` Name string `json:"name"` Description string `json:"description"` Price uint `json:"price"` @@ -37,7 +37,7 @@ func (item *ShopItem) GetID() string { } // GetShopItem ... -func GetShopItem(id string) (*ShopItem, error) { +func GetShopItem(id ID) (*ShopItem, error) { obj, err := DB.Get("ShopItem", id) if err != nil { diff --git a/arn/SoundTrack.go b/arn/SoundTrack.go index 5053b2e1..09605dab 100644 --- a/arn/SoundTrack.go +++ b/arn/SoundTrack.go @@ -347,7 +347,7 @@ func SortSoundTracksPopularFirst(tracks []*SoundTrack) { } // GetSoundTrack ... -func GetSoundTrack(id string) (*SoundTrack, error) { +func GetSoundTrack(id ID) (*SoundTrack, error) { track, err := DB.Get("SoundTrack", id) if err != nil { diff --git a/arn/Thread.go b/arn/Thread.go index aa98e402..680fd535 100644 --- a/arn/Thread.go +++ b/arn/Thread.go @@ -109,7 +109,7 @@ func (thread *Thread) TitleByUser(user *User) string { } // GetThread ... -func GetThread(id string) (*Thread, error) { +func GetThread(id ThreadID) (*Thread, error) { obj, err := DB.Get("Thread", id) if err != nil { diff --git a/pages/editor/filteranime/startdate.go b/pages/editor/filteranime/startdate.go index 77ba63f3..2913a730 100644 --- a/pages/editor/filteranime/startdate.go +++ b/pages/editor/filteranime/startdate.go @@ -5,6 +5,7 @@ import ( "github.com/aerogo/aero" "github.com/animenotifier/notify.moe/arn" + "github.com/animenotifier/notify.moe/arn/validate" ) // StartDate ... @@ -13,7 +14,7 @@ func StartDate(ctx aero.Context) error { ctx, "Anime without a valid start date", func(anime *arn.Anime) bool { - _, err := time.Parse(arn.AnimeDateFormat, anime.StartDate) + _, err := time.Parse(validate.DateFormat, anime.StartDate) return err != nil }, nil,