book.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package datastructure
  2. import (
  3. "notabug.org/apiote/amuse/i18n"
  4. "strings"
  5. "time"
  6. )
  7. type Source struct {
  8. Url string
  9. Name string
  10. }
  11. type Work interface {
  12. GetArticle() string
  13. SetDescription(description string)
  14. }
  15. type Book struct {
  16. Id string
  17. Uri string
  18. Source []Source
  19. Cover string
  20. Authors []string
  21. Year int64
  22. Title string
  23. SerieUri string
  24. SerieName string
  25. PartInSerie string
  26. Genres []string
  27. Article string
  28. Description string
  29. IsOnWantList bool
  30. Experiences []time.Time
  31. }
  32. func (b Book) GetArticle() string {
  33. return b.Article
  34. }
  35. func (b *Book) SetDescription(description string) {
  36. if b.Description == "" {
  37. b.Description = description
  38. }
  39. }
  40. func (b *Book) GetItemInfo() ItemInfo {
  41. return ItemInfo{
  42. Cover: b.Cover,
  43. Title: b.Title,
  44. YearStart: int(b.Year),
  45. Genres: strings.Join(b.Genres, ", "),
  46. }
  47. }
  48. func (b *Book) GetItemType() ItemType {
  49. return ItemTypeBook
  50. }
  51. func (b *Book) SetOnWantList(isOnList bool) {
  52. b.IsOnWantList = isOnList
  53. }
  54. func (b Book) GetLastExperienceFull(strings i18n.Translation) string {
  55. return i18n.FormatDate(b.Experiences[0], strings.Global["date_format_full"], strings.Global)
  56. }
  57. func (b Book) GetLastExperience(strings i18n.Translation, timezone string) string {
  58. return i18n.FormatDateNice(b.Experiences[0], strings, timezone)
  59. }