musicbrainz-provider #2
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user