Make api return full note
This commit is contained in:
parent
3f3e9e039e
commit
44cb7017b2
2 changed files with 6 additions and 6 deletions
|
@ -53,13 +53,14 @@ pub const ApiServer = struct {
|
|||
return std.fmt.allocPrint(alloc, "{}", .{self.last_id});
|
||||
}
|
||||
|
||||
pub fn createNote(self: *ApiServer, info: CreateInfo(models.Note)) !Uuid {
|
||||
pub fn createNote(self: *ApiServer, info: CreateInfo(models.Note)) !models.Note {
|
||||
const id = Uuid.randV4(self.prng.random());
|
||||
// TODO: check for dupes
|
||||
|
||||
const note = reify(models.Note, id, info);
|
||||
try self.db.putNote(note);
|
||||
|
||||
return id;
|
||||
return note;
|
||||
}
|
||||
|
||||
pub fn getNote(self: *ApiServer, id: Uuid, alloc: std.mem.Allocator) !?models.Note {
|
||||
|
|
|
@ -52,11 +52,10 @@ fn respondJson(ctx: *http.server.Context, status: http.Status, value: anytype, a
|
|||
fn createNote(srv: *RequestServer, ctx: *http.server.Context, _: RouteArgs) !void {
|
||||
const body = ctx.request.body orelse return respondJson(ctx, .bad_request, .{ .@"error" = "no note body provided" }, srv.alloc);
|
||||
var tokens = std.json.TokenStream.init(body);
|
||||
const note = try std.json.parse(api.CreateInfo(models.Note), &tokens, .{ .allocator = srv.alloc });
|
||||
defer std.json.parseFree(api.CreateInfo(models.Note), note, .{ .allocator = srv.alloc });
|
||||
const info = try std.json.parse(api.CreateInfo(models.Note), &tokens, .{ .allocator = srv.alloc });
|
||||
defer std.json.parseFree(api.CreateInfo(models.Note), info, .{ .allocator = srv.alloc });
|
||||
|
||||
// TODO
|
||||
_ = try srv.api.createNote(note);
|
||||
const note = try srv.api.createNote(info);
|
||||
|
||||
try respondJson(ctx, .created, note, srv.alloc);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue