Skip to content

Commit

Permalink
✨ [Feature] #844 Team 확정하기 API (#884)
Browse files Browse the repository at this point in the history
  • Loading branch information
AreSain authored Jul 15, 2024
1 parent 56ee506 commit 3d9c74b
Show file tree
Hide file tree
Showing 8 changed files with 307 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import gg.agenda.api.user.agendateam.controller.request.TeamCreateReqDto;
import gg.agenda.api.user.agendateam.controller.request.TeamDetailsReqDto;
import gg.agenda.api.user.agendateam.controller.request.TeamKeyReqDto;
import gg.agenda.api.user.agendateam.controller.response.MyTeamSimpleResDto;
import gg.agenda.api.user.agendateam.controller.response.TeamCreateResDto;
import gg.agenda.api.user.agendateam.controller.response.TeamDetailsResDto;
Expand Down Expand Up @@ -54,8 +55,8 @@ public ResponseEntity<Optional<MyTeamSimpleResDto>> myTeamSimpleDetails(
*/
@GetMapping
public ResponseEntity<TeamDetailsResDto> agendaTeamDetails(@Parameter(hidden = true) @Login UserDto user,
@RequestBody @Valid TeamDetailsReqDto teamDetailsReqDto, @RequestParam("agenda_key") UUID agendaKey) {
TeamDetailsResDto teamDetailsResDto = agendaTeamService.detailsAgendaTeam(user, agendaKey, teamDetailsReqDto);
@RequestBody @Valid TeamKeyReqDto teamKeyReqDto, @RequestParam("agenda_key") UUID agendaKey) {
TeamDetailsResDto teamDetailsResDto = agendaTeamService.detailsAgendaTeam(user, agendaKey, teamKeyReqDto);
return ResponseEntity.ok(teamDetailsResDto);
}

Expand All @@ -70,4 +71,11 @@ public ResponseEntity<TeamCreateResDto> agendaTeamAdd(@Parameter(hidden = true)
TeamCreateResDto teamCreateResDto = agendaTeamService.addAgendaTeam(user, teamCreateReqDto, agendaKey);
return ResponseEntity.status(HttpStatus.CREATED).body(teamCreateResDto);
}

@PatchMapping("/confirm")
public ResponseEntity<Void> confirmTeam(@Parameter(hidden = true) @Login UserDto user,
@RequestBody @Valid TeamKeyReqDto teamKeyReqDto, @RequestParam("agenda_key") UUID agendaKey) {
agendaTeamService.confirmTeam(user, agendaKey, teamKeyReqDto);
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@

@Getter
@NoArgsConstructor(access = lombok.AccessLevel.PROTECTED)
public class TeamDetailsReqDto {
public class TeamKeyReqDto {
@NotNull
private UUID teamKey;

public TeamDetailsReqDto(UUID teamKey) {
public TeamKeyReqDto(UUID teamKey) {
this.teamKey = teamKey;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.springframework.transaction.annotation.Transactional;

import gg.agenda.api.user.agendateam.controller.request.TeamCreateReqDto;
import gg.agenda.api.user.agendateam.controller.request.TeamDetailsReqDto;
import gg.agenda.api.user.agendateam.controller.request.TeamKeyReqDto;
import gg.agenda.api.user.agendateam.controller.response.MyTeamSimpleResDto;
import gg.agenda.api.user.agendateam.controller.response.TeamCreateResDto;
import gg.agenda.api.user.agendateam.controller.response.TeamDetailsResDto;
Expand Down Expand Up @@ -80,12 +80,12 @@ public Optional<MyTeamSimpleResDto> detailsMyTeamSimple(UserDto user, UUID agend
* @return 만들어진 팀 상세 정보
*/
@Transactional(readOnly = true)
public TeamDetailsResDto detailsAgendaTeam(UserDto user, UUID agendaKey, TeamDetailsReqDto teamDetailsReqDto) {
public TeamDetailsResDto detailsAgendaTeam(UserDto user, UUID agendaKey, TeamKeyReqDto teamKeyReqDto) {
Agenda agenda = agendaRepository.findByAgendaKey(agendaKey)
.orElseThrow(() -> new NotExistException(AGENDA_NOT_FOUND));

AgendaTeam agendaTeam = agendaTeamRepository
.findByAgendaAndTeamKeyAndStatus(agenda, teamDetailsReqDto.getTeamKey(), OPEN, CONFIRM)
.findByAgendaAndTeamKeyAndStatus(agenda, teamKeyReqDto.getTeamKey(), OPEN, CONFIRM)
.orElseThrow(() -> new NotExistException(AGENDA_TEAM_NOT_FOUND));

List<AgendaTeamProfile> agendaTeamProfileList = agendaTeamProfileRepository
Expand Down Expand Up @@ -145,4 +145,24 @@ public TeamCreateResDto addAgendaTeam(UserDto user, TeamCreateReqDto teamCreateR
agendaTeamProfileRepository.save(agendaTeamProfile);
return new TeamCreateResDto(agendaTeam.getTeamKey().toString());
}

@Transactional
public void confirmTeam(UserDto user, UUID agendaKey, TeamKeyReqDto teamKeyReqDto) {
Agenda agenda = agendaRepository.findByAgendaKey(agendaKey)
.orElseThrow(() -> new NotExistException(AGENDA_NOT_FOUND));

AgendaTeam agendaTeam = agendaTeamRepository
.findByAgendaAndTeamKeyAndStatus(agenda, teamKeyReqDto.getTeamKey(), OPEN, CONFIRM)
.orElseThrow(() -> new NotExistException(AGENDA_TEAM_NOT_FOUND));

if (!agendaTeam.getLeaderIntraId().equals(user.getIntraId())) {
throw new ForbiddenException(TEAM_LEADER_FORBIDDEN);
}
if (agendaTeam.getMateCount() < agenda.getMinPeople()) {
throw new BusinessException(NOT_ENOUGH_TEAM_MEMBER);
}
agenda.checkAgenda(agendaTeam.getLocation(), LocalDateTime.now());
agendaTeam.confirm();
agendaTeamRepository.save(agendaTeam);
}
}
46 changes: 42 additions & 4 deletions gg-agenda-api/src/test/java/gg/agenda/api/AgendaMockData.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gg.agenda.api;

import static gg.data.agenda.type.AgendaStatus.*;
import static gg.data.agenda.type.AgendaStatus.CONFIRM;
import static gg.data.agenda.type.AgendaTeamStatus.*;
import static gg.data.agenda.type.Coalition.*;
import static gg.data.agenda.type.Location.*;
Expand Down Expand Up @@ -59,7 +58,7 @@ public Agenda createOfficialAgenda() {
.currentTeam(0)
.minPeople(1)
.maxPeople(5)
.status(AgendaStatus.ON_GOING)
.status(ON_GOING)
.posterUri("posterUri")
.hostIntraId("hostIntraId")
.location(Location.MIX)
Expand All @@ -81,7 +80,7 @@ public Agenda createNonOfficialAgenda() {
.currentTeam(0)
.minPeople(1)
.maxPeople(5)
.status(AgendaStatus.ON_GOING)
.status(ON_GOING)
.posterUri("posterUri")
.hostIntraId("hostIntraId")
.location(Location.MIX)
Expand Down Expand Up @@ -164,7 +163,7 @@ public List<Agenda> createAgendaHistory(int size) {
.currentTeam(0)
.minPeople(1)
.maxPeople(5)
.status(CONFIRM)
.status(AgendaStatus.CONFIRM)
.posterUri("posterUri")
.hostIntraId("hostIntraId")
.location(Location.MIX)
Expand Down Expand Up @@ -308,6 +307,28 @@ public Agenda createAgenda(int curruentTeam) {
return agendaRepository.save(agenda);
}

public Agenda createNeedMorePeopleAgenda(int curruentTeam) {
Agenda agenda = Agenda.builder()
.title("title")
.content("content")
.deadline(LocalDateTime.now().plusDays(1))
.startTime(LocalDateTime.now().plusDays(2))
.endTime(LocalDateTime.now().plusDays(3))
.minTeam(1)
.maxTeam(5)
.currentTeam(curruentTeam)
.minPeople(3)
.maxPeople(5)
.posterUri("posterUri")
.hostIntraId("hostIntraId")
.location(SEOUL)
.status(ON_GOING)
.isOfficial(true)
.isRanking(true)
.build();
return agendaRepository.save(agenda);
}

public Agenda createAgenda(AgendaStatus status) {
Agenda agenda = Agenda.builder()
.title("title")
Expand Down Expand Up @@ -453,6 +474,23 @@ public AgendaTeam createAgendaTeam(Agenda agenda, User user, Location location,
return agendaTeamRepository.save(agendaTeam);
}

public AgendaTeam createAgendaTeam(int currentTeam, Agenda agenda, User user, Location location) {
AgendaTeam agendaTeam = AgendaTeam.builder()
.agenda(agenda)
.teamKey(randomUUID())
.name("name")
.content("content")
.leaderIntraId(user.getIntraId())
.status(OPEN)
.location(location)
.mateCount(currentTeam)
.award("award")
.awardPriority(1)
.isPrivate(false)
.build();
return agendaTeamRepository.save(agendaTeam);
}

public AgendaTeam createAgendaTeam(Agenda agenda, User user, Location location, AgendaTeamStatus status,
Boolean isPrivate) {
AgendaTeam agendaTeam = AgendaTeam.builder()
Expand Down
Loading

0 comments on commit 3d9c74b

Please sign in to comment.