Generate random IDs on POST

This commit is contained in:
jaina heartles 2022-05-12 20:29:18 -07:00
parent fc704667af
commit ea950dfe4f
2 changed files with 8 additions and 4 deletions

View file

@ -55,5 +55,5 @@ pub fn getActorById(id: Uuid) !?Actor {
}
pub fn createNote(_: CreateInfo(Note)) !Uuid {
return try Uuid.parse("f75f5160-12d3-42c2-a81d-ad2245b7a74b");
return Uuid.randV4(root.util.getRandom());
}

View file

@ -22,11 +22,15 @@ const this_scheme = "http";
const this_host = "localhost:8080";
fn postNote(ctx: *http.Context, _: *const Route) anyerror!void {
_ = try db.createNote(.{
.author = try Uuid.parse("f75f5160-12d3-42c2-a81d-ad2245b7a74b"),
const id = try db.createNote(.{
.author = Uuid.randV4(util.getRandom()),
.content = "test post",
});
try ctx.response.statusOnly(200);
var writer = try ctx.response.open(200);
try writer.writeAll("{\"id\":\"");
try writer.print("{}", .{id});
try writer.writeAll("\"}");
}
fn getUser(ctx: *http.Context, route: *const Route) anyerror!void {