From 35c479cbc4e6890a915b3b4d562981d143861cb1 Mon Sep 17 00:00:00 2001 From: Haeun-Y Date: Wed, 26 Jun 2024 08:15:59 +0900 Subject: [PATCH 1/2] =?UTF-8?q?#60=20fix:=20=EC=B1=8C=EB=A6=B0=EC=A7=80=20?= =?UTF-8?q?=EA=B2=80=EC=83=89=20API=20=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wecare/challenge/controller/ChallengeController.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/ollie/wecare/challenge/controller/ChallengeController.java b/src/main/java/ollie/wecare/challenge/controller/ChallengeController.java index 0bf8d98..4483ed3 100644 --- a/src/main/java/ollie/wecare/challenge/controller/ChallengeController.java +++ b/src/main/java/ollie/wecare/challenge/controller/ChallengeController.java @@ -2,6 +2,7 @@ import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import ollie.wecare.challenge.dto.*; import ollie.wecare.challenge.service.ChallengeService; import ollie.wecare.common.base.BaseException; @@ -16,6 +17,7 @@ @RestController @RequestMapping(challenge) @RequiredArgsConstructor +@Slf4j public class ChallengeController { private final ChallengeService challengeService; @@ -66,7 +68,7 @@ public BaseResponse participateChallenge(@RequestBody PostChallengeReq p * */ @GetMapping("/search") @ResponseBody - public BaseResponse> getChallenges(@RequestParam(value = "searhWord", defaultValue = "", required = false) String searchWord)throws BaseException { + public BaseResponse> getChallenges(@RequestParam(value = "searchWord", defaultValue = "", required = false) String searchWord)throws BaseException { return new BaseResponse<>(challengeService.getChallenges(searchWord)); } From 7ed208ef616f56d523babb9fcfda869e5aa00e8c Mon Sep 17 00:00:00 2001 From: Haeun-Y Date: Wed, 26 Jun 2024 12:40:11 +0900 Subject: [PATCH 2/2] =?UTF-8?q?#54=20fix:=20=ED=94=84=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EB=9E=A8=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=EC=99=80=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=20=EC=A1=B0=ED=9A=8C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/base/BaseResponseStatus.java | 1 + .../program/controller/ProgramController.java | 7 +++ .../program/dto/GetProgramDetailRes.java | 54 +++++++++++++++++++ .../wecare/program/dto/GetProgramRes.java | 17 ++---- .../ollie/wecare/program/entity/Program.java | 2 + .../program/service/ProgramService.java | 9 +++- 6 files changed, 75 insertions(+), 15 deletions(-) create mode 100644 src/main/java/ollie/wecare/program/dto/GetProgramDetailRes.java diff --git a/src/main/java/ollie/wecare/common/base/BaseResponseStatus.java b/src/main/java/ollie/wecare/common/base/BaseResponseStatus.java index f9ac8b1..e42fb1b 100644 --- a/src/main/java/ollie/wecare/common/base/BaseResponseStatus.java +++ b/src/main/java/ollie/wecare/common/base/BaseResponseStatus.java @@ -35,6 +35,7 @@ public enum BaseResponseStatus { ACCESS_DENIED(false, HttpStatus.BAD_REQUEST, "접근 권한이 없습니다."), // program + INVALID_PROGRAM_IDX(false, HttpStatus.BAD_REQUEST, "잘못된 ProgramIdx 입니다."), // challenge INVALID_ATTENDANCE_CODE(false, HttpStatus.BAD_REQUEST, "잘못된 인증번호입니다."), diff --git a/src/main/java/ollie/wecare/program/controller/ProgramController.java b/src/main/java/ollie/wecare/program/controller/ProgramController.java index 4da611e..ef8e90f 100644 --- a/src/main/java/ollie/wecare/program/controller/ProgramController.java +++ b/src/main/java/ollie/wecare/program/controller/ProgramController.java @@ -3,6 +3,7 @@ import lombok.RequiredArgsConstructor; import ollie.wecare.common.base.BaseException; import ollie.wecare.common.base.BaseResponse; +import ollie.wecare.program.dto.GetProgramDetailRes; import ollie.wecare.program.dto.GetProgramRes; import ollie.wecare.program.dto.PostProgramReq; import ollie.wecare.program.service.ProgramService; @@ -30,6 +31,12 @@ public BaseResponse> getPrograms(@RequestParam(value = "year return new BaseResponse<>(programService.getPrograms(year, month)); } + @GetMapping("/{programIdx}") + @ResponseBody + public BaseResponse getProgram(@PathVariable(value = "programIdx") Long programIdx) { + return new BaseResponse<>(programService.getProgram(programIdx)); + } + /* * 프로그램 등록 * */ diff --git a/src/main/java/ollie/wecare/program/dto/GetProgramDetailRes.java b/src/main/java/ollie/wecare/program/dto/GetProgramDetailRes.java new file mode 100644 index 0000000..c74051b --- /dev/null +++ b/src/main/java/ollie/wecare/program/dto/GetProgramDetailRes.java @@ -0,0 +1,54 @@ +package ollie.wecare.program.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import ollie.wecare.program.entity.Program; + +import java.time.LocalDateTime; + +@Data +@AllArgsConstructor +@Builder +@NoArgsConstructor +public class GetProgramDetailRes { + + + private Long programIdx; + + private String name; + + private DateDto openDate; + + private DateDto dueDate; + + private String location; + + private String host; + + private String schedule; + + private String description; + + + public static GetProgramDetailRes fromProgram(Program program) { + return GetProgramDetailRes.builder() + .programIdx(program.getProgramIdx()) + .name(program.getName()) + .openDate(convertToDateDto(program.getOpenDate())) + .dueDate(convertToDateDto(program.getDueDate())) + .location(program.getLocation()) + .host(program.getHost()) + .schedule(program.getSchedule()) + .description(program.getDescription()).build(); + } + + private static DateDto convertToDateDto(LocalDateTime dueDate) { + if (dueDate == null) return null; + return new DateDto( + dueDate.getYear(), + dueDate.getMonthValue(), + dueDate.getDayOfMonth()); + } +} diff --git a/src/main/java/ollie/wecare/program/dto/GetProgramRes.java b/src/main/java/ollie/wecare/program/dto/GetProgramRes.java index edfd5fd..c6a8a41 100644 --- a/src/main/java/ollie/wecare/program/dto/GetProgramRes.java +++ b/src/main/java/ollie/wecare/program/dto/GetProgramRes.java @@ -19,25 +19,16 @@ public class GetProgramRes { private String name; - private DateDto dueDate; - - private String location; - - private String host; + private DateDto openDate; - private String schedule; - - private String description; + private DateDto dueDate; public static GetProgramRes fromProgram(Program program) { return GetProgramRes.builder() .programIdx(program.getProgramIdx()) .name(program.getName()) - .dueDate(convertToDateDto(program.getDueDate())) - .location(program.getLocation()) - .host(program.getHost()) - .schedule(program.getSchedule()) - .description(program.getDescription()).build(); + .openDate(convertToDateDto(program.getOpenDate())) + .dueDate(convertToDateDto(program.getDueDate())).build(); } private static DateDto convertToDateDto(LocalDateTime dueDate) { diff --git a/src/main/java/ollie/wecare/program/entity/Program.java b/src/main/java/ollie/wecare/program/entity/Program.java index 28bcd25..7b083b7 100644 --- a/src/main/java/ollie/wecare/program/entity/Program.java +++ b/src/main/java/ollie/wecare/program/entity/Program.java @@ -28,6 +28,8 @@ public class Program extends BaseEntity { private LocalDateTime dueDate; + private LocalDateTime openDate; + private String location; private String host; diff --git a/src/main/java/ollie/wecare/program/service/ProgramService.java b/src/main/java/ollie/wecare/program/service/ProgramService.java index 8c59d4c..3ff2c8a 100644 --- a/src/main/java/ollie/wecare/program/service/ProgramService.java +++ b/src/main/java/ollie/wecare/program/service/ProgramService.java @@ -5,6 +5,7 @@ import ollie.wecare.challenge.repository.ChallengeRepository; import ollie.wecare.common.base.BaseException; import ollie.wecare.common.enums.Role; +import ollie.wecare.program.dto.GetProgramDetailRes; import ollie.wecare.program.dto.GetProgramRes; import ollie.wecare.program.dto.PostProgramReq; import ollie.wecare.program.entity.Program; @@ -20,8 +21,7 @@ import java.time.temporal.TemporalAdjusters; import java.util.List; -import static ollie.wecare.common.base.BaseResponseStatus.INVALID_ROLE; -import static ollie.wecare.common.base.BaseResponseStatus.INVALID_USER_IDX; +import static ollie.wecare.common.base.BaseResponseStatus.*; @Service @RequiredArgsConstructor @@ -45,6 +45,11 @@ public List getPrograms(Long year, Long month) { .toList(); } + public GetProgramDetailRes getProgram(Long programIdx) { + return GetProgramDetailRes.fromProgram( + programRepository.findById(programIdx).orElseThrow(()-> new BaseException(INVALID_PROGRAM_IDX))); + } + public void saveProgram(PostProgramReq postProgramReq) { User user = userRepository.findById(authService.getUserIdx()).orElseThrow(()-> new BaseException(INVALID_USER_IDX)); if(!user.getRole().equals(Role.Admin)) throw new BaseException(INVALID_ROLE);