WIP
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
parent
ad94eef630
commit
7a3774cb81
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace IQBall\Api\Controller;
|
||||||
|
|
||||||
|
use IQBall\App\Control;
|
||||||
|
use IQBall\Core\Data\Account;
|
||||||
|
use IQBall\Core\Http\HttpCodes;
|
||||||
|
use IQBall\Core\Http\HttpRequest;
|
||||||
|
use IQBall\Core\Http\HttpResponse;
|
||||||
|
use IQBall\Core\Http\JsonHttpResponse;
|
||||||
|
use IQBall\Core\Model\AuthModel;
|
||||||
|
use IQBall\Core\Validation\FieldValidationFail;
|
||||||
|
use IQBall\Core\Validation\Validator;
|
||||||
|
use IQBall\Core\Validation\Validators;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API endpoint related to tactics
|
||||||
|
*/
|
||||||
|
class APIUserController {
|
||||||
|
private AuthModel $model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param AuthModel $model
|
||||||
|
*/
|
||||||
|
public function __construct(AuthModel $model) {
|
||||||
|
$this->model = $model;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Account $account
|
||||||
|
* @return HttpResponse
|
||||||
|
*/
|
||||||
|
public function updateProfil(Account $account): HttpResponse {
|
||||||
|
return Control::runChecked([
|
||||||
|
"username" => [Validators::name()],
|
||||||
|
"email" => [Validators::email()]
|
||||||
|
], function (HttpRequest $request) use ($account) {
|
||||||
|
|
||||||
|
$failures = $this->model->updateProfil($request["username"], $request["email"], $account->getUser()->getId());
|
||||||
|
|
||||||
|
if (!empty($failures)) {
|
||||||
|
//TODO find a system to handle Unauthorized error codes more easily from failures.
|
||||||
|
return new JsonHttpResponse($failures, HttpCodes::BAD_REQUEST);
|
||||||
|
}
|
||||||
|
|
||||||
|
return HttpResponse::fromCode(HttpCodes::OK);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue