From a15db5fb312c889313e87fb28c6cbea647ff4e5b Mon Sep 17 00:00:00 2001 From: mitteneer Date: Wed, 20 Nov 2024 18:17:14 -0500 Subject: [PATCH] Add views and begin database --- build.zig.zon | 4 +- config/database.zig | 28 ++++ src/app/database/Schema.zig | 130 ++++++++++++++++++ src/app/database/data.db | Bin 16384 -> 0 bytes .../2024-11-15_14-46-12_create_artists.zig | 26 ++++ .../2024-11-15_14-58-47_create_songs.zig | 27 ++++ ...024-11-15_17-52-04_create_artist_songs.zig | 20 +++ ...24-11-15_17-52-28_create_artist_albums.zig | 20 +++ ...2024-11-15_17-52-54_create_album_songs.zig | 20 +++ .../2024-11-20_00-19-54_create_scrobble.zig | 19 +++ .../2024-11-20_19-08-02_create_albums.zig | 28 ++++ src/app/lib/db.zig | 22 --- .../lastfmMiddleware.zig} | 0 .../spotifyMiddleware.zig} | 0 src/app/views/collection.zig | 36 +++++ .../index.zmpl => collection/delete.zmpl} | 0 src/app/views/collection/get.zmpl | 3 + src/app/views/collection/index.zmpl | 8 ++ 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.zig | 36 +++++ src/app/views/concerts/delete.zmpl | 3 + src/app/views/concerts/get.zmpl | 3 + src/app/views/concerts/index.zmpl | 8 ++ 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.zig | 36 +++++ src/app/views/lists/delete.zmpl | 3 + src/app/views/lists/get.zmpl | 3 + src/app/views/lists/index.zmpl | 8 ++ src/app/views/lists/patch.zmpl | 3 + src/app/views/lists/post.zmpl | 3 + src/app/views/lists/put.zmpl | 3 + src/app/views/music.zig | 41 ------ src/app/views/music/index.zmpl | 2 - src/app/views/partials/_header.zmpl | 7 + .../_random.zmpl => partials/_history.zmpl} | 0 .../_recent.zmpl => partials/_random.zmpl} | 0 src/app/views/partials/_recent.zmpl | 0 src/app/views/partials/_table.zmpl | 0 src/app/views/{root => partials}/_top.zmpl | 0 src/app/views/ratings.zig | 36 +++++ src/app/views/ratings/delete.zmpl | 3 + src/app/views/ratings/get.zmpl | 3 + src/app/views/ratings/index.zmpl | 8 ++ src/app/views/ratings/patch.zmpl | 3 + src/app/views/ratings/post.zmpl | 3 + src/app/views/ratings/put.zmpl | 3 + src/app/views/root/_header.zmpl | 6 - src/app/views/root/index.zmpl | 5 +- src/app/views/scrobbles.zig | 36 +++++ src/app/views/scrobbles/delete.zmpl | 3 + src/app/views/scrobbles/get.zmpl | 3 + src/app/views/scrobbles/index.zmpl | 8 ++ src/app/views/scrobbles/patch.zmpl | 3 + src/app/views/scrobbles/post.zmpl | 3 + src/app/views/scrobbles/put.zmpl | 3 + src/app/views/stats.zig | 7 - src/app/views/upload.zig | 48 +++++++ src/app/views/upload/delete.zmpl | 3 + src/app/views/upload/get.zmpl | 3 + src/app/views/upload/index.zmpl | 19 +++ src/app/views/upload/patch.zmpl | 3 + src/app/views/upload/post.zmpl | 3 + src/app/views/upload/put.zmpl | 3 + src/main.zig | 13 +- 68 files changed, 709 insertions(+), 90 deletions(-) create mode 100644 config/database.zig create mode 100644 src/app/database/Schema.zig delete mode 100644 src/app/database/data.db create mode 100644 src/app/database/migrations/2024-11-15_14-46-12_create_artists.zig create mode 100644 src/app/database/migrations/2024-11-15_14-58-47_create_songs.zig create mode 100644 src/app/database/migrations/2024-11-15_17-52-04_create_artist_songs.zig create mode 100644 src/app/database/migrations/2024-11-15_17-52-28_create_artist_albums.zig create mode 100644 src/app/database/migrations/2024-11-15_17-52-54_create_album_songs.zig create mode 100644 src/app/database/migrations/2024-11-20_00-19-54_create_scrobble.zig create mode 100644 src/app/database/migrations/2024-11-20_19-08-02_create_albums.zig delete mode 100644 src/app/lib/db.zig rename src/app/{views/root/_graph.zmpl => middleware/lastfmMiddleware.zig} (100%) rename src/app/{views/root/_history.zmpl => middleware/spotifyMiddleware.zig} (100%) create mode 100644 src/app/views/collection.zig rename src/app/views/{stats/index.zmpl => collection/delete.zmpl} (100%) create mode 100644 src/app/views/collection/get.zmpl create mode 100644 src/app/views/collection/index.zmpl create mode 100644 src/app/views/collection/patch.zmpl create mode 100644 src/app/views/collection/post.zmpl create mode 100644 src/app/views/collection/put.zmpl create mode 100644 src/app/views/concerts.zig create mode 100644 src/app/views/concerts/delete.zmpl create mode 100644 src/app/views/concerts/get.zmpl create mode 100644 src/app/views/concerts/index.zmpl create mode 100644 src/app/views/concerts/patch.zmpl create mode 100644 src/app/views/concerts/post.zmpl create mode 100644 src/app/views/concerts/put.zmpl create mode 100644 src/app/views/lists.zig create mode 100644 src/app/views/lists/delete.zmpl create mode 100644 src/app/views/lists/get.zmpl create mode 100644 src/app/views/lists/index.zmpl create mode 100644 src/app/views/lists/patch.zmpl create mode 100644 src/app/views/lists/post.zmpl create mode 100644 src/app/views/lists/put.zmpl delete mode 100644 src/app/views/music.zig delete mode 100644 src/app/views/music/index.zmpl create mode 100644 src/app/views/partials/_header.zmpl rename src/app/views/{root/_random.zmpl => partials/_history.zmpl} (100%) rename src/app/views/{root/_recent.zmpl => partials/_random.zmpl} (100%) create mode 100644 src/app/views/partials/_recent.zmpl create mode 100644 src/app/views/partials/_table.zmpl rename src/app/views/{root => partials}/_top.zmpl (100%) create mode 100644 src/app/views/ratings.zig create mode 100644 src/app/views/ratings/delete.zmpl create mode 100644 src/app/views/ratings/get.zmpl create mode 100644 src/app/views/ratings/index.zmpl create mode 100644 src/app/views/ratings/patch.zmpl create mode 100644 src/app/views/ratings/post.zmpl create mode 100644 src/app/views/ratings/put.zmpl delete mode 100644 src/app/views/root/_header.zmpl create mode 100644 src/app/views/scrobbles.zig create mode 100644 src/app/views/scrobbles/delete.zmpl create mode 100644 src/app/views/scrobbles/get.zmpl create mode 100644 src/app/views/scrobbles/index.zmpl create mode 100644 src/app/views/scrobbles/patch.zmpl create mode 100644 src/app/views/scrobbles/post.zmpl create mode 100644 src/app/views/scrobbles/put.zmpl delete mode 100644 src/app/views/stats.zig create mode 100644 src/app/views/upload.zig create mode 100644 src/app/views/upload/delete.zmpl create mode 100644 src/app/views/upload/get.zmpl create mode 100644 src/app/views/upload/index.zmpl create mode 100644 src/app/views/upload/patch.zmpl create mode 100644 src/app/views/upload/post.zmpl create mode 100644 src/app/views/upload/put.zmpl diff --git a/build.zig.zon b/build.zig.zon index 9b7f253..e541ab2 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -16,8 +16,8 @@ // internet connectivity. .dependencies = .{ .jetzig = .{ - .url = "https://github.com/jetzig-framework/jetzig/archive/dda433bb73000614482af10a277d47dc9d89600c.tar.gz", - .hash = "12202ce84b803a8b300c91d98afbc7c326298b55a23bf05cf603182e934b621008ec", + .url = "https://github.com/jetzig-framework/jetzig/archive/d887cd5bd88eef611fc145e8acb12eee05b9aeef.tar.gz", + .hash = "12204458ae2b5cb93339296d7ac0f90fc0a0292711fcd82156b6595131fc0a96c648", }, }, .paths = .{ diff --git a/config/database.zig b/config/database.zig new file mode 100644 index 0000000..56b00ec --- /dev/null +++ b/config/database.zig @@ -0,0 +1,28 @@ +pub const database = .{ + .testing = .{ + .adapter = .postgresql, + .hostname = "localhost", + .port = 5432, + .username = "postgres", + .password = "postgres", + .database = "zuletzt_testing", + }, + + .development = .{ + .adapter = .postgresql, + .hostname = "localhost", + .port = 5432, + .username = "postgres", + .password = "postgres", + .database = "zuletzt_dev", + }, + + .production = .{ + .adapter = .postgresql, + .hostname = "localhost", + .port = 5432, + .username = "postgres", + .password = "postgres", + .database = "zuletzt", + }, +}; diff --git a/src/app/database/Schema.zig b/src/app/database/Schema.zig new file mode 100644 index 0000000..7e30fee --- /dev/null +++ b/src/app/database/Schema.zig @@ -0,0 +1,130 @@ +const jetquery = @import("jetzig").jetquery; + +pub const AlbumSong = jetquery.Model( + @This(), + "album_songs", + struct { + id: i32, + album_id: i32, + song_id: i32, + created_at: jetquery.DateTime, + updated_at: jetquery.DateTime, + }, + .{}, +); + +pub const Album = jetquery.Model( + @This(), + "albums", + struct { + id: i32, + title: []const u8, + song_num: i32, + length: f64, + play_count: i32, + score: f64, + avg_song_score: f64, + url: []const u8, + holiday: bool, + compilation: bool, + collaboration: bool, + created_at: jetquery.DateTime, + updated_at: jetquery.DateTime, + }, + .{ + .relations = .{ + .scrobbles = jetquery.hasMany(.Scrobble, .{}), + }, + }, +); + +pub const ArtistAlbum = jetquery.Model( + @This(), + "artist_albums", + struct { + id: i32, + artist_id: i32, + album_id: i32, + created_at: jetquery.DateTime, + updated_at: jetquery.DateTime, + }, + .{}, +); + +pub const ArtistSong = jetquery.Model( + @This(), + "artist_songs", + struct { + id: i32, + artist_id: i32, + song_id: i32, + created_at: jetquery.DateTime, + updated_at: jetquery.DateTime, + }, + .{}, +); + +pub const Artist = jetquery.Model( + @This(), + "artists", + struct { + id: i32, + name: []const u8, + album_num: i32, + song_num: i32, + play_count: i32, + avg_album_score: f64, + avg_song_score: f64, + url: []const u8, + aliased: bool, + created_at: jetquery.DateTime, + updated_at: jetquery.DateTime, + }, + .{ + .relations = .{ + .scrobbles = jetquery.hasMany(.Scrobble, .{}), + }, + }, +); + +pub const Scrobble = jetquery.Model( + @This(), + "scrobbles", + struct { + id: i32, + date: jetquery.DateTime, + created_at: jetquery.DateTime, + updated_at: jetquery.DateTime, + }, + .{ + .relations = .{ + .song = jetquery.belongsTo(.Song, .{}), + .album = jetquery.belongsTo(.Album, .{}), + .artist = jetquery.belongsTo(.Artist, .{}), + }, + }, +); + +pub const Song = jetquery.Model( + @This(), + "songs", + struct { + id: i32, + name: []const u8, + play_count: i32, + length: f64, + score: f64, + url: []const u8, + aliased: bool, + track_num: i32, + hidden: bool, + holiday: bool, + created_at: jetquery.DateTime, + updated_at: jetquery.DateTime, + }, + .{ + .relations = .{ + .scrobbles = jetquery.hasMany(.Scrobble, .{}), + }, + }, +); diff --git a/src/app/database/data.db b/src/app/database/data.db deleted file mode 100644 index fa37ab7169d9ab40592d86dcc9c906a28a52db95..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeI%&rTCT7y$6uEkoN7I^tL>HVwl+E3CTPEs}6B2&5Vm1Zf35nFU5zU3Tm4R>d3d zVB!mSF!4g7kKh9sV|)fZn0W93{C3;Qp97eXc=3aD_xrwCW@dk!zG?ODoE=K>$n&?X zP?X6jqA29L5QLCX_;kRh{gZ@Xf3CC#j<}DKD~~^QGn*tbyCk#A-m;z}p2i^*Kmim$ z0Te(16hHwKKmim$0TgHnJXDgod|uhfhSsVhEkCq_FlgP>nWf59ts-hu({mNkDvFE6 zx?^nz#Y>{tEI~BT@STBlt#ZExan$<`q-XEcDmN=jBg=_ouD4g&Nj4X7RvTM^6<<3J zP9N7`_INOw{m(Kmd9=pCd13#PC-^TetNXVV`qtW$pm|Lk*jBR!+lqtZx7E!qlTOw} z*emGG%WRo-u`ldh=FQ*#p5UeMPf-8`Pyhu`00mG01yBG5Pyhu`;NJ^~vs4`}rj%c| zZFfV=`1V%dxq6gnt%TJ{Cn5c3D2M0DhEdy;QY>tWs+55qCECKK7A5DhR4w$S5@O-G zBWCPyTZcf40``Lp9rtRdd#IZ0O{G7s*v^`#$JbF#RlSr-e1m1g%4YPPeKqv$dUIhd zu4t`FE=PI3kQy_Ls_S`m>FcdKEX)rr-p!^-l3gI|0{h9nvJdPvd&(9MJ%lL=pa2S> z01BW03ZMWApa2S>01EsU0_PQ4;C)Ipw0uVffoT|eJ5~W8vxm@^q=S4=neiGMa4xXz zH|nM_9%ovdsY9K#$VZgwGxh1L>H?m_F~V%OKR| zy+$Ba(E)1=D^+`|?!YmC=WdurS#PFVl&a?vG|vl4bXHJt*G@$1MUa)(6Z-WsEpa2S>01BW03ZMWApa2S>01Eu)0!*Qt zXVXh^y#%KLa08F7mPvmn9p=S!)P6(9?uM4_mY~Itdhm8WLFqL^VgXx7eX}O}ZE#cv^9%ovVWfQcQ=hG`vzLb6m UTK{I0Rpat(;J`#BX#ShgZ+qh$&Hw-a diff --git a/src/app/database/migrations/2024-11-15_14-46-12_create_artists.zig b/src/app/database/migrations/2024-11-15_14-46-12_create_artists.zig new file mode 100644 index 0000000..224877b --- /dev/null +++ b/src/app/database/migrations/2024-11-15_14-46-12_create_artists.zig @@ -0,0 +1,26 @@ +const std = @import("std"); +const jetquery = @import("jetquery"); +const t = jetquery.schema.table; + +pub fn up(repo: anytype) !void { + try repo.createTable( + "artists", + &.{ + t.primaryKey("id", .{}), + t.column("name", .string, .{}), + t.column("album_num", .integer, .{}), + t.column("song_num", .integer, .{}), + t.column("play_count", .integer, .{}), + t.column("avg_album_score", .float, .{}), + t.column("avg_song_score", .float, .{}), + t.column("url", .string, .{}), + t.column("aliased", .boolean, .{}), + t.timestamps(.{}), + }, + .{}, + ); +} + +pub fn down(repo: anytype) !void { + try repo.dropTable("artists", .{}); +} diff --git a/src/app/database/migrations/2024-11-15_14-58-47_create_songs.zig b/src/app/database/migrations/2024-11-15_14-58-47_create_songs.zig new file mode 100644 index 0000000..4852b4d --- /dev/null +++ b/src/app/database/migrations/2024-11-15_14-58-47_create_songs.zig @@ -0,0 +1,27 @@ +const std = @import("std"); +const jetquery = @import("jetquery"); +const t = jetquery.schema.table; + +pub fn up(repo: anytype) !void { + try repo.createTable( + "songs", + &.{ + t.primaryKey("id", .{}), + t.column("name", .string, .{}), + t.column("play_count", .integer, .{}), + t.column("length", .float, .{}), + t.column("score", .float, .{}), + t.column("url", .string, .{}), + t.column("aliased", .boolean, .{}), + t.column("track_num", .integer, .{}), + t.column("hidden", .boolean, .{}), + t.column("holiday", .boolean, .{}), + t.timestamps(.{}), + }, + .{}, + ); +} + +pub fn down(repo: anytype) !void { + try repo.dropTable("songs", .{}); +} diff --git a/src/app/database/migrations/2024-11-15_17-52-04_create_artist_songs.zig b/src/app/database/migrations/2024-11-15_17-52-04_create_artist_songs.zig new file mode 100644 index 0000000..03f6ec4 --- /dev/null +++ b/src/app/database/migrations/2024-11-15_17-52-04_create_artist_songs.zig @@ -0,0 +1,20 @@ +const std = @import("std"); +const jetquery = @import("jetquery"); +const t = jetquery.schema.table; + +pub fn up(repo: anytype) !void { + try repo.createTable( + "artist_songs", + &.{ + t.primaryKey("id", .{}), + t.column("artist_id", .integer, .{}), + t.column("song_id", .integer, .{}), + t.timestamps(.{}), + }, + .{}, + ); +} + +pub fn down(repo: anytype) !void { + try repo.dropTable("artist_songs", .{}); +} diff --git a/src/app/database/migrations/2024-11-15_17-52-28_create_artist_albums.zig b/src/app/database/migrations/2024-11-15_17-52-28_create_artist_albums.zig new file mode 100644 index 0000000..3e186ad --- /dev/null +++ b/src/app/database/migrations/2024-11-15_17-52-28_create_artist_albums.zig @@ -0,0 +1,20 @@ +const std = @import("std"); +const jetquery = @import("jetquery"); +const t = jetquery.schema.table; + +pub fn up(repo: anytype) !void { + try repo.createTable( + "artist_albums", + &.{ + t.primaryKey("id", .{}), + t.column("artist_id", .integer, .{}), + t.column("album_id", .integer, .{}), + t.timestamps(.{}), + }, + .{}, + ); +} + +pub fn down(repo: anytype) !void { + try repo.dropTable("artist_albums", .{}); +} diff --git a/src/app/database/migrations/2024-11-15_17-52-54_create_album_songs.zig b/src/app/database/migrations/2024-11-15_17-52-54_create_album_songs.zig new file mode 100644 index 0000000..9462f82 --- /dev/null +++ b/src/app/database/migrations/2024-11-15_17-52-54_create_album_songs.zig @@ -0,0 +1,20 @@ +const std = @import("std"); +const jetquery = @import("jetquery"); +const t = jetquery.schema.table; + +pub fn up(repo: anytype) !void { + try repo.createTable( + "album_songs", + &.{ + t.primaryKey("id", .{}), + t.column("album_id", .integer, .{}), + t.column("song_id", .integer, .{}), + t.timestamps(.{}), + }, + .{}, + ); +} + +pub fn down(repo: anytype) !void { + try repo.dropTable("album_songs", .{}); +} diff --git a/src/app/database/migrations/2024-11-20_00-19-54_create_scrobble.zig b/src/app/database/migrations/2024-11-20_00-19-54_create_scrobble.zig new file mode 100644 index 0000000..c067423 --- /dev/null +++ b/src/app/database/migrations/2024-11-20_00-19-54_create_scrobble.zig @@ -0,0 +1,19 @@ +const std = @import("std"); +const jetquery = @import("jetquery"); +const t = jetquery.schema.table; + +pub fn up(repo: anytype) !void { + try repo.createTable( + "scrobbles", + &.{ + t.primaryKey("id", .{}), + t.column("date", .datetime, .{}), + t.timestamps(.{}), + }, + .{}, + ); +} + +pub fn down(repo: anytype) !void { + try repo.dropTable("scrobbles", .{}); +} diff --git a/src/app/database/migrations/2024-11-20_19-08-02_create_albums.zig b/src/app/database/migrations/2024-11-20_19-08-02_create_albums.zig new file mode 100644 index 0000000..292793e --- /dev/null +++ b/src/app/database/migrations/2024-11-20_19-08-02_create_albums.zig @@ -0,0 +1,28 @@ +const std = @import("std"); +const jetquery = @import("jetquery"); +const t = jetquery.schema.table; + +pub fn up(repo: anytype) !void { + try repo.createTable( + "albums", + &.{ + t.primaryKey("id", .{}), + t.column("title", .string, .{}), + t.column("song_num", .integer, .{}), + t.column("length", .float, .{}), + t.column("play_count", .integer, .{}), + t.column("score", .float, .{}), + t.column("avg_song_score", .float, .{}), + t.column("url", .string, .{}), + t.column("holiday", .boolean, .{}), + t.column("compilation", .boolean, .{}), + t.column("collaboration", .boolean, .{}), + t.timestamps(.{}), + }, + .{}, + ); +} + +pub fn down(repo: anytype) !void { + try repo.dropTable("albums", .{}); +} diff --git a/src/app/lib/db.zig b/src/app/lib/db.zig deleted file mode 100644 index dd6f7bf..0000000 --- a/src/app/lib/db.zig +++ /dev/null @@ -1,22 +0,0 @@ -pub const addArtist = \\INSERT INTO artists ('artist', 'plays', 'url') VALUES (?,?) -; - -pub const addTrack = \\INSERT INTO tracks ('artist', 'track', 'album', 'plays', 'url') VALUES (?,?,?,?) -; - -pub const getArtist = \\SELECT artist, plays FROM artists WHERE artist == ? -; - -pub const getTrack = \\SELECT artist, track, album, plays FROM tracks WHERE track == ? -; - -pub const getTrackSearch = \\SELECT track, url, form FROM tracks WHERE track LIKE '%' || ? || '%' -; - -pub const getArtistSearch = \\SELECT artist, url, form FROM artists WHERE artist LIKE '%' || ? || '%' -; - -pub const getAlbumSearch = \\SELECT album, url, form FROM albums WHERE album LIKE '%' || ? || '%' -; - -pub const total_search = getArtistSearch ++ " UNION " ++ getAlbumSearch ++ " UNION " ++ getTrackSearch; \ No newline at end of file diff --git a/src/app/views/root/_graph.zmpl b/src/app/middleware/lastfmMiddleware.zig similarity index 100% rename from src/app/views/root/_graph.zmpl rename to src/app/middleware/lastfmMiddleware.zig diff --git a/src/app/views/root/_history.zmpl b/src/app/middleware/spotifyMiddleware.zig similarity index 100% rename from src/app/views/root/_history.zmpl rename to src/app/middleware/spotifyMiddleware.zig diff --git a/src/app/views/collection.zig b/src/app/views/collection.zig new file mode 100644 index 0000000..8125efd --- /dev/null +++ b/src/app/views/collection.zig @@ -0,0 +1,36 @@ +const std = @import("std"); +const jetzig = @import("jetzig"); + +pub fn index(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { + _ = data; + 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, 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/stats/index.zmpl b/src/app/views/collection/delete.zmpl similarity index 100% rename from src/app/views/stats/index.zmpl rename to src/app/views/collection/delete.zmpl diff --git a/src/app/views/collection/get.zmpl b/src/app/views/collection/get.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/collection/get.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/collection/index.zmpl b/src/app/views/collection/index.zmpl new file mode 100644 index 0000000..f802907 --- /dev/null +++ b/src/app/views/collection/index.zmpl @@ -0,0 +1,8 @@ + + +@partial partials/header +
+ Content goes here +
+ + \ No newline at end of file diff --git a/src/app/views/collection/patch.zmpl b/src/app/views/collection/patch.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/collection/patch.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/collection/post.zmpl b/src/app/views/collection/post.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/collection/post.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/collection/put.zmpl b/src/app/views/collection/put.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/collection/put.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/concerts.zig b/src/app/views/concerts.zig new file mode 100644 index 0000000..8125efd --- /dev/null +++ b/src/app/views/concerts.zig @@ -0,0 +1,36 @@ +const std = @import("std"); +const jetzig = @import("jetzig"); + +pub fn index(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { + _ = data; + 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, 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/delete.zmpl b/src/app/views/concerts/delete.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/concerts/delete.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/concerts/get.zmpl b/src/app/views/concerts/get.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/concerts/get.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/concerts/index.zmpl b/src/app/views/concerts/index.zmpl new file mode 100644 index 0000000..f802907 --- /dev/null +++ b/src/app/views/concerts/index.zmpl @@ -0,0 +1,8 @@ + + +@partial partials/header +
+ Content goes here +
+ + \ No newline at end of file diff --git a/src/app/views/concerts/patch.zmpl b/src/app/views/concerts/patch.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/concerts/patch.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/concerts/post.zmpl b/src/app/views/concerts/post.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/concerts/post.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/concerts/put.zmpl b/src/app/views/concerts/put.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/concerts/put.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/lists.zig b/src/app/views/lists.zig new file mode 100644 index 0000000..8125efd --- /dev/null +++ b/src/app/views/lists.zig @@ -0,0 +1,36 @@ +const std = @import("std"); +const jetzig = @import("jetzig"); + +pub fn index(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { + _ = data; + 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, 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/delete.zmpl b/src/app/views/lists/delete.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/lists/delete.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/lists/get.zmpl b/src/app/views/lists/get.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/lists/get.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/lists/index.zmpl b/src/app/views/lists/index.zmpl new file mode 100644 index 0000000..f802907 --- /dev/null +++ b/src/app/views/lists/index.zmpl @@ -0,0 +1,8 @@ + + +@partial partials/header +
+ Content goes here +
+ + \ No newline at end of file diff --git a/src/app/views/lists/patch.zmpl b/src/app/views/lists/patch.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/lists/patch.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/lists/post.zmpl b/src/app/views/lists/post.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/lists/post.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/lists/put.zmpl b/src/app/views/lists/put.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/lists/put.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/music.zig b/src/app/views/music.zig deleted file mode 100644 index 4dd0d07..0000000 --- a/src/app/views/music.zig +++ /dev/null @@ -1,41 +0,0 @@ -const std = @import("std"); -const jetzig = @import("jetzig"); - -pub const static_params = .{ - .index = .{ - //.{ .params = .{ .foo = "hi", .bar = "bye" } }, - //.{ .params = .{ .foo = "hello", .bar = "goodbye" } }, - }, - //.get = .{ - // .{ .id = "1", .params = .{ .foo = "hi", .bar = "bye" } }, - // .{ .id = "2", .params = .{ .foo = "hello", .bar = "goodbye" } }, - //}, -}; - -pub fn index(request: *jetzig.StaticRequest, data: *jetzig.Data) !jetzig.View { - var root = try data.object(); - - const params = try request.params(); - - if (params.get("foo")) |foo| try root.put("foo", foo); - if (params.get("foo") == null) try root.put("foo", data.string("no foo")); - if (params.get("bar")) |bar| try root.put("bar", bar); - if (params.get("bar") == null) try root.put("bar", data.string("no bar")); - - return request.render(.ok); -} - -//pub fn get(id: []const u8, request: *jetzig.StaticRequest, data: *jetzig.Data) !jetzig.View { -// var root = try data.object(); -// -// const params = try request.params(); -// -// if (std.mem.eql(u8, id, "1")) { -// try root.put("id", data.string("id is '1'")); -// } -// -// if (params.get("foo")) |foo| try root.put("foo", foo); -// if (params.get("bar")) |bar| try root.put("bar", bar); -// -// return request.render(.created); -//} \ No newline at end of file diff --git a/src/app/views/music/index.zmpl b/src/app/views/music/index.zmpl deleted file mode 100644 index a14b357..0000000 --- a/src/app/views/music/index.zmpl +++ /dev/null @@ -1,2 +0,0 @@ -
{{.foo}}
-
{{.bar}}
\ No newline at end of file diff --git a/src/app/views/partials/_header.zmpl b/src/app/views/partials/_header.zmpl new file mode 100644 index 0000000..bf80e53 --- /dev/null +++ b/src/app/views/partials/_header.zmpl @@ -0,0 +1,7 @@ +Zuletzt +Scrobbles +Concerts +Collection +Ratings +Lists +
\ No newline at end of file diff --git a/src/app/views/root/_random.zmpl b/src/app/views/partials/_history.zmpl similarity index 100% rename from src/app/views/root/_random.zmpl rename to src/app/views/partials/_history.zmpl diff --git a/src/app/views/root/_recent.zmpl b/src/app/views/partials/_random.zmpl similarity index 100% rename from src/app/views/root/_recent.zmpl rename to src/app/views/partials/_random.zmpl diff --git a/src/app/views/partials/_recent.zmpl b/src/app/views/partials/_recent.zmpl new file mode 100644 index 0000000..e69de29 diff --git a/src/app/views/partials/_table.zmpl b/src/app/views/partials/_table.zmpl new file mode 100644 index 0000000..e69de29 diff --git a/src/app/views/root/_top.zmpl b/src/app/views/partials/_top.zmpl similarity index 100% rename from src/app/views/root/_top.zmpl rename to src/app/views/partials/_top.zmpl diff --git a/src/app/views/ratings.zig b/src/app/views/ratings.zig new file mode 100644 index 0000000..8125efd --- /dev/null +++ b/src/app/views/ratings.zig @@ -0,0 +1,36 @@ +const std = @import("std"); +const jetzig = @import("jetzig"); + +pub fn index(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { + _ = data; + 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, 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 new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/ratings/delete.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/ratings/get.zmpl b/src/app/views/ratings/get.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/ratings/get.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/ratings/index.zmpl b/src/app/views/ratings/index.zmpl new file mode 100644 index 0000000..f802907 --- /dev/null +++ b/src/app/views/ratings/index.zmpl @@ -0,0 +1,8 @@ + + +@partial partials/header +
+ Content goes here +
+ + \ No newline at end of file diff --git a/src/app/views/ratings/patch.zmpl b/src/app/views/ratings/patch.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/ratings/patch.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/ratings/post.zmpl b/src/app/views/ratings/post.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/ratings/post.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/ratings/put.zmpl b/src/app/views/ratings/put.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/ratings/put.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/root/_header.zmpl b/src/app/views/root/_header.zmpl deleted file mode 100644 index 3362c8f..0000000 --- a/src/app/views/root/_header.zmpl +++ /dev/null @@ -1,6 +0,0 @@ -Zuletzt -Artists -Albums -Tracks -Stats -
\ No newline at end of file diff --git a/src/app/views/root/index.zmpl b/src/app/views/root/index.zmpl index ea52da6..c7615bb 100644 --- a/src/app/views/root/index.zmpl +++ b/src/app/views/root/index.zmpl @@ -4,11 +4,10 @@ - - @partial root/header - @partial root/top + @partial partials/header + @partial partials/top diff --git a/src/app/views/scrobbles.zig b/src/app/views/scrobbles.zig new file mode 100644 index 0000000..8125efd --- /dev/null +++ b/src/app/views/scrobbles.zig @@ -0,0 +1,36 @@ +const std = @import("std"); +const jetzig = @import("jetzig"); + +pub fn index(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { + _ = data; + 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, 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/scrobbles/delete.zmpl b/src/app/views/scrobbles/delete.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/scrobbles/delete.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/scrobbles/get.zmpl b/src/app/views/scrobbles/get.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/scrobbles/get.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/scrobbles/index.zmpl b/src/app/views/scrobbles/index.zmpl new file mode 100644 index 0000000..9bf7e31 --- /dev/null +++ b/src/app/views/scrobbles/index.zmpl @@ -0,0 +1,8 @@ + + +@partial partials/header +
+ Content goes here +
+ + diff --git a/src/app/views/scrobbles/patch.zmpl b/src/app/views/scrobbles/patch.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/scrobbles/patch.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/scrobbles/post.zmpl b/src/app/views/scrobbles/post.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/scrobbles/post.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/scrobbles/put.zmpl b/src/app/views/scrobbles/put.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/scrobbles/put.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/stats.zig b/src/app/views/stats.zig deleted file mode 100644 index 4fac587..0000000 --- a/src/app/views/stats.zig +++ /dev/null @@ -1,7 +0,0 @@ -const std = @import("std"); -const jetzig = @import("jetzig"); - -pub fn index(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { - _ = data; - return request.render(.ok); -} diff --git a/src/app/views/upload.zig b/src/app/views/upload.zig new file mode 100644 index 0000000..491579c --- /dev/null +++ b/src/app/views/upload.zig @@ -0,0 +1,48 @@ +const std = @import("std"); +const jetzig = @import("jetzig"); +const jetquery = @import("jetzig").jetquery; + +pub fn index(request: *jetzig.Request, data: *jetzig.Data) !jetzig.View { + _ = data; + try request.repo.insert(.Artist, .{ + .id = 123, + .name = "wilco", + .album_num = 10, + .song_num = 200, + .play_count = 2700, + .avg_album_score = 10.0, + .avg_song_score = 10.0, + .url = "/wilco", + .aliased = false, + }); + 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, 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/upload/delete.zmpl b/src/app/views/upload/delete.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/upload/delete.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/upload/get.zmpl b/src/app/views/upload/get.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/upload/get.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/upload/index.zmpl b/src/app/views/upload/index.zmpl new file mode 100644 index 0000000..66a79f1 --- /dev/null +++ b/src/app/views/upload/index.zmpl @@ -0,0 +1,19 @@ + + +@partial partials/header +
+ Upload Last.fm or Spotify history file here (in json format). +
+
+ + + + + +
+ Last.fm + Spotify +
+
+ + \ No newline at end of file diff --git a/src/app/views/upload/patch.zmpl b/src/app/views/upload/patch.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/upload/patch.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/upload/post.zmpl b/src/app/views/upload/post.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/upload/post.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/app/views/upload/put.zmpl b/src/app/views/upload/put.zmpl new file mode 100644 index 0000000..76457d0 --- /dev/null +++ b/src/app/views/upload/put.zmpl @@ -0,0 +1,3 @@ +
+ Content goes here +
diff --git a/src/main.zig b/src/main.zig index ec577ff..3727351 100644 --- a/src/main.zig +++ b/src/main.zig @@ -5,9 +5,9 @@ const zmd = @import("zmd"); const builtin = @import("builtin"); pub const static = @import("static"); - // Override default settings in `jetzig.config` here: pub const jetzig_options = struct { + pub const Schema = @import("Schema"); /// Middleware chain. Add any custom middleware here, or use middleware provided in /// `jetzig.middleware` (e.g. `jetzig.middleware.HtmxMiddleware`). pub const middleware: []const type = &.{ @@ -95,20 +95,20 @@ pub fn main() !void { // }, // .threading_mode = .MultiThread, //}); - - //const create = + + //const create = // \\CREATE TABLE artists ('artist', 'plays') //; - //const query = + //const query = // \\INSERT INTO artists ('artist', 'plays') VALUES (?,?) //; //var build = try db.prepare(create); //defer build.deinit(); - + //try build.exec(.{},.{}); - + //var stmt = try db.prepare(query); //defer stmt.deinit(); @@ -117,7 +117,6 @@ pub fn main() !void { // .plays = 2500, //}); - var gpa = std.heap.GeneralPurposeAllocator(.{}){}; defer std.debug.assert(gpa.deinit() == .ok); const allocator = gpa.allocator();