refactor: consolidate title formatting
This commit is contained in:
@@ -1,12 +1,19 @@
|
|||||||
package database
|
package database
|
||||||
|
|
||||||
|
import "database/sql"
|
||||||
|
|
||||||
// DisplayTitle returns the English title if available, otherwise Japanese, otherwise original
|
// DisplayTitle returns the English title if available, otherwise Japanese, otherwise original
|
||||||
func (r GetUserWatchListRow) DisplayTitle() string {
|
func DisplayTitle(titleEnglish, titleJapanese sql.NullString, titleOriginal string) string {
|
||||||
if r.TitleEnglish.Valid && r.TitleEnglish.String != "" {
|
if titleEnglish.Valid && titleEnglish.String != "" {
|
||||||
return r.TitleEnglish.String
|
return titleEnglish.String
|
||||||
}
|
}
|
||||||
if r.TitleJapanese.Valid && r.TitleJapanese.String != "" {
|
if titleJapanese.Valid && titleJapanese.String != "" {
|
||||||
return r.TitleJapanese.String
|
return titleJapanese.String
|
||||||
}
|
}
|
||||||
return r.TitleOriginal
|
return titleOriginal
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: use DisplayTitle function directly
|
||||||
|
func (r GetUserWatchListRow) DisplayTitle() string {
|
||||||
|
return DisplayTitle(r.TitleEnglish, r.TitleJapanese, r.TitleOriginal)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,17 +103,6 @@ type ExportData struct {
|
|||||||
Entries []ExportEntry `json:"entries"`
|
Entries []ExportEntry `json:"entries"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// displayTitle returns the best available title
|
|
||||||
func displayTitle(e database.GetUserWatchListRow) string {
|
|
||||||
if e.TitleEnglish.Valid && e.TitleEnglish.String != "" {
|
|
||||||
return e.TitleEnglish.String
|
|
||||||
}
|
|
||||||
if e.TitleJapanese.Valid && e.TitleJapanese.String != "" {
|
|
||||||
return e.TitleJapanese.String
|
|
||||||
}
|
|
||||||
return e.TitleOriginal
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Service) Export(ctx context.Context, userID string) (ExportData, error) {
|
func (s *Service) Export(ctx context.Context, userID string) (ExportData, error) {
|
||||||
entries, err := s.GetUserWatchlist(ctx, userID)
|
entries, err := s.GetUserWatchlist(ctx, userID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -128,7 +117,7 @@ func (s *Service) Export(ctx context.Context, userID string) (ExportData, error)
|
|||||||
for i, entry := range entries {
|
for i, entry := range entries {
|
||||||
export.Entries[i] = ExportEntry{
|
export.Entries[i] = ExportEntry{
|
||||||
AnimeID: entry.AnimeID,
|
AnimeID: entry.AnimeID,
|
||||||
Title: displayTitle(entry),
|
Title: database.DisplayTitle(entry.TitleEnglish, entry.TitleJapanese, entry.TitleOriginal),
|
||||||
ImageURL: entry.ImageUrl,
|
ImageURL: entry.ImageUrl,
|
||||||
Status: entry.Status,
|
Status: entry.Status,
|
||||||
UpdatedAt: entry.UpdatedAt.Format(time.RFC3339),
|
UpdatedAt: entry.UpdatedAt.Format(time.RFC3339),
|
||||||
|
|||||||
@@ -106,13 +106,7 @@ templ UpcomingSeasonCard(item database.GetUpcomingSeasonsRow) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func displaySeasonTitle(entry database.GetUpcomingSeasonsRow) string {
|
func displaySeasonTitle(entry database.GetUpcomingSeasonsRow) string {
|
||||||
if entry.TitleEnglish.Valid && entry.TitleEnglish.String != "" {
|
return database.DisplayTitle(entry.TitleEnglish, entry.TitleJapanese, entry.TitleOriginal)
|
||||||
return entry.TitleEnglish.String
|
|
||||||
}
|
|
||||||
if entry.TitleJapanese.Valid && entry.TitleJapanese.String != "" {
|
|
||||||
return entry.TitleJapanese.String
|
|
||||||
}
|
|
||||||
return entry.TitleOriginal
|
|
||||||
}
|
}
|
||||||
|
|
||||||
templ NotificationCard(item WatchingAnimeWithDetails) {
|
templ NotificationCard(item WatchingAnimeWithDetails) {
|
||||||
@@ -151,13 +145,7 @@ templ NotificationCard(item WatchingAnimeWithDetails) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func displayTitle(entry database.GetWatchingAnimeRow) string {
|
func displayTitle(entry database.GetWatchingAnimeRow) string {
|
||||||
if entry.TitleEnglish.Valid && entry.TitleEnglish.String != "" {
|
return database.DisplayTitle(entry.TitleEnglish, entry.TitleJapanese, entry.TitleOriginal)
|
||||||
return entry.TitleEnglish.String
|
|
||||||
}
|
|
||||||
if entry.TitleJapanese.Valid && entry.TitleJapanese.String != "" {
|
|
||||||
return entry.TitleJapanese.String
|
|
||||||
}
|
|
||||||
return entry.TitleOriginal
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func truncate(s string, max int) string {
|
func truncate(s string, max int) string {
|
||||||
|
|||||||
Reference in New Issue
Block a user