From eb001b39a440f7b8f75459e87bd235edf9db66f1 Mon Sep 17 00:00:00 2001 From: jaina heartles Date: Fri, 9 Dec 2022 22:37:03 -0800 Subject: [PATCH] split getUser into helper --- src/api/lib.zig | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/api/lib.zig b/src/api/lib.zig index a3f4cd6..6a00524 100644 --- a/src/api/lib.zig +++ b/src/api/lib.zig @@ -434,19 +434,14 @@ fn ApiConn(comptime DbConn: type) type { }, } - return self.getUser(user_id) catch |err| switch (err) { + return self.getUserUnchecked(user_id) catch |err| switch (err) { error.NotFound => error.Unexpected, else => err, }; } - pub fn getUser(self: *Self, user_id: Uuid) !UserResponse { + fn getUserUnchecked(self: *Self, user_id: Uuid) !UserResponse { const user = try services.actors.get(self.db, user_id, self.allocator); - errdefer util.deepFree(self.allocator, user); - - if (self.user_id == null) { - if (!Uuid.eql(self.community.id, user.community_id)) return error.NotFound; - } return UserResponse{ .id = user.id, @@ -469,6 +464,17 @@ fn ApiConn(comptime DbConn: type) type { }; } + pub fn getUser(self: *Self, user_id: Uuid) !UserResponse { + const user = try self.getUserUnchecked(user_id); + errdefer util.deepFree(self.allocator, user); + + if (self.user_id == null) { + if (!Uuid.eql(self.community.id, user.community_id)) return error.NotFound; + } + + return user; + } + pub fn createNote(self: *Self, content: []const u8) !NoteResponse { // You cannot post on admin accounts if (self.community.kind == .admin) return error.WrongCommunity;