Closed danirod closed 4 years ago
Congratulations :beers:. DeepCode analyzed your code in 0.393 seconds and we found no issues. Enjoy a moment of no bugs :sunny:.
:speech_balloon: This comment has been generated by the DeepCode bot, installed by the owner of the repository. The DeepCode bot protects your repository by detecting and commenting on security vulnerabilities or other critical issues.
:relaxed: If you want to provide feedback on our bot, here is how to contact us.
⚠️ This breaks the API schema and will require rework in openrpg-ui. I think that the refactor will enhance things this time and that it will be worth to address this in openrpg-ui.
This commit refactors the index and show actions of the Charater and User controller in order to use Laravel API Resources, which will produce a more streamlined and uniform API response format than having each controller have a different way of sending responses.
Collections (index) make use of the ResourceCollection, which already handles pagination for free and it's provided by Laravel. It is robust enough to nest stuff in objects and provides out of the box a pagination metadata object and a HATEOAS-compatible link map with pointers to pages.
Resources (show) make use of the JsonResource to coerce a resource into a JSON object. JsonResource plays nice and wraps the resource into a data object.
Two base resources called LinkedCollection and LinkedResource have been introduced in this commit.
LinkedResource takes care of adding an extra metadata field called links, providing a HATEOAS-compatible link map that can be populated by each resource subclass.
LinkedCollection is a base class that can be used for collections of linked resources, allowing the link map provided by a linked resource to be embedded into the data array itself.