Switch to using newtable partial for all tables

Will be renamed eventually, don't care right now. Also cleans up a lot of code I wasn't particularly happy about
This commit is contained in:
mitteneer 2025-05-13 14:24:14 -04:00
parent 153ea869e0
commit 365b9dbf11
10 changed files with 128 additions and 166 deletions

View file

@ -1,6 +1,7 @@
const std = @import("std");
const jetzig = @import("jetzig");
const jetquery = @import("jetzig").jetquery;
const TableRow = @import("../../types.zig").TableRows;
const dateFmt = @import("../../date_fmt.zig").dateFmt;
const ordinalFmt = @import("../../ordinal_fmt.zig").ordinalFmt;
@ -25,10 +26,12 @@ pub fn index(request: *jetzig.Request) !jetzig.View {
while (try artists_jq_result.postgresql.result.next()) |artist_row| {
const artist = try artist_row.to(Artist, .{ .dupe = true, .allocator = request.allocator });
var artist_view = try artists_view.append(.object);
try artist_view.put("name", artist.name);
try artist_view.put("url", artist.id);
try artist_view.put("scrobbles", artist.scrobbles);
const row = TableRow{
.artist = .{ .name = artist.name, .id = artist.id },
.scrobbles = artist.scrobbles,
};
try artists_view.append(row);
}
return request.render(.ok);
@ -84,7 +87,12 @@ pub fn get(id: []const u8, request: *jetzig.Request) !jetzig.View {
while (try albums_jq_result.postgresql.result.next()) |album_row| {
const album = try album_row.to(AlbumsResult, .{ .dupe = true, .allocator = request.allocator });
try albums_view.append(album);
const album_table_row = TableRow{
.album = .{ .name = album.name, .id = album.id },
.scrobbles = album.scrobbles,
};
try albums_view.append(album_table_row);
}
//albums_jq_result.drain();
@ -107,7 +115,12 @@ pub fn get(id: []const u8, request: *jetzig.Request) !jetzig.View {
while (try appears_jq_result.postgresql.result.next()) |appears_row| {
const appears = try appears_row.to(AlbumsResult, .{ .dupe = true, .allocator = request.allocator });
try appears_view.append(appears);
const appears_table_row = TableRow{
.album = .{ .name = appears.name, .id = appears.id },
.scrobbles = appears.scrobbles,
};
try appears_view.append(appears_table_row);
}
//appears_jq_result.drain();