routes.go (1310B)
1 package routes 2 3 import ( 4 "fmt" 5 "lyrics/internal/domain" 6 ) 7 8 func Song(song domain.Song) string { 9 title := song.Title 10 if song.LatinTitle != nil { 11 title = *song.LatinTitle 12 } 13 14 return SongPath(song.ID, title) 15 } 16 17 func SongEdit(song domain.Song) string { 18 return fmt.Sprintf("%s/edit", Song(song)) 19 } 20 21 func SongPath(id domain.SongID, title string) string { 22 return fmt.Sprintf("/song/%d/%s", id, domain.Slug(title)) 23 } 24 25 func Release(release domain.Release) string { 26 title := release.Title 27 if release.LatinTitle != nil { 28 title = *release.LatinTitle 29 } 30 31 return ReleasePath(release.ID, title) 32 } 33 34 func ReleaseEdit(release domain.Release) string { 35 return fmt.Sprintf("%s/edit", Release(release)) 36 } 37 38 func ReleasePath(id domain.ReleaseID, title string) string { 39 return fmt.Sprintf("/release/%d/%s", id, domain.Slug(title)) 40 } 41 42 func ReleaseCover(release domain.Release) string { 43 return fmt.Sprintf("%s/cover", Release(release)) 44 } 45 46 func Artist(artist domain.Artist) string { 47 name := artist.Name 48 if artist.LatinName != nil { 49 name = *artist.LatinName 50 } 51 52 return ArtistPath(artist.ID, name) 53 } 54 55 func ArtistPath(id domain.ArtistID, name string) string { 56 return fmt.Sprintf("/artist/%d/%s", id, domain.Slug(name)) 57 } 58 59 func ArtistEdit(artist domain.Artist) string { 60 return fmt.Sprintf("%s/edit", Artist(artist)) 61 }