Cleanup
This commit is contained in:
parent
ab81556651
commit
9e62774eb4
@ -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 {
|
||||
|
64
arn/Anime.go
64
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"
|
||||
|
53
arn/Anime.init.go
Normal file
53
arn/Anime.init.go
Normal file
@ -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(),
|
||||
})
|
||||
}
|
@ -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 {
|
||||
|
@ -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]
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user