Pass note ID to db
This commit is contained in:
parent
5933e37f85
commit
b738a02e16
2 changed files with 4 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
|||
const std = @import("std");
|
||||
|
||||
const models = @import("./models.zig");
|
||||
const Id = []const u8;
|
||||
|
||||
// Clones a struct and its fields to a single layer of depth.
|
||||
// Caller owns memory, can be freed using free below
|
||||
|
@ -54,8 +55,8 @@ pub const Database = struct {
|
|||
return db;
|
||||
}
|
||||
|
||||
pub fn getNote(self: *Database, alloc: std.mem.Allocator) !models.Note {
|
||||
return try clone(alloc, self.notes.get("1").?);
|
||||
pub fn getNote(self: *Database, id: Id, alloc: std.mem.Allocator) !models.Note {
|
||||
return try clone(alloc, self.notes.get(id).?);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ fn respondJson(ctx: *http.server.Context, value: anytype, alloc: std.mem.Allocat
|
|||
}
|
||||
|
||||
fn getNote(srv: *RequestServer, ctx: *http.server.Context, _: RouteArgs) !void {
|
||||
const note = try srv.db.getNote(srv.alloc);
|
||||
const note = try srv.db.getNote("1", srv.alloc);
|
||||
defer db.free(srv.alloc, note);
|
||||
|
||||
try respondJson(ctx, note, srv.alloc);
|
||||
|
|
Loading…
Reference in a new issue