Skip to content

Commit

Permalink
[Feature] 팀 참가 API 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
AreSain committed Jul 23, 2024
1 parent 4dfb839 commit d4e617d
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,15 @@ public ResponseEntity<List<ConfirmTeamResDto>> confirmTeamList(@RequestBody @Val
List<ConfirmTeamResDto> confirmTeamResDto = agendaTeamService.listConfirmTeam(agendaKey, pageable);
return ResponseEntity.ok(confirmTeamResDto);
}

/**
* 아젠다 팀 참여하기
* @param user 사용자 정보, teamKeyReqDto 팀 KEY 요청 정보, agendaId 아젠다 아이디
*/
@PatchMapping
public ResponseEntity<Void> attendTeamModify(@Parameter(hidden = true) @Login UserDto user,
@RequestBody @Valid TeamKeyReqDto teamKeyReqDto, @RequestParam("agenda_key") UUID agendaKey) {
agendaTeamService.modifyAttendTeam(user, teamKeyReqDto, agendaKey);
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public TeamDetailsResDto detailsAgendaTeam(UserDto user, UUID agendaKey, TeamKey
if (agendaTeam.getStatus().equals(CONFIRM)) { // 팀이 확정 상태인 경우에
if (agendaTeamProfileList.stream() // 팀에 속한 유저가 아닌 경우
.noneMatch(profile -> profile.getProfile().getUserId().equals(user.getId()))) {
throw new ForbiddenException(TEAM_FORBIDDEN); // 조회 불가
throw new ForbiddenException(NOT_TEAM_MATE); // 조회 불가
}
}
return new TeamDetailsResDto(agendaTeam, agendaTeamProfileList);
Expand Down Expand Up @@ -131,7 +131,7 @@ public TeamKeyResDto addAgendaTeam(UserDto user, TeamCreateReqDto teamCreateReqD
}

agendaTeamProfileRepository.findByAgendaProfileAndIsExistTrue(agenda, agendaProfile).ifPresent(teamProfile -> {
throw new DuplicationException(TEAM_FORBIDDEN);
throw new DuplicationException(AGENDA_TEAM_FORBIDDEN);
});

if (agenda.getIsOfficial()) {
Expand All @@ -146,7 +146,7 @@ public TeamKeyResDto addAgendaTeam(UserDto user, TeamCreateReqDto teamCreateReqD
});

AgendaTeam agendaTeam = TeamCreateReqDto.toEntity(teamCreateReqDto, agenda, user.getIntraId());
AgendaTeamProfile agendaTeamProfile = new AgendaTeamProfile(agendaTeam, agendaProfile);
AgendaTeamProfile agendaTeamProfile = new AgendaTeamProfile(agendaTeam, agenda, agendaProfile);
agendaRepository.save(agenda);
agendaTeamRepository.save(agendaTeam);
agendaTeamProfileRepository.save(agendaTeamProfile);
Expand Down Expand Up @@ -258,4 +258,36 @@ public List<ConfirmTeamResDto> listConfirmTeam(UUID agendaKey, Pageable pageable
})
.collect(Collectors.toList());
}

/**
* 아젠다 팀 참여하기
* @param user 사용자 정보, teamKeyReqDto 팀 KEY 요청 정보, agendaId 아젠다 아이디
*/
public void modifyAttendTeam(UserDto user, TeamKeyReqDto teamKeyReqDto, UUID agendaKey) {
AgendaProfile agendaProfile = agendaProfileRepository.findByUserId(user.getId())
.orElseThrow(() -> new NotExistException(AGENDA_PROFILE_NOT_FOUND));

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 (agenda.getLocation() != Location.MIX && agenda.getLocation() != agendaProfile.getLocation()) {
throw new BusinessException(LOCATION_NOT_VALID);
}

Ticket ticket = ticketRepository.findByAgendaProfileAndIsApprovedTrueAndIsUsedFalse(agendaProfile)
.orElseThrow(() -> new ForbiddenException(TICKET_NOT_EXIST));

agendaTeamProfileRepository.findByAgendaAndProfileAndIsExistTrue(agenda, agendaProfile)
.ifPresent(profile -> {
throw new ForbiddenException(AGENDA_TEAM_FORBIDDEN);
});

agendaTeam.attendTeam(agenda);
ticket.useTicket(agenda.getAgendaKey());
agendaTeamProfileRepository.save(new AgendaTeamProfile(agendaTeam, agenda, agendaProfile));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ public AgendaTeam createAgendaTeam(Agenda agenda, User user, Location location,
public AgendaTeamProfile createAgendaTeamProfile(AgendaTeam agendaTeam, AgendaProfile agendaProfile) {
AgendaTeamProfile agendaTeamProfile = AgendaTeamProfile.builder()
.agendaTeam(agendaTeam)
.agenda(agendaTeam.getAgenda())
.profile(agendaProfile)
.isExist(true)
.build();
Expand Down
13 changes: 13 additions & 0 deletions gg-data/src/main/java/gg/data/agenda/AgendaTeam.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,17 @@ public void leaveTeamMate() {
}
this.mateCount--;
}

public void attendTeam(Agenda agenda) {
if (this.status == AgendaTeamStatus.CANCEL) {
throw new BusinessException(AGENDA_TEAM_ALREADY_CANCEL);
}
if (this.status == AgendaTeamStatus.CONFIRM) {
throw new BusinessException(AGENDA_TEAM_ALREADY_CONFIRM);
}
if (this.mateCount >= agenda.getMaxPeople()) {
throw new BusinessException(AGENDA_TEAM_FULL);
}
this.mateCount++;
}
}
10 changes: 8 additions & 2 deletions gg-data/src/main/java/gg/data/agenda/AgendaTeamProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public class AgendaTeamProfile extends BaseTimeEntity {
@JoinColumn(name = "profile_id", nullable = false)
private AgendaProfile profile;

@ManyToOne
@JoinColumn(name = "agenda_id", nullable = false)
private Agenda agenda;

@ManyToOne
@JoinColumn(name = "agenda_team_id", nullable = false)
private AgendaTeam agendaTeam;
Expand All @@ -35,14 +39,16 @@ public class AgendaTeamProfile extends BaseTimeEntity {
private Boolean isExist;

@Builder
public AgendaTeamProfile(AgendaProfile profile, AgendaTeam agendaTeam, Boolean isExist) {
public AgendaTeamProfile(AgendaProfile profile, Agenda agenda, AgendaTeam agendaTeam, Boolean isExist) {
this.profile = profile;
this.agenda = agenda;
this.agendaTeam = agendaTeam;
this.isExist = isExist;
}

public AgendaTeamProfile(AgendaTeam agendaTeam, AgendaProfile profile) {
public AgendaTeamProfile(AgendaTeam agendaTeam, Agenda agenda, AgendaProfile profile) {
this.agendaTeam = agendaTeam;
this.agenda = agenda;
this.profile = profile;
this.isExist = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,14 @@ CREATE TABLE `agenda_team_profile`
(
`id` BIGINT NOT NULL AUTO_INCREMENT,
`profile_id` BIGINT NOT NULL,
`agenda_id` BIGINT NOT NULL,
`agenda_team_id` BIGINT NOT NULL,
`is_exist` BIT(1) NOT NULL,
`created_at` DATETIME NOT NULL,
`modified_at` DATETIME NOT NULL,
PRIMARY KEY (`id`),
KEY `fk_agenda_team_profile_profile_profile_id` (`profile_id`),
KEY `fk_agenda_team_profile_agenda_agenda_id` (`agenda_id`),
KEY `fk_agenda_team_profile_agenda_team_agenda_team_id` (`agenda_team_id`),
CONSTRAINT `fk_agenda_team_profile_profile_profile_id` FOREIGN KEY (`profile_id`) REFERENCES `agenda_profile` (`id`),
CONSTRAINT `fk_agenda_team_profile_agenda_team_agenda_team_id` FOREIGN KEY (`agenda_team_id`) REFERENCES `agenda_team` (`id`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ public interface AgendaTeamProfileRepository extends JpaRepository<AgendaTeamPro

@Query("SELECT atp FROM AgendaTeamProfile atp WHERE atp.agendaTeam = :agendaTeam AND atp.isExist = true")
List<AgendaTeamProfile> findByAgendaTeamAndIsExistTrue(AgendaTeam agendaTeam);

Optional<AgendaTeamProfile> findByAgendaAndProfileAndIsExistTrue(Agenda agenda, AgendaProfile agendaProfile);
}
3 changes: 2 additions & 1 deletion gg-utils/src/main/java/gg/utils/exception/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ public enum ErrorCode {
AGENDA_TEAM_ALREADY_CONFIRM(409, "AG", "이미 확정된 팀입니다."),
AGENDA_TEAM_ALREADY_CANCEL(400, "AG", "이미 취소된 팀입니다."),
NOT_ENOUGH_TEAM_MEMBER(400, "AG", "팀원이 부족합니다."),
AGENDA_TEAM_FULL(400, "AG", "팀이 꽉 찼습니다."),
AGENDA_NO_CAPACITY(403, "AG", "해당 일정에 참여할 수 있는 팀이 꽉 찼습니다."),
AGENDA_INVALID_SCHEDULE(400, "AG", "유효하지 않은 일정입니다."),
AGENDA_INVALID_PARAM(400, "AG", "유효하지 않은 파라미터입니다."),
Expand All @@ -208,7 +209,7 @@ public enum ErrorCode {
CONFIRM_FORBIDDEN(403, "AG", "개최자만 일정을 종료할 수 있습니다."),
AGENDA_MODIFICATION_FORBIDDEN(403, "AG", "개최자만 일정을 수정할 수 있습니다."),
LOCATION_NOT_VALID(400, "AG", "유효하지 않은 지역입니다."),
TEAM_FORBIDDEN(403, "AG", "일정에는 한 팀으로만 참여할 수 있습니다."),
AGENDA_TEAM_FORBIDDEN(403, "AG", "일정에 참여한 팀이 있습니다."),
NOT_TEAM_MATE(403, "AG", "팀원이 아닙니다."),
TEAM_NAME_EXIST(409, "AG", "이미 존재하는 팀 이름입니다."),
TICKET_NOT_EXIST(403, "AG", "보유한 티켓이 부족합니다."),
Expand Down

0 comments on commit d4e617d

Please sign in to comment.