edit-release.go (1427B)
1 package editrelease 2 3 import ( 4 "encoding/json" 5 "lyrics/internal/domain" 6 ) 7 8 type EditReleaseParams struct { 9 Release domain.Release 10 } 11 12 type editReleaseArtist struct { 13 UID int `json:"uid"` 14 Selected bool `json:"selected"` 15 ArtistID domain.ArtistID `json:"artistId"` 16 ArtistName string `json:"artistName"` 17 } 18 19 type editReleaseSong struct { 20 ID domain.SongID `json:"id"` 21 Title string `json:"title"` 22 TrackNumber int `json:"trackNumber"` 23 } 24 25 func editReleaseArtistsJSON(artists []domain.ReleaseArtist) string { 26 jsonArtists := make([]editReleaseArtist, 0, len(artists)) 27 28 for i, aa := range artists { 29 jsonArtists = append(jsonArtists, editReleaseArtist{ 30 UID: i, 31 Selected: true, 32 ArtistID: aa.Artist.ID, 33 ArtistName: aa.Artist.Name, 34 }) 35 } 36 37 bytes, err := json.Marshal(jsonArtists) 38 if err != nil { 39 return "[]" 40 } 41 42 return string(bytes) 43 } 44 45 func editReleaseSongsJSON(songs []domain.ReleaseSong) string { 46 jsonSongs := make([]editReleaseSong, 0, len(songs)) 47 48 for _, as := range songs { 49 title := as.Song.Title 50 if as.Song.LatinTitle != nil { 51 title += " (" + *as.Song.LatinTitle + ")" 52 } 53 jsonSongs = append(jsonSongs, editReleaseSong{ 54 ID: as.Song.ID, 55 Title: title, 56 TrackNumber: as.TrackNumber, 57 }) 58 } 59 60 bytes, err := json.Marshal(jsonSongs) 61 if err != nil { 62 return "[]" 63 } 64 65 return string(bytes) 66 }