diff --git a/src/app/views/albums.zig b/src/app/views/albums.zig index b081c39..0805e67 100644 --- a/src/app/views/albums.zig +++ b/src/app/views/albums.zig @@ -5,12 +5,27 @@ const jetquery = @import("jetzig").jetquery; pub fn index(request: *jetzig.Request) !jetzig.View { var root = try request.data(.object); var albums_view = try root.put("albums", .array); - const query = jetzig.database.Query(.Album).select(.{}).orderBy(.{ .name = .asc }); + const query = jetzig.database.Query(.Album).select(.{}) + .include(.albumartists, .{ .select = .{.artist_id} }) + .orderBy(.{ .name = .asc }); const albums = try request.repo.all(query); for (albums) |album| { + const scrobbles = try jetzig.database.Query(.Scrobble).where(.{ .album_id = album.id }).count().execute(request.repo); var album_view = try albums_view.append(.object); + + var artist_infos = try album_view.put("artist_info", .array); + for (album.albumartists) |artist| { + var artist_info = try artist_infos.append(.object); + const artist_data = try jetzig.database.Query(.Artist).where(.{ .id = artist.artist_id }).all(request.repo); + for (artist_data) |ad| { + try artist_info.put("name", ad.name); + try artist_info.put("id", ad.id); + } + } + try album_view.put("name", album.name); try album_view.put("url", album.id); + try album_view.put("scrobbles", scrobbles); } return request.render(.ok); } diff --git a/src/app/views/albums/index.zmpl b/src/app/views/albums/index.zmpl index 27fae46..b4a0142 100644 --- a/src/app/views/albums/index.zmpl +++ b/src/app/views/albums/index.zmpl @@ -1,19 +1,41 @@ + @partial partials/header

Albums

- +
+ + + + + + @for (.albums) |album| { + + } +
NameArtist(s)Scrobbles
{{album.name}} + @for (album.get("artist_info").?) |ai| { + {{ai.name}} + } + {{album.scrobbles}}
+ + \ No newline at end of file diff --git a/src/app/views/rules.zig b/src/app/views/rules.zig new file mode 100644 index 0000000..a2a222e --- /dev/null +++ b/src/app/views/rules.zig @@ -0,0 +1,104 @@ +const std = @import("std"); +const jetzig = @import("jetzig"); + +pub fn index(request: *jetzig.Request) !jetzig.View { + return request.render(.ok); +} + +pub fn get(id: []const u8, request: *jetzig.Request) !jetzig.View { + _ = id; + return request.render(.ok); +} + +pub fn new(request: *jetzig.Request) !jetzig.View { + return request.render(.ok); +} + +pub fn edit(id: []const u8, request: *jetzig.Request) !jetzig.View { + _ = id; + return request.render(.ok); +} + +pub fn post(request: *jetzig.Request) !jetzig.View { + return request.render(.created); +} + +pub fn put(id: []const u8, request: *jetzig.Request) !jetzig.View { + _ = id; + return request.render(.ok); +} + +pub fn patch(id: []const u8, request: *jetzig.Request) !jetzig.View { + _ = id; + return request.render(.ok); +} + +pub fn delete(id: []const u8, request: *jetzig.Request) !jetzig.View { + _ = id; + return request.render(.ok); +} + + +test "index" { + var app = try jetzig.testing.app(std.testing.allocator, @import("routes")); + defer app.deinit(); + + const response = try app.request(.GET, "/rules", .{}); + try response.expectStatus(.ok); +} + +test "get" { + var app = try jetzig.testing.app(std.testing.allocator, @import("routes")); + defer app.deinit(); + + const response = try app.request(.GET, "/rules/example-id", .{}); + try response.expectStatus(.ok); +} + +test "new" { + var app = try jetzig.testing.app(std.testing.allocator, @import("routes")); + defer app.deinit(); + + const response = try app.request(.GET, "/rules/new", .{}); + try response.expectStatus(.ok); +} + +test "edit" { + var app = try jetzig.testing.app(std.testing.allocator, @import("routes")); + defer app.deinit(); + + const response = try app.request(.GET, "/rules/example-id/edit", .{}); + try response.expectStatus(.ok); +} + +test "post" { + var app = try jetzig.testing.app(std.testing.allocator, @import("routes")); + defer app.deinit(); + + const response = try app.request(.POST, "/rules", .{}); + try response.expectStatus(.created); +} + +test "put" { + var app = try jetzig.testing.app(std.testing.allocator, @import("routes")); + defer app.deinit(); + + const response = try app.request(.PUT, "/rules/example-id", .{}); + try response.expectStatus(.ok); +} + +test "patch" { + var app = try jetzig.testing.app(std.testing.allocator, @import("routes")); + defer app.deinit(); + + const response = try app.request(.PATCH, "/rules/example-id", .{}); + try response.expectStatus(.ok); +} + +test "delete" { + var app = try jetzig.testing.app(std.testing.allocator, @import("routes")); + defer app.deinit(); + + const response = try app.request(.DELETE, "/rules/example-id", .{}); + try response.expectStatus(.ok); +} diff --git a/src/app/views/rules/delete.zmpl b/src/app/views/rules/delete.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/rules/delete.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/rules/edit.zmpl b/src/app/views/rules/edit.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/rules/edit.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/rules/get.zmpl b/src/app/views/rules/get.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/rules/get.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/rules/index.zmpl b/src/app/views/rules/index.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/rules/index.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/rules/new.zmpl b/src/app/views/rules/new.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/rules/new.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/rules/patch.zmpl b/src/app/views/rules/patch.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/rules/patch.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/rules/post.zmpl b/src/app/views/rules/post.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/rules/post.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/rules/put.zmpl b/src/app/views/rules/put.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/rules/put.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/scrobbles.zig b/src/app/views/scrobbles.zig index 7bd4f19..0fff9c3 100644 --- a/src/app/views/scrobbles.zig +++ b/src/app/views/scrobbles.zig @@ -25,8 +25,8 @@ pub fn index(request: *jetzig.Request) !jetzig.View { try scrobble_view.put("song_name", scrobble.song.name); try scrobble_view.put("song_id", scrobble.song.id); - try scrobble_view.put("artist_name", "placeholder"); - try scrobble_view.put("artist_id", "placeholder"); + //try scrobble_view.put("artist_name", "placeholder"); + //try scrobble_view.put("artist_id", "placeholder"); try scrobble_view.put("album_name", scrobble.album.name); try scrobble_view.put("album_id", scrobble.album.id); try scrobble_view.put("date", scrobble.date);