diff --git a/src/app/views/songs.zig b/src/app/views/songs.zig index 4be4f43..24e4f86 100644 --- a/src/app/views/songs.zig +++ b/src/app/views/songs.zig @@ -24,13 +24,20 @@ pub fn get(id: []const u8, request: *jetzig.Request) !jetzig.View { var root = try request.data(.object); const id_int = blk: { const rn = try decode(request.allocator, id); - const songs = try jetzig.database.Query(.Song).select(.{.id}).where(.{ .name = rn }).all(request.repo); - if (songs.len == 0) { + // Try to find the song by name + const queried_songs = try jetzig.database.Query(.Song).select(.{.id}).where(.{ .name = rn }).all(request.repo); + if (queried_songs.len == 0) { + // Either we've been given an id in the db, or the song doesn't exist break :blk std.fmt.parseInt(i64, id, 10) catch return request.fail(.not_found); - } else if (songs.len == 1) { - break :blk songs[0].id; + } else if (queried_songs.len == 1) { + // It can only be one song + break :blk queried_songs[0].id; } else { - return request.redirect("http://127.0.0.1:8080", .found); + // It could be a variety of songs + const songs = try queries.entityQueryResult(request, queries.loadQuery(.song, .entities_by_name), .{rn}); + try root.put("songs", songs); + try root.put("disambiguation", true); + return request.render(.ok); } }; diff --git a/src/app/views/songs/get.zmpl b/src/app/views/songs/get.zmpl index 2acb7d4..e2f6b54 100644 --- a/src/app/views/songs/get.zmpl +++ b/src/app/views/songs/get.zmpl @@ -1,7 +1,7 @@ @zig { const ColumnChoices = []const enum{song, album, artist, artistlist, scrobbles, date}; const columns: ColumnChoices = &.{.song, .artistlist, .album, .date}; - const reviews = try zmpl.coerceArray(".reviews"); + const dis_columns: ColumnChoices = &.{.song, .album, .artistlist, .scrobbles}; } @@ -11,6 +11,14 @@
@partial partials/header +@if ($.disambiguation) +