Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ev.v2 into 945-feature-admin-티켓-조회-api
  • Loading branch information
kimjieun0301 committed Aug 30, 2024
2 parents 2b3d773 + 9dc5196 commit 6958553
Show file tree
Hide file tree
Showing 20 changed files with 371 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,11 @@ public ResponseEntity<Void> agendaTeamUpdate(@RequestBody @Valid AgendaTeamUpdat
agendaTeamAdminService.updateAgendaTeam(agendaTeamUpdateDto);
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}

@PatchMapping("/cancel")
public ResponseEntity<Void> agendaTeamCancel(@RequestParam("team_key") UUID teamKey) {
AgendaTeam agendaTeam = agendaTeamAdminService.getAgendaTeamByTeamKey(teamKey);
agendaTeamAdminService.cancelAgendaTeam(agendaTeam);
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,12 @@ public void updateAgendaTeam(AgendaTeamUpdateDto agendaTeamUpdateDto) {
agendaTeamProfileAdminRepository.save(agendaTeamProfile);
});
}

@Transactional
public void cancelAgendaTeam(AgendaTeam agendaTeam) {
List<AgendaTeamProfile> agendaTeamProfiles = agendaTeamProfileAdminRepository
.findAllByAgendaTeamAndIsExistIsTrue(agendaTeam);
agendaTeamProfiles.forEach(AgendaTeamProfile::changeExistFalse);
agendaTeam.adminCancelTeam();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
import gg.agenda.api.user.agenda.controller.response.AgendaSimpleResDto;
import gg.agenda.api.user.agenda.service.AgendaService;
import gg.agenda.api.user.agendaannouncement.service.AgendaAnnouncementService;
import gg.agenda.api.utils.AgendaSlackService;
import gg.auth.UserDto;
import gg.auth.argumentresolver.Login;
import gg.data.agenda.Agenda;
import gg.data.agenda.AgendaTeam;
import gg.utils.dto.PageRequestDto;
import gg.utils.dto.PageResponseDto;
import gg.utils.exception.custom.InvalidParameterException;
import gg.utils.exception.user.UserImageLargeException;
import io.swagger.v3.oas.annotations.Parameter;
import lombok.RequiredArgsConstructor;

Expand All @@ -48,7 +49,7 @@
public class AgendaController {

private final AgendaService agendaService;

private final AgendaSlackService agendaSlackService;
private final AgendaAnnouncementService agendaAnnouncementService;

@GetMapping
Expand All @@ -73,7 +74,7 @@ public ResponseEntity<List<AgendaSimpleResDto>> agendaListCurrent() {
public ResponseEntity<AgendaKeyResDto> agendaAdd(@Login @Parameter(hidden = true) UserDto user,
@ModelAttribute @Valid AgendaCreateReqDto agendaCreateReqDto,
@RequestParam(required = false) MultipartFile agendaPoster) {
if (Objects.nonNull(agendaPoster) && agendaPoster.getSize() > 1024 * 1024) { // 1MB
if (Objects.nonNull(agendaPoster) && agendaPoster.getSize() > 1024 * 1024) { // 1MB
throw new InvalidParameterException(AGENDA_POSTER_SIZE_TOO_LARGE);
}
UUID agendaKey = agendaService.addAgenda(agendaCreateReqDto, agendaPoster, user).getAgendaKey();
Expand Down Expand Up @@ -107,6 +108,7 @@ public ResponseEntity<Void> agendaEndWithAwards(@RequestParam("agenda_key") UUID
agendaService.awardAgenda(agendaAwardsReqDto, agenda);
}
agendaService.finishAgenda(agenda);
agendaSlackService.slackFinishAgenda(agenda);
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}

Expand All @@ -115,7 +117,9 @@ public ResponseEntity<Void> agendaConfirm(@RequestParam("agenda_key") UUID agend
@Login @Parameter(hidden = true) UserDto user) {
Agenda agenda = agendaService.findAgendaByAgendaKey(agendaKey);
agenda.mustModifiedByHost(user.getIntraId());
agendaService.confirmAgendaAndRefundTicketForOpenTeam(agenda);
List<AgendaTeam> failTeam = agendaService.confirmAgendaAndRefundTicketForOpenTeam(agenda);
agendaSlackService.slackConfirmAgenda(agenda);
agendaSlackService.slackCancelByAgendaConfirm(agenda, failTeam);
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}

Expand All @@ -125,6 +129,7 @@ public ResponseEntity<Void> agendaCancel(@RequestParam("agenda_key") UUID agenda
Agenda agenda = agendaService.findAgendaByAgendaKey(agendaKey);
agenda.mustModifiedByHost(user.getIntraId());
agendaService.cancelAgenda(agenda);
agendaSlackService.slackCancelAgenda(agenda);
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
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.agenda.api.utils.SnsMessageUtil;
import gg.auth.UserDto;
import gg.data.agenda.Agenda;
import gg.data.agenda.AgendaTeam;
Expand All @@ -33,6 +33,7 @@
import gg.utils.exception.custom.ForbiddenException;
import gg.utils.exception.custom.NotExistException;
import gg.utils.file.handler.ImageHandler;
import gg.utils.sns.MessageSender;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

Expand All @@ -47,12 +48,14 @@ public class AgendaService {

private final AgendaTeamProfileRepository agendaTeamProfileRepository;

private final TicketService ticketService;

private final AgendaTeamService agendaTeamService;

private final ImageHandler imageHandler;

private final MessageSender messageSender;

private final SnsMessageUtil snsMessageUtil;

@Value("${info.image.defaultUrl}")
private String defaultUri;

Expand Down Expand Up @@ -110,7 +113,7 @@ public void awardAgenda(AgendaAwardsReqDto agendaAwardsReqDto, Agenda agenda) {
}

@Transactional
public void confirmAgendaAndRefundTicketForOpenTeam(Agenda agenda) {
public List<AgendaTeam> confirmAgendaAndRefundTicketForOpenTeam(Agenda agenda) {
if (agenda.getCurrentTeam() < agenda.getMinTeam()) {
throw new ForbiddenException("팀이 모두 구성되지 않았습니다.");
}
Expand All @@ -120,6 +123,7 @@ public void confirmAgendaAndRefundTicketForOpenTeam(Agenda agenda) {
agendaTeamService.leaveTeamAll(openTeam);
}
agenda.confirmAgenda();
return openTeams;
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import gg.agenda.api.user.agendaannouncement.controller.request.AgendaAnnouncementCreateReqDto;
import gg.agenda.api.user.agendaannouncement.controller.response.AgendaAnnouncementResDto;
import gg.agenda.api.user.agendaannouncement.service.AgendaAnnouncementService;
import gg.agenda.api.utils.AgendaSlackService;
import gg.auth.UserDto;
import gg.auth.argumentresolver.Login;
import gg.data.agenda.Agenda;
Expand All @@ -38,15 +39,17 @@
public class AgendaAnnouncementController {

private final AgendaService agendaService;

private final AgendaSlackService agendaSlackService;
private final AgendaAnnouncementService agendaAnnouncementService;

@PostMapping
public ResponseEntity<Void> agendaAnnouncementAdd(@Login UserDto user, @RequestParam("agenda_key") UUID agendaKey,
@RequestBody @Valid AgendaAnnouncementCreateReqDto agendaAnnouncementCreateReqDto) {
Agenda agenda = agendaService.findAgendaByAgendaKey(agendaKey);
agenda.mustModifiedByHost(user.getIntraId());
agendaAnnouncementService.addAgendaAnnouncement(agendaAnnouncementCreateReqDto, agenda);
AgendaAnnouncement newAnnounce = agendaAnnouncementService
.addAgendaAnnouncement(agendaAnnouncementCreateReqDto, agenda);
agendaSlackService.slackAddAgendaAnnouncement(agenda, newAnnounce);
return ResponseEntity.status(HttpStatus.CREATED).build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package gg.agenda.api.user.agendaannouncement.service;

import java.util.List;
import java.util.Optional;

import org.springframework.data.domain.Page;
Expand All @@ -9,22 +8,28 @@
import org.springframework.transaction.annotation.Transactional;

import gg.agenda.api.user.agendaannouncement.controller.request.AgendaAnnouncementCreateReqDto;
import gg.agenda.api.utils.SnsMessageUtil;
import gg.data.agenda.Agenda;
import gg.data.agenda.AgendaAnnouncement;
import gg.repo.agenda.AgendaAnnouncementRepository;
import gg.repo.agenda.AgendaTeamProfileRepository;
import gg.utils.sns.MessageSender;
import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class AgendaAnnouncementService {

private final MessageSender messageSender;
private final SnsMessageUtil snsMessageUtil;
private final AgendaTeamProfileRepository agendaTeamProfileRepository;
private final AgendaAnnouncementRepository agendaAnnouncementRepository;

@Transactional
public void addAgendaAnnouncement(AgendaAnnouncementCreateReqDto announceCreateDto, Agenda agenda) {
public AgendaAnnouncement addAgendaAnnouncement(AgendaAnnouncementCreateReqDto announceCreateDto, Agenda agenda) {
AgendaAnnouncement newAnnounce = AgendaAnnouncementCreateReqDto
.MapStruct.INSTANCE.toEntity(announceCreateDto, agenda);
agendaAnnouncementRepository.save(newAnnounce);
return agendaAnnouncementRepository.save(newAnnounce);
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;
import java.util.stream.Collectors;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.springframework.data.domain.Page;
Expand Down Expand Up @@ -73,10 +74,10 @@ public ResponseEntity<AgendaProfileInfoDetailsResDto> myAgendaProfileInfoDetails
*/
@GetMapping
public ResponseEntity<MyAgendaProfileDetailsResDto> myAgendaProfileDetails(
@Login @Parameter(hidden = true) UserDto user) {
@Login @Parameter(hidden = true) UserDto user, HttpServletResponse response) {
AgendaProfile profile = agendaProfileFindService.findAgendaProfileByIntraId(user.getIntraId());
int ticketCount = ticketService.findTicketList(profile).size();
IntraProfile intraProfile = intraProfileUtils.getIntraProfile();
IntraProfile intraProfile = intraProfileUtils.getIntraProfile(response);
MyAgendaProfileDetailsResDto agendaProfileDetails = MyAgendaProfileDetailsResDto.toDto(
profile, ticketCount, intraProfile);
return ResponseEntity.ok(agendaProfileDetails);
Expand Down Expand Up @@ -109,9 +110,10 @@ public ResponseEntity<List<CurrentAttendAgendaListResDto>> getCurrentAttendAgend
}

@GetMapping("/{intraId}")
public ResponseEntity<AgendaProfileDetailsResDto> agendaProfileDetails(@PathVariable String intraId) {
public ResponseEntity<AgendaProfileDetailsResDto> agendaProfileDetails(@PathVariable String intraId,
HttpServletResponse response) {
AgendaProfile profile = agendaProfileFindService.findAgendaProfileByIntraId(intraId);
IntraProfile intraProfile = intraProfileUtils.getIntraProfile(intraId);
IntraProfile intraProfile = intraProfileUtils.getIntraProfile(intraId, response);
AgendaProfileDetailsResDto resDto = AgendaProfileDetailsResDto.toDto(profile, intraProfile);
return ResponseEntity.ok(resDto);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.List;
import java.util.Objects;

import javax.servlet.http.HttpServletResponse;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Component;
Expand All @@ -14,6 +16,7 @@
import gg.agenda.api.user.agendaprofile.service.intraprofile.IntraProfile;
import gg.agenda.api.user.agendaprofile.service.intraprofile.IntraProfileResponse;
import gg.auth.FortyTwoAuthUtil;
import gg.utils.cookie.CookieUtil;
import gg.utils.exception.custom.AuthenticationException;
import gg.utils.external.ApiUtil;
import lombok.RequiredArgsConstructor;
Expand All @@ -31,7 +34,9 @@ public class IntraProfileUtils {

private final ApiUtil apiUtil;

public IntraProfile getIntraProfile() {
private final CookieUtil cookieUtil;

public IntraProfile getIntraProfile(HttpServletResponse response) {
try {
IntraProfileResponse intraProfileResponse = requestIntraProfile(INTRA_PROFILE_URL);
intraProfileResponseValidation(intraProfileResponse);
Expand All @@ -40,11 +45,12 @@ public IntraProfile getIntraProfile() {
return new IntraProfile(intraImage.getLink(), intraAchievements);
} catch (Exception e) {
log.error("42 Intra Profile API 호출 실패", e);
cookieUtil.deleteCookie(response, "refresh_token");
throw new AuthenticationException(AUTH_NOT_FOUND);
}
}

public IntraProfile getIntraProfile(String intraId) {
public IntraProfile getIntraProfile(String intraId, HttpServletResponse response) {
try {
IntraProfileResponse intraProfileResponse = requestIntraProfile(INTRA_USERS_URL + intraId);
intraProfileResponseValidation(intraProfileResponse);
Expand All @@ -53,6 +59,7 @@ public IntraProfile getIntraProfile(String intraId) {
return new IntraProfile(intraImage.getLink(), intraAchievements);
} catch (Exception e) {
log.error("42 Intra Profile API 호출 실패", e);
cookieUtil.deleteCookie(response, "refresh_token");
throw new AuthenticationException(AUTH_NOT_FOUND);
}
}
Expand All @@ -71,7 +78,6 @@ private IntraProfileResponse requestIntraProfile(String requestUrl) {
}
}


private void intraProfileResponseValidation(IntraProfileResponse intraProfileResponse) {
if (Objects.isNull(intraProfileResponse)) {
throw new AuthenticationException(AUTH_NOT_FOUND);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import gg.agenda.api.user.agenda.service.AgendaService;
import gg.agenda.api.user.agendateam.controller.request.TeamCreateReqDto;
import gg.agenda.api.user.agendateam.controller.request.TeamKeyReqDto;
import gg.agenda.api.user.agendateam.controller.request.TeamUpdateReqDto;
Expand All @@ -33,8 +34,10 @@
import gg.agenda.api.user.agendateam.controller.response.TeamDetailsResDto;
import gg.agenda.api.user.agendateam.controller.response.TeamKeyResDto;
import gg.agenda.api.user.agendateam.service.AgendaTeamService;
import gg.agenda.api.utils.AgendaSlackService;
import gg.auth.UserDto;
import gg.auth.argumentresolver.Login;
import gg.data.agenda.Agenda;
import gg.data.agenda.AgendaTeam;
import gg.data.agenda.type.Coalition;
import gg.utils.dto.PageRequestDto;
Expand All @@ -46,7 +49,9 @@
@RequiredArgsConstructor
@RequestMapping("/agenda/team")
public class AgendaTeamController {
private final AgendaService agendaService;
private final AgendaTeamService agendaTeamService;
private final AgendaSlackService agendaSlackService;

/**
* 내 팀 간단 정보 조회
Expand Down Expand Up @@ -94,7 +99,9 @@ public ResponseEntity<TeamKeyResDto> agendaTeamAdd(@Parameter(hidden = true) @Lo
@PatchMapping("/confirm")
public ResponseEntity<Void> confirmTeam(@Parameter(hidden = true) @Login UserDto user,
@ModelAttribute @Valid TeamKeyReqDto teamKeyReqDto, @RequestParam("agenda_key") UUID agendaKey) {
agendaTeamService.confirmTeam(user, agendaKey, teamKeyReqDto.getTeamKey());
Agenda agenda = agendaService.findAgendaByAgendaKey(agendaKey);
AgendaTeam agendaTeam = agendaTeamService.confirmTeam(user, agenda, teamKeyReqDto.getTeamKey());
agendaSlackService.slackConfirmAgendaTeam(agenda, agendaTeam);
return ResponseEntity.ok().build();
}

Expand All @@ -110,9 +117,11 @@ public ResponseEntity<Void> leaveAgendaTeam(@Parameter(hidden = true) @Login Use
if (agendaTeam.getLeaderIntraId().equals(user.getIntraId())) {
agendaTeam.agendaTeamStatusMustBeOpenAndConfirm();
agendaTeamService.leaveTeamAll(agendaTeam);
agendaSlackService.slackCancelAgendaTeam(agendaTeam.getAgenda(), agendaTeam);
} else {
agendaTeam.agendaTeamStatusMustBeOpen();
agendaTeamService.leaveTeamMate(agendaTeam, user);
agendaSlackService.slackLeaveTeamMate(agendaTeam.getAgenda(), agendaTeam, user.getIntraId());
}
return ResponseEntity.noContent().build();
}
Expand Down Expand Up @@ -174,7 +183,10 @@ public ResponseEntity<PageResponseDto<ConfirmTeamResDto>> confirmTeamList(
@PostMapping("/join")
public ResponseEntity<Void> attendTeamModify(@Parameter(hidden = true) @Login UserDto user,
@ModelAttribute @Valid TeamKeyReqDto teamKeyReqDto, @RequestParam("agenda_key") UUID agendaKey) {
agendaTeamService.modifyAttendTeam(user, teamKeyReqDto, agendaKey);
Agenda agenda = agendaService.findAgendaByAgendaKey(agendaKey);
AgendaTeam agendaTeam = agendaTeamService.getAgendaTeam(teamKeyReqDto.getTeamKey());
agendaTeamService.modifyAttendTeam(user, agendaTeam, agenda);
agendaSlackService.slackAttendTeamMate(agenda, agendaTeam, user.getIntraId());
return ResponseEntity.status(HttpStatus.CREATED).build();
}

Expand Down
Loading

0 comments on commit 6958553

Please sign in to comment.