Skip to content
This repository was archived by the owner on Dec 27, 2024. It is now read-only.

Commit 2b176b6

Browse files
dev/codeforces/ Добавил контроллеры
1 parent 824c2a6 commit 2b176b6

File tree

3 files changed

+131
-0
lines changed

3 files changed

+131
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,63 @@
11
package com.cf.cfteam.controllers.codeforces;
22

3+
import com.cf.cfteam.models.entities.codeforces.Player;
4+
import com.cf.cfteam.models.entities.codeforces.Team;
5+
import com.cf.cfteam.services.codeforces.PlayerService;
6+
import com.cf.cfteam.transfer.payloads.codeforces.GroupPayload;
7+
import com.cf.cfteam.transfer.payloads.codeforces.TeamPayload;
8+
import lombok.RequiredArgsConstructor;
9+
import org.springframework.http.ResponseEntity;
10+
import org.springframework.security.core.Authentication;
11+
import org.springframework.web.bind.annotation.*;
12+
13+
import java.util.List;
14+
15+
@RestController
16+
@RequiredArgsConstructor
17+
@RequestMapping("api/cf/players")
318
public class PlayerController {
19+
20+
private final PlayerService playerService;
21+
22+
@GetMapping("/team/{teamId}")
23+
public ResponseEntity<List<Player>> getAllPlayersByTeam(@PathVariable Long teamId, Authentication authentication) {
24+
List<Player> players = playerService.getAllPlayersByTeam(teamId);
25+
return ResponseEntity.ok(players);
26+
}
27+
28+
@GetMapping("/{playerId}")
29+
public ResponseEntity<Player> getPlayerById(@PathVariable Long playerId, Authentication authentication) {
30+
Player player = playerService.getPlayerById(playerId);
31+
return ResponseEntity.ok(player);
32+
}
33+
34+
@PostMapping("/team/{teamId}")
35+
public ResponseEntity<Player> addPlayerToTeam(@PathVariable Long teamId, @RequestBody TeamPayload teamPayload,
36+
Authentication authentication) {
37+
Player player = playerService.addPlayerToTeam(teamId, teamPayload);
38+
return ResponseEntity.ok(player);
39+
}
40+
41+
@PutMapping("/players/{playerId}/teams/{teamId}")
42+
public ResponseEntity<Player> updatePlayerInTeam(@PathVariable Long playerId,
43+
@PathVariable Long teamId,
44+
@RequestBody GroupPayload groupPayload,
45+
Authentication authentication) {
46+
Player player = playerService.updatePlayer(playerId, teamId, groupPayload);
47+
return ResponseEntity.ok(player);
48+
}
49+
50+
@DeleteMapping("/players/{playerId}/teams/{teamId}")
51+
public ResponseEntity<Void> deletePlayerFromTeam(@PathVariable Long playerId,
52+
@PathVariable Long teamId,
53+
Authentication authentication) {
54+
playerService.deletePlayerFromTeam(playerId, teamId);
55+
return ResponseEntity.noContent().build();
56+
}
57+
58+
@DeleteMapping("/team/{teamId}")
59+
public ResponseEntity<Void> deleteAllPlayersFromTeam(@PathVariable Long teamId, Authentication authentication) {
60+
playerService.deleteAllPlayersFromTeam(teamId);
61+
return ResponseEntity.noContent().build();
62+
}
463
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,58 @@
11
package com.cf.cfteam.controllers.codeforces;
22

3+
import com.cf.cfteam.models.entities.codeforces.Team;
4+
import com.cf.cfteam.services.codeforces.TeamService;
5+
import com.cf.cfteam.transfer.payloads.codeforces.GroupPayload;
6+
import com.cf.cfteam.transfer.payloads.codeforces.TeamPayload;
7+
import lombok.RequiredArgsConstructor;
8+
import org.springframework.http.ResponseEntity;
9+
import org.springframework.security.core.Authentication;
10+
import org.springframework.web.bind.annotation.*;
11+
12+
import java.util.List;
13+
14+
@RestController
15+
@RequiredArgsConstructor
16+
@RequestMapping("api/cf/teams")
317
public class TeamController {
18+
19+
private final TeamService teamService;
20+
21+
@GetMapping("/group/{groupId}")
22+
public ResponseEntity<List<Team>> getAllTeamsByGroup(@PathVariable Long groupId, Authentication authentication) {
23+
List<Team> teams = teamService.getAllTeamsByGroup(groupId);
24+
return ResponseEntity.ok(teams);
25+
}
26+
27+
@GetMapping("/{teamId}")
28+
public ResponseEntity<Team> getTeamById(@PathVariable Long teamId, Authentication authentication) {
29+
Team team = teamService.getTeamById(teamId);
30+
return ResponseEntity.ok(team);
31+
}
32+
33+
@PostMapping("/group/{groupId}")
34+
public ResponseEntity<Team> addTeamToGroup(@PathVariable Long groupId, @RequestBody TeamPayload teamPayload,
35+
Authentication authentication) {
36+
Team createdTeam = teamService.addTeamToGroup(groupId, teamPayload);
37+
return ResponseEntity.ok(createdTeam);
38+
}
39+
40+
@PutMapping("/{teamId}")
41+
public ResponseEntity<Team> updateTeam(@PathVariable Long teamId, @RequestBody GroupPayload groupPayload,
42+
Authentication authentication) {
43+
Team team = teamService.updateTeam(teamId, groupPayload);
44+
return ResponseEntity.ok(team);
45+
}
46+
47+
@DeleteMapping("/{teamId}")
48+
public ResponseEntity<Void> deleteTeam(@PathVariable Long teamId, Authentication authentication) {
49+
teamService.deleteTeam(teamId);
50+
return ResponseEntity.noContent().build();
51+
}
52+
53+
@DeleteMapping("/group/{groupId}")
54+
public ResponseEntity<Void> deleteAllTeamsByUser(@PathVariable Long groupId, Authentication authentication) {
55+
teamService.deleteAllTeamsByGroup(groupId);
56+
return ResponseEntity.noContent().build();
57+
}
458
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.cf.cfteam.services.client;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import lombok.Getter;
5+
import lombok.Setter;
6+
7+
import java.util.List;
8+
9+
@Getter
10+
@Setter
11+
public class UserInfoResponse {
12+
13+
@JsonProperty("status")
14+
private String status;
15+
16+
@JsonProperty("result")
17+
private List<CodeforcesPlayerResponse> result;
18+
}

0 commit comments

Comments
 (0)