Subterfuge-Revived / Remake-Backend

Server side validation and API
Creative Commons Zero v1.0 Universal
10 stars 1 forks source link

WIP: feat/rest #24

Closed griendt closed 4 years ago

griendt commented 4 years ago

Description

All of the backend endpoint logic has been changed from a single endpoint with a type field to distinguish the intended action, to a RESTful implementation of the database resources. This will allow users/admins greater control over how to fetch information as well as how to save and update it, as it follows a universal and hierarchically logical standard. GET requests get information, POST requests post information, and so on, and the URLs indicate what (type of) resource is to be mutated.

You can list an overview of all endpoints generated by the current routes file by logging into the container and running:

php artisan route:list

Some of these routes, such as deleting a chat group, currently make no sense (as there is no system admin roles or such yet). Therefore they will always return a 403 Unauthorized response, despite existing for future purposes.

Type of change

Testing

I have called all endpoints manually through Insomnia (an alternative to Postman) and tested several scenarios. I absolutely wish to add automated unit tests (they will need to be added sooner or later anyway). At request I will add them, even for this PR!

Checklist:

Questions / Discussion

Before this PR could be merged, I'd like for the following to be answered:

QuinnBast commented 4 years ago

Comments:

The REST URL updates are great. All endpoints appear to be working as expected with the exception of the PUT, PATCH, and DELETE methods which will return "401 Unauthorized" even when the user is authorized. Additionally, POST actions for for all endpoints except for the "register account" endpoint will throw the following error (but the trace varies based on which controller sends the response).

{
    "message": "Call to undefined function App\\Http\\Responses\\resource_url()",
    "exception": "Error",
    "file": "/var/www/app/Http/Responses/CreatedResponse.php",
    "line": 23,
    "trace": [
        {
            "file": "/var/www/app/Http/Controllers/RoomController.php",
            "line": 131,
            "function": "__construct",
            "class": "App\\Http\\Responses\\CreatedResponse",
            "type": "->"
        },
        {
            "function": "store",
            "class": "App\\Http\\Controllers\\RoomController",
            "type": "->"
        },
        {
            "file": "/var/www/vendor/laravel/framework/src/Illuminate/Routing/Controller.php",
            "line": 54,
            "function": "call_user_func_array"
        },

QoL changes

It may be useful to have the groups endpoint be a subset of the rooms. Something like api/rooms/2/groups which returns a list of groups in room 2 that the player is in. Having /api/groups we will likely need to filter out groups from other games the player is in.

In /api/room/#/events I think the filter and filter_arg parameters should not be required. If not set, just assume the user wants all events from the beginning of the room.