@@ -31,13 +31,16 @@ public function create(mixed $data): array|object
3131
3232
3333 if (UserDal::create ($ userEntity ) === false ) {
34- // Set an internal error when we cannot add an entry to the database
34+ // Set an internal error 500 when we cannot add an entry to the database
3535 Http::setHeadersByCode (StatusCode::INTERNAL_SERVER_ERROR );
3636
3737 // Set to empty result, because an issue happened. The client has to handle this properly
3838 $ data = [];
3939 }
4040
41+ // Send a 201 when the user has been successfully added to DB
42+ Http::setHeadersByCode (StatusCode::CREATED );
43+
4144 return $ data ; // return statement exists the function and doesn't go beyond this scope
4245 }
4346
@@ -64,6 +67,9 @@ public function update(mixed $postBody): array|object
6467 }
6568
6669 if (UserDal::update ($ userUuid , $ userEntity ) === false ) {
70+ // Set an internal error 500 when we cannot add an entry to the database
71+ Http::setHeadersByCode (StatusCode::INTERNAL_SERVER_ERROR );
72+
6773 // If invalid or got an error, give back an empty response
6874 return [];
6975 }
@@ -101,10 +107,16 @@ public function retrieve(string $userUuid): array
101107 throw new InvalidValidationException ("Invalid user UUID " );
102108 }
103109
104- public function remove (object $ data ): bool
110+ /**
111+ * @internal Set `mixed` type, because if we get an incorrect payload with syntax errors, `json_decode` gives NULL,
112+ * and `object` wouldn't be a valid datatype here.
113+ */
114+ public function remove (mixed $ data ): bool
105115 {
106116 $ userValidation = new UserValidation ($ data );
107117 if ($ userValidation ->isRemoveSchemaValid ()) {
118+ // Send a 204 if the user got removed
119+ //Http::setHeadersByCode(StatusCode::NO_CONTENT);
108120 return UserDal::remove ($ data ->userUuid );
109121 }
110122
0 commit comments