Create GET function for a song view

This commit is contained in:
mitteneer 2025-05-29 15:33:10 -04:00
parent 3ff973e193
commit d638fa66c5
3 changed files with 106 additions and 21 deletions

View file

@ -12,6 +12,21 @@ pub fn index(request: *jetzig.Request) !jetzig.View {
}
pub fn get(id: []const u8, request: *jetzig.Request) !jetzig.View {
_ = id;
var root = try request.data(.object);
const song = try queries.entityQueryResult(request, queries.generateQuery(.song, .entity_info), .{id}, .object);
try root.put("song", song.get("entity_info"));
const scrobbles = try queries.entityQueryResult(request, queries.generateQuery(.song, .entity_items), .{id}, .array);
try root.put("scrobbles", scrobbles);
const appears = try queries.entityQueryResult(request, queries.generateQuery(.song, .appears), .{id}, .array);
try root.put("appears", appears);
const firstlast = try queries.entityQueryResult(request, queries.generateQuery(.song, .firstlast), .{id}, .array);
try root.put("firstlast", firstlast);
const timescale = try queries.entityQueryResult(request, queries.generateQuery(.song, .timescale), .{id}, .array);
try root.put("yearly", timescale);
return request.render(.ok);
}

View file

@ -1,3 +1,19 @@
<div>
<span>Content goes here</span>
</div>
@zig {
const ColumnChoices = []const enum{song, album, artist, artistlist, scrobbles, date};
const columns: ColumnChoices = &.{.song, .artistlist, .album, .date};
}
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
@partial partials/header
<h1>{{.song}}</h1>
@partial partials/firstlast_listens(scrobbles: .song.scrobbles, rank: .song.rank, firstlast: .firstlast)
<h3>Yearly Performance</h3>
@partial partials/timescale(range: .yearly)
<h2>Scrobbles</h2>
@partial partials/newtable(T: ColumnChoices, table_data: .scrobbles, columns: columns)
</body>
</html>