2023-01-03 01:21:08 +00:00
|
|
|
const std = @import("std");
|
|
|
|
const util = @import("util");
|
|
|
|
const types = @import("../types.zig");
|
2023-01-04 19:03:23 +00:00
|
|
|
const pkg = @import("../lib.zig");
|
2023-01-03 01:21:08 +00:00
|
|
|
|
|
|
|
const Uuid = util.Uuid;
|
|
|
|
const DateTime = util.DateTime;
|
2023-01-04 19:03:23 +00:00
|
|
|
const ApiContext = pkg.ApiContext;
|
|
|
|
const Community = types.communities.Community;
|
|
|
|
const QueryArgs = types.communities.QueryArgs;
|
|
|
|
const QueryResult = types.communities.QueryResult;
|
2023-01-03 01:21:08 +00:00
|
|
|
|
2023-01-04 19:03:23 +00:00
|
|
|
pub fn create(
|
|
|
|
alloc: std.mem.Allocator,
|
|
|
|
ctx: ApiContext,
|
|
|
|
svcs: anytype,
|
|
|
|
origin: []const u8,
|
|
|
|
name: ?[]const u8,
|
|
|
|
) !Uuid {
|
|
|
|
if (!ctx.isAdmin()) {
|
|
|
|
return error.PermissionDenied;
|
|
|
|
}
|
2023-01-03 01:21:08 +00:00
|
|
|
|
2023-01-04 19:03:23 +00:00
|
|
|
return try svcs.createCommunity(
|
|
|
|
alloc,
|
|
|
|
origin,
|
|
|
|
.{ .name = name },
|
|
|
|
);
|
|
|
|
}
|
2023-01-03 01:21:08 +00:00
|
|
|
|
2023-01-04 19:03:23 +00:00
|
|
|
pub fn get(
|
|
|
|
alloc: std.mem.Allocator,
|
|
|
|
_: ApiContext,
|
|
|
|
svcs: anytype,
|
|
|
|
id: Uuid,
|
|
|
|
) !Community {
|
|
|
|
return try svcs.getCommunity(alloc, id);
|
|
|
|
}
|
2023-01-03 01:21:08 +00:00
|
|
|
|
2023-01-04 19:03:23 +00:00
|
|
|
pub fn query(
|
|
|
|
alloc: std.mem.Allocator,
|
|
|
|
ctx: ApiContext,
|
|
|
|
svcs: anytype,
|
|
|
|
args: QueryArgs,
|
|
|
|
) !QueryResult {
|
|
|
|
if (!ctx.isAdmin()) return error.PermissionDenied;
|
|
|
|
return try svcs.queryCommunities(alloc, args);
|
2023-01-03 01:21:08 +00:00
|
|
|
}
|