diff --git a/src/main/java/com/softeer/backend/bo_domain/admin/controller/MainPageController.java b/src/main/java/com/softeer/backend/bo_domain/admin/controller/AdminMainPageController.java similarity index 95% rename from src/main/java/com/softeer/backend/bo_domain/admin/controller/MainPageController.java rename to src/main/java/com/softeer/backend/bo_domain/admin/controller/AdminMainPageController.java index 07303d34..824b3b39 100644 --- a/src/main/java/com/softeer/backend/bo_domain/admin/controller/MainPageController.java +++ b/src/main/java/com/softeer/backend/bo_domain/admin/controller/AdminMainPageController.java @@ -11,7 +11,7 @@ @RestController @RequiredArgsConstructor @RequestMapping("/admin") -public class MainPageController { +public class AdminMainPageController { private final MainPageService mainPageService; @GetMapping("/main") diff --git a/src/main/java/com/softeer/backend/bo_domain/admin/controller/WinnerPageController.java b/src/main/java/com/softeer/backend/bo_domain/admin/controller/WinnerPageController.java index e7d5a902..d2a661ee 100644 --- a/src/main/java/com/softeer/backend/bo_domain/admin/controller/WinnerPageController.java +++ b/src/main/java/com/softeer/backend/bo_domain/admin/controller/WinnerPageController.java @@ -17,7 +17,7 @@ public class WinnerPageController { private final WinnerPageService winnerPageService; @GetMapping("/fcfs/{round}") - public ResponseDto getFcfsWinnerList(@PathVariable int round) { + public ResponseDto getFcfsWinnerList(@PathVariable Integer round) { FcfsWinnerListResponseDto fcfsWinnerListResponseDto = winnerPageService.getFcfsWinnerList(round); @@ -25,7 +25,7 @@ public ResponseDto getFcfsWinnerList(@PathVariable in } @GetMapping("/draw/{rank}") - public ResponseDto getDrawWinnerList(@PathVariable int rank) { + public ResponseDto getDrawWinnerList(@PathVariable Integer rank) { DrawWinnerListResponseDto drawWinnerListResponseDto = winnerPageService.getDrawWinnerList(rank); diff --git a/src/main/java/com/softeer/backend/bo_domain/admin/dto/winner/DrawWinnerUpdateRequestDto.java b/src/main/java/com/softeer/backend/bo_domain/admin/dto/winner/DrawWinnerUpdateRequestDto.java index d141dff8..5fe792fa 100644 --- a/src/main/java/com/softeer/backend/bo_domain/admin/dto/winner/DrawWinnerUpdateRequestDto.java +++ b/src/main/java/com/softeer/backend/bo_domain/admin/dto/winner/DrawWinnerUpdateRequestDto.java @@ -1,5 +1,9 @@ package com.softeer.backend.bo_domain.admin.dto.winner; +import com.softeer.backend.global.common.constant.ValidationConstant; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotNull; import lombok.*; @NoArgsConstructor(access = AccessLevel.PRIVATE) @@ -8,9 +12,18 @@ @Getter public class DrawWinnerUpdateRequestDto { - private int firstWinnerNum; + @NotNull + @Min(value = 1, message = ValidationConstant.MIN_VALUE_MSG) + @Max(value = 5, message = ValidationConstant.MAX_VALUE_MSG) + private Integer firstWinnerNum; - private int secondWinnerNum; + @NotNull + @Min(value = 1, message = ValidationConstant.MIN_VALUE_MSG) + @Max(value = 10, message = ValidationConstant.MAX_VALUE_MSG) + private Integer secondWinnerNum; - private int thirdWinnerNum; + @NotNull + @Min(value = 1, message = ValidationConstant.MIN_VALUE_MSG) + @Max(value = 100, message = ValidationConstant.MAX_VALUE_MSG) + private Integer thirdWinnerNum; } diff --git a/src/main/java/com/softeer/backend/bo_domain/admin/dto/winner/FcfsWinnerUpdateRequestDto.java b/src/main/java/com/softeer/backend/bo_domain/admin/dto/winner/FcfsWinnerUpdateRequestDto.java index 6553eda3..0c8105b7 100644 --- a/src/main/java/com/softeer/backend/bo_domain/admin/dto/winner/FcfsWinnerUpdateRequestDto.java +++ b/src/main/java/com/softeer/backend/bo_domain/admin/dto/winner/FcfsWinnerUpdateRequestDto.java @@ -1,5 +1,9 @@ package com.softeer.backend.bo_domain.admin.dto.winner; +import com.softeer.backend.global.common.constant.ValidationConstant; +import jakarta.validation.constraints.Max; +import jakarta.validation.constraints.Min; +import jakarta.validation.constraints.NotNull; import lombok.*; @NoArgsConstructor(access = AccessLevel.PRIVATE) @@ -8,7 +12,11 @@ @Getter public class FcfsWinnerUpdateRequestDto { - private int round; + @NotNull + private Integer round; - private int fcfsWinnerNum; + @NotNull + @Min(value = 1, message = ValidationConstant.MIN_VALUE_MSG) + @Max(value = 50, message = ValidationConstant.MAX_VALUE_MSG) + private Integer fcfsWinnerNum; } diff --git a/src/main/java/com/softeer/backend/bo_domain/admin/service/EventPageService.java b/src/main/java/com/softeer/backend/bo_domain/admin/service/EventPageService.java index 1f32c029..ba36e143 100644 --- a/src/main/java/com/softeer/backend/bo_domain/admin/service/EventPageService.java +++ b/src/main/java/com/softeer/backend/bo_domain/admin/service/EventPageService.java @@ -60,10 +60,10 @@ private void updateFcfsSetting(FcfsSetting setting, LocalDate date, LocalTime ti } private void updateDrawSetting(DrawSetting drawSetting, LocalDate startDate, LocalDate endDate) { - LocalDate startDateOfDraw = startDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.SUNDAY)); + LocalDate startDateOfDraw = startDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)); - LocalDate endDateOfPreviousWeek = endDate.with(TemporalAdjusters.nextOrSame(DayOfWeek.SATURDAY)); - LocalDate endDateOfDraw = endDateOfPreviousWeek.with(TemporalAdjusters.next(DayOfWeek.SATURDAY)); + LocalDate endDateOfPreviousWeek = endDate.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY)); + LocalDate endDateOfDraw = endDateOfPreviousWeek.with(TemporalAdjusters.next(DayOfWeek.SUNDAY)); drawSetting.setStartDate(startDateOfDraw); drawSetting.setEndDate(endDateOfDraw); diff --git a/src/main/java/com/softeer/backend/bo_domain/admin/validator/FcfsDateRangeValidator.java b/src/main/java/com/softeer/backend/bo_domain/admin/validator/FcfsDateRangeValidator.java index 5ba2208e..3627bcce 100644 --- a/src/main/java/com/softeer/backend/bo_domain/admin/validator/FcfsDateRangeValidator.java +++ b/src/main/java/com/softeer/backend/bo_domain/admin/validator/FcfsDateRangeValidator.java @@ -27,8 +27,8 @@ public boolean isValid(FcfsEventTimeRequestDto value, ConstraintValidatorContext LocalDate startDate = value.getStartDate(); LocalDate endDate = value.getEndDate(); - LocalDate startDateWeekStart = startDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.SUNDAY)); - LocalDate endDateWeekStart = endDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.SUNDAY)); + LocalDate startDateWeekStart = startDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)); + LocalDate endDateWeekStart = endDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)); boolean isSameWeek = startDateWeekStart.equals(endDateWeekStart); diff --git a/src/main/java/com/softeer/backend/fo_domain/comment/constant/ExpectationComment.java b/src/main/java/com/softeer/backend/fo_domain/comment/constant/ExpectationComment.java index d407cfb5..271a7525 100644 --- a/src/main/java/com/softeer/backend/fo_domain/comment/constant/ExpectationComment.java +++ b/src/main/java/com/softeer/backend/fo_domain/comment/constant/ExpectationComment.java @@ -27,14 +27,14 @@ public int getCommentOrder() { return this.ordinal() + 1; } - public static ExpectationComment of(int commentNum) { + public static ExpectationComment of(int commentType) { for (ExpectationComment comment : values()) { - if (comment.getCommentOrder() == commentNum) { + if (comment.getCommentOrder() == commentType) { return comment; } } - log.error("Invalid comment number: " + commentNum); + log.error("Invalid comment number: " + commentType); throw new CommentException(ErrorStatus._NOT_FOUND); } } diff --git a/src/main/java/com/softeer/backend/fo_domain/comment/controller/CommentController.java b/src/main/java/com/softeer/backend/fo_domain/comment/controller/CommentController.java index 2f94d3b5..fce14939 100644 --- a/src/main/java/com/softeer/backend/fo_domain/comment/controller/CommentController.java +++ b/src/main/java/com/softeer/backend/fo_domain/comment/controller/CommentController.java @@ -29,10 +29,10 @@ ResponseDto getComment(@RequestParam(name = "cursor", requi } @PostMapping("/comment") - ResponseDto saveComment(@RequestParam(name = "commentNum") int commentNum, + ResponseDto saveComment(@RequestParam(name = "commentType") int commentType, @AuthInfo Integer userId) { - commentService.saveComment(userId, commentNum); + commentService.saveComment(userId, commentType); return ResponseDto.onSuccess(); diff --git a/src/main/java/com/softeer/backend/fo_domain/comment/service/CommentService.java b/src/main/java/com/softeer/backend/fo_domain/comment/service/CommentService.java index 0f4652aa..145229c3 100644 --- a/src/main/java/com/softeer/backend/fo_domain/comment/service/CommentService.java +++ b/src/main/java/com/softeer/backend/fo_domain/comment/service/CommentService.java @@ -41,7 +41,7 @@ public CommentsResponseDto getComments(Integer userId, Integer cursor) { * 기대평을 저장하는 메서드 */ @Transactional - public void saveComment(Integer userId, int commentNum) { + public void saveComment(Integer userId, int commentType) { // 로그인 한 유저가 기대평을 등록했다면 User entity의 id값을 기반으로 닉네임을 설정한다. // 로그인 하지 않았다면, 랜덤으로 닉네임을 설정한다. @@ -50,7 +50,7 @@ public void saveComment(Integer userId, int commentNum) { commentRepository.save(Comment.builder() .nickname(randomNickname) - .expectationComment(ExpectationComment.of(commentNum)) + .expectationComment(ExpectationComment.of(commentType)) .userId(userId) .build() ); diff --git a/src/main/java/com/softeer/backend/fo_domain/mainpage/controller/MainPageController.java b/src/main/java/com/softeer/backend/fo_domain/mainpage/controller/MainPageController.java new file mode 100644 index 00000000..33f4860c --- /dev/null +++ b/src/main/java/com/softeer/backend/fo_domain/mainpage/controller/MainPageController.java @@ -0,0 +1,7 @@ +package com.softeer.backend.fo_domain.mainpage.controller; + +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class MainPageController { +} diff --git a/src/main/java/com/softeer/backend/fo_domain/mainpage/service/MainPageService.java b/src/main/java/com/softeer/backend/fo_domain/mainpage/service/MainPageService.java new file mode 100644 index 00000000..9fd0bbf9 --- /dev/null +++ b/src/main/java/com/softeer/backend/fo_domain/mainpage/service/MainPageService.java @@ -0,0 +1,4 @@ +package com.softeer.backend.fo_domain.mainpage.service; + +public class MainPageService { +} diff --git a/src/main/java/com/softeer/backend/fo_domain/user/service/LoginService.java b/src/main/java/com/softeer/backend/fo_domain/user/service/LoginService.java index 64f6170a..60c1ee0a 100644 --- a/src/main/java/com/softeer/backend/fo_domain/user/service/LoginService.java +++ b/src/main/java/com/softeer/backend/fo_domain/user/service/LoginService.java @@ -28,7 +28,7 @@ public class LoginService { * 3. 전화번호가 이미 User DB에 등록되어 있는 경우, 전화번호로 User 객체를 조회한다. * 4. User 객체의 id를 얻은 후에, access & refresh token을 client에게 전달한다. */ - @Transactional(readOnly = true) + @Transactional public JwtTokenResponseDto handleLogin(LoginRequestDto loginRequestDto) { // 인증번호가 인증 되지 않은 경우, 예외 발생 diff --git a/src/main/java/com/softeer/backend/global/common/constant/ValidationConstant.java b/src/main/java/com/softeer/backend/global/common/constant/ValidationConstant.java index 8e802a14..c823ea04 100644 --- a/src/main/java/com/softeer/backend/global/common/constant/ValidationConstant.java +++ b/src/main/java/com/softeer/backend/global/common/constant/ValidationConstant.java @@ -20,4 +20,7 @@ public class ValidationConstant { public static final String ADMIN_PASSWORD_REGEX = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[@#$%^&*!])[A-Za-z\\d@#$%^&*!]{8,20}$"; public static final String ADMIN_PASSWORD_MSG = "잘못된 비밀번호 형식입니다."; + public static final String MIN_VALUE_MSG = "값은 최소 {value}이어야 합니다."; + public static final String MAX_VALUE_MSG = "값은 최대 {value}이어야 합니다."; + } diff --git a/src/main/java/com/softeer/backend/global/common/exception/ExceptionAdvice.java b/src/main/java/com/softeer/backend/global/common/exception/ExceptionAdvice.java index 279a4061..f0ebd1a2 100644 --- a/src/main/java/com/softeer/backend/global/common/exception/ExceptionAdvice.java +++ b/src/main/java/com/softeer/backend/global/common/exception/ExceptionAdvice.java @@ -17,9 +17,7 @@ import org.springframework.web.context.request.WebRequest; import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler; -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.Optional; +import java.util.*; /** @@ -56,12 +54,13 @@ public ResponseEntity handleEventLockException(EventLockException eventL */ @ExceptionHandler public ResponseEntity handleValidationException(ConstraintViolationException constraintViolationException, WebRequest request) { - String errorMessage = constraintViolationException.getConstraintViolations().stream() - .map(ConstraintViolation::getMessage) - .findFirst() - .orElseThrow(() -> new RuntimeException("ConstraintViolationException 추출 도중 에러 발생")); - return handleConstraintExceptionInternal(constraintViolationException, ErrorStatus.valueOf(errorMessage), HttpHeaders.EMPTY, request); + List errorMessages = constraintViolationException.getConstraintViolations().stream() + .map(violation -> Optional.ofNullable(violation.getMessage()).orElse("")) + .toList(); + + return handleConstraintExceptionInternal(constraintViolationException, ErrorStatus._VALIDATION_ERROR, HttpHeaders.EMPTY, request, + errorMessages); } /** @@ -157,10 +156,12 @@ private ResponseEntity handleEventLockExceptionInternal(EventLockExcepti // ConstraintViolationException에 대한 client 응답 객체를 생성하는 메서드 private ResponseEntity handleConstraintExceptionInternal(Exception e, ErrorStatus errorCommonStatus, - HttpHeaders headers, WebRequest request) { + HttpHeaders headers, WebRequest request, + List errorMessages) { + log.error("ConstraintViolationException captured in ExceptionAdvice", e); - ResponseDto body = ResponseDto.onFailure(errorCommonStatus.getCode(), errorCommonStatus.getMessage(), null); + ResponseDto body = ResponseDto.onFailure(errorCommonStatus.getCode(), errorCommonStatus.getMessage(), errorMessages); return super.handleExceptionInternal( e, body, diff --git a/src/main/java/com/softeer/backend/global/staticresources/constant/StaticText.java b/src/main/java/com/softeer/backend/global/staticresources/constant/StaticText.java new file mode 100644 index 00000000..7d474d3b --- /dev/null +++ b/src/main/java/com/softeer/backend/global/staticresources/constant/StaticText.java @@ -0,0 +1,89 @@ +package com.softeer.backend.global.staticresources.constant; + +public enum StaticText { + + EVENT_PERIOD("%s ~ %s"), + FCFS_INFO("매주 %s, %s %s %s시 선착순 %"), + FCFS_TITLE("'24시 내 차' 이벤트"), + FCFS_CONTENT("하단의 The new IONIQ 5 정보를 바탕으로 빠르게 문장 퀴즈를 맞춰\n" + + "24시간 렌트권과 신차 할인권을 얻을 수 있어요."), + + TOTAL_DRAW_WINNER("추첨 %s명"), + REMAIN_DRAW_COUNT("남은 경품 %s개"), + DRAW_TITLE("매일 복권 긁고 경품 받기"), + DRAW_CONTENT("이벤트 기간 동안 추첨을 통해 아이패드 pro 11인치, 현대백화점 10만원권, 1만원권을 드려요.\n" + + "일주일 연속 참여 시, 스타벅스 쿠폰을 무조건 받을 수 있어요."), + + MAIN_TITLE("The new IONIQ 5"), + MAIN_SUBTITLE("새롭게 돌아온 The new IONIQ 5를 소개합니다"), + + INTERIOR_TITLE("Interior"), + INTERIOR_SUBTITLE("내부 인테리어"), + INTERIOR_IMAGE_TITLE("Living Space"), + INTERIOR_IMAGE_CONTENT("편안한 거주 공간 (Living Space) 테마를 반영하여 더 넓은 실내 공간을 즐길 수 있도록 연출합니다."), + INTERIOR_OPENNESS_TITLE("개방감"), + INTERIOR_OPENNESS_SUBTITLE("개방감과 와이드한 이미지 제공"), + INTERIOR_OPENNESS_CONENT("심리스 스타일의 12.3인치 LCD 클러스터는 탁월한 개방감으로 즐거운 드라이빙 환경을 제공합니다.\n" + + "클러스터와 인포테인먼트 시스템에 일체형 커버글래스를 적용하여 와이드한 이미지를 제공합니다."), + + INTERIOR_WELLNESS_TITLE("웰니스"), + INTERIOR_WELLNESS_SUBTITLE("웰니스와 친환경"), + INTERIOR_WELLNESS_CONTENT("혼커버, 스위치, 스티어링 휠, 도어 등에 유채꽃과 옥수수에서 추출한 성분 약 10%가 함유된 바이오 페인트를 이용했습니다.\n" + + "시트와 도어 트림에는 재활용 투명 PET병을 재활용한 원사 약 20%의 섬유가 사용됐습니다."), + + PERFORMANCE_TITLE("Performance"), + PERFORMANCE_SUBTITLE("주행성능"), + PERFORMANCE_IMAGE_TITLE("Large Capacity Battery"), + PERFORMANCE_IMAGE_CONTENT("항속형 대용량 배터리를 적용하여 주행 가능 거리를 높였습니다."), + PERFORMANCE_BRAKING_TITLE("에너지 효율"), + PERFORMANCE_BRAKING_SUBTITLE("회생 제동 시스템"), + PERFORMANCE_BRAKING_CONENT("스티어링 휠의 패들쉬프트를 통해 회생제동 수준을 단계별로 조작할 수 있어\n" + + "브레이크 및 가족 페달 작동을 최소화하여 에너지 효율을 높일 수 있습니다."), + + PERFORMANCE_DRIVING_TITLE("주행성능"), + PERFORMANCE_DRIVING_SUBTITLE("주행 성능"), + PERFORMANCE_DRIVING_CONTENT("1회 충전 주행 가능 거리: 485km (2WD, 19인치, 빌트인 캠 미적용 기준)\n" + + "최고 출력 / 최대 토크: 239 kW (325 PS) / 605 Nm\n" + + "84.0 kWh 대용량 배터리를 장착하여 보다 여유 있는 장거리 주행이 가능합니다."), + + CHARGING_TITLE("Charging"), + CHARGING_SUBTITLE("급속 충전"), + CHARGING_IMAGE_TITLE("V2L/Charging"), + CHARGING_IMAGE_CONTENT("차량 외부로 전력을 공급할 수 있는 V2L 기능과 쉽고 빠르게 충전 관련 서비스는 사용자에게 새로운 경험을 제공합니다."), + CHARGING_FAST_TITLE("초급속 충전"), + CHARGING_FAST_SUBTITLE("18분 초급속 충전 경험"), + CHARGING_FAST_CONENT("400V/800V 멀티 급속 충전 시스템으로 다양한 충전 인프라를 사용할 수 있으며,\n" + + "급속 충전기(350kW) 사용 시 18분 이내에 배터리 용량의 10%에서 80%까지 충전이 가능합니다."), + + CHARGING_V2L_TITLE("실외/실내\n" + + "V2L"), + CHARGING_V2L_SUBTITLE("실외/실내 V2L"), + CHARGING_V2L_CONTENT("차량 외부에서도 실외 V2L 기능을 통해 다양한 전자기기 사용이 가능합니다.\n" + + "2열 시트 하단의 실내 V2L을 사용하여 차량 내부에서 배터리 걱정 없이 전자기기 사용이 가능합니다."), + + SAFE_TITLE("Safe, Convenient"), + SAFE_SUBTITLE("안전성과 편리함"), + SAFE_IMAGE_TITLE("Safe & Convenient Environment"), + SAFE_IMAGE_CONTENT("다양한 안전, 편의 기술로 편리하고 안전한 드라이빙 환경을 제공합니다."), + SAFE_DRIVING_TITLE("주행 안전"), + SAFE_DRIVING_SUBTITLE("도로 주행 중 안전"), + SAFE_DRIVING_CONENT("고속도로 및 자동차 전용도로 주행 시 도로 상황에 맞춰 안전한 속도로 주행하도록 도와주며,\n" + + "안전속도 구간, 곡선 구간, 진출입로 진입 전에 자동으로 속도를 줄이고 해당 구간을 지나면 원래 설정한 속도로 복귀합니다.\n" + + "일정 속도 이상으로 주행 시, 스티어링 휠을 잡은 상태에서 방향지시등 스위치를 변경하고자 하는 차로 방향으로 자동으로 움직입니다."), + + SAFE_ADVANCED_TITLE("후석 승객 알림"), + SAFE_ADVANCED_SUBTITLE("어드밴스드 후석 승객 알림"), + SAFE_ADVANCED_CONTENT("정밀한 레이더 센서가 실내의 승객을 감지하여, 운전자가 후석에 탑승한 유아를 인지하지 못하고 차를 떠나면\n" + + "알림을 주어 안전사고를 예방합니다."); + + + private final String text; + + StaticText(String text) { + this.text = text; + } + + public String format(Object... args) { + return String.format(text, args); + } +} diff --git a/src/main/java/com/softeer/backend/global/staticresources/domain/StaticResources.java b/src/main/java/com/softeer/backend/global/staticresources/domain/StaticResources.java new file mode 100644 index 00000000..5c36b4af --- /dev/null +++ b/src/main/java/com/softeer/backend/global/staticresources/domain/StaticResources.java @@ -0,0 +1,27 @@ +package com.softeer.backend.global.staticresources.domain; +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +@Entity +@NoArgsConstructor +@AllArgsConstructor +@Getter +@Builder +@Table(name = "static_resources") +public class StaticResources { + + @Id + @Column(name = "static_resources_id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @Column(name = "file_name", nullable = false) + private String fileName; + + @Column(name = "file_url", nullable = false) + private String fileUrl; +} diff --git a/src/main/java/com/softeer/backend/global/staticresources/repository/StaticResourcesRepository.java b/src/main/java/com/softeer/backend/global/staticresources/repository/StaticResourcesRepository.java new file mode 100644 index 00000000..57932b85 --- /dev/null +++ b/src/main/java/com/softeer/backend/global/staticresources/repository/StaticResourcesRepository.java @@ -0,0 +1,7 @@ +package com.softeer.backend.global.staticresources.repository; + +import com.softeer.backend.global.staticresources.domain.StaticResources; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface StaticResourcesRepository extends JpaRepository { +} diff --git a/src/main/java/com/softeer/backend/global/staticresources/util/StaticResourcesUtil.java b/src/main/java/com/softeer/backend/global/staticresources/util/StaticResourcesUtil.java new file mode 100644 index 00000000..3a9c2456 --- /dev/null +++ b/src/main/java/com/softeer/backend/global/staticresources/util/StaticResourcesUtil.java @@ -0,0 +1,43 @@ +package com.softeer.backend.global.staticresources.util; + +import com.softeer.backend.fo_domain.fcfs.domain.FcfsSetting; +import com.softeer.backend.global.staticresources.domain.StaticResources; +import com.softeer.backend.global.staticresources.repository.StaticResourcesRepository; +import jakarta.annotation.PostConstruct; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Component +@RequiredArgsConstructor +public class StaticResourcesUtil { + + private final StaticResourcesRepository staticResourcesRepository; + + private Map s3Urls; + + @PostConstruct + public void init() { + loadInitialData(); + } + + public void loadInitialData() { + List staticResourcesList = staticResourcesRepository.findAll(); + + s3Urls.putAll( + staticResourcesList.stream() + .collect(Collectors.toMap( + StaticResources::getFileName, // Key mapper + StaticResources::getFileUrl // Value mapper + )) + ); + } + + public String getFileUrl(String filename) { + return s3Urls.get(filename); + } +}