pull/97/head
samuel 1 year ago committed by sam
parent 088b1a5281
commit b0d0409a06

@ -63,8 +63,9 @@ function getRoutes(): AltoRouter {
$router->map("POST", "/admin/user/remove-all", Action::noAuth(fn() => getAccountController()->removeUsers())); $router->map("POST", "/admin/user/remove-all", Action::noAuth(fn() => getAccountController()->removeUsers()));
$router->map("POST", "/admin/user/[i:id]/update", Action::noAuth(fn(int $id) => getAccountController()->updateUser($id))); $router->map("POST", "/admin/user/[i:id]/update", Action::noAuth(fn(int $id) => getAccountController()->updateUser($id)));
$router->map("GET", "/admin/server-info", Action::noAuth(fn() => getServerController()->getServerInfo())); $router->map("GET", "/admin/server-info", Action::noAuth(fn() => getServerController()->getServerInfo()));
$router->map("GET", "/admin/list-team", Action::noAuth(fn() => getAPITeamController()->listTeam($_GET))); $router->map("GET", "/admin/list-team", Action::noAuth(fn() => getAPITeamController()->listTeams($_GET)));
$router->map("POST", "/admin/add-team", Action::noAuth(fn() => getAPITeamController()->addTeam())); $router->map("POST", "/admin/add-team", Action::noAuth(fn() => getAPITeamController()->addTeam()));
$router->map("POST", "/admin/delete-teams", Action::noAuth(fn() => getAPITeamController()->deleteTeamSelected()));

@ -28,7 +28,7 @@ class APITeamController {
* @param array<string, mixed> $req_params * @param array<string, mixed> $req_params
* @return HttpResponse * @return HttpResponse
*/ */
public function listTeam(array $req_params): HttpResponse { public function listTeams(array $req_params): HttpResponse {
return Control::runCheckedFrom($req_params, [ return Control::runCheckedFrom($req_params, [
'start' => [DefaultValidators::isUnsignedInteger()], 'start' => [DefaultValidators::isUnsignedInteger()],
'n' => [DefaultValidators::isUnsignedInteger()] 'n' => [DefaultValidators::isUnsignedInteger()]
@ -54,5 +54,14 @@ class APITeamController {
}, true); }, true);
} }
public function deleteTeamSelected(): HttpResponse{
return Control::runChecked([
'teams' => []
], function (HttpRequest $req){
$this->teamModel->deleteTeamSelected($req['teams']);
return HttpResponse::fromCode(HttpCodes::OK);
},true);
}
} }

@ -147,11 +147,10 @@ class TeamGateway {
*/ */
public function listAll(int $start, int $n): array { public function listAll(int $start, int $n): array {
$rows = $this->con->fetch( $rows = $this->con->fetch(
"SELECT * FROM Team WHERE id BETWEEN :start AND :n LIMIT :limit", "SELECT * FROM Team LIMIT :start, :n",
[ [
":start" => [$start, PDO::PARAM_INT], ":start" => [$start, PDO::PARAM_INT],
":n" => [$n, PDO::PARAM_INT], ":n" => [$n, PDO::PARAM_INT],
":limit" => [$n - $start + 1, PDO::PARAM_INT], //nombre de lignes à récupérer
] ]
); );
return array_map(fn($row) => new TeamInfo($row['id'], $row['name'], $row['picture'], $row['main_color'], $row['second_color']), $rows); return array_map(fn($row) => new TeamInfo($row['id'], $row['name'], $row['picture'], $row['main_color'], $row['second_color']), $rows);
@ -159,12 +158,23 @@ class TeamGateway {
public function countTeam(): int { public function countTeam(): int {
$result = $this->con->fetch( $result = $this->con->fetch(
"SELECT count(*) FROM Team", []); "SELECT count(*) as count FROM Team", []);
if (empty($result) || !isset($result[0]['count'])) { if (empty($result) || !isset($result[0]['count'])) {
return 0; return 0;
} }
return $result[0]['count']; return $result[0]['count'];
} }
public function deleteTeamSelected(array $selectedTeams): void {
foreach ($selectedTeams as $team) {
$this->con->exec(
"DELETE FROM TEAM WHERE id=:team",
[
"team" => [$team, PDO::PARAM_INT],
]
);
}
}
} }

@ -153,4 +153,8 @@ class TeamModel {
return $this->teams->countTeam(); return $this->teams->countTeam();
} }
public function deleteTeamSelected(array $selectedTeams){
$this->teams->deleteTeamSelected($selectedTeams);
}
} }

Loading…
Cancel
Save