This commit is contained in:
Eduard Urbach 2019-11-18 15:13:51 +09:00
parent ab81556651
commit 9e62774eb4
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
20 changed files with 89 additions and 89 deletions

View File

@ -237,7 +237,7 @@ func (amv *AMV) Self() Loggable {
} }
// GetAMV returns the AMV with the given ID. // 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) obj, err := DB.Get("AMV", id)
if err != nil { if err != nil {

View File

@ -8,7 +8,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/aerogo/api"
"github.com/aerogo/nano" "github.com/aerogo/nano"
"github.com/akyoto/color" "github.com/akyoto/color"
"github.com/animenotifier/kitsu" "github.com/animenotifier/kitsu"
@ -17,59 +16,6 @@ import (
"github.com/animenotifier/twist" "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. // AnimeID represents an anime ID.
type AnimeID = ID type AnimeID = ID
@ -112,7 +58,7 @@ type Anime struct {
// NewAnime creates a new anime. // NewAnime creates a new anime.
func NewAnime() *Anime { func NewAnime() *Anime {
anime := Anime{} anime := &Anime{}
return anime.init() return anime.init()
} }
@ -355,10 +301,10 @@ func (anime *Anime) Link() string {
// StartDateTime returns the start date as a time object. // StartDateTime returns the start date as a time object.
func (anime *Anime) StartDateTime() time.Time { func (anime *Anime) StartDateTime() time.Time {
format := AnimeDateFormat format := validate.DateFormat
switch { switch {
case len(anime.StartDate) >= len(AnimeDateFormat): case len(anime.StartDate) >= len(validate.DateFormat):
// ... // ...
case len(anime.StartDate) >= len("2006-01"): case len(anime.StartDate) >= len("2006-01"):
format = "2006-01" format = "2006-01"
@ -372,10 +318,10 @@ func (anime *Anime) StartDateTime() time.Time {
// EndDateTime returns the end date as a time object. // EndDateTime returns the end date as a time object.
func (anime *Anime) EndDateTime() time.Time { func (anime *Anime) EndDateTime() time.Time {
format := AnimeDateFormat format := validate.DateFormat
switch { switch {
case len(anime.EndDate) >= len(AnimeDateFormat): case len(anime.EndDate) >= len(validate.DateFormat):
// ... // ...
case len(anime.EndDate) >= len("2006-01"): case len(anime.EndDate) >= len("2006-01"):
format = "2006-01" format = "2006-01"

53
arn/Anime.init.go Normal file
View 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(),
})
}

View File

@ -134,7 +134,7 @@ func (character *Character) Anime() []*Anime {
} }
// GetCharacter ... // GetCharacter ...
func GetCharacter(id string) (*Character, error) { func GetCharacter(id CharacterID) (*Character, error) {
obj, err := DB.Get("Character", id) obj, err := DB.Get("Character", id)
if err != nil { if err != nil {

View File

@ -32,6 +32,6 @@ func (finder *CharacterFinder) Add(character *Character) {
} }
// GetCharacter tries to find an external anime in our anime database. // 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] return finder.idToCharacter[id]
} }

View File

@ -108,7 +108,7 @@ func (company *Company) Self() Loggable {
} }
// GetCompany returns a single company. // GetCompany returns a single company.
func GetCompany(id string) (*Company, error) { func GetCompany(id CompanyID) (*Company, error) {
obj, err := DB.Get("Company", id) obj, err := DB.Get("Company", id)
if err != nil { if err != nil {

View File

@ -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" primary:"true"` UserID UserID `json:"userId" primary:"true"`
GroupID string `json:"groupId"` GroupID GroupID `json:"groupId"`
SoundTrackID string `json:"soundTrackId"` SoundTrackID ID `json:"soundTrackId"`
CompanyID string `json:"companyId"` CompanyID CompanyID `json:"companyId"`
QuoteID string `json:"quoteId"` QuoteID QuoteID `json:"quoteId"`
CharacterID string `json:"characterId"` CharacterID CharacterID `json:"characterId"`
AnimeID AnimeID `json:"animeId"` AnimeID AnimeID `json:"animeId"`
AMVID string `json:"amvId"` AMVID ID `json:"amvId"`
} }
// NewDraftIndex ... // NewDraftIndex ...
@ -55,7 +55,7 @@ func (index *DraftIndex) GetID() string {
} }
// GetDraftIndex ... // GetDraftIndex ...
func GetDraftIndex(id string) (*DraftIndex, error) { func GetDraftIndex(id ID) (*DraftIndex, error) {
obj, err := DB.Get("DraftIndex", id) obj, err := DB.Get("DraftIndex", id)
if err != nil { if err != nil {

View File

@ -159,7 +159,7 @@ func StreamEpisodes() <-chan *Episode {
} }
// GetEpisode returns the episode with the given ID. // 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) obj, err := DB.Get("Episode", id)
if err != nil { if err != nil {

View File

@ -262,7 +262,7 @@ func (group *Group) DeleteImages() {
} }
// GetGroup ... // GetGroup ...
func GetGroup(id string) (*Group, error) { func GetGroup(id GroupID) (*Group, error) {
obj, err := DB.Get("Group", id) obj, err := DB.Get("Group", id)
if err != nil { if err != nil {

View File

@ -9,8 +9,8 @@ import (
// IDCollection ... // IDCollection ...
type IDCollection interface { type IDCollection interface {
Add(id string) error Add(id ID) error
Remove(id string) bool Remove(id ID) bool
Save() Save()
} }

View File

@ -1,10 +1,10 @@
package arn package arn
// IDList stores lists of IDs that are retrievable by name. // IDList stores lists of IDs that are retrievable by name.
type IDList []string type IDList []ID
// GetIDList ... // GetIDList ...
func GetIDList(id string) (IDList, error) { func GetIDList(id ID) (IDList, error) {
obj, err := DB.Get("IDList", id) obj, err := DB.Get("IDList", id)
if err != nil { 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. // 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) return append(idList, id)
} }

View File

@ -19,7 +19,7 @@ type IgnoreAnimeDifference struct {
} }
// GetIgnoreAnimeDifference ... // GetIgnoreAnimeDifference ...
func GetIgnoreAnimeDifference(id string) (*IgnoreAnimeDifference, error) { func GetIgnoreAnimeDifference(id ID) (*IgnoreAnimeDifference, error) {
obj, err := DB.Get("IgnoreAnimeDifference", id) obj, err := DB.Get("IgnoreAnimeDifference", id)
if err != nil { if err != nil {

View File

@ -48,7 +48,7 @@ func NewNotification(userID UserID, pushNotification *PushNotification) *Notific
} }
// GetNotification ... // GetNotification ...
func GetNotification(id string) (*Notification, error) { func GetNotification(id ID) (*Notification, error) {
obj, err := DB.Get("Notification", id) obj, err := DB.Get("Notification", id)
if err != nil { if err != nil {

View File

@ -95,7 +95,7 @@ func (person *Person) HasImage() bool {
} }
// GetPerson ... // GetPerson ...
func GetPerson(id string) (*Person, error) { func GetPerson(id ID) (*Person, error) {
obj, err := DB.Get("Person", id) obj, err := DB.Get("Person", id)
if err != nil { if err != nil {

View File

@ -154,7 +154,7 @@ func (post *Post) OnLike(likedBy *User) {
} }
// GetPost ... // GetPost ...
func GetPost(id string) (*Post, error) { func GetPost(id PostID) (*Post, error) {
obj, err := DB.Get("Post", id) obj, err := DB.Get("Post", id)
if err != nil { if err != nil {

View File

@ -153,7 +153,7 @@ func (quote *Quote) String() string {
} }
// GetQuote returns a single quote. // GetQuote returns a single quote.
func GetQuote(id string) (*Quote, error) { func GetQuote(id QuoteID) (*Quote, error) {
obj, err := DB.Get("Quote", id) obj, err := DB.Get("Quote", id)
if err != nil { if err != nil {

View File

@ -21,7 +21,7 @@ const (
// ShopItem is a purchasable item in the shop. // ShopItem is a purchasable item in the shop.
type ShopItem struct { type ShopItem struct {
ID string `json:"id" primary:"true"` ID ID `json:"id" primary:"true"`
Name string `json:"name"` Name string `json:"name"`
Description string `json:"description"` Description string `json:"description"`
Price uint `json:"price"` Price uint `json:"price"`
@ -37,7 +37,7 @@ func (item *ShopItem) GetID() string {
} }
// GetShopItem ... // GetShopItem ...
func GetShopItem(id string) (*ShopItem, error) { func GetShopItem(id ID) (*ShopItem, error) {
obj, err := DB.Get("ShopItem", id) obj, err := DB.Get("ShopItem", id)
if err != nil { if err != nil {

View File

@ -347,7 +347,7 @@ func SortSoundTracksPopularFirst(tracks []*SoundTrack) {
} }
// GetSoundTrack ... // GetSoundTrack ...
func GetSoundTrack(id string) (*SoundTrack, error) { func GetSoundTrack(id ID) (*SoundTrack, error) {
track, err := DB.Get("SoundTrack", id) track, err := DB.Get("SoundTrack", id)
if err != nil { if err != nil {

View File

@ -109,7 +109,7 @@ func (thread *Thread) TitleByUser(user *User) string {
} }
// GetThread ... // GetThread ...
func GetThread(id string) (*Thread, error) { func GetThread(id ThreadID) (*Thread, error) {
obj, err := DB.Get("Thread", id) obj, err := DB.Get("Thread", id)
if err != nil { if err != nil {

View File

@ -5,6 +5,7 @@ import (
"github.com/aerogo/aero" "github.com/aerogo/aero"
"github.com/animenotifier/notify.moe/arn" "github.com/animenotifier/notify.moe/arn"
"github.com/animenotifier/notify.moe/arn/validate"
) )
// StartDate ... // StartDate ...
@ -13,7 +14,7 @@ func StartDate(ctx aero.Context) error {
ctx, ctx,
"Anime without a valid start date", "Anime without a valid start date",
func(anime *arn.Anime) bool { func(anime *arn.Anime) bool {
_, err := time.Parse(arn.AnimeDateFormat, anime.StartDate) _, err := time.Parse(validate.DateFormat, anime.StartDate)
return err != nil return err != nil
}, },
nil, nil,