|
|
|
@ -15,13 +15,15 @@ use IQBall\Core\Validation\DefaultValidators;
|
|
|
|
|
/**
|
|
|
|
|
* API endpoint related to tactics
|
|
|
|
|
*/
|
|
|
|
|
class APITacticController {
|
|
|
|
|
class APITacticController
|
|
|
|
|
{
|
|
|
|
|
private TacticModel $model;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param TacticModel $model
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(TacticModel $model) {
|
|
|
|
|
public function __construct(TacticModel $model)
|
|
|
|
|
{
|
|
|
|
|
$this->model = $model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -31,7 +33,8 @@ class APITacticController {
|
|
|
|
|
* @param Account $account
|
|
|
|
|
* @return HttpResponse
|
|
|
|
|
*/
|
|
|
|
|
public function updateName(int $tactic_id, Account $account): HttpResponse {
|
|
|
|
|
public function updateName(int $tactic_id, Account $account): HttpResponse
|
|
|
|
|
{
|
|
|
|
|
return APIControl::runChecked([
|
|
|
|
|
"name" => [DefaultValidators::lenBetween(1, 50), DefaultValidators::nameWithSpaces()],
|
|
|
|
|
], function (HttpRequest $request) use ($tactic_id, $account) {
|
|
|
|
@ -44,14 +47,15 @@ class APITacticController {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return HttpResponse::fromCode(HttpCodes::OK);
|
|
|
|
|
});
|
|
|
|
|
}, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param int $id
|
|
|
|
|
* @return HttpResponse
|
|
|
|
|
*/
|
|
|
|
|
public function saveContent(int $id, Account $account): HttpResponse {
|
|
|
|
|
public function saveContent(int $id, Account $account): HttpResponse
|
|
|
|
|
{
|
|
|
|
|
return APIControl::runChecked([
|
|
|
|
|
"content" => [],
|
|
|
|
|
], function (HttpRequest $req) use ($id) {
|
|
|
|
@ -60,7 +64,7 @@ class APITacticController {
|
|
|
|
|
return new JsonHttpResponse([$fail], HttpCodes::BAD_REQUEST);
|
|
|
|
|
}
|
|
|
|
|
return HttpResponse::fromCode(HttpCodes::OK);
|
|
|
|
|
});
|
|
|
|
|
}, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -68,7 +72,8 @@ class APITacticController {
|
|
|
|
|
* @param int $userId
|
|
|
|
|
* @return HttpResponse given user information.
|
|
|
|
|
*/
|
|
|
|
|
public function getUserTactics(int $userId): HttpResponse {
|
|
|
|
|
public function getUserTactics(int $userId): HttpResponse
|
|
|
|
|
{
|
|
|
|
|
$tactics = $this->model->listAllOf($userId);
|
|
|
|
|
|
|
|
|
|
$response = array_map(fn(TacticInfo $t) => [
|
|
|
|
@ -76,6 +81,7 @@ class APITacticController {
|
|
|
|
|
'name' => $t->getName(),
|
|
|
|
|
'court' => $t->getCourtType(),
|
|
|
|
|
'creation_date' => $t->getCreationDate(),
|
|
|
|
|
|
|
|
|
|
], $tactics);
|
|
|
|
|
|
|
|
|
|
return new JsonHttpResponse($response);
|
|
|
|
|