|
|
|
@ -6,10 +6,12 @@ use IQBall\App\Control;
|
|
|
|
|
use IQBall\Core\Data\Account;
|
|
|
|
|
use IQBall\Core\Data\Team;
|
|
|
|
|
use IQBall\Core\Data\TeamInfo;
|
|
|
|
|
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;
|
|
|
|
|
use IQBall\Core\Validation\Validators;
|
|
|
|
|
|
|
|
|
|
class APITeamController {
|
|
|
|
@ -22,27 +24,35 @@ class APITeamController {
|
|
|
|
|
$this->teamModel = $teamModel;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array<string, mixed> $req_params
|
|
|
|
|
* @return HttpResponse
|
|
|
|
|
*/
|
|
|
|
|
public function listTeam(array $req_params): HttpResponse {
|
|
|
|
|
|
|
|
|
|
return Control::runCheckedFrom($req_params, [
|
|
|
|
|
'start' => [Validators::isUnsignedInteger()],
|
|
|
|
|
'n' => [Validators::isUnsignedInteger()]
|
|
|
|
|
'start' => [DefaultValidators::isUnsignedInteger()],
|
|
|
|
|
'n' => [DefaultValidators::isUnsignedInteger()]
|
|
|
|
|
], function (HttpRequest $req) {
|
|
|
|
|
$team = $this->teamModel->listAll(intval($req['start']), intval($req['n']));
|
|
|
|
|
$response = array_map(fn(Team $t) => $this->accountExposedFields($t), $team);
|
|
|
|
|
return new JsonHttpResponse($response);
|
|
|
|
|
$teams = $this->teamModel->listAll(intval($req['start']), intval($req['n']));
|
|
|
|
|
return new JsonHttpResponse([
|
|
|
|
|
"totalCount" => $this->teamModel->countTeam(),
|
|
|
|
|
"teams" => $teams
|
|
|
|
|
]);
|
|
|
|
|
}, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function accountExposedFields(Team $team): array {
|
|
|
|
|
$info = $team->getInfo();
|
|
|
|
|
return [
|
|
|
|
|
'id' => $info->getId(),
|
|
|
|
|
'name' => $info->getName(),
|
|
|
|
|
'picture' => $info->getPicture(),
|
|
|
|
|
'maincolor' => $info->getMainColor(),
|
|
|
|
|
'secondcolor' => $info->getSecondColor(),
|
|
|
|
|
];
|
|
|
|
|
public function addTeam(): HttpResponse {
|
|
|
|
|
return Control::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);
|
|
|
|
|
}, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|