From 5bf0d29ed5ff0f121bab0addac59b77c5a06a036 Mon Sep 17 00:00:00 2001 From: seokjin8678 Date: Thu, 16 Nov 2023 15:14:14 +0900 Subject: [PATCH] =?UTF-8?q?[BE]=20refactor:=20=EC=82=AC=EC=9A=A9=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20AdminService=20=EC=A0=9C?= =?UTF-8?q?=EA=B1=B0=20(#610)=20(#611)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * test: 테스트 코드에 서비스 클래스 제거 * refactor: AdminService 삭제 * refactor: AdminDTO 삭제 * style: 개행 수정 --- .../admin/application/AdminService.java | 108 ------------------ .../admin/dto/AdminFestivalResponse.java | 13 --- .../com/festago/admin/dto/AdminResponse.java | 11 -- .../admin/dto/AdminSchoolResponse.java | 17 --- .../festago/admin/dto/AdminStageResponse.java | 13 --- .../admin/dto/AdminTicketResponse.java | 15 --- .../festago/presentation/AdminController.java | 10 -- .../presentation/AdminViewController.java | 1 - .../presentation/AdminControllerTest.java | 4 - 9 files changed, 192 deletions(-) delete mode 100644 backend/src/main/java/com/festago/admin/application/AdminService.java delete mode 100644 backend/src/main/java/com/festago/admin/dto/AdminFestivalResponse.java delete mode 100644 backend/src/main/java/com/festago/admin/dto/AdminResponse.java delete mode 100644 backend/src/main/java/com/festago/admin/dto/AdminSchoolResponse.java delete mode 100644 backend/src/main/java/com/festago/admin/dto/AdminStageResponse.java delete mode 100644 backend/src/main/java/com/festago/admin/dto/AdminTicketResponse.java diff --git a/backend/src/main/java/com/festago/admin/application/AdminService.java b/backend/src/main/java/com/festago/admin/application/AdminService.java deleted file mode 100644 index 6caf46f1a..000000000 --- a/backend/src/main/java/com/festago/admin/application/AdminService.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.festago.admin.application; - -import com.festago.admin.dto.AdminFestivalResponse; -import com.festago.admin.dto.AdminResponse; -import com.festago.admin.dto.AdminSchoolResponse; -import com.festago.admin.dto.AdminStageResponse; -import com.festago.admin.dto.AdminTicketResponse; -import com.festago.festival.domain.Festival; -import com.festago.festival.repository.FestivalRepository; -import com.festago.school.domain.School; -import com.festago.school.repository.SchoolRepository; -import com.festago.stage.domain.Stage; -import com.festago.stage.repository.StageRepository; -import com.festago.ticket.domain.Ticket; -import com.festago.ticket.domain.TicketAmount; -import com.festago.ticket.domain.TicketEntryTime; -import com.festago.ticket.repository.TicketRepository; -import java.time.LocalDateTime; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Transactional -@Service -@RequiredArgsConstructor -public class AdminService { - - private final FestivalRepository festivalRepository; - private final StageRepository stageRepository; - private final TicketRepository ticketRepository; - private final SchoolRepository schoolRepository; - - @Transactional(readOnly = true) - public AdminResponse getAdminResponse() { - List allSchool = schoolRepository.findAll(); - List allTicket = ticketRepository.findAll(); - List allStage = stageRepository.findAll(); - List allFestival = festivalRepository.findAll(); - return new AdminResponse( - schoolResponses(allSchool), - ticketResponses(allTicket), - stageResponses(allStage), - festivalResponses(allFestival)); - } - - private List schoolResponses(List schools) { - return schools.stream() - .map(AdminSchoolResponse::from) - .toList(); - } - - private List ticketResponses(List tickets) { - return tickets.stream() - .map(this::ticketResponse) - .toList(); - } - - private AdminTicketResponse ticketResponse(Ticket ticket) { - TicketAmount ticketAmount = ticket.getTicketAmount(); - Map amountByEntryTime = ticket.getTicketEntryTimes().stream() - .collect(Collectors.toMap( - TicketEntryTime::getEntryTime, - TicketEntryTime::getAmount - )); - return new AdminTicketResponse( - ticket.getId(), - ticket.getStage().getId(), - ticket.getTicketType(), - ticketAmount.getTotalAmount(), - ticketAmount.getReservedAmount(), - amountByEntryTime - ); - } - - private List stageResponses(List stages) { - return stages.stream() - .map(this::stageResponse) - .toList(); - } - - private AdminStageResponse stageResponse(Stage stage) { - List ticketIds = stage.getTickets().stream() - .map(Ticket::getId) - .toList(); - return new AdminStageResponse( - stage.getId(), - stage.getFestival().getId(), - stage.getStartTime(), - stage.getLineUp(), - ticketIds - ); - } - - private List festivalResponses(List festivals) { - return festivals.stream() - .map(festival -> new AdminFestivalResponse( - festival.getId(), - festival.getSchool().getId(), - festival.getName(), - festival.getStartDate(), - festival.getEndDate(), - festival.getThumbnail())) - .toList(); - } -} diff --git a/backend/src/main/java/com/festago/admin/dto/AdminFestivalResponse.java b/backend/src/main/java/com/festago/admin/dto/AdminFestivalResponse.java deleted file mode 100644 index ea59b850e..000000000 --- a/backend/src/main/java/com/festago/admin/dto/AdminFestivalResponse.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.festago.admin.dto; - -import java.time.LocalDate; - -public record AdminFestivalResponse( - Long id, - Long schoolId, - String name, - LocalDate startDate, - LocalDate endDate, - String thumbnail) { - -} diff --git a/backend/src/main/java/com/festago/admin/dto/AdminResponse.java b/backend/src/main/java/com/festago/admin/dto/AdminResponse.java deleted file mode 100644 index 59c473a7f..000000000 --- a/backend/src/main/java/com/festago/admin/dto/AdminResponse.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.festago.admin.dto; - -import java.util.List; - -public record AdminResponse( - List adminSchools, - List adminTickets, - List adminStageResponse, - List adminFestivalResponse) { - -} diff --git a/backend/src/main/java/com/festago/admin/dto/AdminSchoolResponse.java b/backend/src/main/java/com/festago/admin/dto/AdminSchoolResponse.java deleted file mode 100644 index 6a898ba24..000000000 --- a/backend/src/main/java/com/festago/admin/dto/AdminSchoolResponse.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.festago.admin.dto; - -import com.festago.school.domain.School; - -public record AdminSchoolResponse( - Long id, - String domain, - String name) { - - public static AdminSchoolResponse from(School school) { - return new AdminSchoolResponse( - school.getId(), - school.getDomain(), - school.getName() - ); - } -} diff --git a/backend/src/main/java/com/festago/admin/dto/AdminStageResponse.java b/backend/src/main/java/com/festago/admin/dto/AdminStageResponse.java deleted file mode 100644 index ab568d4c2..000000000 --- a/backend/src/main/java/com/festago/admin/dto/AdminStageResponse.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.festago.admin.dto; - -import java.time.LocalDateTime; -import java.util.List; - -public record AdminStageResponse( - Long id, - Long festivalId, - LocalDateTime startTime, - String lineUp, - List ticketId) { - -} diff --git a/backend/src/main/java/com/festago/admin/dto/AdminTicketResponse.java b/backend/src/main/java/com/festago/admin/dto/AdminTicketResponse.java deleted file mode 100644 index 88c93754d..000000000 --- a/backend/src/main/java/com/festago/admin/dto/AdminTicketResponse.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.festago.admin.dto; - -import com.festago.ticket.domain.TicketType; -import java.time.LocalDateTime; -import java.util.Map; - -public record AdminTicketResponse( - Long id, - Long stageId, - TicketType ticketType, - Integer totalAmount, - Integer reservedAmount, - Map entryTimeAmount) { - -} diff --git a/backend/src/main/java/com/festago/presentation/AdminController.java b/backend/src/main/java/com/festago/presentation/AdminController.java index adb63cff4..62f74a362 100644 --- a/backend/src/main/java/com/festago/presentation/AdminController.java +++ b/backend/src/main/java/com/festago/presentation/AdminController.java @@ -1,7 +1,5 @@ package com.festago.presentation; -import com.festago.admin.application.AdminService; -import com.festago.admin.dto.AdminResponse; import com.festago.auth.annotation.Admin; import com.festago.auth.application.AdminAuthService; import com.festago.auth.dto.AdminLoginRequest; @@ -54,7 +52,6 @@ public class AdminController { private final FestivalService festivalService; private final StageService stageService; private final TicketService ticketService; - private final AdminService adminService; private final AdminAuthService adminAuthService; private final SchoolService schoolService; private final Optional properties; @@ -147,13 +144,6 @@ private String getCookie(String token) { .build().toString(); } - @GetMapping("/data") - public ResponseEntity adminData() { - AdminResponse response = adminService.getAdminResponse(); - return ResponseEntity.ok() - .body(response); - } - @GetMapping("/version") public ResponseEntity getVersion() { return properties.map(it -> ResponseEntity.ok(it.getTime().atZone(ZoneId.of("Asia/Seoul")).toString())) diff --git a/backend/src/main/java/com/festago/presentation/AdminViewController.java b/backend/src/main/java/com/festago/presentation/AdminViewController.java index 994e2e614..eba8e66c7 100644 --- a/backend/src/main/java/com/festago/presentation/AdminViewController.java +++ b/backend/src/main/java/com/festago/presentation/AdminViewController.java @@ -60,7 +60,6 @@ public String manageStagePage(@PathVariable String stageId) { @ExceptionHandler(UnauthorizedException.class) public View handle(UnauthorizedException e, HttpServletResponse response) { - if (e.getErrorCode() == ErrorCode.EXPIRED_AUTH_TOKEN) { return new RedirectView("/admin/login"); } diff --git a/backend/src/test/java/com/festago/presentation/AdminControllerTest.java b/backend/src/test/java/com/festago/presentation/AdminControllerTest.java index 2fc07ecbd..d4a9b6644 100644 --- a/backend/src/test/java/com/festago/presentation/AdminControllerTest.java +++ b/backend/src/test/java/com/festago/presentation/AdminControllerTest.java @@ -13,7 +13,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import com.fasterxml.jackson.databind.ObjectMapper; -import com.festago.admin.application.AdminService; import com.festago.auth.application.AdminAuthService; import com.festago.auth.application.AuthExtractor; import com.festago.auth.domain.Role; @@ -70,9 +69,6 @@ class AdminControllerTest { @MockBean TicketService ticketService; - @MockBean - AdminService adminService; - @MockBean AdminAuthService adminAuthService;