diff --git a/Cpp/fostgres/response.csj.cpp b/Cpp/fostgres/response.csj.cpp index 738810e..774bd68 100644 --- a/Cpp/fostgres/response.csj.cpp +++ b/Cpp/fostgres/response.csj.cpp @@ -215,14 +215,28 @@ namespace { error = handler.update(linedata, records); break; } - if (error.first) return error; + if (error.first) { + return error; + } else if (error.second) { + switch (error.second) { + case 404: + return fostlib::urlhandler::view::execute( + fostlib::json{"fost.response.404"}, "", req, + fostlib::host{}); + default: + throw fostlib::exceptions::not_implemented( + __PRETTY_FUNCTION__, + "Canned response for this status code", + fostlib::coerce(error.second)); + } + } ++records; } cnx.commit(); fostlib::insert(work_done, "records", records); boost::shared_ptr response(new fostlib::text_body( fostlib::json::unparse(work_done, true), - fostlib::mime::mime_headers(), L"application/json")); + fostlib::mime::mime_headers(), "application/json")); return std::make_pair(response, 200); } diff --git a/Cpp/fostgres/updater.cpp b/Cpp/fostgres/updater.cpp index 0e9b9b4..5c7c995 100644 --- a/Cpp/fostgres/updater.cpp +++ b/Cpp/fostgres/updater.cpp @@ -108,7 +108,16 @@ std::pair, int> fostgres::updater::update( fostgres::updater::intermediate_data d, std::optional row) { auto rel = relation; - cnx.update(rel.shrink_to_fit(), d.first, d.second); + std::vector returning = {"*"}; + auto rs = cnx.update(rel.shrink_to_fit(), d.first, d.second, returning); + auto pos = rs.begin(); + if (pos == rs.end()) { + return {nullptr, 404}; + } else if (++pos != rs.end()) { + throw fostlib::exceptions::not_implemented( + __PRETTY_FUNCTION__, + "Update for multiple rows not supported by Fostgres"); + } return {nullptr, 0}; } diff --git a/Example/films/films.fg b/Example/films/films.fg index 7a2f047..5dba7b7 100644 --- a/Example/films/films.fg +++ b/Example/films/films.fg @@ -6,7 +6,7 @@ ## `UPDATE` statements instead of `INSERT` ones. If these don't actually ## update anything then we will get a 404 back, denoting that the ## resource we're trying to update doesn't exist. -#PATCH film.slug.error / (module.path.join films.edit.csj) 404 +PATCH film.slug.error / (module.path.join films.edit.csj) 404 ## ## Add films normally