diff --git a/src/app/views/ratings/songs.zig b/src/app/views/ratings/songs.zig index 3145fb4..e77c2ac 100644 --- a/src/app/views/ratings/songs.zig +++ b/src/app/views/ratings/songs.zig @@ -3,9 +3,11 @@ const jetzig = @import("jetzig"); pub fn post(request: *jetzig.Request) !jetzig.View { var root = try request.data(.object); const params = try request.params(); - const id = params.getT(.integer, "song_id"); + const id = params.getT(.integer, "song_id").?; + const score = if (params.getT(.integer, "score")) |score| @as(i16, @truncate(score)) else null; const review = params.getT(.string, "review"); - try root.put("song_id", id); + try jetzig.database.Query(.Songrating).insert(.{ .song = id, .rating = score, .rating_text = review, .date = @divFloor(request.start_time, 1_000) }).execute(request.repo); + try root.put("score", score); try root.put("review", review); return request.render(.created); diff --git a/src/app/views/ratings/songs/post.zmpl b/src/app/views/ratings/songs/post.zmpl index 3366a0c..ca54fd7 100644 --- a/src/app/views/ratings/songs/post.zmpl +++ b/src/app/views/ratings/songs/post.zmpl @@ -1,2 +1 @@ -{{.song_id}} -{{.review}} \ No newline at end of file + {{.score}}: {{.review}} (Today) \ No newline at end of file diff --git a/src/app/views/songs.zig b/src/app/views/songs.zig index 00ec085..2f1772b 100644 --- a/src/app/views/songs.zig +++ b/src/app/views/songs.zig @@ -59,5 +59,9 @@ pub fn get(id: []const u8, request: *jetzig.Request) !jetzig.View { const timescale = try queries.entityQueryResult(request, queries.loadQuery(.song, .timescale), .{id_int}); try root.put("yearly", timescale); + + const ratings = try queries.entityQueryResult(request, queries.loadQuery(.song, .get_ratings), .{id_int}); + try root.put("reviews", ratings); + return request.render(.ok); } diff --git a/src/app/views/songs/get.zmpl b/src/app/views/songs/get.zmpl index 33e6886..f07b03c 100644 --- a/src/app/views/songs/get.zmpl +++ b/src/app/views/songs/get.zmpl @@ -1,6 +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"); } @@ -25,13 +26,21 @@