From e8c7c1dca7f1ba1d84cb2621cb1104c8f474833c Mon Sep 17 00:00:00 2001 From: kimdongjun Date: Thu, 2 Jan 2025 14:58:21 +0900 Subject: [PATCH 01/11] =?UTF-8?q?:recycle:=20refactor:=20DailyController?= =?UTF-8?q?=20API=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 의약품 정보 페이지 API 수정 --- .../controller/DailyController.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/foregg/foreggserver/controller/DailyController.java b/src/main/java/foregg/foreggserver/controller/DailyController.java index 1d922de..64b1460 100644 --- a/src/main/java/foregg/foreggserver/controller/DailyController.java +++ b/src/main/java/foregg/foreggserver/controller/DailyController.java @@ -1,11 +1,13 @@ + package foregg.foreggserver.controller; import foregg.foreggserver.apiPayload.ApiResponse; +import foregg.foreggserver.domain.enums.RecordType; import foregg.foreggserver.dto.dailyDTO.*; import foregg.foreggserver.dto.dailyDTO.DailyRequestDTO.DailyReplyRequestDTO; import foregg.foreggserver.dto.dailyDTO.DailyResponseDTO.DailyAllResponseDTO; import foregg.foreggserver.dto.dailyDTO.DailyResponseDTO.DailyByCountResponseDTO; -import foregg.foreggserver.dto.injectionDTO.InjectionResponseDTO; +import foregg.foreggserver.dto.injectionDTO.MedicalResponseDTO; import foregg.foreggserver.service.dailyService.DailyQueryService; import foregg.foreggserver.service.dailyService.DailyService; import foregg.foreggserver.service.injectionService.InjectionQueryService; @@ -184,12 +186,23 @@ public ApiResponse sendNotificationInjection(@PathVariable(name = "id") return ApiResponse.onSuccess(); } - @Operation(summary = "주사 정보 페이지 API") + @Operation(summary = "의약품 정보 페이지 API") @PreAuthorize("isAuthenticated()") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "DAILY4001", description = "존재하지 않는 일정입니다"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "DAILY4005", description = "주사와 약 정보만 제공됩니다"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "DAILY4006", description = "해당 시간에 기록이 없습니다"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "DAILY4007", description = "일정의 타입이 일치하지 않습니다"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "DAILY4009", description = "나의 주사 일정을 찾을 수 없습니다"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "DAILY4011", description = "해당 날짜에는 일정이 존재하지 않습니다"), + }) @GetMapping("/injectionInfo/{id}") - public ApiResponse getInjectionInfo(@PathVariable(name = "id") Long id, - @RequestParam(name = "time") String time) { - InjectionResponseDTO dto = injectionQueryService.getInjectionInfo(id, time); + public ApiResponse getInjectionInfo(@PathVariable(name = "id") Long id, + @RequestParam(name = "type") RecordType type, + @RequestParam(name = "date") String date, + @RequestParam(name = "time") String time) { + MedicalResponseDTO dto = injectionQueryService.getMedicalInfo(id, type, date, time); return ApiResponse.onSuccess(dto); } From 644a0be76e27f86de0642a93f5e34404e8e54d01 Mon Sep 17 00:00:00 2001 From: kimdongjun Date: Thu, 2 Jan 2025 14:59:23 +0900 Subject: [PATCH 02/11] =?UTF-8?q?:recycle:=20refactor:=20=EC=9D=98?= =?UTF-8?q?=EC=95=BD=ED=92=88=20=EC=A0=95=EB=B3=B4=20API=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 의약품 Res DTO date 필드 추가 약 정보 로직 추가 --- .../InjectionQueryService.java | 67 +++++++++++++------ 1 file changed, 47 insertions(+), 20 deletions(-) diff --git a/src/main/java/foregg/foreggserver/service/injectionService/InjectionQueryService.java b/src/main/java/foregg/foreggserver/service/injectionService/InjectionQueryService.java index e4f98b5..b21c586 100644 --- a/src/main/java/foregg/foreggserver/service/injectionService/InjectionQueryService.java +++ b/src/main/java/foregg/foreggserver/service/injectionService/InjectionQueryService.java @@ -1,22 +1,25 @@ package foregg.foreggserver.service.injectionService; +import foregg.foreggserver.apiPayload.exception.handler.DailyHandler; import foregg.foreggserver.apiPayload.exception.handler.RecordHandler; import foregg.foreggserver.apiPayload.exception.handler.UserHandler; import foregg.foreggserver.domain.*; import foregg.foreggserver.domain.Record; import foregg.foreggserver.domain.enums.RecordType; -import foregg.foreggserver.dto.injectionDTO.InjectionResponseDTO; +import foregg.foreggserver.dto.injectionDTO.MedicalResponseDTO; import foregg.foreggserver.jwt.SecurityUtil; -import foregg.foreggserver.repository.InjectionRepository; +import foregg.foreggserver.repository.MedicalRepository; import foregg.foreggserver.repository.RecordRepository; import foregg.foreggserver.repository.RepeatTimeRepository; import foregg.foreggserver.service.fcmService.FcmService; import foregg.foreggserver.service.userService.UserQueryService; +import foregg.foreggserver.util.DateUtil; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.io.IOException; +import java.util.List; import java.util.Optional; import static foregg.foreggserver.apiPayload.code.status.ErrorStatus.*; @@ -28,7 +31,7 @@ public class InjectionQueryService { private final UserQueryService userQueryService; private final FcmService fcmService; - private final InjectionRepository injectionRepository; + private final MedicalRepository medicalRepository; private final RecordRepository recordRepository; private final RepeatTimeRepository repeatTimeRepository; @@ -42,7 +45,7 @@ public void shareInjection(Long id, String time) { User spouse = userQueryService.returnSpouse(); if (spouse != null) { try { - fcmService.sendMessageTo(spouse.getFcmToken(), "주사 푸시 알림입니다", String.format("%s님이 일정을 완료했어요.", user.getNickname(),foundRecord.get().getName()),"inj_med_info_screen", id.toString(),time, null); + fcmService.sendMessageTo(spouse.getFcmToken(), "주사 푸시 알림입니다", String.format("%s님이 일정을 완료했어요.", user.getNickname(),foundRecord.get().getName()),"inj_med_info_screen", id.toString(), time, null); } catch (IOException e) { throw new RuntimeException(e); } @@ -51,29 +54,25 @@ public void shareInjection(Long id, String time) { } } - public InjectionResponseDTO getInjectionInfo(Long id, String time) { + public MedicalResponseDTO getMedicalInfo(Long id, RecordType type, String date, String time) { + Record record = recordRepository.findById(id).orElseThrow(() -> new RecordHandler(RECORD_NOT_FOUND)); isMyInjectionRecord(record); - if (record.getType() != RecordType.INJECTION) { - throw new RecordHandler(NOT_INJECTION_RECORD); - } + isValidateRecord(record, type, time, date); - Optional repeatTime = repeatTimeRepository.findByRecordAndTime(record, time); - if (repeatTime.isEmpty()) { - throw new RecordHandler(NOT_FOUND_REPEATTIME); - } - - Optional injection = injectionRepository.findByName(record.getName()); - if (injection.isPresent()) { - return InjectionResponseDTO.builder() - .name(injection.get().getName()) - .description(injection.get().getDescription()) - .image(injection.get().getImage()) + Optional medical = medicalRepository.findByName(record.getName()); + if (medical.isPresent()) { + return MedicalResponseDTO.builder() + .name(medical.get().getName()) + .date(date) + .description(medical.get().getDescription()) + .image(medical.get().getImage()) .time(time).build(); } - return InjectionResponseDTO.builder() + return MedicalResponseDTO.builder() .name(record.getName()) + .date(date) .description(null) .image(null) .time(time).build(); @@ -91,6 +90,34 @@ public void isMyInjectionRecord(Record record) { throw new RecordHandler(NOT_FOUND_MY_INJECTION_RECORD); } } + } + private void isValidateRecord(Record record, RecordType type, String time, String date) { + if (type.equals(RecordType.ETC) || type.equals(RecordType.HOSPITAL)) { + throw new DailyHandler(ONLY_INJECTION_MEDICINE); + } + + if (!record.getType().equals(type)) { + throw new DailyHandler(MISMATCH_RECORD_AND_TYPE); + } + + Optional repeatTime = repeatTimeRepository.findByRecordAndTime(record, time); + if (repeatTime.isEmpty()) { + throw new RecordHandler(NOT_FOUND_REPEATTIME); + } + + if (record.getDate() != null) { + if (!record.getDate().equals(date)) { + throw new RecordHandler(INVALID_RECORD_DATE); + } + } else { + List intervalDates = DateUtil.getIntervalDates(record.getStart_date(), record.getEnd_date()); + if (!intervalDates.contains(date)) { + throw new RecordHandler(INVALID_RECORD_DATE); + } + if (!record.getRepeat_date().contains(DateUtil.getKoreanDayOfWeek(date))) { + throw new RecordHandler(INVALID_RECORD_DATE); + } + } } } From 0eb425ed8fda59885611684627ca0da9aed13c49 Mon Sep 17 00:00:00 2001 From: kimdongjun Date: Thu, 2 Jan 2025 14:59:44 +0900 Subject: [PATCH 03/11] =?UTF-8?q?:recycle:=20refactor:=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=20=EC=9D=B4=EB=A6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection -> Medicine --- .../foregg/foreggserver/domain/{Injection.java => Medical.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/main/java/foregg/foreggserver/domain/{Injection.java => Medical.java} (92%) diff --git a/src/main/java/foregg/foreggserver/domain/Injection.java b/src/main/java/foregg/foreggserver/domain/Medical.java similarity index 92% rename from src/main/java/foregg/foreggserver/domain/Injection.java rename to src/main/java/foregg/foreggserver/domain/Medical.java index 03f289c..b83ecb1 100644 --- a/src/main/java/foregg/foreggserver/domain/Injection.java +++ b/src/main/java/foregg/foreggserver/domain/Medical.java @@ -12,7 +12,7 @@ @AllArgsConstructor @NoArgsConstructor @Builder -public class Injection extends BaseEntity { +public class Medical extends BaseEntity { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) From a23089e6f9d94dcd2de8132f1287faccdd6f2ae6 Mon Sep 17 00:00:00 2001 From: kimdongjun Date: Thu, 2 Jan 2025 14:59:55 +0900 Subject: [PATCH 04/11] =?UTF-8?q?:recycle:=20refactor:=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=20=EC=9D=B4=EB=A6=84=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection -> Medical --- .../foreggserver/repository/InjectionRepository.java | 12 ------------ .../foreggserver/repository/MedicalRepository.java | 12 ++++++++++++ 2 files changed, 12 insertions(+), 12 deletions(-) delete mode 100644 src/main/java/foregg/foreggserver/repository/InjectionRepository.java create mode 100644 src/main/java/foregg/foreggserver/repository/MedicalRepository.java diff --git a/src/main/java/foregg/foreggserver/repository/InjectionRepository.java b/src/main/java/foregg/foreggserver/repository/InjectionRepository.java deleted file mode 100644 index 826ee9f..0000000 --- a/src/main/java/foregg/foreggserver/repository/InjectionRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -package foregg.foreggserver.repository; - -import foregg.foreggserver.domain.Injection; -import org.springframework.data.jpa.repository.JpaRepository; - -import java.util.Optional; - -public interface InjectionRepository extends JpaRepository { - - Optional findByName(String name); - -} diff --git a/src/main/java/foregg/foreggserver/repository/MedicalRepository.java b/src/main/java/foregg/foreggserver/repository/MedicalRepository.java new file mode 100644 index 0000000..da8cb83 --- /dev/null +++ b/src/main/java/foregg/foreggserver/repository/MedicalRepository.java @@ -0,0 +1,12 @@ +package foregg.foreggserver.repository; + +import foregg.foreggserver.domain.Medical; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface MedicalRepository extends JpaRepository { + + Optional findByName(String name); + +} From cf83a023e9a19fc91bc75ce49458c391089bc6a3 Mon Sep 17 00:00:00 2001 From: kimdongjun Date: Thu, 2 Jan 2025 15:00:11 +0900 Subject: [PATCH 05/11] =?UTF-8?q?:recycle:=20refactor:=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=20=EC=9D=B4=EB=A6=84=20=EC=88=98=EC=A0=95,?= =?UTF-8?q?=20=ED=95=84=EB=93=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection -> Medical date 필드 추가 --- .../{InjectionResponseDTO.java => MedicalResponseDTO.java} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename src/main/java/foregg/foreggserver/dto/injectionDTO/{InjectionResponseDTO.java => MedicalResponseDTO.java} (79%) diff --git a/src/main/java/foregg/foreggserver/dto/injectionDTO/InjectionResponseDTO.java b/src/main/java/foregg/foreggserver/dto/injectionDTO/MedicalResponseDTO.java similarity index 79% rename from src/main/java/foregg/foreggserver/dto/injectionDTO/InjectionResponseDTO.java rename to src/main/java/foregg/foreggserver/dto/injectionDTO/MedicalResponseDTO.java index 4668f82..c045ac7 100644 --- a/src/main/java/foregg/foreggserver/dto/injectionDTO/InjectionResponseDTO.java +++ b/src/main/java/foregg/foreggserver/dto/injectionDTO/MedicalResponseDTO.java @@ -4,14 +4,14 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import org.checkerframework.checker.units.qual.N; @Getter @Builder @NoArgsConstructor @AllArgsConstructor -public class InjectionResponseDTO { +public class MedicalResponseDTO { private String name; + private String date; private String description; private String image; private String time; From 88ac345bbe2f22a13ebd26d2d070aed2abf25ec8 Mon Sep 17 00:00:00 2001 From: kimdongjun Date: Thu, 2 Jan 2025 15:00:36 +0900 Subject: [PATCH 06/11] =?UTF-8?q?:recycle:=20refactor:=20NotificationServi?= =?UTF-8?q?ce=20=EB=A9=94=EC=84=9C=EB=93=9C=20=ED=8C=8C=EB=9D=BC=EB=AF=B8?= =?UTF-8?q?=ED=84=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit time -> date+time --- .../service/notificationService/NotificationService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/foregg/foreggserver/service/notificationService/NotificationService.java b/src/main/java/foregg/foreggserver/service/notificationService/NotificationService.java index 8b10625..df3817f 100644 --- a/src/main/java/foregg/foreggserver/service/notificationService/NotificationService.java +++ b/src/main/java/foregg/foreggserver/service/notificationService/NotificationService.java @@ -162,7 +162,7 @@ public void scheduleNotification(User user, LocalDateTime notificationDateTime, Date date = Date.from(notificationDateTime.atZone(ZoneId.systemDefault()).toInstant()); ScheduledFuture scheduledFuture = taskScheduler.schedule(() -> { try { - fcmService.sendMessageTo(user.getFcmToken(), "주사 일정 알림", String.format("%s님 %s 주사 맞을 시간이에요.",user.getNickname(),time), "injection female", recordId.toString(), time, null); + fcmService.sendMessageTo(user.getFcmToken(), "주사 일정 알림", String.format("%s님 %s 주사 맞을 시간이에요.",user.getNickname(),date+time), "injection female", recordId.toString(), time, null); log.info("FCM 푸시 알림이 성공적으로 {}에게 전송되었습니다.", user.getNickname()); } catch (IOException e) { log.error("FCM 푸시 알림을 보내는 도중 오류 발생: {}", e.getMessage()); From dae4902db0740804caf5ab2473a9ca75dd51c632 Mon Sep 17 00:00:00 2001 From: kimdongjun Date: Thu, 2 Jan 2025 15:00:55 +0900 Subject: [PATCH 07/11] =?UTF-8?q?:recycle:=20refactor:=20ErrorStatus=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ErrorStatus 추가 --- .../foreggserver/apiPayload/code/status/ErrorStatus.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/foregg/foreggserver/apiPayload/code/status/ErrorStatus.java b/src/main/java/foregg/foreggserver/apiPayload/code/status/ErrorStatus.java index 639687a..dc3de1d 100644 --- a/src/main/java/foregg/foreggserver/apiPayload/code/status/ErrorStatus.java +++ b/src/main/java/foregg/foreggserver/apiPayload/code/status/ErrorStatus.java @@ -43,10 +43,11 @@ public enum ErrorStatus implements BaseErrorCode { NOT_FOUND_MY_RECORD(BAD_REQUEST, "RECORD4004", "나의 기록이 존재하지 않습니다"), NOT_RESERVED_HOSPITAL_RECORD(BAD_REQUEST, "RECORD4005", "예약된 병원 기록이 존재하지 않습니다"), NOT_FOUND_REPEATTIME(BAD_REQUEST, "RECORD4006", "해당 시간에 기록이 없습니다"), - NOT_INJECTION_RECORD(BAD_REQUEST, "RECORD4007", "주사 일정이 아닙니다"), + MISMATCH_RECORD_AND_TYPE(BAD_REQUEST, "RECORD4007", "일정의 타입이 일치하지 않습니다"), NOT_FOUND_LATEST_MEDICAL_RECORD(BAD_REQUEST, "RECORD4008", "최근의 진료 기록이 없습니다"), NOT_FOUND_MY_INJECTION_RECORD(BAD_REQUEST, "RECORD4009","나의 주사 일정을 찾을 수 없습니다"), MEN_ONLY_ETC(BAD_REQUEST, "RECORD4010","남편은 기타 일정 외에는 추가할 수 없습니다"), + INVALID_RECORD_DATE(BAD_REQUEST, "RECORD4011", "해당 날짜에는 일정이 존재하지 않습니다"), //챌린지 관련 에러 @@ -85,6 +86,7 @@ public enum ErrorStatus implements BaseErrorCode { NOT_FOUND_DAILY(BAD_REQUEST, "DAILY4002","하루 기록이 존재하지 않습니다"), NOT_FRIDAY(BAD_REQUEST, "DAILY4003","금요일이 아닙니다"), ALREADY_REPLY(BAD_REQUEST, "DAILY4004","이미 답장을 했습니다"), + ONLY_INJECTION_MEDICINE(BAD_REQUEST, "DAILY_4005", "주사와 약 정보만 제공됩니다"), //부작용 관련 에러 NOT_FOUND_SIDEEFFECT(BAD_REQUEST, "SIDEEFFECT4001", "부작용이 존재하지 않습니다"), From b1d321dfc2accb393aab41cd254857337f2fe23c Mon Sep 17 00:00:00 2001 From: kimdongjun Date: Thu, 2 Jan 2025 16:04:28 +0900 Subject: [PATCH 08/11] =?UTF-8?q?:recycle:=20refactor:=20=EC=B0=8C?= =?UTF-8?q?=EB=A5=B4=EA=B8=B0=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=95=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 챌린지 컨트롤러 파라미터 수정 --- .../foreggserver/controller/ChallengeController.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/foregg/foreggserver/controller/ChallengeController.java b/src/main/java/foregg/foreggserver/controller/ChallengeController.java index 1307244..532d68c 100644 --- a/src/main/java/foregg/foreggserver/controller/ChallengeController.java +++ b/src/main/java/foregg/foreggserver/controller/ChallengeController.java @@ -19,6 +19,8 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; @@ -188,9 +190,15 @@ public ApiResponse getChallengeName() { @GetMapping("/{challengeId}/{isSuccess}/participants") @ApiResponses({ @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "PAGE4001", description = "페이지 사이즈를 벗어났습니다") }) - public ApiResponse> getCompleteList(@PathVariable(name = "challengeId") Long challengeId, @PathVariable(name = "isSuccess") boolean isSuccess) { - List result = challengeQueryService.getParticipants(challengeId, isSuccess); + public ApiResponse getCompleteList( + @PathVariable(name = "challengeId") Long challengeId, + @PathVariable(name = "isSuccess") boolean isSuccess, + @RequestParam(name = "page", defaultValue = "0") int page, + @RequestParam(name = "size", defaultValue = "10") int size) { + Pageable pageable = PageRequest.of(page, size); + ChallengeParticipantsDTO result = challengeQueryService.getParticipants(challengeId, isSuccess, pageable); return ApiResponse.onSuccess(result); } From 9b10a61ddf87879334697db7bbd83c34fd64535f Mon Sep 17 00:00:00 2001 From: kimdongjun Date: Thu, 2 Jan 2025 16:04:47 +0900 Subject: [PATCH 09/11] =?UTF-8?q?:recycle:=20refactor:=20=EC=B0=8C?= =?UTF-8?q?=EB=A5=B4=EA=B8=B0=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=95=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 컨버터 수정 --- .../foregg/foreggserver/converter/ChallengeConverter.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/foregg/foreggserver/converter/ChallengeConverter.java b/src/main/java/foregg/foreggserver/converter/ChallengeConverter.java index a723866..ce792db 100644 --- a/src/main/java/foregg/foreggserver/converter/ChallengeConverter.java +++ b/src/main/java/foregg/foreggserver/converter/ChallengeConverter.java @@ -4,7 +4,7 @@ import foregg.foreggserver.domain.ChallengeParticipation; import foregg.foreggserver.domain.User; import foregg.foreggserver.dto.challengeDTO.ChallengeResponseDTO.ChallengeDTO; -import foregg.foreggserver.dto.challengeDTO.ChallengeResponseDTO.ChallengeParticipantsDTO; +import foregg.foreggserver.dto.challengeDTO.ChallengeResponseDTO.ChallengeParticipantsDTO.ChallengeParticipantDTO; import foregg.foreggserver.dto.challengeDTO.ChallengeResponseDTO.MyChallengeTotalDTO.MyChallengeDTO; import lombok.RequiredArgsConstructor; @@ -48,8 +48,8 @@ public static MyChallengeDTO toMyChallengeDTO(ChallengeParticipation cp, int par .successDays(cp.getSuccessDays()).build(); } - public static ChallengeParticipantsDTO toChallengeParticipantDTO(ChallengeParticipation challengeParticipations, boolean isSupported) { - return ChallengeParticipantsDTO.builder() + public static ChallengeParticipantDTO toChallengeParticipantDTO(ChallengeParticipation challengeParticipations, boolean isSupported) { + return ChallengeParticipantDTO.builder() .userId(challengeParticipations.getUser().getId()) .nickname(challengeParticipations.getUser().getChallengeName()) .thoughts(challengeParticipations.getThoughts()) From 52093cfe63af6d8d1bf3cb760c4c20ac3ac80bc6 Mon Sep 17 00:00:00 2001 From: kimdongjun Date: Thu, 2 Jan 2025 16:06:06 +0900 Subject: [PATCH 10/11] =?UTF-8?q?:recycle:=20refactor:=20=EC=B0=8C?= =?UTF-8?q?=EB=A5=B4=EA=B8=B0=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=95=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 서비스 로직 수정 --- .../ChallengeQueryService.java | 59 ++++++++++++------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/src/main/java/foregg/foreggserver/service/challengeService/ChallengeQueryService.java b/src/main/java/foregg/foreggserver/service/challengeService/ChallengeQueryService.java index 3d4b435..2424944 100644 --- a/src/main/java/foregg/foreggserver/service/challengeService/ChallengeQueryService.java +++ b/src/main/java/foregg/foreggserver/service/challengeService/ChallengeQueryService.java @@ -1,6 +1,7 @@ package foregg.foreggserver.service.challengeService; import foregg.foreggserver.apiPayload.exception.handler.ChallengeHandler; +import foregg.foreggserver.apiPayload.exception.handler.PageHandler; import foregg.foreggserver.converter.ChallengeConverter; import foregg.foreggserver.domain.Challenge; import foregg.foreggserver.domain.ChallengeParticipation; @@ -10,6 +11,7 @@ import foregg.foreggserver.dto.challengeDTO.ChallengeResponseDTO; import foregg.foreggserver.dto.challengeDTO.ChallengeResponseDTO.ChallengeDTO; import foregg.foreggserver.dto.challengeDTO.ChallengeResponseDTO.ChallengeParticipantsDTO; +import foregg.foreggserver.dto.challengeDTO.ChallengeResponseDTO.ChallengeParticipantsDTO.ChallengeParticipantDTO; import foregg.foreggserver.repository.NotificationRepository; import foregg.foreggserver.repository.ChallengeParticipationRepository; import foregg.foreggserver.repository.ChallengeRepository; @@ -17,6 +19,7 @@ import foregg.foreggserver.util.DateUtil; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -76,42 +79,58 @@ public ChallengeResponseDTO.MyChallengeTotalDTO getMyChallenges() { return ChallengeResponseDTO.MyChallengeTotalDTO.builder().dtos(result).firstDateOfWeek(DateUtil.getFirstDayOfWeek()).build(); } - public List getParticipants(Long challengeId, boolean isSuccess) { - - List result = new ArrayList<>(); + public ChallengeParticipantsDTO getParticipants(Long challengeId, boolean isSuccess, Pageable pageable) { + List result = new ArrayList<>(); + // 기존 로직 수행 User currentUser = userQueryService.getUser(); Challenge challenge = isParticipating(challengeId); List challengeParticipations = challenge.getChallengeParticipations(); challengeParticipations.removeIf(cp -> cp.getUser().equals(currentUser)); - if (isSuccess) { challengeParticipations.removeIf(cp -> !cp.getSuccessDays().contains(DateUtil.getTodayDayOfWeek())); - }else{ + } else { challengeParticipations.removeIf(cp -> cp.getSuccessDays().contains(DateUtil.getTodayDayOfWeek())); } - if (challengeParticipations.isEmpty()) { - return new ArrayList<>(); + if (!challengeParticipations.isEmpty()) { + for (ChallengeParticipation cp : challengeParticipations) { + Notification notification; + if (isSuccess) { + notification = notificationRepository.findBySenderAndReceiverAndDateAndNotificationType(currentUser.getChallengeName(), cp.getUser(), LocalDate.now().toString(), NotificationType.CLAP); + } else { + notification = notificationRepository.findBySenderAndReceiverAndDateAndNotificationType(currentUser.getChallengeName(), cp.getUser(), LocalDate.now().toString(), NotificationType.SUPPORT); + } + boolean supported = notification != null; + result.add(ChallengeConverter.toChallengeParticipantDTO(cp, supported)); + } } - for (ChallengeParticipation cp : challengeParticipations) { - Notification notification; - if (isSuccess) { - notification = notificationRepository.findBySenderAndReceiverAndDateAndNotificationType(currentUser.getChallengeName(), cp.getUser(), LocalDate.now().toString(), NotificationType.CLAP); - } else { - notification = notificationRepository.findBySenderAndReceiverAndDateAndNotificationType(currentUser.getChallengeName(), cp.getUser(), LocalDate.now().toString(), NotificationType.SUPPORT); - } - if (notification == null) { - result.add(ChallengeConverter.toChallengeParticipantDTO(cp, false)); - } else { - result.add(ChallengeConverter.toChallengeParticipantDTO(cp, true)); - } + // 페이징 처리 + int fromIndex = (int) pageable.getOffset(); + int toIndex = Math.min(fromIndex + pageable.getPageSize(), result.size()); + + // 요청 범위 검증 + if (fromIndex > result.size()) { + throw new PageHandler(PAGE_OUT_OF_RANGE); } - return result; + + List paginatedList = result.subList(fromIndex, toIndex); + + // 페이징 정보만 포함한 PageResponse 반환 + int totalPages = (int) Math.ceil((double) result.size() / pageable.getPageSize()); + return ChallengeParticipantsDTO.builder() + .dto(paginatedList) + .currentPage(pageable.getPageNumber()) + .totalPage(totalPages) + .totalItems(result.size()) + .build(); } + + + //챌린지 검색 메서드 public ChallengeResponseDTO searchChallenge(String keyword) { User user = userQueryService.getUser(); From b36d9299fecdaea6d272d9cbde5fc811697e60c6 Mon Sep 17 00:00:00 2001 From: kimdongjun Date: Thu, 2 Jan 2025 16:06:39 +0900 Subject: [PATCH 11/11] =?UTF-8?q?:recycle:=20refactor:=20=EC=B1=8C?= =?UTF-8?q?=EB=A6=B0=EC=A7=80=20=EC=B0=8C=EB=A5=B4=EA=B8=B0=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20Res=20DTO=20=ED=95=84=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DTO에 페이징 정보 추가 --- .../dto/challengeDTO/ChallengeResponseDTO.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/foregg/foreggserver/dto/challengeDTO/ChallengeResponseDTO.java b/src/main/java/foregg/foreggserver/dto/challengeDTO/ChallengeResponseDTO.java index 7f849ad..07614e6 100644 --- a/src/main/java/foregg/foreggserver/dto/challengeDTO/ChallengeResponseDTO.java +++ b/src/main/java/foregg/foreggserver/dto/challengeDTO/ChallengeResponseDTO.java @@ -55,11 +55,21 @@ public static class MyChallengeDTO{ @NoArgsConstructor public static class ChallengeParticipantsDTO { - private Long userId; - private String nickname; - private String thoughts; - private boolean isSupported; + private List dto; + private int currentPage; + private int totalPage; + private int totalItems; + @Getter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class ChallengeParticipantDTO { + private Long userId; + private String nickname; + private String thoughts; + private boolean isSupported; + } } }