Skip to content

OBPIH-6021 Add an API endpoint to delete a product supplier + remove unnecessary url mapping #4442

Merged
awalkowiak merged 2 commits intofeature/product-supplier-list-redesignfrom
OBPIH-6021
Jan 12, 2024
Merged

OBPIH-6021 Add an API endpoint to delete a product supplier + remove unnecessary url mapping #4442
awalkowiak merged 2 commits intofeature/product-supplier-list-redesignfrom
OBPIH-6021

Conversation

@kchelstowski
Copy link
Collaborator

It seems not to be necessary to add a url mapping for this (and it was not necessary to add it for the list method), as it's handled fine by the generic mappings:

"/api/${resource}s"(parseRequest: true) {
    controller = { "${params.resource}Api" }
    action = [GET: "list", POST: "create"]
}

"/api/${resource}s/$id/status"(parseRequest: true) {
    controller = { "${params.resource}Api" }
    action = [GET: "status", DELETE: "deleteStatus", POST: "updateStatus"]
}

"/api/${resource}s/$id"(parseRequest: true) {
    controller = { "${params.resource}Api" }
    action = [GET: "read", POST: "update", PUT: "update", DELETE: "delete"]
}

By doing so, I've also applied @jmiranda 's suggestion from here to change the url to be in plural form (productSuppliers, not productSupplier).

Comment on lines +18 to +19
productSupplierService.delete(params.id)
render status: 204
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I know, the delete method from @Service won't throw an exception if the entity we want to delete doesn't exist. Shouldn't we return another status in this case? Or we won't tell the frontend part whether this entity is deleted?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alannadolny I described the decision under the ticket. I apologize not for tagging everyone there.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's definitely an important decision in terms of coding conventions, so I suppose we'll discuss it in details.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it's a good question. For what it's worth 204 = "No Content", so it's not saying "delete was successful".

It looks like the Grails docs imply that they always return 204.
https://docs.grails.org/5.2.4/guide/REST.html#_implementing_the_delete_action

I would be interested to see what a scaffolded controller looks like when generated in Grails 3.

As for the REST convention, it seems like 204 on the first attempt and then 404 on subsequent attempts is an accepted convention (based on the upvotes).
https://stackoverflow.com/questions/6439416/status-code-when-deleting-a-resource-using-http-delete-for-the-second-time

I need to read a little bit more, but I feel like returning 204 would be fine for now (and maybe the proper solution because it's not leaking implementation details i.e. 404 is telling me something that I wouldn't otherwise know). With that said, 204 is misleading.

So let's leave it as 204 for now. I'll add a tech debt label and we can come back to this when we've had some more time to investigate.

@awalkowiak awalkowiak merged commit f2e49fa into feature/product-supplier-list-redesign Jan 12, 2024
@awalkowiak awalkowiak deleted the OBPIH-6021 branch January 12, 2024 09:55
awalkowiak pushed a commit that referenced this pull request Mar 12, 2024
…unnecessary url mapping (#4442)

* OBPIH-6021 Remove unnecessary url mapping for productSupplier and change the url on the frontend to be in plural form (productSuppliers, not productSupplier)

* OBPIH-6021 Add an api endpoint to delete a product supplier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants