aboutsummaryrefslogtreecommitdiffstats
path: root/src/web/picks/pick.zig
diff options
context:
space:
mode:
authorsadbeast <sadbeast@sadbeast.com>2024-06-23 15:36:59 -0700
committersadbeast <sadbeast@sadbeast.com>2024-07-13 21:58:23 -0700
commit8d018d996c1eddb882dc64ebbd228bb0135944f3 (patch)
treed01956546a77dbae33357c9a5d174f511ac9b282 /src/web/picks/pick.zig
downloadteamdraft-8d018d996c1eddb882dc64ebbd228bb0135944f3.tar.gz
teamdraft-8d018d996c1eddb882dc64ebbd228bb0135944f3.tar.bz2
Diffstat (limited to 'src/web/picks/pick.zig')
-rw-r--r--src/web/picks/pick.zig37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/web/picks/pick.zig b/src/web/picks/pick.zig
new file mode 100644
index 0000000..51e05c4
--- /dev/null
+++ b/src/web/picks/pick.zig
@@ -0,0 +1,37 @@
+const Team = struct {
+ team_id: i16,
+ rank: ?i16,
+ name: []const u8,
+ division: []const u8,
+ league_user_id: ?i32,
+};
+
+pub fn handler(env: *Env, req: *httpz.Request, res: *httpz.Response) !void {
+ const query = try req.query();
+ if (query.get("team_id")) |team_id| {
+ if (req.params.get("id")) |draft_id| {
+ var result = try env.app.pool.query("SELECT cr.*, picks.league_user_id from current_rankings cr left join picks on cr.team_id = picks.team_id AND picks.draft_id = $1 WHERE cr.team_id = $2", .{ draft_id, team_id });
+ defer result.deinit();
+
+ var team: Team = undefined;
+ while (try result.next()) |row| {
+ team = try row.to(Team, .{});
+ }
+ try web.renderWithDataPartials("pick", .{}, .{
+ .team_id = team.team_id,
+ .rank = team.rank,
+ .name = team.name,
+ .division = team.division,
+ .league_user_id = team.league_user_id,
+ .draft_id = draft_id,
+ }, req, res);
+ }
+ } else {
+ @panic("oh no");
+ }
+}
+
+const httpz = @import("httpz");
+const Env = @import("../../env.zig").Env;
+const web = @import("../../web/web.zig");
+const std = @import("std");