2022-10-11 03:28:23 +00:00
|
|
|
const api = @import("api");
|
|
|
|
const util = @import("util");
|
2022-07-22 06:53:05 +00:00
|
|
|
|
2022-09-08 07:52:23 +00:00
|
|
|
pub const create = struct {
|
|
|
|
pub const method = .POST;
|
2022-11-27 01:52:30 +00:00
|
|
|
pub const path = "/notes";
|
2022-09-08 07:52:23 +00:00
|
|
|
|
2022-10-11 03:28:23 +00:00
|
|
|
pub const Body = struct {
|
|
|
|
content: []const u8,
|
|
|
|
};
|
2022-09-08 07:52:23 +00:00
|
|
|
|
2022-10-11 03:28:23 +00:00
|
|
|
pub fn handler(req: anytype, res: anytype, srv: anytype) !void {
|
|
|
|
const note = try srv.createNote(req.body.content);
|
2022-09-08 07:52:23 +00:00
|
|
|
|
2022-10-11 03:28:23 +00:00
|
|
|
try res.json(.created, note);
|
2022-09-08 07:52:23 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
pub const get = struct {
|
|
|
|
pub const method = .GET;
|
2022-11-27 01:52:30 +00:00
|
|
|
pub const path = "/notes/:id";
|
2022-09-08 07:52:23 +00:00
|
|
|
|
2022-10-11 03:28:23 +00:00
|
|
|
pub const Args = struct {
|
|
|
|
id: util.Uuid,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub fn handler(req: anytype, res: anytype, srv: anytype) !void {
|
|
|
|
const note = try srv.getNote(req.args.id);
|
2022-09-08 07:52:23 +00:00
|
|
|
|
2022-10-11 03:28:23 +00:00
|
|
|
try res.json(.ok, note);
|
2022-09-08 07:52:23 +00:00
|
|
|
}
|
|
|
|
};
|