diff --git a/src/app/views/albums/get.zmpl b/src/app/views/albums/get.zmpl
index 22f99d8..7e089e7 100644
--- a/src/app/views/albums/get.zmpl
+++ b/src/app/views/albums/get.zmpl
@@ -9,7 +9,8 @@
@partial partials/header
-
{{.artist.scrobbles}} scrobbles ({{.artist.rank}} place)
{{.artist.song_num}} songs
diff --git a/src/app/views/songs/get.zmpl b/src/app/views/songs/get.zmpl
index 5b68145..e912930 100644
--- a/src/app/views/songs/get.zmpl
+++ b/src/app/views/songs/get.zmpl
@@ -9,7 +9,7 @@
@partial partials/header
-
{{.song.name}}
+
{{.song.song_name}}
{{.song.scrobbles}} scrobbles ({{.song.rank}} place)
@partial partials/firstlast_listens(firstlast: .firstlast)
Yearly Performance
diff --git a/src/queries.zig b/src/queries.zig
index a22b68e..194ef7f 100644
--- a/src/queries.zig
+++ b/src/queries.zig
@@ -17,7 +17,7 @@ pub fn entityQueryResult(request: *jetzig.Request, query: GeneratedQuery, args:
if (query.query_type == .entity_info) {
var out: *jetzig.Data.Value = try Data.object();
- const entity = try (try result.next()).?.to(struct { name: []const u8, id: i32, scrobbles: i64, album_num: ?i64 = null, song_num: ?i64 = null, rank: []const u8 }, .{ .dupe = true, .allocator = request.allocator, .map = .name });
+ const entity = try (try result.next()).?.to(EntityInfoResult, .{ .dupe = true, .allocator = request.allocator, .map = .name });
try out.put("entity_info", entity);
try result.drain();
return out.get("entity_info").?;
@@ -74,6 +74,20 @@ const UnifiedResult = struct {
date: ?[]const u8 = null,
};
+const EntityInfoResult = struct {
+ album_name: ?[]const u8 = null,
+ album_id: ?i32 = null,
+ song_name: ?[]const u8 = null,
+ song_id: ?i32 = null,
+ artist_name: ?[]const u8 = null,
+ artist_id: ?i32 = null,
+ scrobbles: ?i64 = null,
+ date: ?[]const u8 = null,
+ rank: []const u8,
+ song_num: ?i64 = null,
+ album_num: ?i64 = null,
+};
+
pub fn loadQuery(entity: EntityType, query_type: QueryTypeEnum) GeneratedQuery {
return GeneratedQuery{
.entity = entity,
@@ -301,28 +315,30 @@ pub fn loadQuery(entity: EntityType, query_type: QueryTypeEnum) GeneratedQuery {
.song =>
\\SELECT * FROM
\\(SELECT *, TO_CHAR(ROW_NUMBER() OVER (ORDER BY scrobbles DESC),'FM99999th') AS rank FROM
- \\(SELECT songs.name AS name, songs.id AS id, COUNT(scrobbles) AS scrobbles
+ \\(SELECT songs.name AS song_name, songs.id AS song_id, COUNT(scrobbles) AS scrobbles
\\FROM albumsongs
\\INNER JOIN songs ON albumsongs.song_id = songs.id
\\INNER JOIN scrobbles ON scrobbles.albumsong = albumsongs.id
\\GROUP BY songs.id))
- \\WHERE id = $1
+ \\WHERE song_id = $1
,
.album =>
- \\SELECT * FROM
+ \\SELECT album_name, t.album_id, artists.name AS artist_name, artists.id AS artist_id, song_num, scrobbles, rank FROM
\\(SELECT *, TO_CHAR(ROW_NUMBER() OVER (ORDER BY scrobbles DESC),'FM9999th') AS rank FROM
- \\(SELECT albums.name AS name, albums.id AS id, COUNT(DISTINCT songs.id) AS song_num, COUNT(scrobbles) AS scrobbles
+ \\(SELECT albums.name AS album_name, albums.id AS album_id, COUNT(DISTINCT songs.id) AS song_num, COUNT(scrobbles) AS scrobbles
\\FROM albumsongs
\\INNER JOIN albums ON albumsongs.album_id = albums.id
\\INNER JOIN scrobbles ON scrobbles.albumsong = albumsongs.id
\\INNER JOIN songs ON songs.id = albumsongs.song_id
- \\GROUP BY albums.id))
- \\WHERE id = $1;
+ \\GROUP BY albums.id)) AS t
+ \\INNER JOIN artistalbums ON artistalbums.album_id = t.album_id
+ \\INNER JOIN artists ON artists.id = artistalbums.artist_id
+ \\WHERE t.album_id = $1
,
.artist =>
\\SELECT * FROM
\\(SELECT *, TO_CHAR(ROW_NUMBER() OVER (ORDER BY scrobbles DESC),'FM9999th') AS rank FROM
- \\(SELECT artists.name AS name, artists.id AS id, COUNT(scrobbles) AS scrobbles, COUNT(DISTINCT albums.id) AS album_num, COUNT(DISTINCT songs.id) AS song_num
+ \\(SELECT artists.name AS artist_name, artists.id AS artist_id, COUNT(scrobbles) AS scrobbles, COUNT(DISTINCT albums.id) AS album_num, COUNT(DISTINCT songs.id) AS song_num
\\FROM albumsongsartists
\\INNER JOIN artists ON albumsongsartists.artist_id = artists.id
\\INNER JOIN albumsongs ON albumsongsartists.albumsong_id = albumsongs.id
@@ -330,7 +346,7 @@ pub fn loadQuery(entity: EntityType, query_type: QueryTypeEnum) GeneratedQuery {
\\INNER JOIN albums ON albums.id = albumsongs.album_id
\\INNER JOIN songs ON songs.id = albumsongs.song_id
\\GROUP BY artists.id))
- \\WHERE id = $1
+ \\WHERE artist_id = $1
,
},