|
|
@ -2,19 +2,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
namespace IQBall\Api\Controller;
|
|
|
|
namespace IQBall\Api\Controller;
|
|
|
|
|
|
|
|
|
|
|
|
use IQBall\App\Control;
|
|
|
|
use IQBall\Api\APIControl;
|
|
|
|
use IQBall\Core\Data\Account;
|
|
|
|
use IQBall\Core\Data\Account;
|
|
|
|
use IQBall\Core\Data\Team;
|
|
|
|
use IQBall\Core\Data\Team;
|
|
|
|
use IQBall\Core\Data\TeamInfo;
|
|
|
|
use IQBall\Core\Data\TeamInfo;
|
|
|
|
|
|
|
|
use IQBall\Core\Gateway\TeamGateway;
|
|
|
|
use IQBall\Core\Http\HttpCodes;
|
|
|
|
use IQBall\Core\Http\HttpCodes;
|
|
|
|
use IQBall\Core\Http\HttpRequest;
|
|
|
|
use IQBall\Core\Http\HttpRequest;
|
|
|
|
use IQBall\Core\Http\HttpResponse;
|
|
|
|
use IQBall\Core\Http\HttpResponse;
|
|
|
|
use IQBall\Core\Http\JsonHttpResponse;
|
|
|
|
use IQBall\Core\Http\JsonHttpResponse;
|
|
|
|
use IQBall\Core\Model\TeamModel;
|
|
|
|
use IQBall\Core\Model\TeamModel;
|
|
|
|
use IQBall\Core\Validation\DefaultValidators;
|
|
|
|
use IQBall\Core\Validation\DefaultValidators;
|
|
|
|
use IQBall\Core\Validation\Validators;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class APITeamController {
|
|
|
|
class APITeamController {
|
|
|
|
|
|
|
|
|
|
|
|
private TeamModel $teamModel;
|
|
|
|
private TeamModel $teamModel;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -29,38 +30,50 @@ class APITeamController {
|
|
|
|
* @return HttpResponse
|
|
|
|
* @return HttpResponse
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function listTeams(array $req_params): HttpResponse {
|
|
|
|
public function listTeams(array $req_params): HttpResponse {
|
|
|
|
return Control::runCheckedFrom($req_params, [
|
|
|
|
return APIControl::runCheckedFrom($req_params, [
|
|
|
|
'start' => [DefaultValidators::isUnsignedInteger()],
|
|
|
|
'start' => [DefaultValidators::isUnsignedInteger()],
|
|
|
|
'n' => [DefaultValidators::isUnsignedInteger()]
|
|
|
|
'n' => [DefaultValidators::isUnsignedInteger()],
|
|
|
|
], function (HttpRequest $req) {
|
|
|
|
], function (HttpRequest $req) {
|
|
|
|
$teams = $this->teamModel->listAll(intval($req['start']), intval($req['n']));
|
|
|
|
$teams = $this->teamModel->listAll(intval($req['start']), intval($req['n']));
|
|
|
|
return new JsonHttpResponse([
|
|
|
|
return new JsonHttpResponse([
|
|
|
|
"totalCount" => $this->teamModel->countTeam(),
|
|
|
|
"totalCount" => $this->teamModel->countTeam(),
|
|
|
|
"teams" => $teams
|
|
|
|
"teams" => $teams,
|
|
|
|
]);
|
|
|
|
]);
|
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function addTeam(): HttpResponse {
|
|
|
|
public function addTeam(): HttpResponse {
|
|
|
|
return Control::runChecked([
|
|
|
|
return APIControl::runChecked([
|
|
|
|
'name' => [DefaultValidators::name()],
|
|
|
|
'name' => [DefaultValidators::name()],
|
|
|
|
'picture' => [DefaultValidators::isURL()],
|
|
|
|
'picture' => [DefaultValidators::isURL()],
|
|
|
|
'mainColor' => [DefaultValidators::hexColor()],
|
|
|
|
'mainColor' => [DefaultValidators::hexColor()],
|
|
|
|
'secondaryColor' => [DefaultValidators::hexColor()]
|
|
|
|
'secondaryColor' => [DefaultValidators::hexColor()],
|
|
|
|
|
|
|
|
|
|
|
|
], function (HttpRequest $req){
|
|
|
|
], function (HttpRequest $req) {
|
|
|
|
$this->teamModel->createTeam($req['name'],$req['picture'],$req['mainColor'],$req['secondaryColor']);
|
|
|
|
$this->teamModel->createTeam($req['name'], $req['picture'], $req['mainColor'], $req['secondaryColor']);
|
|
|
|
return HttpResponse::fromCode(HttpCodes::OK);
|
|
|
|
return HttpResponse::fromCode(HttpCodes::OK);
|
|
|
|
}, true);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function deleteTeamSelected(): HttpResponse{
|
|
|
|
public function deleteTeamSelected(): HttpResponse {
|
|
|
|
return Control::runChecked([
|
|
|
|
return APIControl::runChecked([
|
|
|
|
'teams' => []
|
|
|
|
'teams' => [],
|
|
|
|
], function (HttpRequest $req){
|
|
|
|
], function (HttpRequest $req) {
|
|
|
|
$this->teamModel->deleteTeamSelected($req['teams']);
|
|
|
|
$this->teamModel->deleteTeamSelected($req['teams']);
|
|
|
|
return HttpResponse::fromCode(HttpCodes::OK);
|
|
|
|
return HttpResponse::fromCode(HttpCodes::OK);
|
|
|
|
},true);
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|