Add Administration API for teams's administration panel (#97)
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
Co-authored-by: Override-6 <maximebatista18@gmail.com> Co-authored-by: samuel <Samuel.BERION@etu.uca.fr> Co-authored-by: sam <sam@LAPTOPSam.lan> Co-authored-by: sam <sam@laptop.lan> Reviewed-on: #97 Co-authored-by: Samuel BERION <samuel.berion@etu.uca.fr> Co-committed-by: Samuel BERION <samuel.berion@etu.uca.fr>shareTactic^2
parent
93612c473b
commit
55d5970055
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace IQBall\Api\Controller;
|
||||
|
||||
use IQBall\Api\APIControl;
|
||||
use IQBall\Core\Data\Account;
|
||||
use IQBall\Core\Data\Team;
|
||||
use IQBall\Core\Data\TeamInfo;
|
||||
use IQBall\Core\Gateway\TeamGateway;
|
||||
use IQBall\Core\Http\HttpCodes;
|
||||
use IQBall\Core\Http\HttpRequest;
|
||||
use IQBall\Core\Http\HttpResponse;
|
||||
use IQBall\Core\Http\JsonHttpResponse;
|
||||
use IQBall\Core\Model\TeamModel;
|
||||
use IQBall\Core\Validation\DefaultValidators;
|
||||
|
||||
class APITeamController {
|
||||
private TeamModel $teamModel;
|
||||
|
||||
/**
|
||||
* @param TeamModel $teamModel
|
||||
*/
|
||||
public function __construct(TeamModel $teamModel) {
|
||||
$this->teamModel = $teamModel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $req_params
|
||||
* @return HttpResponse
|
||||
*/
|
||||
public function listTeams(array $req_params): HttpResponse {
|
||||
return APIControl::runCheckedFrom($req_params, [
|
||||
'start' => [DefaultValidators::isUnsignedInteger()],
|
||||
'n' => [DefaultValidators::isUnsignedInteger()],
|
||||
], function (HttpRequest $req) {
|
||||
$teams = $this->teamModel->listAll(intval($req['start']), intval($req['n']));
|
||||
return new JsonHttpResponse([
|
||||
"totalCount" => $this->teamModel->countTeam(),
|
||||
"teams" => $teams,
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
public function addTeam(): HttpResponse {
|
||||
return APIControl::runChecked([
|
||||
'name' => [DefaultValidators::name()],
|
||||
'picture' => [DefaultValidators::isURL()],
|
||||
'mainColor' => [DefaultValidators::hexColor()],
|
||||
'secondaryColor' => [DefaultValidators::hexColor()],
|
||||
|
||||
], function (HttpRequest $req) {
|
||||
$this->teamModel->createTeam($req['name'], $req['picture'], $req['mainColor'], $req['secondaryColor']);
|
||||
return HttpResponse::fromCode(HttpCodes::OK);
|
||||
});
|
||||
}
|
||||
|
||||
public function deleteTeamSelected(): HttpResponse {
|
||||
return APIControl::runChecked([
|
||||
'teams' => [],
|
||||
], function (HttpRequest $req) {
|
||||
$this->teamModel->deleteTeamSelected($req['teams']);
|
||||
return HttpResponse::fromCode(HttpCodes::OK);
|
||||
});
|
||||
}
|
||||
|
||||
public function updateTeam(int $id): HttpResponse {
|
||||
return APIControl::runChecked([
|
||||
'name' => [DefaultValidators::name()],
|
||||
'picture' => [DefaultValidators::isURL()],
|
||||
'mainColor' => [DefaultValidators::hexColor()],
|
||||
'secondaryColor' => [DefaultValidators::hexColor()],
|
||||
], function (HttpRequest $req) {
|
||||
$this->teamModel->editTeam($req['id'], $req['name'], $req['picture'], $req['mainColor'], $req['secondaryColor']);
|
||||
return HttpResponse::fromCode(HttpCodes::OK);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in new issue