parent
cfa9b40bc1
commit
9117d4afab
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace IQBall\Api\Controller;
|
||||||
|
|
||||||
|
use IQBall\App\Control;
|
||||||
|
use IQBall\Core\Data\Account;
|
||||||
|
use IQBall\Core\Data\Team;
|
||||||
|
use IQBall\Core\Data\TeamInfo;
|
||||||
|
use IQBall\Core\Http\HttpRequest;
|
||||||
|
use IQBall\Core\Http\HttpResponse;
|
||||||
|
use IQBall\Core\Http\JsonHttpResponse;
|
||||||
|
use IQBall\Core\Model\TeamModel;
|
||||||
|
use IQBall\Core\Validation\Validators;
|
||||||
|
|
||||||
|
class APITeamController {
|
||||||
|
private TeamModel $teamModel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param TeamModel $teamModel
|
||||||
|
*/
|
||||||
|
public function __construct(TeamModel $teamModel) {
|
||||||
|
$this->teamModel = $teamModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listTeam(array $req_params): HttpResponse {
|
||||||
|
|
||||||
|
return Control::runCheckedFrom($req_params, [
|
||||||
|
'start' => [Validators::isUnsignedInteger()],
|
||||||
|
'n' => [Validators::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);
|
||||||
|
}, 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(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue