Check users for duplicates
This commit is contained in:
parent
f5548c0243
commit
2092bbdffa
2 changed files with 22 additions and 1 deletions
|
@ -64,8 +64,20 @@ pub const ApiServer = struct {
|
|||
}
|
||||
|
||||
pub fn createUser(self: *ApiServer, info: CreateInfo(models.User)) !models.User {
|
||||
try self.db.users.lock();
|
||||
defer self.db.users.unlock();
|
||||
// TODO; real queries
|
||||
|
||||
const id = Uuid.randV4(self.prng.random());
|
||||
// TODO: check for dupes
|
||||
|
||||
// check for handle dupes
|
||||
var iter = self.db.users.data.iterator();
|
||||
while (iter.next()) |it| {
|
||||
if (std.mem.eql(u8, it.value_ptr.handle, info.handle)) {
|
||||
return error.DuplicateHandle;
|
||||
}
|
||||
}
|
||||
// TODO: check for id dupes
|
||||
|
||||
const user = reify(models.User, id, info);
|
||||
try self.db.users.put(user);
|
||||
|
|
|
@ -93,6 +93,15 @@ pub fn Table(comptime T: type) type {
|
|||
}
|
||||
try self.data.put(key, copy);
|
||||
}
|
||||
|
||||
// TODO
|
||||
pub fn lock(_: *Self) !void {
|
||||
return;
|
||||
}
|
||||
|
||||
pub fn unlock(_: *Self) void {
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue