commit dad844ccb63032156019cb34ee58f6da2cc6848b
parent 756334431a4018da6eef92130cc5170b7cfa179a
Author: brookjeynes <me@brookjeynes.dev>
Date: Fri, 8 May 2026 06:20:22 +1000
refactor: use dedicated types for ids
Signed-off-by: brookjeynes <me@brookjeynes.dev>
Diffstat:
4 files changed, 27 insertions(+), 21 deletions(-)
diff --git a/internal/domain/album.go b/internal/domain/album.go
@@ -2,8 +2,10 @@ package domain
import "time"
+type AlbumID int64
+
type Album struct {
- ID int64
+ ID AlbumID
Title string
LatinName *string
ReleaseDate time.Time
@@ -11,7 +13,7 @@ type Album struct {
}
type AlbumArtist struct {
- AlbumID int64
- ArtistID int64
+ AlbumID AlbumID
+ ArtistID ArtistID
SortOrder int
}
diff --git a/internal/domain/artist.go b/internal/domain/artist.go
@@ -1,7 +1,9 @@
package domain
+type ArtistID int64
+
type Artist struct {
- ID int64
+ ID ArtistID
Name string
LatinName *string
Disambiguation *string
diff --git a/internal/domain/song.go b/internal/domain/song.go
@@ -4,14 +4,16 @@ import (
"time"
)
+type SongID int64
+
type Song struct {
- ID int64
+ ID SongID
Title string
LatinTitle *string
Lyrics string
ReleaseDate time.Time
Artists []SongArtist
- AlbumIDs []int64
+ AlbumIDs []AlbumID
Genres []Genre
}
@@ -23,8 +25,8 @@ const (
)
type SongArtist struct {
- SongID int64
- ArtistID int64
+ SongID SongID
+ ArtistID ArtistID
Role SongArtistRole
SortOrder int
}
diff --git a/internal/server/new-song.go b/internal/server/new-song.go
@@ -11,14 +11,14 @@ import (
)
type NewSongForm struct {
- ArtistID []int64 `schema:"artist-id"`
- Title string `schema:"title"`
- LatinTitle string `schema:"latin-title"`
- Albums []string `schema:"album"`
- Genres []string `schema:"genres"`
- Lyrics string `schema:"lyrics"`
- FeaturingID []int64 `schema:"featuring-id"`
- ReleaseDate string `schema:"release-date"`
+ ArtistID []domain.ArtistID `schema:"artist-id"`
+ Title string `schema:"title"`
+ LatinTitle string `schema:"latin-title"`
+ Albums []string `schema:"album"`
+ Genres []string `schema:"genres"`
+ Lyrics string `schema:"lyrics"`
+ FeaturingID []domain.ArtistID `schema:"featuring-id"`
+ ReleaseDate string `schema:"release-date"`
}
func parseNewSongForm(form NewSongForm) (domain.Song, error) {
@@ -36,10 +36,10 @@ func parseNewSongForm(form NewSongForm) (domain.Song, error) {
if id < 0 {
return song, fmt.Errorf("Invalid artist selection")
}
- if _, exists := seenArtists[id]; exists {
+ if _, exists := seenArtists[int64(id)]; exists {
return song, fmt.Errorf("An artist cannot be added more than once")
}
- seenArtists[id] = struct{}{}
+ seenArtists[int64(id)] = struct{}{}
artists = append(artists, domain.SongArtist{
ArtistID: id,
@@ -53,10 +53,10 @@ func parseNewSongForm(form NewSongForm) (domain.Song, error) {
if id < 0 {
return song, fmt.Errorf("Invalid artist selection")
}
- if _, exists := seenArtists[id]; exists {
+ if _, exists := seenArtists[int64(id)]; exists {
return song, fmt.Errorf("An artist cannot be added more than once")
}
- seenArtists[id] = struct{}{}
+ seenArtists[int64(id)] = struct{}{}
artists = append(artists, domain.SongArtist{
ArtistID: id,
@@ -101,7 +101,7 @@ func parseNewSongForm(form NewSongForm) (domain.Song, error) {
}
// albums
- var albumIDs []int64
+ var albumIDs []domain.AlbumID
for _, a := range form.Albums {
if a == "" {
continue