Changeset View
Changeset View
Standalone View
Standalone View
src/api/replies.rs
Show First 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | impl<T> ApiResponse<T> for QueryResult<T> { | ||||
/// .get_result::<Player>(&*connection) | /// .get_result::<Player>(&*connection) | ||||
/// .into_json_response() | /// .into_json_response() | ||||
/// } | /// } | ||||
/// ``` | /// ``` | ||||
/// | /// | ||||
/// This will produce a JSON representation of the newly inserted player if successful. | /// This will produce a JSON representation of the newly inserted player if successful. | ||||
/// If the insert fails because of an unique constraint violation (e.g. an username already | /// If the insert fails because of an unique constraint violation (e.g. an username already | ||||
/// taken), it returns a 409 Conflict. | /// taken), it returns a 409 Conflict. | ||||
/// If the failure is from a forreign key integrity constraint, it returns a 400. | /// If the failure is from a foreign key integrity constraint, it returns a 400. | ||||
/// If there is any other database issue, it returns a 500. | /// If there is any other database issue, it returns a 500. | ||||
fn into_json_response(self) -> ApiJsonResponse<T> { | fn into_json_response(self) -> ApiJsonResponse<T> { | ||||
self | self | ||||
// CASE I - The query returns one value, we return a JSON representation fo the item | // CASE I - The query returns one value, we return a JSON representation fo the item | ||||
.map(|item| Json(item)) | .map(|item| Json(item)) | ||||
.map_err(|error| match error { | .map_err(|error| match error { | ||||
// Case II - The query returns no result, we return a 404 Not found response | // Case II - The query returns no result, we return a 404 Not found response | ||||
ResultError::NotFound => Failure::from(Status::NotFound), | ResultError::NotFound => Failure::from(Status::NotFound), | ||||
▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines |
Nasqueron DevCentral · If it had been much bigger the moon would have had a core of ice. · Powered by Phabricator