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