fix: address code review findings

This commit is contained in:
2026-07-19 20:06:41 +03:00
parent b21bf07208
commit 4da5ee5f8c
4 changed files with 13 additions and 12 deletions

View File

@@ -49,7 +49,7 @@ func main() {
cancel() cancel()
}() }()
app, err := NewApp(ctx, cfg) app, err := NewApp(ctx, cfg, "naviwatcher.db")
if err != nil { if err != nil {
log.Fatalf("Failed to initialize application: %v", err) log.Fatalf("Failed to initialize application: %v", err)
} }
@@ -63,9 +63,10 @@ func main() {
} }
// NewApp initializes all application components: config, database, and MusicBrainz client. // NewApp initializes all application components: config, database, and MusicBrainz client.
func NewApp(ctx context.Context, cfg *config.Config) (*App, error) { // dbPath is the SQLite database path (use ":memory:" for tests).
// Initialize database (uses default path or could be made configurable). func NewApp(ctx context.Context, cfg *config.Config, dbPath string) (*App, error) {
db, err := database.New("naviwatcher.db") // Initialize database.
db, err := database.New(dbPath)
if err != nil { if err != nil {
return nil, fmt.Errorf("failed to initialize database: %w", err) return nil, fmt.Errorf("failed to initialize database: %w", err)
} }

View File

@@ -132,7 +132,7 @@ func TestNewApp_CreatesMusicBrainzClient(t *testing.T) {
} }
ctx := context.Background() ctx := context.Background()
app, err := NewApp(ctx, cfg) app, err := NewApp(ctx, cfg, ":memory:")
if err != nil { if err != nil {
t.Fatalf("NewApp returned error: %v", err) t.Fatalf("NewApp returned error: %v", err)
} }
@@ -167,7 +167,7 @@ func TestNewApp_GracefulShutdown(t *testing.T) {
} }
ctx := context.Background() ctx := context.Background()
app, err := NewApp(ctx, cfg) app, err := NewApp(ctx, cfg, ":memory:")
if err != nil { if err != nil {
t.Fatalf("NewApp returned error: %v", err) t.Fatalf("NewApp returned error: %v", err)
} }
@@ -195,7 +195,7 @@ func TestAppRun_GracefulShutdown(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
app, err := NewApp(ctx, cfg) app, err := NewApp(ctx, cfg, ":memory:")
if err != nil { if err != nil {
t.Fatalf("NewApp returned error: %v", err) t.Fatalf("NewApp returned error: %v", err)
} }

View File

@@ -24,9 +24,9 @@ func FormatCachedAt(t time.Time) interface{} {
return t.UTC().Format(utcLayout) return t.UTC().Format(utcLayout)
} }
// joinSecondaryTypes renders a slice of secondary types as a comma-separated // JoinSecondaryTypes renders a slice of secondary types as a comma-separated
// string for storage in the secondary_types TEXT column (empty when none). // string for storage in the secondary_types TEXT column (empty when none).
func joinSecondaryTypes(types []string) string { func JoinSecondaryTypes(types []string) string {
return strings.Join(types, ",") return strings.Join(types, ",")
} }
@@ -72,7 +72,7 @@ func SaveExternalRelease(db *DB, release *ExternalRelease) error {
var cachedAt interface{} = FormatCachedAt(release.CachedAt) var cachedAt interface{} = FormatCachedAt(release.CachedAt)
_, err := db.Conn().Exec( _, err := db.Conn().Exec(
"INSERT OR REPLACE INTO external_releases (rgid, artist_id, title, type, release_date, is_ignored, cached_at, secondary_types) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", "INSERT OR REPLACE INTO external_releases (rgid, artist_id, title, type, release_date, is_ignored, cached_at, secondary_types) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
release.RGID, release.ArtistID, release.Title, release.Type, release.ReleaseDate, release.IsIgnored, cachedAt, joinSecondaryTypes(release.SecondaryTypes), release.RGID, release.ArtistID, release.Title, release.Type, release.ReleaseDate, release.IsIgnored, cachedAt, JoinSecondaryTypes(release.SecondaryTypes),
) )
if err != nil { if err != nil {
return fmt.Errorf("save external release: %w", err) return fmt.Errorf("save external release: %w", err)

View File

@@ -136,8 +136,8 @@ func SyncArtistDiscography(
} }
if _, err := tx.Exec( if _, err := tx.Exec(
"INSERT INTO external_releases (rgid, artist_id, title, type, release_date, is_ignored, cached_at) VALUES (?, ?, ?, ?, ?, ?, ?)", "INSERT INTO external_releases (rgid, artist_id, title, type, release_date, is_ignored, cached_at, secondary_types) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
ext.RGID, ext.ArtistID, ext.Title, ext.Type, ext.ReleaseDate, ext.IsIgnored, database.FormatCachedAt(ext.CachedAt), ext.RGID, ext.ArtistID, ext.Title, ext.Type, ext.ReleaseDate, ext.IsIgnored, database.FormatCachedAt(ext.CachedAt), database.JoinSecondaryTypes(ext.SecondaryTypes),
); err != nil { ); err != nil {
return nil, fmt.Errorf("sync artist discography: insert release %s: %w", rg.ID, err) return nil, fmt.Errorf("sync artist discography: insert release %s: %w", rg.ID, err)
} }