diff --git a/arn/AMV.go b/arn/AMV.go index da2ab0c9..b9852108 100644 --- a/arn/AMV.go +++ b/arn/AMV.go @@ -17,9 +17,9 @@ import ( type AMV struct { File string `json:"file" editable:"true" type:"upload" filetype:"video" endpoint:"/api/upload/amv/:id/file"` Title AMVTitle `json:"title" editable:"true"` - MainAnimeID string `json:"mainAnimeId" editable:"true"` - ExtraAnimeIDs []string `json:"extraAnimeIds" editable:"true"` - VideoEditorIDs []string `json:"videoEditorIds" editable:"true"` + MainAnimeID AnimeID `json:"mainAnimeId" editable:"true"` + ExtraAnimeIDs []AnimeID `json:"extraAnimeIds" editable:"true"` + VideoEditorIDs []UserID `json:"videoEditorIds" editable:"true"` Links []Link `json:"links" editable:"true"` Tags []string `json:"tags" editable:"true"` Info video.Info `json:"info"` diff --git a/arn/Activity.go b/arn/Activity.go index 282e024c..12d395b4 100644 --- a/arn/Activity.go +++ b/arn/Activity.go @@ -12,7 +12,7 @@ import ( type Activity interface { Creator() *User TypeName() string - GetID() string + GetID() ID GetCreated() string GetCreatedBy() UserID GetCreatedTime() time.Time diff --git a/arn/ActivityCreate.go b/arn/ActivityCreate.go index ba3f771b..f9db80aa 100644 --- a/arn/ActivityCreate.go +++ b/arn/ActivityCreate.go @@ -5,7 +5,7 @@ import "github.com/aerogo/nano" // ActivityCreate is a user activity that creates something. type ActivityCreate struct { ObjectType string `json:"objectType"` - ObjectID string `json:"objectId"` + ObjectID ID `json:"objectId"` hasID hasCreator diff --git a/arn/Analytics.go b/arn/Analytics.go index 29691e3e..d9bf04d5 100644 --- a/arn/Analytics.go +++ b/arn/Analytics.go @@ -4,7 +4,7 @@ import "github.com/aerogo/nano" // Analytics stores user-related statistics. type Analytics struct { - UserID string `json:"userId" primary:"true"` + UserID UserID `json:"userId" primary:"true"` General GeneralAnalytics `json:"general"` Screen ScreenAnalytics `json:"screen"` System SystemAnalytics `json:"system"` diff --git a/arn/Anime.go b/arn/Anime.go index 8df120c5..77f074ca 100644 --- a/arn/Anime.go +++ b/arn/Anime.go @@ -71,7 +71,7 @@ func init() { } // AnimeID represents an anime ID. -type AnimeID = string +type AnimeID = ID // Anime represents an anime. type Anime struct { @@ -102,15 +102,12 @@ type Anime struct { hasDraft // Company IDs - StudioIDs []string `json:"studios" editable:"true"` - ProducerIDs []string `json:"producers" editable:"true"` - LicensorIDs []string `json:"licensors" editable:"true"` + StudioIDs []CompanyID `json:"studios" editable:"true"` + ProducerIDs []CompanyID `json:"producers" editable:"true"` + LicensorIDs []CompanyID `json:"licensors" editable:"true"` // Links to external websites Links []*Link `json:"links" editable:"true"` - - // SynopsisSource string `json:"synopsisSource" editable:"true"` - // Hashtag string `json:"hashtag"` } // NewAnime creates a new anime. diff --git a/arn/Character.go b/arn/Character.go index 0c775a49..fc189294 100644 --- a/arn/Character.go +++ b/arn/Character.go @@ -8,11 +8,14 @@ import ( "github.com/aerogo/nano" ) +// CharacterID represents a character ID. +type CharacterID = ID + // Character represents an anime or manga character. type Character struct { Name CharacterName `json:"name" editable:"true"` Image Image `json:"image"` - MainQuoteID string `json:"mainQuoteId" editable:"true"` + MainQuoteID QuoteID `json:"mainQuoteId" editable:"true"` Description string `json:"description" editable:"true" type:"textarea"` Spoilers []Spoiler `json:"spoilers" editable:"true"` Attributes []*CharacterAttribute `json:"attributes" editable:"true"` diff --git a/arn/Company.go b/arn/Company.go index 98d4966f..9981862d 100644 --- a/arn/Company.go +++ b/arn/Company.go @@ -6,6 +6,9 @@ import ( "github.com/aerogo/nano" ) +// CompanyID represents a company ID. +type CompanyID = ID + // Company represents an anime studio, producer or licensor. type Company struct { Name CompanyName `json:"name" editable:"true"` diff --git a/arn/EditLogEntry.go b/arn/EditLogEntry.go index 04ba7109..d8a2add2 100644 --- a/arn/EditLogEntry.go +++ b/arn/EditLogEntry.go @@ -9,21 +9,24 @@ import ( // EditLogEntry is an entry in the editor log. type EditLogEntry struct { - ID string `json:"id" primary:"true"` - UserID string `json:"userId"` + UserID UserID `json:"userId"` Action string `json:"action"` + ObjectID ID `json:"objectId"` // The ID of what was edited ObjectType string `json:"objectType"` // The typename of what was edited - ObjectID string `json:"objectId"` // The ID of what was edited Key string `json:"key"` OldValue string `json:"oldValue"` NewValue string `json:"newValue"` Created string `json:"created"` + + hasID } -// NewEditLogEntry ... -func NewEditLogEntry(userID, action, objectType, objectID, key, oldValue, newValue string) *EditLogEntry { +// NewEditLogEntry creates a new edit log entry. +func NewEditLogEntry(userID UserID, action string, objectType string, objectID ID, key string, oldValue string, newValue string) *EditLogEntry { return &EditLogEntry{ - ID: GenerateID("EditLogEntry"), + hasID: hasID{ + ID: GenerateID("EditLogEntry"), + }, UserID: userID, Action: action, ObjectType: objectType, diff --git a/arn/Episode.go b/arn/Episode.go index 75c5a1c0..06abcca3 100644 --- a/arn/Episode.go +++ b/arn/Episode.go @@ -7,14 +7,18 @@ import ( "github.com/animenotifier/notify.moe/arn/validate" ) +// EpisodeID represents an episode ID. +type EpisodeID = ID + // Episode represents a single episode for an anime. type Episode struct { - ID string `json:"id" primary:"true"` AnimeID AnimeID `json:"animeId"` Number int `json:"number" editable:"true"` Title EpisodeTitle `json:"title" editable:"true"` AiringDate AiringDate `json:"airingDate" editable:"true"` Links map[string]string `json:"links"` + + hasID } // EpisodeTitle contains the title information for an anime episode. @@ -27,7 +31,9 @@ type EpisodeTitle struct { // NewAnimeEpisode creates a new anime episode. func NewAnimeEpisode() *Episode { return &Episode{ - ID: GenerateID("Episode"), + hasID: hasID{ + ID: GenerateID("Episode"), + }, Number: -1, } } diff --git a/arn/Group.go b/arn/Group.go index a9703476..427b18ea 100644 --- a/arn/Group.go +++ b/arn/Group.go @@ -11,6 +11,9 @@ import ( "github.com/akyoto/color" ) +// GroupID represents a group ID. +type GroupID = ID + // Group represents a group of users. type Group struct { Name string `json:"name" editable:"true"` @@ -21,7 +24,7 @@ type Group struct { Restricted bool `json:"restricted" editable:"true" tooltip:"Restricted groups can only be joined with the founder's permission."` Tags []string `json:"tags" editable:"true"` Members []*GroupMember `json:"members"` - Neighbors []string `json:"neighbors"` + Neighbors []GroupID `json:"neighbors"` // Applications []UserApplication `json:"applications"` // Mixins diff --git a/arn/HasEditor.go b/arn/HasEditor.go index c4b26108..49b88130 100644 --- a/arn/HasEditor.go +++ b/arn/HasEditor.go @@ -3,7 +3,7 @@ package arn // HasEditor includes user ID and date for the last edit of this object. type hasEditor struct { Edited string `json:"edited"` - EditedBy string `json:"editedBy"` + EditedBy UserID `json:"editedBy"` } // Editor returns the user who last edited this object. diff --git a/arn/HasID.go b/arn/HasID.go index f69e0603..9dc3cb7f 100644 --- a/arn/HasID.go +++ b/arn/HasID.go @@ -2,10 +2,10 @@ package arn // hasID includes an object ID. type hasID struct { - ID string `json:"id" primary:"true"` + ID ID `json:"id" primary:"true"` } // GetID returns the ID. -func (obj *hasID) GetID() string { +func (obj *hasID) GetID() ID { return obj.ID } diff --git a/arn/HasLikes.go b/arn/HasLikes.go index f2e426bf..a3d5b40c 100644 --- a/arn/HasLikes.go +++ b/arn/HasLikes.go @@ -2,7 +2,7 @@ package arn // HasLikes implements common like and unlike methods. type hasLikes struct { - Likes []string `json:"likes"` + Likes []UserID `json:"likes"` } // Like makes the given user ID like the object. diff --git a/arn/HasPosts.go b/arn/HasPosts.go index ca731500..7be8410e 100644 --- a/arn/HasPosts.go +++ b/arn/HasPosts.go @@ -6,7 +6,7 @@ import ( // HasPosts includes a list of Post IDs. type hasPosts struct { - PostIDs []string `json:"posts"` + PostIDs []PostID `json:"posts"` } // AddPost adds a post to the object. diff --git a/arn/ID.go b/arn/ID.go new file mode 100644 index 00000000..b639b865 --- /dev/null +++ b/arn/ID.go @@ -0,0 +1,4 @@ +package arn + +// ID is used for object identification and is simply a string. +type ID = string diff --git a/arn/Notification.go b/arn/Notification.go index 333edb72..58c477cf 100644 --- a/arn/Notification.go +++ b/arn/Notification.go @@ -9,7 +9,7 @@ import ( // Notification represents a user-associated notification. type Notification struct { - UserID string `json:"userId"` + UserID UserID `json:"userId"` Created string `json:"created"` Seen string `json:"seen"` diff --git a/arn/PayPalPayment.go b/arn/PayPalPayment.go index 42930ad4..bdfc7c9b 100644 --- a/arn/PayPalPayment.go +++ b/arn/PayPalPayment.go @@ -8,7 +8,7 @@ import ( // PayPalPayment is an approved and exeucted PayPal payment. type PayPalPayment struct { - UserID string `json:"userId"` + UserID UserID `json:"userId"` PayerID string `json:"payerId"` Amount string `json:"amount"` Currency string `json:"currency"` diff --git a/arn/Post.go b/arn/Post.go index 20a3511a..37354a4d 100644 --- a/arn/Post.go +++ b/arn/Post.go @@ -10,10 +10,13 @@ import ( "github.com/aerogo/nano" ) +// PostID represents a post ID. +type PostID = ID + // Post is a comment related to any parent type in the database. type Post struct { Tags []string `json:"tags" editable:"true"` - ParentID string `json:"parentId" editable:"true"` + ParentID ID `json:"parentId" editable:"true"` ParentType string `json:"parentType"` Edited string `json:"edited"` diff --git a/arn/Postable.go b/arn/Postable.go index 5e8bab03..4423ead6 100644 --- a/arn/Postable.go +++ b/arn/Postable.go @@ -19,10 +19,10 @@ type Postable interface { // Use Get prefix for these to avoid a // name clash with the internal fields. - GetID() string + GetID() ID GetText() string GetCreated() string - GetParentID() string + GetParentID() ID GetParentType() string } diff --git a/arn/Purchase.go b/arn/Purchase.go index 0dfe4239..adf7d9a6 100644 --- a/arn/Purchase.go +++ b/arn/Purchase.go @@ -4,8 +4,8 @@ import "github.com/aerogo/nano" // Purchase represents an item purchase by a user. type Purchase struct { - UserID string `json:"userId"` - ItemID string `json:"itemId"` + UserID UserID `json:"userId"` + ItemID ID `json:"itemId"` Quantity int `json:"quantity"` Price int `json:"price"` Currency string `json:"currency"` diff --git a/arn/Quote.go b/arn/Quote.go index e819152c..49dbad53 100644 --- a/arn/Quote.go +++ b/arn/Quote.go @@ -10,13 +10,16 @@ import ( "github.com/akyoto/color" ) +// QuoteID represents a quote ID. +type QuoteID = ID + // Quote is a quote made by a character in an anime. type Quote struct { - Text QuoteText `json:"text" editable:"true"` - CharacterID string `json:"characterId" editable:"true"` - AnimeID AnimeID `json:"animeId" editable:"true"` - EpisodeNumber int `json:"episode" editable:"true"` - Time int `json:"time" editable:"true"` + Text QuoteText `json:"text" editable:"true"` + CharacterID CharacterID `json:"characterId" editable:"true"` + AnimeID AnimeID `json:"animeId" editable:"true"` + EpisodeNumber int `json:"episode" editable:"true"` + Time int `json:"time" editable:"true"` hasID hasPosts diff --git a/arn/Session.go b/arn/Session.go index 0ec670f6..588a2321 100644 --- a/arn/Session.go +++ b/arn/Session.go @@ -1,4 +1,7 @@ package arn +// SessionID represents a session ID. +type SessionID = ID + // Session stores session-related data. -type Session map[string]interface{} +type Session map[SessionID]interface{} diff --git a/arn/Settings.go b/arn/Settings.go index 7da8b032..0e0ac705 100644 --- a/arn/Settings.go +++ b/arn/Settings.go @@ -29,7 +29,7 @@ const ( // Settings represents user settings. type Settings struct { - UserID string `json:"userId" primary:"true"` + UserID UserID `json:"userId" primary:"true"` SortBy string `json:"sortBy" editable:"true"` TitleLanguage string `json:"titleLanguage" editable:"true"` Providers ServiceProviders `json:"providers"` diff --git a/arn/Thread.go b/arn/Thread.go index 05734f88..aa98e402 100644 --- a/arn/Thread.go +++ b/arn/Thread.go @@ -7,6 +7,9 @@ import ( "github.com/aerogo/nano" ) +// ThreadID represents a thread ID. +type ThreadID = ID + // Thread is a forum thread. type Thread struct { Title string `json:"title" editable:"true"` diff --git a/arn/User.go b/arn/User.go index ac52d9c6..d1add695 100644 --- a/arn/User.go +++ b/arn/User.go @@ -33,7 +33,7 @@ func init() { } // UserID represents a user ID. -type UserID = string +type UserID = ID // User is a registered person. type User struct { diff --git a/arn/Utils.go b/arn/Utils.go index 317a72e4..04791f6b 100644 --- a/arn/Utils.go +++ b/arn/Utils.go @@ -32,7 +32,7 @@ var ( ) // GenerateID generates a unique ID for a given collection. -func GenerateID(collection string) string { +func GenerateID(collection string) ID { id, _ := shortid.Generate() // Retry until we find an unused ID