42 lines
1.3 KiB
Zig
42 lines
1.3 KiB
Zig
const root = @import("root");
|
|
const std = @import("std");
|
|
const http = @import("http");
|
|
const Uuid = @import("util").Uuid;
|
|
|
|
const utils = @import("../controllers.zig").utils;
|
|
|
|
const RequestServer = root.RequestServer;
|
|
const RouteArgs = http.RouteArgs;
|
|
|
|
pub const create = struct {
|
|
pub const path = "/invites";
|
|
pub const method = .POST;
|
|
pub fn handler(srv: *RequestServer, ctx: *http.server.Context, _: RouteArgs) !void {
|
|
// TODO: get rid of this temporary struct, find json library that lets me extend
|
|
// it to parse UUIDs/etc in place
|
|
const InviteRequest = struct {
|
|
const Kind = @import("api").InviteRequest.Kind;
|
|
|
|
name: ?[]const u8 = null,
|
|
|
|
// admin only options
|
|
kind: Kind = .user,
|
|
to_community: ?[]const u8 = null,
|
|
};
|
|
|
|
const opt = try utils.parseRequestBody(InviteRequest, ctx);
|
|
defer utils.freeRequestBody(opt, ctx.alloc);
|
|
|
|
var api = try utils.getApiConn(srv, ctx);
|
|
defer api.close();
|
|
|
|
const invite = try api.createInvite(.{
|
|
.name = opt.name,
|
|
.kind = opt.kind,
|
|
.to_community = if (opt.to_community) |id| try Uuid.parse(id) else null,
|
|
});
|
|
|
|
try utils.respondJson(ctx, .created, invite);
|
|
}
|
|
};
|