diff --git a/build.zig.zon b/build.zig.zon
index d5fa9fa..306d79f 100644
--- a/build.zig.zon
+++ b/build.zig.zon
@@ -1,8 +1,9 @@
.{
- .name = "zuletzt",
+ .name = .zuletzt,
// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",
+ .fingerprint = 0xfe1b5c182b3fe5f,
// This field is optional.
// This is currently advisory only; Zig does not yet do anything
@@ -16,8 +17,8 @@
// internet connectivity.
.dependencies = .{
.jetzig = .{
- .url = "https://github.com/jetzig-framework/jetzig/archive/8a4f91f26a5d6a9b34a47011e63e779280590bc2.tar.gz",
- .hash = "1220dac633f4b6a3c40d2b8d5a3cb2fdd513601eb762ccb15c418e0646923d42cfe9",
+ .url = "https://github.com/jetzig-framework/jetzig/archive/d3157e4247211091127daba88a2552af3be8f5ed.tar.gz",
+ .hash = "jetzig-0.0.0-IpAgLe0QDwC-6XH_ElHKUmPGxGxr1XdgiLeHEalerM7B",
},
.zeit = .{
.url = "https://github.com/rockorager/zeit/archive/refs/heads/main.tar.gz",
@@ -31,10 +32,12 @@
// in the same contents hash.
"",
// For example...
- //"build.zig",
- //"build.zig.zon",
- //"src",
- //"LICENSE",
- //"README.md",
+ "build.zig",
+ "build.zig.zon",
+ "src",
+ "LICENSE",
+ "README.md",
+ "public",
+ "config",
},
}
diff --git a/common_queries.md b/common_queries.md
index 4ec13b1..85b24d8 100644
--- a/common_queries.md
+++ b/common_queries.md
@@ -1,7 +1,3 @@
-> [!note] Notice
-> Queries involving artists are likely inaccurate due to database structure and
-> limitations of scrobbles. Specifics and fixes are being planned.
-
Get all albums from specified artist:
```sql
SELECT artists.name, albums.name
@@ -95,3 +91,61 @@ 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.name
+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.name
+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.name
+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.name
+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.name
+ORDER BY count DESC;
+```
\ No newline at end of file
diff --git a/src/app/views/album.zig b/src/app/views/albums.zig
similarity index 73%
rename from src/app/views/album.zig
rename to src/app/views/albums.zig
index 9a7bc76..07cf4a1 100644
--- a/src/app/views/album.zig
+++ b/src/app/views/albums.zig
@@ -1,12 +1,31 @@
const std = @import("std");
const jetzig = @import("jetzig");
+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 albums = try request.repo.all(query);
+ for (albums) |album| {
+ var album_view = try albums_view.append(.object);
+ try album_view.put("name", album.name);
+ try album_view.put("url", album.id);
+ }
return request.render(.ok);
}
pub fn get(id: []const u8, request: *jetzig.Request) !jetzig.View {
- _ = id;
+ var root = try request.data(.object);
+ try root.put("album_id", id);
+ var songs_view = try root.put("songs", .array);
+ const query = jetzig.database.Query(.Albumsong).include(.song, .{ .select = .{ .name, .id } }).join(.inner, .album).where(.{ .album = .{ .id = id } });
+ const songs = try request.repo.all(query);
+ for (songs) |song| {
+ var song_view = try songs_view.append(.object);
+ try song_view.put("name", song.song.name);
+ try song_view.put("url", song.song.id);
+ }
return request.render(.ok);
}
@@ -38,7 +57,6 @@ pub fn delete(id: []const u8, request: *jetzig.Request) !jetzig.View {
return request.render(.ok);
}
-
test "index" {
var app = try jetzig.testing.app(std.testing.allocator, @import("routes"));
defer app.deinit();
diff --git a/src/app/views/album/delete.zmpl b/src/app/views/albums/delete.zmpl
similarity index 100%
rename from src/app/views/album/delete.zmpl
rename to src/app/views/albums/delete.zmpl
diff --git a/src/app/views/album/edit.zmpl b/src/app/views/albums/edit.zmpl
similarity index 100%
rename from src/app/views/album/edit.zmpl
rename to src/app/views/albums/edit.zmpl
diff --git a/src/app/views/albums/get.zmpl b/src/app/views/albums/get.zmpl
new file mode 100644
index 0000000..ac3760d
--- /dev/null
+++ b/src/app/views/albums/get.zmpl
@@ -0,0 +1,19 @@
+
+
+
+
\ No newline at end of file
diff --git a/src/app/views/album/new.zmpl b/src/app/views/albums/new.zmpl
similarity index 100%
rename from src/app/views/album/new.zmpl
rename to src/app/views/albums/new.zmpl
diff --git a/src/app/views/album/patch.zmpl b/src/app/views/albums/patch.zmpl
similarity index 100%
rename from src/app/views/album/patch.zmpl
rename to src/app/views/albums/patch.zmpl
diff --git a/src/app/views/album/post.zmpl b/src/app/views/albums/post.zmpl
similarity index 100%
rename from src/app/views/album/post.zmpl
rename to src/app/views/albums/post.zmpl
diff --git a/src/app/views/album/put.zmpl b/src/app/views/albums/put.zmpl
similarity index 100%
rename from src/app/views/album/put.zmpl
rename to src/app/views/albums/put.zmpl
diff --git a/src/app/views/artist/get.zmpl b/src/app/views/artist/get.zmpl
deleted file mode 100644
index 76457d0..0000000
--- a/src/app/views/artist/get.zmpl
+++ /dev/null
@@ -1,3 +0,0 @@
-
+
+
\ No newline at end of file
diff --git a/src/app/views/artist/new.zmpl b/src/app/views/artists/new.zmpl
similarity index 100%
rename from src/app/views/artist/new.zmpl
rename to src/app/views/artists/new.zmpl
diff --git a/src/app/views/artist/patch.zmpl b/src/app/views/artists/patch.zmpl
similarity index 100%
rename from src/app/views/artist/patch.zmpl
rename to src/app/views/artists/patch.zmpl
diff --git a/src/app/views/artist/post.zmpl b/src/app/views/artists/post.zmpl
similarity index 100%
rename from src/app/views/artist/post.zmpl
rename to src/app/views/artists/post.zmpl
diff --git a/src/app/views/artist/put.zmpl b/src/app/views/artists/put.zmpl
similarity index 100%
rename from src/app/views/artist/put.zmpl
rename to src/app/views/artists/put.zmpl
diff --git a/src/app/views/song/get.zmpl b/src/app/views/song/get.zmpl
deleted file mode 100644
index 76457d0..0000000
--- a/src/app/views/song/get.zmpl
+++ /dev/null
@@ -1,3 +0,0 @@
-
diff --git a/src/app/views/song.zig b/src/app/views/songs.zig
similarity index 100%
rename from src/app/views/song.zig
rename to src/app/views/songs.zig
diff --git a/src/app/views/song/delete.zmpl b/src/app/views/songs/delete.zmpl
similarity index 100%
rename from src/app/views/song/delete.zmpl
rename to src/app/views/songs/delete.zmpl
diff --git a/src/app/views/song/edit.zmpl b/src/app/views/songs/edit.zmpl
similarity index 100%
rename from src/app/views/song/edit.zmpl
rename to src/app/views/songs/edit.zmpl
diff --git a/src/app/views/album/get.zmpl b/src/app/views/songs/get.zmpl
similarity index 100%
rename from src/app/views/album/get.zmpl
rename to src/app/views/songs/get.zmpl
diff --git a/src/app/views/album/index.zmpl b/src/app/views/songs/index.zmpl
similarity index 100%
rename from src/app/views/album/index.zmpl
rename to src/app/views/songs/index.zmpl
diff --git a/src/app/views/song/new.zmpl b/src/app/views/songs/new.zmpl
similarity index 100%
rename from src/app/views/song/new.zmpl
rename to src/app/views/songs/new.zmpl
diff --git a/src/app/views/song/patch.zmpl b/src/app/views/songs/patch.zmpl
similarity index 100%
rename from src/app/views/song/patch.zmpl
rename to src/app/views/songs/patch.zmpl
diff --git a/src/app/views/song/post.zmpl b/src/app/views/songs/post.zmpl
similarity index 100%
rename from src/app/views/song/post.zmpl
rename to src/app/views/songs/post.zmpl
diff --git a/src/app/views/song/put.zmpl b/src/app/views/songs/put.zmpl
similarity index 100%
rename from src/app/views/song/put.zmpl
rename to src/app/views/songs/put.zmpl