From 762a4fd51e2d6ce4c85b9cbd7b8abff3331767e9 Mon Sep 17 00:00:00 2001 From: mitteneer Date: Fri, 2 May 2025 10:00:47 -0400 Subject: [PATCH 1/6] Create partial for view agnostic table --- src/app/views/partials/_newtable.zmpl | 55 +++++++++++++++++++++++++++ src/types.zig | 8 ++++ 2 files changed, 63 insertions(+) create mode 100644 src/app/views/partials/_newtable.zmpl diff --git a/src/app/views/partials/_newtable.zmpl b/src/app/views/partials/_newtable.zmpl new file mode 100644 index 0000000..bee43c1 --- /dev/null +++ b/src/app/views/partials/_newtable.zmpl @@ -0,0 +1,55 @@ +@args table_data *ZmplValue, table_headers: []enum{Song, Album, Artist, Scrobbles, Date} + + + + +@zig { + for (table_headers) |header| { + switch (header) { + .Artist => { + + }, + inline else => |other| { + const h = @tagName(other); + + }, + } + } +} + + + +@zig { + for (table_data) |data| { + + for (table_header) |header| { + switch (header) { + .Song => { + + }, + .Album => { + + }, + .Artist => { + + }, + .Scrobbles => { + + }, + .Date =>{ + + } + }; + } + } +} + +
Artist(s){{h}}
+ {{data.name}} + + {{data.name}} + + @for (data.get("artist_info").?) |ai| { + {{ai.name}} + } + {{data.scrobbles}}{{data.date}}
\ No newline at end of file diff --git a/src/types.zig b/src/types.zig index 704adc0..2574610 100644 --- a/src/types.zig +++ b/src/types.zig @@ -61,3 +61,11 @@ pub const Rule = struct { pub const Rules = struct { rules: []const Rule, }; + +pub const Headers = []enum { + Song, + Album, + Artist, + Scrobbles, + Date, +}; From c574885f8dd17286e6464a050e2394f952af2cc1 Mon Sep 17 00:00:00 2001 From: mitteneer Date: Mon, 5 May 2025 10:37:18 -0400 Subject: [PATCH 2/6] Get rid of unused views --- src/app/views/albums/delete.zmpl | 3 --- src/app/views/albums/edit.zmpl | 3 --- src/app/views/albums/new.zmpl | 3 --- src/app/views/albums/patch.zmpl | 3 --- src/app/views/albums/post.zmpl | 3 --- src/app/views/albums/put.zmpl | 3 --- src/app/views/artists/delete.zmpl | 3 --- src/app/views/artists/edit.zmpl | 3 --- src/app/views/artists/new.zmpl | 3 --- src/app/views/artists/patch.zmpl | 3 --- src/app/views/artists/post.zmpl | 3 --- src/app/views/artists/put.zmpl | 3 --- src/app/views/collection/delete.zmpl | 3 --- src/app/views/collection/patch.zmpl | 3 --- src/app/views/collection/post.zmpl | 3 --- src/app/views/collection/put.zmpl | 3 --- src/app/views/concerts/delete.zmpl | 3 --- src/app/views/concerts/patch.zmpl | 3 --- src/app/views/concerts/post.zmpl | 3 --- src/app/views/concerts/put.zmpl | 3 --- src/app/views/lists/delete.zmpl | 3 --- src/app/views/lists/patch.zmpl | 3 --- src/app/views/lists/put.zmpl | 3 --- src/app/views/rules/delete.zmpl | 3 --- src/app/views/rules/edit.zmpl | 3 --- src/app/views/rules/get.zmpl | 3 --- src/app/views/rules/new.zmpl | 3 --- src/app/views/rules/patch.zmpl | 3 --- src/app/views/rules/put.zmpl | 3 --- src/app/views/scrobbles/delete.zmpl | 3 --- src/app/views/scrobbles/get.zmpl | 3 --- src/app/views/scrobbles/patch.zmpl | 3 --- src/app/views/scrobbles/post.zmpl | 3 --- src/app/views/scrobbles/put.zmpl | 3 --- src/app/views/songs/delete.zmpl | 3 --- src/app/views/songs/edit.zmpl | 3 --- src/app/views/songs/new.zmpl | 3 --- src/app/views/songs/patch.zmpl | 3 --- src/app/views/songs/post.zmpl | 3 --- src/app/views/songs/put.zmpl | 3 --- src/app/views/upload/delete.zmpl | 3 --- src/app/views/upload/get.zmpl | 3 --- src/app/views/upload/patch.zmpl | 3 --- src/app/views/upload/put.zmpl | 3 --- 44 files changed, 132 deletions(-) delete mode 100644 src/app/views/albums/delete.zmpl delete mode 100644 src/app/views/albums/edit.zmpl delete mode 100644 src/app/views/albums/new.zmpl delete mode 100644 src/app/views/albums/patch.zmpl delete mode 100644 src/app/views/albums/post.zmpl delete mode 100644 src/app/views/albums/put.zmpl delete mode 100644 src/app/views/artists/delete.zmpl delete mode 100644 src/app/views/artists/edit.zmpl delete mode 100644 src/app/views/artists/new.zmpl delete mode 100644 src/app/views/artists/patch.zmpl delete mode 100644 src/app/views/artists/post.zmpl delete mode 100644 src/app/views/artists/put.zmpl delete mode 100644 src/app/views/collection/delete.zmpl delete mode 100644 src/app/views/collection/patch.zmpl delete mode 100644 src/app/views/collection/post.zmpl delete mode 100644 src/app/views/collection/put.zmpl delete mode 100644 src/app/views/concerts/delete.zmpl delete mode 100644 src/app/views/concerts/patch.zmpl delete mode 100644 src/app/views/concerts/post.zmpl delete mode 100644 src/app/views/concerts/put.zmpl delete mode 100644 src/app/views/lists/delete.zmpl delete mode 100644 src/app/views/lists/patch.zmpl delete mode 100644 src/app/views/lists/put.zmpl delete mode 100644 src/app/views/rules/delete.zmpl delete mode 100644 src/app/views/rules/edit.zmpl delete mode 100644 src/app/views/rules/get.zmpl delete mode 100644 src/app/views/rules/new.zmpl delete mode 100644 src/app/views/rules/patch.zmpl delete mode 100644 src/app/views/rules/put.zmpl delete mode 100644 src/app/views/scrobbles/delete.zmpl delete mode 100644 src/app/views/scrobbles/get.zmpl delete mode 100644 src/app/views/scrobbles/patch.zmpl delete mode 100644 src/app/views/scrobbles/post.zmpl delete mode 100644 src/app/views/scrobbles/put.zmpl delete mode 100644 src/app/views/songs/delete.zmpl delete mode 100644 src/app/views/songs/edit.zmpl delete mode 100644 src/app/views/songs/new.zmpl delete mode 100644 src/app/views/songs/patch.zmpl delete mode 100644 src/app/views/songs/post.zmpl delete mode 100644 src/app/views/songs/put.zmpl delete mode 100644 src/app/views/upload/delete.zmpl delete mode 100644 src/app/views/upload/get.zmpl delete mode 100644 src/app/views/upload/patch.zmpl delete mode 100644 src/app/views/upload/put.zmpl diff --git a/src/app/views/albums/delete.zmpl b/src/app/views/albums/delete.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/albums/delete.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/albums/edit.zmpl b/src/app/views/albums/edit.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/albums/edit.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/albums/new.zmpl b/src/app/views/albums/new.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/albums/new.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/albums/patch.zmpl b/src/app/views/albums/patch.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/albums/patch.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/albums/post.zmpl b/src/app/views/albums/post.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/albums/post.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/albums/put.zmpl b/src/app/views/albums/put.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/albums/put.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/artists/delete.zmpl b/src/app/views/artists/delete.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/artists/delete.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/artists/edit.zmpl b/src/app/views/artists/edit.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/artists/edit.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/artists/new.zmpl b/src/app/views/artists/new.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/artists/new.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/artists/patch.zmpl b/src/app/views/artists/patch.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/artists/patch.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/artists/post.zmpl b/src/app/views/artists/post.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/artists/post.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/artists/put.zmpl b/src/app/views/artists/put.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/artists/put.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/collection/delete.zmpl b/src/app/views/collection/delete.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/collection/delete.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/collection/patch.zmpl b/src/app/views/collection/patch.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/collection/patch.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/collection/post.zmpl b/src/app/views/collection/post.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/collection/post.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/collection/put.zmpl b/src/app/views/collection/put.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/collection/put.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/concerts/delete.zmpl b/src/app/views/concerts/delete.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/concerts/delete.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/concerts/patch.zmpl b/src/app/views/concerts/patch.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/concerts/patch.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/concerts/post.zmpl b/src/app/views/concerts/post.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/concerts/post.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/concerts/put.zmpl b/src/app/views/concerts/put.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/concerts/put.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/lists/delete.zmpl b/src/app/views/lists/delete.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/lists/delete.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/lists/patch.zmpl b/src/app/views/lists/patch.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/lists/patch.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/lists/put.zmpl b/src/app/views/lists/put.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/lists/put.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/rules/delete.zmpl b/src/app/views/rules/delete.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/rules/delete.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/rules/edit.zmpl b/src/app/views/rules/edit.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/rules/edit.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/rules/get.zmpl b/src/app/views/rules/get.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/rules/get.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/rules/new.zmpl b/src/app/views/rules/new.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/rules/new.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/rules/patch.zmpl b/src/app/views/rules/patch.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/rules/patch.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/rules/put.zmpl b/src/app/views/rules/put.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/rules/put.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/scrobbles/delete.zmpl b/src/app/views/scrobbles/delete.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/scrobbles/delete.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/scrobbles/get.zmpl b/src/app/views/scrobbles/get.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/scrobbles/get.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/scrobbles/patch.zmpl b/src/app/views/scrobbles/patch.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/scrobbles/patch.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/scrobbles/post.zmpl b/src/app/views/scrobbles/post.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/scrobbles/post.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/scrobbles/put.zmpl b/src/app/views/scrobbles/put.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/scrobbles/put.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/songs/delete.zmpl b/src/app/views/songs/delete.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/songs/delete.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/songs/edit.zmpl b/src/app/views/songs/edit.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/songs/edit.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/songs/new.zmpl b/src/app/views/songs/new.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/songs/new.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/songs/patch.zmpl b/src/app/views/songs/patch.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/songs/patch.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/songs/post.zmpl b/src/app/views/songs/post.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/songs/post.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/songs/put.zmpl b/src/app/views/songs/put.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/songs/put.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/upload/delete.zmpl b/src/app/views/upload/delete.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/upload/delete.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/upload/get.zmpl b/src/app/views/upload/get.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/upload/get.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/upload/patch.zmpl b/src/app/views/upload/patch.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/upload/patch.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/upload/put.zmpl b/src/app/views/upload/put.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/upload/put.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
From 94cc6e3bd5751bdc5e202452b120af74f8fc75a0 Mon Sep 17 00:00:00 2001 From: mitteneer Date: Mon, 5 May 2025 11:06:52 -0400 Subject: [PATCH 3/6] Remove unused views and functions --- src/app/views/albums.zig | 92 ------------------------ src/app/views/artists.zig | 92 ------------------------ src/app/views/collection.zig | 23 ------ src/app/views/concerts.zig | 23 ------ src/app/views/lists.zig | 18 ----- src/app/views/ratings.zig | 18 ----- src/app/views/ratings/delete.zmpl | 3 - src/app/views/ratings/patch.zmpl | 3 - src/app/views/ratings/put.zmpl | 3 - src/app/views/rules.zig | 94 ------------------------ src/app/views/scrobbles.zig | 29 -------- src/app/views/search.zig | 104 --------------------------- src/app/views/search/delete.zmpl | 3 - src/app/views/search/edit.zmpl | 3 - src/app/views/search/get.zmpl | 3 - src/app/views/search/index.zmpl | 3 - src/app/views/search/new.zmpl | 3 - src/app/views/search/patch.zmpl | 3 - src/app/views/search/post.zmpl | 3 - src/app/views/search/put.zmpl | 3 - src/app/views/songs.zig | 116 ------------------------------ src/app/views/upload.zig | 24 ------- 22 files changed, 666 deletions(-) delete mode 100644 src/app/views/ratings/delete.zmpl delete mode 100644 src/app/views/ratings/patch.zmpl delete mode 100644 src/app/views/ratings/put.zmpl delete mode 100644 src/app/views/search.zig delete mode 100644 src/app/views/search/delete.zmpl delete mode 100644 src/app/views/search/edit.zmpl delete mode 100644 src/app/views/search/get.zmpl delete mode 100644 src/app/views/search/index.zmpl delete mode 100644 src/app/views/search/new.zmpl delete mode 100644 src/app/views/search/patch.zmpl delete mode 100644 src/app/views/search/post.zmpl delete mode 100644 src/app/views/search/put.zmpl diff --git a/src/app/views/albums.zig b/src/app/views/albums.zig index cc6d765..06d6831 100644 --- a/src/app/views/albums.zig +++ b/src/app/views/albums.zig @@ -79,95 +79,3 @@ pub fn get(id: []const u8, request: *jetzig.Request) !jetzig.View { } 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, "/album", .{}); - 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, "/album/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, "/album/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, "/album/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, "/album", .{}); - 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, "/album/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, "/album/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, "/album/example-id", .{}); - try response.expectStatus(.ok); -} diff --git a/src/app/views/artists.zig b/src/app/views/artists.zig index 728ee2c..4164fc1 100644 --- a/src/app/views/artists.zig +++ b/src/app/views/artists.zig @@ -156,95 +156,3 @@ pub fn get(id: []const u8, request: *jetzig.Request) !jetzig.View { 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, "/artist", .{}); - 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, "/artist/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, "/artist/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, "/artist/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, "/artist", .{}); - 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, "/artist/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, "/artist/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, "/artist/example-id", .{}); - try response.expectStatus(.ok); -} diff --git a/src/app/views/collection.zig b/src/app/views/collection.zig index 8125efd..1b0b502 100644 --- a/src/app/views/collection.zig +++ b/src/app/views/collection.zig @@ -11,26 +11,3 @@ pub fn get(id: []const u8, request: *jetzig.Request, data: *jetzig.Data) !jetzig _ = id; return request.render(.ok); } - -pub fn post(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = data; - return request.render(.created); -} - -pub fn put(id: []const u8, request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = data; - _ = id; - return request.render(.ok); -} - -pub fn patch(id: []const u8, request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = data; - _ = id; - return request.render(.ok); -} - -pub fn delete(id: []const u8, request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = data; - _ = id; - return request.render(.ok); -} diff --git a/src/app/views/concerts.zig b/src/app/views/concerts.zig index 8125efd..1b0b502 100644 --- a/src/app/views/concerts.zig +++ b/src/app/views/concerts.zig @@ -11,26 +11,3 @@ pub fn get(id: []const u8, request: *jetzig.Request, data: *jetzig.Data) !jetzig _ = id; return request.render(.ok); } - -pub fn post(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = data; - return request.render(.created); -} - -pub fn put(id: []const u8, request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = data; - _ = id; - return request.render(.ok); -} - -pub fn patch(id: []const u8, request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = data; - _ = id; - return request.render(.ok); -} - -pub fn delete(id: []const u8, request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = data; - _ = id; - return request.render(.ok); -} diff --git a/src/app/views/lists.zig b/src/app/views/lists.zig index 8125efd..aecf0dc 100644 --- a/src/app/views/lists.zig +++ b/src/app/views/lists.zig @@ -16,21 +16,3 @@ pub fn post(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { _ = data; return request.render(.created); } - -pub fn put(id: []const u8, request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = data; - _ = id; - return request.render(.ok); -} - -pub fn patch(id: []const u8, request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = data; - _ = id; - return request.render(.ok); -} - -pub fn delete(id: []const u8, request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = data; - _ = id; - return request.render(.ok); -} diff --git a/src/app/views/ratings.zig b/src/app/views/ratings.zig index 8125efd..aecf0dc 100644 --- a/src/app/views/ratings.zig +++ b/src/app/views/ratings.zig @@ -16,21 +16,3 @@ pub fn post(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { _ = data; return request.render(.created); } - -pub fn put(id: []const u8, request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = data; - _ = id; - return request.render(.ok); -} - -pub fn patch(id: []const u8, request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = data; - _ = id; - return request.render(.ok); -} - -pub fn delete(id: []const u8, request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = data; - _ = id; - return request.render(.ok); -} diff --git a/src/app/views/ratings/delete.zmpl b/src/app/views/ratings/delete.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/ratings/delete.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/ratings/patch.zmpl b/src/app/views/ratings/patch.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/ratings/patch.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/ratings/put.zmpl b/src/app/views/ratings/put.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/ratings/put.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/rules.zig b/src/app/views/rules.zig index 7a2df91..eb85a72 100644 --- a/src/app/views/rules.zig +++ b/src/app/views/rules.zig @@ -4,21 +4,6 @@ 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 { const params = try request.params(); @@ -54,82 +39,3 @@ 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/scrobbles.zig b/src/app/views/scrobbles.zig index 6ee80d8..1386a83 100644 --- a/src/app/views/scrobbles.zig +++ b/src/app/views/scrobbles.zig @@ -55,32 +55,3 @@ pub fn index(request: *jetzig.Request) !jetzig.View { return request.render(.ok); } - -pub fn get(id: []const u8, request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = id; - _ = data; - return request.render(.ok); -} - -pub fn post(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = data; - return request.render(.created); -} - -pub fn put(id: []const u8, request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = data; - _ = id; - return request.render(.ok); -} - -pub fn patch(id: []const u8, request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = data; - _ = id; - return request.render(.ok); -} - -pub fn delete(id: []const u8, request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = data; - _ = id; - return request.render(.ok); -} diff --git a/src/app/views/search.zig b/src/app/views/search.zig deleted file mode 100644 index be5f7e0..0000000 --- a/src/app/views/search.zig +++ /dev/null @@ -1,104 +0,0 @@ -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, "/search", .{}); - 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, "/search/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, "/search/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, "/search/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, "/search", .{}); - 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, "/search/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, "/search/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, "/search/example-id", .{}); - try response.expectStatus(.ok); -} diff --git a/src/app/views/search/delete.zmpl b/src/app/views/search/delete.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/search/delete.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/search/edit.zmpl b/src/app/views/search/edit.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/search/edit.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/search/get.zmpl b/src/app/views/search/get.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/search/get.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/search/index.zmpl b/src/app/views/search/index.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/search/index.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/search/new.zmpl b/src/app/views/search/new.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/search/new.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/search/patch.zmpl b/src/app/views/search/patch.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/search/patch.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/search/post.zmpl b/src/app/views/search/post.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/search/post.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/search/put.zmpl b/src/app/views/search/put.zmpl deleted file mode 100644 index 76457d0..0000000 --- a/src/app/views/search/put.zmpl +++ /dev/null @@ -1,3 +0,0 @@ -
- Content goes here -
diff --git a/src/app/views/songs.zig b/src/app/views/songs.zig index 19711d1..cd220f8 100644 --- a/src/app/views/songs.zig +++ b/src/app/views/songs.zig @@ -4,12 +4,6 @@ const jetzig = @import("jetzig"); pub fn index(request: *jetzig.Request) !jetzig.View { var root = try request.data(.object); var songs_view = try root.put("songs", .array); - //const songs = try jetzig.database.Query(.Song) - // .select(.{ .id, .name }) - // .include(.songartists, .{ .select = .{.artist_id} }) - // .include(.scrobbles, .{ .select = .{.id} }) - // .orderBy(.{ .name = .asc }) - // .all(request.repo); const query = \\SELECT songs.name, songs.id, artists.name, artists.id, COUNT(scrobbles) AS scrobbles @@ -52,24 +46,6 @@ pub fn index(request: *jetzig.Request) !jetzig.View { prev_artist_infos = artist_infos; prev_song_id = song.id; } - - //for (songs) |song| { - // var song_view = try songs_view.append(.object); - - // var artist_infos = try song_view.put("artist_info", .array); - // for (song.songartists) |artist| { - // var artist_info = try artist_infos.append(.object); - // const artist_data = try jetzig.database.Query(.Artist) - // .find(artist.artist_id) - // .select(.{ .id, .name }) - // .execute(request.repo); - // try artist_info.put("name", artist_data.?.name); - // try artist_info.put("id", artist_data.?.id); - // } - // try song_view.put("name", song.name); - // try song_view.put("url", song.id); - // try song_view.put("scrobbles", (song.scrobbles).len); - //} return request.render(.ok); } @@ -77,95 +53,3 @@ 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, "/song", .{}); - 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, "/song/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, "/song/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, "/song/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, "/song", .{}); - 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, "/song/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, "/song/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, "/song/example-id", .{}); - try response.expectStatus(.ok); -} diff --git a/src/app/views/upload.zig b/src/app/views/upload.zig index 59442a8..5f47cc4 100644 --- a/src/app/views/upload.zig +++ b/src/app/views/upload.zig @@ -10,12 +10,6 @@ pub fn index(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { return request.render(.ok); } -pub fn get(id: []const u8, request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = data; - _ = id; - return request.render(.ok); -} - pub fn post(request: *jetzig.Request) !jetzig.View { var root = try request.data(.object); @@ -166,21 +160,3 @@ pub fn post(request: *jetzig.Request) !jetzig.View { return request.render(.created); } - -pub fn put(id: []const u8, request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = data; - _ = id; - return request.render(.ok); -} - -pub fn patch(id: []const u8, request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = data; - _ = id; - return request.render(.ok); -} - -pub fn delete(id: []const u8, request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = data; - _ = id; - return request.render(.ok); -} From 9ffc45b207fa12352dbf3f52ae26cfd15e49a83d Mon Sep 17 00:00:00 2001 From: mitteneer Date: Mon, 5 May 2025 11:15:30 -0400 Subject: [PATCH 4/6] Delete common_queries.md No longer relevant --- common_queries.md | 164 ---------------------------------------------- 1 file changed, 164 deletions(-) delete mode 100644 common_queries.md diff --git a/common_queries.md b/common_queries.md deleted file mode 100644 index 833d2c0..0000000 --- a/common_queries.md +++ /dev/null @@ -1,164 +0,0 @@ -Get all albums from specified artist: -```sql -SELECT artists.name, albums.name -FROM "Albumartists" -INNER JOIN artists -ON "Albumartists".artist_id = artists.id -INNER JOIN albums -ON "Albumartists".album_id = albums.id -WHERE artists.name = {ARTIST}; -``` - -Get all songs from specified artist: -```sql -SELECT artists.name, songs.name -FROM "Songartists" -INNER JOIN artists -ON "Songartists".artist_id = artists.id -INNER JOIN songs -ON "Songartists".song_id = songs.id -WHERE artists.name = {ARTIST}; -``` - -Get all songs from any album of the specified name: -```sql -SELECT songs.name -FROM "Albumsongs" -INNER JOIN albums -ON "Albumsongs".album_id = albums.id -INNER JOIN songs -ON "Albumsongs".song_id = songs.id -WHERE albums.name = {ALBUM}; -``` - -Sort all songs by plays (does not list artist or album): -```sql -SELECT songs.name, COUNT(scrobbles.song_id) AS scount -FROM songs, scrobbles -WHERE songs.id = scrobbles.song_id -GROUP BY songs.id -ORDER BY scount DESC; -``` - -Sort all songs by plays, and include artist: -```sql -SELECT songs.name, artists.name, COUNT(scrobbles.song_id) AS scount -FROM scrobbles, "Songartists" -INNER JOIN artists -ON "Songartists".artist_id = artists.id -INNER JOIN songs -ON "Songartists".song_id = songs.id -WHERE songs.id = scrobbles.song_id -GROUP BY songs.id, artists.id -ORDER BY scount DESC; -``` - -Sort all songs by plays, and include artist and album: -```sql -SELECT songs.name, artists.name, albums.name, COUNT(scrobbles.song_id) AS scount -FROM scrobbles CROSS JOIN "Songartists" CROSS JOIN "Albumsongs" -INNER JOIN artists -ON "Songartists".artist_id = artists.id -INNER JOIN songs -ON "Songartists".song_id = songs.id AND "Albumsongs".song_id = songs.id -INNER JOIN albums -ON "Albumsongs".album_id = albums.id -WHERE songs.id = scrobbles.song_id -GROUP BY songs.id, artists.id, albums.id -ORDER BY scount DESC; -``` - -Sort all albums by plays, and include artist: -```sql -SELECT albums.name, artists.name, COUNT(scrobbles.album_id) AS scount -FROM scrobbles, "Albumartists" -INNER JOIN albums -ON "Albumartists".album_id = albums.id -INNER JOIN artists -ON "Albumartists".artist_id = artists.id -WHERE albums.id = scrobbles.album_id -GROUP BY artists.id, albums.id -ORDER BY scount DESC; -``` - -Sort all artists by plays: -```sql -SELECT artists.name, COUNT(scrobbles.id) AS scount -FROM artists, "Scrobbleartists" -INNER JOIN scrobbles -ON scrobbles.id = "Scrobbleartists".scrobble_id -WHERE "Scrobbleartists".artist_id = artists.id -GROUP BY artists.id -ORDER BY scount DESC; -``` - -Sort all artists by alphabetical order, and include the first time you listened to that artist: -```sql -SELECT artists.name, MIN(scrobbles.date) -FROM "Scrobbleartists" -INNER JOIN artists -ON "Scrobbleartists".artist_id = artists.id -INNER JOIN scrobbles -ON "Scrobbleartists".scrobble_id = scrobbles.id -GROUP BY artists.id -ORDER BY artists.name ASC; -``` - -Sort all songs by alphabetical order, and include the first time you listened to that song: -```sql -SELECT songs.name, MIN(scrobbles.date) -FROM scrobbles -INNER JOIN songs -ON scrobbles.song_id = songs.id -GROUP BY songs.id -ORDER BY songs.name ASC; -``` - -Sort all albums by alphabetical order, and include the first time you listened to that album: -```sql -SELECT albums.name, MIN(scrobbles.date) -FROM scrobbles -INNER JOIN albums -ON scrobbles.album_id = albums.id -GROUP BY albums.id -ORDER BY albums.name ASC; -``` - -Select all songs by specified artists, include the number of plays of each song, and sort by plays: -```sql -SELECT songs.name, COUNT(scrobbles.song_id) as count -FROM songs, "Scrobbleartists" -INNER JOIN artists -ON "Scrobbleartists".artist_id = artists.id -INNER JOIN scrobbles -ON "Scrobbleartists".scrobble_id = scrobbles.id -WHERE songs.id = scrobbles.song_id AND artists.name = {ARTIST} -GROUP BY songs.id -ORDER BY count DESC; -``` - -Select all albums by specified artist, include the number of plays of each album, and sort by plays: -```sql -SELECT albums.name, COUNT(scrobbles.song_id) as count -FROM albums, "Scrobbleartists" -INNER JOIN artists -ON "Scrobbleartists".artist_id = artists.id -INNER JOIN scrobbles -ON "Scrobbleartists".scrobble_id = scrobbles.id -WHERE albums.id = scrobbles.album_id AND artists.name = {ARTIST} -GROUP BY albums.id -ORDER BY count DESC; -``` - -Select all songs from an album specified by an ID, and sort by plays -```sql -SELECT songs.name, COUNT(scrobbles.song_id) AS count -FROM "Albumsongs" -INNER JOIN songs -ON songs.id = "Albumsongs".song_id -INNER JOIN scrobbles -ON scrobbles.song_id = "Albumsongs".song_id -WHERE "Albumsongs".album_id = {ALBUM_ID} -GROUP BY songs.id -ORDER BY count DESC; -``` \ No newline at end of file From 4758885c68469aadcc0d1b0455ac9f6f4447cc1c Mon Sep 17 00:00:00 2001 From: mitteneer Date: Mon, 5 May 2025 13:09:16 -0400 Subject: [PATCH 5/6] Keep cleaning --- src/app/middleware/DemoMiddleware.zig | 65 --------------------------- src/app/views/partials/_history.zmpl | 0 src/app/views/partials/_random.zmpl | 0 src/app/views/partials/_recent.zmpl | 0 4 files changed, 65 deletions(-) delete mode 100644 src/app/middleware/DemoMiddleware.zig delete mode 100644 src/app/views/partials/_history.zmpl delete mode 100644 src/app/views/partials/_random.zmpl delete mode 100644 src/app/views/partials/_recent.zmpl diff --git a/src/app/middleware/DemoMiddleware.zig b/src/app/middleware/DemoMiddleware.zig deleted file mode 100644 index a6758d2..0000000 --- a/src/app/middleware/DemoMiddleware.zig +++ /dev/null @@ -1,65 +0,0 @@ -/// Demo middleware. Assign middleware by declaring `pub const middleware` in the -/// `jetzig_options` defined in your application's `src/main.zig`. -/// -/// Middleware is called before and after the request, providing full access to the active -/// request, allowing you to execute any custom code for logging, tracking, inserting response -/// headers, etc. -/// -/// This middleware is configured in the demo app's `src/main.zig`: -/// -/// ``` -/// pub const jetzig_options = struct { -/// pub const middleware: []const type = &.{@import("app/middleware/DemoMiddleware.zig")}; -/// }; -/// ``` -const std = @import("std"); -const jetzig = @import("jetzig"); - -/// Define any custom data fields you want to store here. Assigning to these fields in the `init` -/// function allows you to access them in various middleware callbacks defined below, where they -/// can also be modified. -my_custom_value: []const u8, - -const Self = @This(); - -/// Initialize middleware. -pub fn init(request: *jetzig.http.Request) !*Self { - var middleware = try request.allocator.create(Self); - middleware.my_custom_value = "initial value"; - return middleware; -} - -/// Invoked immediately after the request is received but before it has started processing. -/// Any calls to `request.render` or `request.redirect` will prevent further processing of the -/// request, including any other middleware in the chain. -pub fn afterRequest(self: *Self, request: *jetzig.http.Request) !void { - try request.server.logger.DEBUG( - "[DemoMiddleware:afterRequest] my_custom_value: {s}", - .{self.my_custom_value}, - ); - self.my_custom_value = @tagName(request.method); -} - -/// Invoked immediately before the response renders to the client. -/// The response can be modified here if needed. -pub fn beforeResponse(self: *Self, request: *jetzig.http.Request, response: *jetzig.http.Response) !void { - try request.server.logger.DEBUG( - "[DemoMiddleware:beforeResponse] my_custom_value: {s}, response status: {s}", - .{ self.my_custom_value, @tagName(response.status_code) }, - ); -} - -/// Invoked immediately after the response has been finalized and sent to the client. -/// Response data can be accessed for logging, but any modifications will have no impact. -pub fn afterResponse(self: *Self, request: *jetzig.http.Request, response: *jetzig.http.Response) !void { - _ = self; - _ = response; - try request.server.logger.DEBUG("[DemoMiddleware:afterResponse] response completed", .{}); -} - -/// Invoked after `afterResponse` is called. Use this function to do any clean-up. -/// Note that `request.allocator` is an arena allocator, so any allocations are automatically -/// freed before the next request starts processing. -pub fn deinit(self: *Self, request: *jetzig.http.Request) void { - request.allocator.destroy(self); -} diff --git a/src/app/views/partials/_history.zmpl b/src/app/views/partials/_history.zmpl deleted file mode 100644 index e69de29..0000000 diff --git a/src/app/views/partials/_random.zmpl b/src/app/views/partials/_random.zmpl deleted file mode 100644 index e69de29..0000000 diff --git a/src/app/views/partials/_recent.zmpl b/src/app/views/partials/_recent.zmpl deleted file mode 100644 index e69de29..0000000 From 153ea869e013ac8ac195699ece6d59de2132a3f2 Mon Sep 17 00:00:00 2001 From: mitteneer Date: Thu, 8 May 2025 18:17:45 -0400 Subject: [PATCH 6/6] Work on making partials for views --- build.zig.zon | 8 +-- src/app/views/albums.zig | 14 ++--- src/app/views/albums/get.zmpl | 16 ++--- src/app/views/albums/index.zmpl | 37 ++---------- src/app/views/artists.zig | 20 ++++--- src/app/views/artists/get.zmpl | 53 ++++------------ .../views/partials/_firstlast_listens.zmpl | 9 +++ src/app/views/partials/_newtable.zmpl | 60 ++++++++++++------- src/types.zig | 17 +++--- 9 files changed, 102 insertions(+), 132 deletions(-) create mode 100644 src/app/views/partials/_firstlast_listens.zmpl diff --git a/build.zig.zon b/build.zig.zon index c06a1ac..f2e5778 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -17,12 +17,12 @@ // internet connectivity. .dependencies = .{ .jetzig = .{ - .url = "https://github.com/jetzig-framework/jetzig/archive/1feb18fb74e626fe068ec67532318640a9cb83be.tar.gz", - .hash = "jetzig-0.0.0-IpAgLfMzDwDyAqZ05btcLDd9dfE_bxUbfOI_Wx7a19ed", + .url = "https://github.com/jetzig-framework/jetzig/archive/a298192bb0cddf9c45d7d0d976a9852804457de2.tar.gz", + .hash = "jetzig-0.0.0-IpAgLf5aDwB4UOKMhIjtK22zBsPfbWEwCYgHT0hayyT-", }, .zeit = .{ - .url = "https://github.com/rockorager/zeit/archive/refs/heads/main.tar.gz", - .hash = "zeit-0.6.0-5I6bk5daAgC-P60TjxRqW0bYknfCGxJp-03eS9UjGrO7", + .url = "https://github.com/rockorager/zeit/archive/refs/tags/v0.6.0.tar.gz", + .hash = "zeit-0.0.0-5I6bk_pZAgB03N1p1GmVOZ--gOFwwQSRKj1UXb5tnaKS", }, }, .paths = .{ diff --git a/src/app/views/albums.zig b/src/app/views/albums.zig index 06d6831..1264dac 100644 --- a/src/app/views/albums.zig +++ b/src/app/views/albums.zig @@ -29,19 +29,19 @@ pub fn index(request: *jetzig.Request) !jetzig.View { if (album.id == prev_album_id) { var artist_info = try prev_artist_infos.?.append(.object); try artist_info.put("name", album.artist_name); - try artist_info.put("url", album.artist_id); + try artist_info.put("id", album.artist_id); continue :blk; } var album_view = try albums_view.append(.object); + try album_view.put("name", album.name); + try album_view.put("id", album.id); + try album_view.put("scrobbles", album.scrobbles); + var artist_infos = try album_view.put("artist_info", .array); var artist_info = try artist_infos.append(.object); try artist_info.put("name", album.artist_name); - try artist_info.put("url", album.artist_id); - - try album_view.put("name", album.name); - try album_view.put("url", album.id); - try album_view.put("scrobbles", album.scrobbles); + try artist_info.put("id", album.artist_id); prev_artist_infos = artist_infos; prev_album_id = album.id; @@ -74,7 +74,7 @@ pub fn get(id: []const u8, request: *jetzig.Request) !jetzig.View { const song = try song_row.to(Song, .{ .dupe = true, .allocator = request.allocator }); var song_view = try songs_view.append(.object); try song_view.put("name", song.name); - try song_view.put("url", song.id); + try song_view.put("id", song.id); try song_view.put("scrobbles", song.scrobbles); } return request.render(.ok); diff --git a/src/app/views/albums/get.zmpl b/src/app/views/albums/get.zmpl index 8084038..3a1641b 100644 --- a/src/app/views/albums/get.zmpl +++ b/src/app/views/albums/get.zmpl @@ -1,3 +1,8 @@ +@zig { + const ColumnChoices = []const enum{song, album, artist, artistlist, scrobbles, date}; + const columns: ColumnChoices = &.{.song, .scrobbles}; +} + @@ -5,15 +10,6 @@ @partial partials/header

{{.album}}

- - - -@for (.songs) |song| { - - - - -} -
Name
{{song.name}}{{song.scrobbles}}
+@partial partials/newtable(T: ColumnChoices, table_data: .songs, columns: columns) \ No newline at end of file diff --git a/src/app/views/albums/index.zmpl b/src/app/views/albums/index.zmpl index e5536eb..43ff1de 100644 --- a/src/app/views/albums/index.zmpl +++ b/src/app/views/albums/index.zmpl @@ -1,40 +1,15 @@ +@zig { + const ColumnChoices = []const enum{song, album, artist, artistlist, scrobbles, date}; + const columns: ColumnChoices = &.{.album, .artistlist, .scrobbles}; +} + - @partial partials/header

Albums

- - - - - - - - - -@for (.albums) |album| { - - - - - -} - -
NameArtist(s)Scrobbles
{{album.name}} - @for (album.get("artist_info").?) |ai| { - {{ai.name}} - } - {{album.scrobbles}}
- - +@partial partials/newtable(T: ColumnChoices, table_data: .albums, columns: columns) \ No newline at end of file diff --git a/src/app/views/artists.zig b/src/app/views/artists.zig index 4164fc1..34cea3e 100644 --- a/src/app/views/artists.zig +++ b/src/app/views/artists.zig @@ -138,19 +138,23 @@ pub fn get(id: []const u8, request: *jetzig.Request) !jetzig.View { defer first_last_songs_jq_result.deinit(); // These look backwards, but it's correct this way + var last_song_view = try root.put("last", .object); + if (try first_last_songs_jq_result.postgresql.result.next()) |last_song_row| { const last_song = try last_song_row.to(ScrobbleResult, .{ .dupe = true, .allocator = request.allocator }); - try root.put("last_song_name", last_song.name); - try root.put("last_song_id", last_song.id); - try root.put("last_song_date", (try dateFmt(request.allocator, last_song.date))); - } + try last_song_view.put("name", last_song.name); + try last_song_view.put("id", last_song.id); + try last_song_view.put("date", (try dateFmt(request.allocator, last_song.date))); + } else unreachable; + + var first_song_view = try root.put("first", .object); if (try first_last_songs_jq_result.postgresql.result.next()) |first_song_row| { const first_song = try first_song_row.to(ScrobbleResult, .{ .dupe = true, .allocator = request.allocator }); - try root.put("first_song_name", first_song.name); - try root.put("first_song_id", first_song.id); - try root.put("first_song_date", (try dateFmt(request.allocator, first_song.date))); - } + try first_song_view.put("name", first_song.name); + try first_song_view.put("id", first_song.id); + try first_song_view.put("date", (try dateFmt(request.allocator, first_song.date))); + } else unreachable; try first_last_songs_jq_result.drain(); diff --git a/src/app/views/artists/get.zmpl b/src/app/views/artists/get.zmpl index adf6158..48c1c25 100644 --- a/src/app/views/artists/get.zmpl +++ b/src/app/views/artists/get.zmpl @@ -1,53 +1,22 @@ +@zig { + const ColumnChoices = []const enum{song, album, artist, artistlist, scrobbles, date}; + const columns: ColumnChoices = &.{.album, .scrobbles}; +} + - @partial partials/header

{{.artist.name}}

-{{.artist.scrobbles}} scrobbles ({{.artist.rank}} place) -
-First listen: {{.first_song_name}} ({{.first_song_date}}) -
-Most recent listen: {{.last_song_name}} ({{.last_song_date}}) +@partial partials/firstlast_listens(scrobbles: .artist.scrobbles, rank: .artist.rank, last_song: .last, first_song: .first) +

Albums

- - - - - - - -@for (.albums) |album| { - - - - -} - -
NameScrobbles
{{album.name}}{{album.scrobbles}}
+@partial partials/newtable(T: ColumnChoices, table_data: .albums, columns: columns) +

Albums Featured On

- - - - - - - - @for (.appears) |album| { - - - - - } - -
NameScrobbles
{{album.name}}{{album.scrobbles}}
- - +@partial partials/newtable(T: ColumnChoices, table_data: .appears, columns: columns) + \ No newline at end of file diff --git a/src/app/views/partials/_firstlast_listens.zmpl b/src/app/views/partials/_firstlast_listens.zmpl new file mode 100644 index 0000000..322a0e8 --- /dev/null +++ b/src/app/views/partials/_firstlast_listens.zmpl @@ -0,0 +1,9 @@ +@args scrobbles: i64, rank: []const u8, last_song: *ZmplValue, first_song: *ZmplValue + +
+{{scrobbles}} scrobbles ({{rank}} place) +
+First listen: {{first_song.name}} ({{first_song.date}}) +
+Most recent listen: {{last_song.name}} ({{last_song.date}}) +
\ No newline at end of file diff --git a/src/app/views/partials/_newtable.zmpl b/src/app/views/partials/_newtable.zmpl index bee43c1..8960e21 100644 --- a/src/app/views/partials/_newtable.zmpl +++ b/src/app/views/partials/_newtable.zmpl @@ -1,18 +1,29 @@ -@args table_data *ZmplValue, table_headers: []enum{Song, Album, Artist, Scrobbles, Date} +@args T: type, table_data: *ZmplValue, columns: T
@zig { - for (table_headers) |header| { + for (columns) |header| { switch (header) { - .Artist => { + .song => { + + }, + .album => { + + }, + .artist => { + + }, + .artistlist => { }, - inline else => |other| { - const h = @tagName(other); - + .scrobbles => { + }, + .date => { + + } } } } @@ -20,35 +31,38 @@ @zig { - for (table_data) |data| { + const array = table_data.items(.array); + for (array) |ent| { - for (table_header) |header| { + for (columns) |header| { switch (header) { - .Song => { + .song, .album, .artist => { + const path = switch (header) { + .song => "songs", + .album => "albums", + .artist => "artists", + else => unreachable + }; }, - .Album => { + .artistlist => { - }, - .Artist => { - }, - .Scrobbles => { - + .scrobbles => { + }, - .Date =>{ - + .date =>{ + } - }; + } } + } } diff --git a/src/types.zig b/src/types.zig index 2574610..455f282 100644 --- a/src/types.zig +++ b/src/types.zig @@ -62,10 +62,13 @@ pub const Rules = struct { rules: []const Rule, }; -pub const Headers = []enum { - Song, - Album, - Artist, - Scrobbles, - Date, -}; +// Can't import types in .zmpl files, so defining this here +// doesn't really do much (except maybe in the .zig file for views?) +//pub const HeaderTypes = []enum { +// song, +// album, +// artist, +// artistlist, +// scrobbles, +// date, +//};
SongAlbumArtistArtist(s){{h}}ScrobblesDate
- {{data.name}} + {{ent.name}} - {{data.name}} - - @for (data.get("artist_info").?) |ai| { - {{ai.name}} + @for (ent.get("artist_info").?) |artist| { + {{artist.name}} } {{data.scrobbles}}{{ent.scrobbles}}{{data.date}}{{ent.date}}