nu-api/types.go

85 lines
2.0 KiB
Go
Raw Normal View History

2023-03-03 14:37:16 +01:00
package nuapi
import (
"encoding/json"
"time"
)
type NovelID string
type ChapterID string
type ReadingListID string
type GroupID string
type ReadingList struct {
ID ReadingListID `json:"id"`
Entries []ReadingListEntry `json:"entries"`
}
type ReadingListEntry struct {
Novel NovelEntry `json:"novel"`
CurrentChapter ReadingListChapterEntry `json:"current_chapter"`
LatestChapter ReadingListChapterEntry `json:"latest_chapter"`
}
func (e ReadingListEntry) NewChapterAvailable() bool {
return e.CurrentChapter.ID != e.LatestChapter.ID
}
type ReadingListChapterEntry struct {
NovelID NovelID `json:"novel_id"`
ID ChapterID `json:"id"`
Link string `json:"link"`
}
type NovelEntry struct {
NovelID NovelID `json:"id"`
Name string `json:"name"`
}
type Novel struct {
ID NovelID `json:"id"`
Name string `json:"name"`
AssociatedNames []string `json:"associated_names"`
Description string `json:"description"`
Cover string `json:"cover"`
Type NovelType `json:"type"`
OriginalLanguage Language `json:"original_language"`
Genres []GenreID `json:"genres"`
Tags []TagID `json:"tags"`
}
type NovelType string
const (
TypeLightNovel NovelType = "Light Novel"
TypePublishedNovel NovelType = "Published Novel"
TypeWebNovel NovelType = "Web Novel"
)
type Language string
const (
LanguageJapanese Language = "jp"
LanguageChinese Language = "cn"
LanguageMalaysian Language = "my"
LanguageFilipino Language = "fil"
LanguageKhmer Language = "khm"
LanguageThai Language = "th"
LanguageIndonesian Language = "id"
LanguageKorean Language = "kr"
LanguageVietnamese Language = "vn"
)
type NovelChapterEntry struct {
ID ChapterID `json:"id"`
Link string `json:"link"`
NovelID NovelID `json:"novel_id"`
Date time.Time `json:"date"`
Group GroupID `json:"group"`
}
func (nce NovelChapterEntry) String() string {
data, _ := json.MarshalIndent(nce, "", "\t")
return string(data)
}