summaryrefslogtreecommitdiff
path: root/backend/src
diff options
context:
space:
mode:
Diffstat (limited to 'backend/src')
-rw-r--r--backend/src/API/WeaponsAPI.zig2
-rw-r--r--backend/src/Models/User.zig47
-rw-r--r--backend/src/main.zig1
3 files changed, 49 insertions, 1 deletions
diff --git a/backend/src/API/WeaponsAPI.zig b/backend/src/API/WeaponsAPI.zig
index c15738e..75cd6e8 100644
--- a/backend/src/API/WeaponsAPI.zig
+++ b/backend/src/API/WeaponsAPI.zig
@@ -48,7 +48,7 @@ fn newRangedWeapon(_: *Handler.Handler, req: *httpz.Request, res: *httpz.Respons
var weapon = body.ToModel();
db.RangedWeapons.Create(&weapon) catch |err| {
if (err == db.ResultErrors.AlreadyExists) {
- res.status = 400;
+ res.setStatus(.bad_request);
try res.json(errDesc.ErrorDescriptor {
.Message = "A weapon with that ID already exists"
}, .{});
diff --git a/backend/src/Models/User.zig b/backend/src/Models/User.zig
new file mode 100644
index 0000000..1b7943a
--- /dev/null
+++ b/backend/src/Models/User.zig
@@ -0,0 +1,47 @@
+const std = @import("std");
+const pg = @import("pg");
+
+const RoleError = error {
+ NotSupported
+};
+
+const RolesMap = std.static_string_map.StaticStringMap(Role).initComptime(.{
+ .{ "user", .user },
+ .{ "editor", .editor },
+});
+
+pub const Role = enum {
+ user,
+ editor,
+
+ pub fn ToString(self: Role) []const u8 {
+ return switch (self) {
+ .user => "user",
+ .editor => "editor"
+ };
+ }
+
+ pub fn FromString(string: []const u8) !Role {
+ return RolesMap.get(string) orelse RoleError.NotSupported;
+ }
+};
+
+pub const User = struct {
+ // UUID
+ Id: [36]u8,
+ Username: []const u8,
+ PasswordHash: []const u8,
+ Role: []const u8
+
+ // pub fn Map(row: *const pg.Row) !User {
+ // }
+};
+
+test "Roles transformation" {
+ const roleString = "user";
+ const roleVar: Role = .editor;
+
+ try std.testing.expectEqualStrings("editor", Role.ToString(roleVar));
+ const actual = try Role.FromString(roleString);
+ try std.testing.expectEqual(Role.user, actual);
+}
diff --git a/backend/src/main.zig b/backend/src/main.zig
index a949b4d..e7641cc 100644
--- a/backend/src/main.zig
+++ b/backend/src/main.zig
@@ -42,4 +42,5 @@ fn index(_: *handler.Handler, _: *httpz.Request, res: *httpz.Response) !void {
test "TestRunner" {
_ = @import("Models/RangedWeapon.zig");
+ _ = @import("Models/User.zig");
}