Skip to content

Commit

Permalink
๐Ÿ› [Bug][Refactoring] ๋ช…์„ธ์™€ ๋‹ค๋ฅธ ๋ถ€๋ถ„ ์ˆ˜์ • ๋ฐ GetMapping์—์„œ Body๋ฐ›๋Š” ๋ถ€๋ถ„ ์ˆ˜์ • #930 (#933
Browse files Browse the repository at this point in the history
)
  • Loading branch information
AreSain authored Aug 6, 2024
1 parent 942146f commit 48703b8
Show file tree
Hide file tree
Showing 15 changed files with 222 additions and 268 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand Down Expand Up @@ -47,7 +48,7 @@ public ResponseEntity<AgendaResDto> agendaDetails(@RequestParam("agenda_key") UU
Agenda agenda = agendaService.findAgendaByAgendaKey(agendaKey);
String announcementTitle = agendaAnnouncementService
.findLatestAnnounceTitleByAgendaOrDefault(agenda, "");
AgendaResDto agendaResDto = AgendaResDto.MapStruct.INSTANCE.toDto(agenda, announcementTitle);
AgendaResDto agendaResDto = AgendaResDto.MapStruct.INSTANCE.toDto(agenda, announcementTitle);
return ResponseEntity.ok(agendaResDto);
}

Expand All @@ -69,7 +70,8 @@ public ResponseEntity<AgendaKeyResDto> agendaAdd(@Login @Parameter(hidden = true
}

@GetMapping("/history")
public ResponseEntity<List<AgendaSimpleResDto>> agendaListHistory(@RequestBody @Valid PageRequestDto pageRequest) {
public ResponseEntity<List<AgendaSimpleResDto>> agendaListHistory(
@ModelAttribute @Valid PageRequestDto pageRequest) {
int page = pageRequest.getPage();
int size = pageRequest.getSize();
Pageable pageable = PageRequest.of(page - 1, size, Sort.by("startTime").descending());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


import gg.agenda.api.user.agenda.controller.request.AgendaAwardsReqDto;
import gg.agenda.api.user.agenda.controller.request.AgendaCreateReqDto;
import gg.agenda.api.user.agenda.controller.request.AgendaTeamAward;
import gg.agenda.api.user.agendateam.service.AgendaTeamService;
import gg.agenda.api.user.ticket.service.TicketService;
import gg.auth.UserDto;
import gg.data.agenda.Agenda;
import gg.data.agenda.AgendaProfile;
import gg.data.agenda.AgendaTeam;
import gg.data.agenda.AgendaTeamProfile;
import gg.data.agenda.type.AgendaStatus;
import gg.data.agenda.type.AgendaTeamStatus;
import gg.repo.agenda.AgendaRepository;
Expand All @@ -41,6 +39,8 @@ public class AgendaService {

private final TicketService ticketService;

private final AgendaTeamService agendaTeamService;

@Transactional(readOnly = true)
public Agenda findAgendaByAgendaKey(UUID agendaKey) {
return agendaRepository.findByAgendaKey(agendaKey)
Expand Down Expand Up @@ -91,13 +91,7 @@ public void awardAgenda(AgendaAwardsReqDto agendaAwardsReqDto, Agenda agenda) {
public void confirmAgendaAndRefundTicketForOpenTeam(Agenda agenda) {
List<AgendaTeam> openTeams = agendaTeamRepository.findAllByAgendaAndStatus(agenda, AgendaTeamStatus.OPEN);
for (AgendaTeam openTeam : openTeams) {
// TODO: AgendaTeamService์˜ cancelTeam ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๊ฒƒ์ด ๋” ์ข‹์„ ์ˆ˜๋„ ์žˆ์Œ
List<AgendaProfile> participants = agendaTeamProfileRepository
.findAllByAgendaTeamWithFetchProfile(openTeam).stream()
.map(AgendaTeamProfile::getProfile)
.collect(Collectors.toList());
ticketService.refundTickets(participants, agenda.getAgendaKey());
openTeam.cancelTeam();
agendaTeamService.leaveTeamAll(openTeam);
}
agenda.confirmAgenda();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand Down Expand Up @@ -48,7 +49,7 @@ public ResponseEntity<Void> agendaAnnouncementAdd(@Login UserDto user, @RequestP

@GetMapping
public ResponseEntity<List<AgendaAnnouncementResDto>> agendaAnnouncementList(
@RequestParam("agenda_key") UUID agendaKey, @RequestBody @Valid PageRequestDto pageRequest) {
@RequestParam("agenda_key") UUID agendaKey, @ModelAttribute @Valid PageRequestDto pageRequest) {
Agenda agenda = agendaService.findAgendaByAgendaKey(agendaKey);
int page = pageRequest.getPage();
int size = pageRequest.getSize();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gg.agenda.api.user.agendateam.controller;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
Expand All @@ -12,6 +13,7 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -30,6 +32,7 @@
import gg.agenda.api.user.agendateam.service.AgendaTeamService;
import gg.auth.UserDto;
import gg.auth.argumentresolver.Login;
import gg.data.agenda.AgendaTeam;
import gg.utils.dto.PageRequestDto;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;
Expand All @@ -47,8 +50,7 @@ public class AgendaTeamController {
*/
@GetMapping("/my")
public ResponseEntity<Optional<MyTeamSimpleResDto>> myTeamSimpleDetails(
@Parameter(hidden = true) @Login UserDto user,
@RequestParam("agenda_key") UUID agendaKey) {
@Parameter(hidden = true) @Login UserDto user, @RequestParam("agenda_key") UUID agendaKey) {
Optional<MyTeamSimpleResDto> myTeamSimpleResDto = agendaTeamService.detailsMyTeamSimple(user, agendaKey);
if (myTeamSimpleResDto.isEmpty()) {
return ResponseEntity.noContent().build();
Expand Down Expand Up @@ -98,16 +100,24 @@ public ResponseEntity<Void> confirmTeam(@Parameter(hidden = true) @Login UserDto
@PatchMapping("/cancel")
public ResponseEntity<Void> leaveAgendaTeam(@Parameter(hidden = true) @Login UserDto user,
@RequestBody @Valid TeamKeyReqDto teamKeyReqDto, @RequestParam("agenda_key") UUID agendaKey) {
agendaTeamService.agendaTeamLeave(user, agendaKey, teamKeyReqDto.getTeamKey());
UUID teamKey = teamKeyReqDto.getTeamKey();

AgendaTeam agendaTeam = agendaTeamService.getAgendaTeam(agendaKey, teamKey);
agendaTeam.getAgenda().leaveTeam(LocalDateTime.now());
if (agendaTeam.getLeaderIntraId().equals(user.getIntraId())) {
agendaTeamService.leaveTeamAll(agendaTeam);
} else {
agendaTeamService.leaveTeamMate(agendaTeam, user);
}
return ResponseEntity.noContent().build();
}

/**
* ์•„์  ๋‹ค ํŒ€ ๊ณต๊ฐœ ๋ชจ์ง‘์ธ ํŒ€ ๋ชฉ๋ก ์กฐํšŒ
* @param pageRequest ํŽ˜์ด์ง€๋„ค์ด์…˜ ์š”์ฒญ ์ •๋ณด, agendaId ์•„์  ๋‹ค ์•„์ด๋””
*/
@GetMapping("/open")
public ResponseEntity<List<OpenTeamResDto>> openTeamList(@RequestBody @Valid PageRequestDto pageRequest,
@GetMapping("/open/list")
public ResponseEntity<List<OpenTeamResDto>> openTeamList(@ModelAttribute @Valid PageRequestDto pageRequest,
@RequestParam("agenda_key") UUID agendaKey) {
int page = pageRequest.getPage();
int size = pageRequest.getSize();
Expand All @@ -121,7 +131,7 @@ public ResponseEntity<List<OpenTeamResDto>> openTeamList(@RequestBody @Valid Pag
* @param pageRequest ํŽ˜์ด์ง€๋„ค์ด์…˜ ์š”์ฒญ ์ •๋ณด, agendaId ์•„์  ๋‹ค ์•„์ด๋””
*/
@GetMapping("/confirm/list")
public ResponseEntity<List<ConfirmTeamResDto>> confirmTeamList(@RequestBody @Valid PageRequestDto pageRequest,
public ResponseEntity<List<ConfirmTeamResDto>> confirmTeamList(@ModelAttribute @Valid PageRequestDto pageRequest,
@RequestParam("agenda_key") UUID agendaKey) {
int page = pageRequest.getPage();
int size = pageRequest.getSize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import gg.agenda.api.user.agendateam.controller.request.TeamCreateReqDto;
Expand Down Expand Up @@ -136,7 +137,8 @@ public TeamKeyResDto addAgendaTeam(UserDto user, TeamCreateReqDto teamCreateReqD
});

if (agenda.getIsOfficial()) {
Ticket ticket = ticketRepository.findByAgendaProfileAndIsApprovedTrueAndIsUsedFalse(agendaProfile)
Ticket ticket = ticketRepository.findFirstByAgendaProfileAndIsApprovedTrueAndIsUsedFalseOrderByCreatedAtAsc(
agendaProfile)
.orElseThrow(() -> new ForbiddenException(TICKET_NOT_EXIST));
ticket.useTicket(agenda.getAgendaKey());
}
Expand Down Expand Up @@ -179,42 +181,58 @@ public void confirmTeam(UserDto user, UUID agendaKey, UUID teamKey) {
}

/**
* ์•„์  ๋‹ค ํŒ€ ๋‚˜๊ฐ€๊ธฐ
* @param user ์‚ฌ์šฉ์ž ์ •๋ณด, teamKeyReqDto ํŒ€ KEY ์š”์ฒญ ์ •๋ณด, agendaId ์•„์  ๋‹ค ์•„์ด๋””
* ํŠธ๋žœ์žญ์…˜์˜ ์›์ž์„ฑ์„ ๋ณด์žฅํ•˜๊ธฐ ์œ„ํ•ด ํŒ€ ๋‚˜๊ฐ€๊ธฐ์™€ ํ‹ฐ์ผ“ ํ™˜๋ถˆ์„ ํ•œ ๋ฉ”์„œ๋“œ์—์„œ ์ฒ˜๋ฆฌ
* ์•„์  ๋‹ค ํŒ€ ์ฐพ๊ธฐ
* @param agendaKey ์•„์  ๋‹ค ํ‚ค, teamKey ํŒ€ ํ‚ค
*/
@Transactional
public void agendaTeamLeave(UserDto user, UUID agendaKey, UUID teamKey) {
@Transactional(readOnly = true)
public AgendaTeam getAgendaTeam(UUID agendaKey, UUID teamKey) {
Agenda agenda = agendaRepository.findByAgendaKey(agendaKey)
.orElseThrow(() -> new NotExistException(AGENDA_NOT_FOUND));

AgendaTeam agendaTeam = agendaTeamRepository
return agendaTeamRepository
.findByAgendaAndTeamKeyAndStatus(agenda, teamKey, OPEN, CONFIRM)
.orElseThrow(() -> new NotExistException(AGENDA_TEAM_NOT_FOUND));
}

agenda.cancelTeam(LocalDateTime.now());
/**
* ์•„์  ๋‹ค ํŒ€์› ๋‚˜๊ฐ€๊ธฐ
* @param agendaTeam ์•„์  ๋‹ค ํŒ€, user ์‚ฌ์šฉ์ž ์ •๋ณด
*/
@Transactional
public void leaveTeamMate(AgendaTeam agendaTeam, UserDto user) {
AgendaProfile agendaProfile = agendaProfileRepository.findByUserId(user.getId())
.orElseThrow(() -> new NotExistException(AGENDA_PROFILE_NOT_FOUND));
AgendaTeamProfile agendaTeamProfile = agendaTeamProfileRepository
.findByAgendaAndProfileAndIsExistTrue(agendaTeam.getAgenda(), agendaProfile)
.orElseThrow(() -> new ForbiddenException(NOT_TEAM_MATE));
leaveTeam(agendaTeamProfile);
}

List<AgendaTeamProfile> profiles = agendaTeamProfileRepository.findByAgendaTeamAndIsExistTrue(agendaTeam);
/**
* ํŒ€์›์ด ํŒ€ ๋‚˜๊ฐ€๊ธฐ
* @param agendaTeamProfile ํŒ€ ํ”„๋กœํ•„
*/
@Transactional(propagation = Propagation.MANDATORY)
public void leaveTeam(AgendaTeamProfile agendaTeamProfile) {
AgendaTeam agendaTeam = agendaTeamProfile.getAgendaTeam();
agendaTeamProfile.leaveTeam();
agendaTeam.leaveTeamMate();
if (agendaTeamProfile.getAgenda().getIsOfficial()) {
ticketService.refundTicket(agendaTeamProfile);
}
}

List<AgendaProfile> changedProfiles;
/**
* ํŒ€์žฅ์ด ํŒ€ ๋‚˜๊ฐ€๊ธฐ
* @param agendaTeam ํŒ€
*/
@Transactional(propagation = Propagation.MANDATORY)
public void leaveTeamAll(AgendaTeam agendaTeam) {
List<AgendaTeamProfile> teamProfiles = agendaTeamProfileRepository.findByAgendaTeamAndIsExistTrue(agendaTeam);

if (agendaTeam.getLeaderIntraId().equals(user.getIntraId())) {
changedProfiles = profiles
.stream()
.peek(AgendaTeamProfile::leaveTeam)
.map(AgendaTeamProfile::getProfile)
.collect(Collectors.toList());
agendaTeam.leaveTeamLeader();
ticketService.refundTickets(changedProfiles, agendaKey);
return;
for (AgendaTeamProfile teamProfile : teamProfiles) {
leaveTeam(teamProfile);
}
AgendaTeamProfile teamMateProfile = profiles.stream()
.filter(profile -> profile.getProfile().getUserId().equals(user.getId()))
.findFirst().orElseThrow(() -> new ForbiddenException(NOT_TEAM_MATE));
teamMateProfile.leaveTeam();
agendaTeam.leaveTeamMate();
changedProfiles = List.of(teamMateProfile.getProfile());
ticketService.refundTickets(changedProfiles, agendaKey);
agendaTeam.leaveTeamLeader();
}

/**
Expand Down Expand Up @@ -276,17 +294,19 @@ public void modifyAttendTeam(UserDto user, TeamKeyReqDto teamKeyReqDto, UUID age
.findByAgendaAndTeamKeyAndStatus(agenda, teamKeyReqDto.getTeamKey(), OPEN, CONFIRM)
.orElseThrow(() -> new NotExistException(AGENDA_TEAM_NOT_FOUND));

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

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

if (agenda.getIsOfficial()) {
Ticket ticket = ticketRepository
.findFirstByAgendaProfileAndIsApprovedTrueAndIsUsedFalseOrderByCreatedAtAsc(agendaProfile)
.orElseThrow(() -> new ForbiddenException(TICKET_NOT_EXIST));
ticket.useTicket(agenda.getAgendaKey());
}
agenda.attendTeam(agendaProfile.getLocation(), LocalDateTime.now());
agendaTeam.attendTeam(agenda);
ticket.useTicket(agenda.getAgendaKey());
agendaTeamProfileRepository.save(new AgendaTeamProfile(agendaTeam, agenda, agendaProfile));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
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.RestController;

Expand Down Expand Up @@ -52,7 +52,7 @@ public ResponseEntity<TicketCountResDto> ticketCountFind(@Parameter(hidden = tru

@GetMapping("/history")
public ResponseEntity<List<TicketHistoryResDto>> ticketHistoryList(@Parameter(hidden = true) @Login UserDto user,
@RequestBody @Valid PageRequestDto pageRequest) {
@ModelAttribute @Valid PageRequestDto pageRequest) {
int page = pageRequest.getPage();
int size = pageRequest.getSize();
Pageable pageable = PageRequest.of(page - 1, size, Sort.by("id").descending());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import static gg.utils.exception.ErrorCode.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;

import org.springframework.data.domain.Page;
Expand All @@ -18,6 +16,7 @@
import gg.auth.UserDto;
import gg.data.agenda.Agenda;
import gg.data.agenda.AgendaProfile;
import gg.data.agenda.AgendaTeamProfile;
import gg.data.agenda.Ticket;
import gg.repo.agenda.AgendaProfileRepository;
import gg.repo.agenda.AgendaRepository;
Expand All @@ -33,21 +32,9 @@ public class TicketService {
private final AgendaRepository agendaRepository;
private final AgendaProfileRepository agendaProfileRepository;

/**
* ํ‹ฐ์ผ“ ํ™˜๋ถˆ
* @param changedProfiles ๋ณ€๊ฒฝ๋œ ํ”„๋กœํ•„ ๋ชฉ๋ก
* @param agendaKey ์•„์  ๋‹ค ํ‚ค
* @Annotation ํŠธ๋žœ์žญ์…˜์˜ ์›์ž์„ฑ์„ ๋ณด์žฅํ•˜๊ธฐ ์œ„ํ•ด ๋ถ€๋ชจ ํŠธ๋žœ์žญ์…˜์ด ์—†์„๊ฒฝ์šฐ ์˜ˆ์™ธ๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๋Š” Propagation.MANDATORY๋กœ ์„ค์ •
*/
@Transactional(propagation = Propagation.MANDATORY)
public void refundTickets(List<AgendaProfile> changedProfiles, UUID agendaKey) {
List<Ticket> tickets = new ArrayList<>();
for (
AgendaProfile profile : changedProfiles) {
Ticket ticket = Ticket.createRefundedTicket(profile, agendaKey);
tickets.add(ticket);
}
ticketRepository.saveAll(tickets);
public void refundTicket(AgendaTeamProfile changedTeamProfile) {
Ticket.createRefundedTicket(changedTeamProfile);
}

/**
Expand Down
Loading

0 comments on commit 48703b8

Please sign in to comment.