@@ -26,11 +26,11 @@ public function getResponse(): string
2626 $ user = new User ();
2727 try {
2828 $ response = match ($ this ) {
29- self ::CREATE => $ user ->create ($ postBody ),
30- self ::RETRIEVE_ALL => $ user ->retrieveAll (),
31- self ::RETRIEVE => $ user ->retrieve ($ userId ),
32- self ::REMOVE => $ user ->remove ($ postBody ),
33- self ::UPDATE => $ user ->update ($ postBody ),
29+ self ::CREATE => $ user ->create ($ postBody ), // TODO Add send 201
30+ self ::RETRIEVE_ALL => $ user ->retrieveAll (), // TODO send 200
31+ self ::RETRIEVE => $ user ->retrieve ($ userId ), // TODO send 200
32+ self ::REMOVE => $ user ->remove ($ postBody ), // TODO send 204 status code
33+ self ::UPDATE => $ user ->update ($ postBody ), // TODO send 200
3434 };
3535 } catch (InvalidValidationException $ e ) {
3636 // Send 400 http status code
@@ -50,17 +50,9 @@ public function getResponse(): string
5050
5151$ action = $ _REQUEST ['action ' ] ?? null ;
5252
53- // PHP 8.0 match - https://stitcher.io/blog/php-8-match-or-switch
54- // Various HTTP codes explained here: https://www.apiscience.com/blog/7-ways-to-validate-that-your-apis-are-working-correctly/
55- $ userAction = match ($ action ) {
56- 'create ' => UserAction::CREATE , // send 201
57- 'retrieve ' => UserAction::RETRIEVE , // send 200
58- 'retrieveall ' => UserAction::RETRIEVE_ALL ,
59- 'remove ' => UserAction::REMOVE , // send 204 status code
60- 'update ' => UserAction::UPDATE , //
61- default => UserAction::RETRIEVE_ALL , // send 200
62- };
63-
64-
65- // response, as described in https://jsonapi.org/format/#profile-rules
66- echo $ userAction ->getResponse ();
53+ $ userAction = UserAction::tryFrom ($ action );
54+ if ($ userAction ) {
55+ echo $ userAction ->getResponse ();
56+ } else {
57+ require_once 'not-found.routes.php ' ;
58+ }
0 commit comments