-
Notifications
You must be signed in to change notification settings - Fork 151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DeleteById REST Support #172
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fast turn around! Just some minor fixes needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Just update the description to remove the work in progress because its no longer the case :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is good apart from the comment I left about validation.
Why is the NotFound response in this strange format:
Instead of the exception format we use for all other exceptions. Can you change it to match our other exceptions? |
…mments. Updated code comments.
@JelteF Updated |
Summary
Closes #80 by adding capability to DELETE objects via primary key. Please note: refresh your local database schemas
with the updated
MsSqlBooks.sql
andPostgreSqlBooks.sql
if you are running tests locally.Sample Requests
https://localhost:5001/books/id/1
JSON Response:
HTTP 204 No Content
JSON Body:
Null
JSON Response:
HTTP 404 Not Found
JSON Body:
Implementation Notes
SqlDeleteQueryStructure.cs
Predicates must be properly created in order to have the runtime type/database type resolved. The right-hand side of the predicate looks like
new PredicateOperand($"@{MakeParamWithValue(GetParamAsColumnSystemType(param.Value.ToString(), param.Key))}")
to avoid Postgres Test issue with DELETE parameters where primary key id, of type integer, is sent to Postgres as a string.
This results in bigint != text errors.
SqlTestHelper.cs
In
VerifyResult()
, I used a C# 7 feature of switching off of Types to keep the code neat. TheactionResult
(of typeIActionResult
) is then matched against the correct implementation (OkObjectResult
,NoContentResult
, etc.) to then have aligning logic pulling out HTTP status code and message, if available. More info about switching on type can be found in this Microsoft Announcement blogRestController.cs
Queries that result in the database returning 0 results will return a DataGateway exception with
statusCode:NotFound
. This includes GET (no item found) and DELETE (no item exists to delete).Additional Notes
DeleteById requests must have the primary key validated. Prior to this PR, the code path in RestService.cs validates PK when it is included, otherwise not. Logic is now added to accommodate for DELETE requests.
Tests
DeleteById integration tests check the following:
204 NoContent
.404 Not Found
.400 Bad Request
.There are dedicated items added to the SQL/PG SQL files used to create the test tables. This ensures DELETE tests are consistent such that they only delete and validate items exclusive to their tests if running concurrently to other tests. i.e. Delete will not touch database records other tests rely on and vice versa.
Todo Future PR