diff --git a/src/request.zig b/src/request.zig index b2a9a73..8c6ef22 100644 --- a/src/request.zig +++ b/src/request.zig @@ -20,15 +20,23 @@ pub fn process(jobj: *json.Obj, db: *sqlite.Db) !void { pub fn add(jobj: *json.Obj, db: *sqlite.Db, allocator: std.mem.Allocator) !void { // TODO: Maybe return error when no items in the array? + var jret = json.Obj.newArray(); + defer jret.deinit(); + var iter = jobj.arrayGetIterator(); while(iter.next()) |*jtags| { var item = Item { .id = null, .tags = try Item.tagsFromJson(jtags, allocator), }; - defer item.deinit(); + item.deinit(); - // TODO: Return the things that have been added with ID + // Insert new items into the DB try item.persist(db); + + // Add item to new json array (Makes a deep copy, freed with jret.deinit()) + jret.arrayAdd(&item.toJson()); } + + std.debug.print("{s}", .{ jret.toString() }); }