@@ -83,9 +83,9 @@ public function create(mixed $data): array|object
8383 );
8484 }
8585
86- if (UserDal::create ($ userEntity ) === false ) {
87- // Set an internal error 500 when we cannot add an entry to the database
88- HttpResponse::setHeadersByCode (StatusCode::INTERNAL_SERVER_ERROR );
86+ if (! $ userUuid = UserDal::create ($ userEntity )) {
87+ // If we receive an error while creating a user to the database, give a 400 to client
88+ HttpResponse::setHeadersByCode (StatusCode::BAD_REQUEST );
8989
9090 // Set to empty result, because an issue happened. The client has to handle this properly
9191 $ data = [];
@@ -94,7 +94,10 @@ public function create(mixed $data): array|object
9494 // Send a 201 when the user has been successfully added to DB
9595 HttpResponse::setHeadersByCode (StatusCode::CREATED );
9696
97- return $ data ; // return statement exists the function and doesn't go beyond this scope
97+ // Add user UUID to the object to give back the user's UUID to the client
98+ $ data ->userUuid = $ userUuid ;
99+
100+ return $ data ;
98101 }
99102
100103 throw new InvalidValidationException ("Invalid user payload " );
@@ -120,8 +123,8 @@ public function update(mixed $postBody): array|object
120123 }
121124
122125 if (UserDal::update ($ userUuid , $ userEntity ) === false ) {
123- // Set an internal error 500 when we cannot add an entry to the database
124- HttpResponse::setHeadersByCode (StatusCode::INTERNAL_SERVER_ERROR );
126+ // Most likely, the user isn't found, set a 404 to the client
127+ HttpResponse::setHeadersByCode (StatusCode::NOT_FOUND );
125128
126129 // If invalid or got an error, give back an empty response
127130 return [];
0 commit comments