From f0347fc2f9d40b25864af2f8ae56aabc90e592e2 Mon Sep 17 00:00:00 2001 From: YuJungHyun <0703olivia@naver.com> Date: Tue, 22 Nov 2022 11:31:15 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[FIX]=20#44=20=EB=82=B4=20=EC=8B=9D?= =?UTF-8?q?=EB=AC=BC=20=EC=83=81=EC=84=B8=20=EB=B3=B4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MyPlantApiController.java | 12 +++++--- .../domain/myPlant/MyPlantDetailRes.java | 29 +++++++++++++++++++ .../server/repository/MyPlantRepository.java | 2 ++ 3 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 server/src/main/java/com/plantity/server/domain/myPlant/MyPlantDetailRes.java diff --git a/server/src/main/java/com/plantity/server/controller/MyPlantApiController.java b/server/src/main/java/com/plantity/server/controller/MyPlantApiController.java index d02b432..7adb44f 100644 --- a/server/src/main/java/com/plantity/server/controller/MyPlantApiController.java +++ b/server/src/main/java/com/plantity/server/controller/MyPlantApiController.java @@ -9,10 +9,7 @@ import com.plantity.server.config.BaseException; import com.plantity.server.config.BaseResponse2; import com.plantity.server.constants.ExceptionCode; -import com.plantity.server.domain.myPlant.MyPlant; -import com.plantity.server.domain.myPlant.MyPlantRequestDto; -import com.plantity.server.domain.myPlant.MyPlantResponseDto; -import com.plantity.server.domain.myPlant.MyPlantSaveRequestDto; +import com.plantity.server.domain.myPlant.*; import com.plantity.server.domain.plant.detail.PlantDetail; import com.plantity.server.domain.plantlog.DateMyPlantLogResponseDto; import com.plantity.server.domain.plantlog.MyPlantLogRequestDto; @@ -136,6 +133,13 @@ public BaseResponse2> myPlantInfo(@PathVariable Long us return new BaseResponse2<>(myPlantResponseDtos); } + // 내 식물 상세 보기 + @GetMapping("/{userId}/{myPlantId}") + public BaseResponse2 getMyPlantDetail(@PathVariable Long userId, @PathVariable Long myPlantId){ + MyPlantDetailRes myPlantDetailRes = myPlantRepository.findByMyPlantId(myPlantId); + return new BaseResponse2<>(myPlantDetailRes); + } + // 식물 로그 상세 조회 /* @GetMapping("/plantLog/{userId}/{myPlantId}/{plantLogId}") diff --git a/server/src/main/java/com/plantity/server/domain/myPlant/MyPlantDetailRes.java b/server/src/main/java/com/plantity/server/domain/myPlant/MyPlantDetailRes.java new file mode 100644 index 0000000..42ced65 --- /dev/null +++ b/server/src/main/java/com/plantity/server/domain/myPlant/MyPlantDetailRes.java @@ -0,0 +1,29 @@ +package com.plantity.server.domain.myPlant; + +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +public class MyPlantDetailRes { + + private Long myPlantId; + private String plantNickName; + private String plantName; + private String adaptDate; + private String waterCycle; // 관수 설명 + private String filePath; + + private MyPlantDetailRes(MyPlant myPlant){ + this.myPlantId = myPlant.getMyPlantId(); + this.plantNickName = myPlant.getPlantNickName(); + this.plantName = myPlant.getPlantName(); + this.adaptDate = myPlant.getPlantAdaptTime(); + this.waterCycle = myPlant.getWatercycleSprngCodeNm(); + this.filePath = myPlant.getFilePath(); + } + + public static MyPlantDetailRes from(MyPlant myPlant){ + return new MyPlantDetailRes(myPlant); + } +} diff --git a/server/src/main/java/com/plantity/server/repository/MyPlantRepository.java b/server/src/main/java/com/plantity/server/repository/MyPlantRepository.java index 5433459..f8108f0 100644 --- a/server/src/main/java/com/plantity/server/repository/MyPlantRepository.java +++ b/server/src/main/java/com/plantity/server/repository/MyPlantRepository.java @@ -1,6 +1,7 @@ package com.plantity.server.repository; import com.plantity.server.domain.myPlant.MyPlant; +import com.plantity.server.domain.myPlant.MyPlantDetailRes; import com.plantity.server.domain.myPlant.MyPlantResponseDto; import org.springframework.data.jpa.repository.JpaRepository; @@ -8,4 +9,5 @@ public interface MyPlantRepository extends JpaRepository { List findAllByUserIdx(Long userId); + MyPlantDetailRes findByMyPlantId(Long myPlantId); } From 51cfaa456b6e1cf19c357321551037e191a9e735 Mon Sep 17 00:00:00 2001 From: YuJungHyun <0703olivia@naver.com> Date: Tue, 22 Nov 2022 11:41:32 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[FEAT]=20#44=20=EC=9C=A0=EC=A0=80=EC=99=80?= =?UTF-8?q?=20=EC=8B=9D=EB=AC=BC=20=EC=9C=A0=ED=9A=A8=EC=84=B1=20=EA=B2=80?= =?UTF-8?q?=EC=82=AC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/plantity/server/config/BaseResponseStatus.java | 8 +++++++- .../server/controller/MyPlantApiController.java | 10 ++++++++++ .../plantity/server/repository/MyPlantRepository.java | 1 + .../plantity/server/repository/UsersRepository.java | 8 ++------ 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/server/src/main/java/com/plantity/server/config/BaseResponseStatus.java b/server/src/main/java/com/plantity/server/config/BaseResponseStatus.java index b2873f2..fcc0aec 100644 --- a/server/src/main/java/com/plantity/server/config/BaseResponseStatus.java +++ b/server/src/main/java/com/plantity/server/config/BaseResponseStatus.java @@ -17,7 +17,13 @@ public enum BaseResponseStatus { * 2000: Request 오류 */ // post - POST_CNTNTSNO_INVALID(false, 2001, "cntntsNo가 유효하지 않습니다"); + POST_CNTNTSNO_INVALID(false, 2001, "cntntsNo가 유효하지 않습니다"), + + // user + USER_ID_INVALID(false, 2010, "해당 유저가 없습니다"), + + // myPlant + MYPLANT_ID_INVALID(false, 2015, "해당 식물이 없습니다"); /** * 3000: Response 오류 diff --git a/server/src/main/java/com/plantity/server/controller/MyPlantApiController.java b/server/src/main/java/com/plantity/server/controller/MyPlantApiController.java index 7adb44f..be54d4f 100644 --- a/server/src/main/java/com/plantity/server/controller/MyPlantApiController.java +++ b/server/src/main/java/com/plantity/server/controller/MyPlantApiController.java @@ -136,6 +136,16 @@ public BaseResponse2> myPlantInfo(@PathVariable Long us // 내 식물 상세 보기 @GetMapping("/{userId}/{myPlantId}") public BaseResponse2 getMyPlantDetail(@PathVariable Long userId, @PathVariable Long myPlantId){ + // 유저 아이디 유효성 검사 + if(!usersRepository.existsByUserId(userId)){ + return new BaseResponse2<>(USER_ID_INVALID); + } + + // 식물 아이디 유효성 검사 + if(!myPlantRepository.existsByMyPlantId(myPlantId)){ + return new BaseResponse2<>(MYPLANT_ID_INVALID); + } + MyPlantDetailRes myPlantDetailRes = myPlantRepository.findByMyPlantId(myPlantId); return new BaseResponse2<>(myPlantDetailRes); } diff --git a/server/src/main/java/com/plantity/server/repository/MyPlantRepository.java b/server/src/main/java/com/plantity/server/repository/MyPlantRepository.java index f8108f0..e897ea6 100644 --- a/server/src/main/java/com/plantity/server/repository/MyPlantRepository.java +++ b/server/src/main/java/com/plantity/server/repository/MyPlantRepository.java @@ -10,4 +10,5 @@ public interface MyPlantRepository extends JpaRepository { List findAllByUserIdx(Long userId); MyPlantDetailRes findByMyPlantId(Long myPlantId); + Boolean existsByMyPlantId(Long myPlantId); } diff --git a/server/src/main/java/com/plantity/server/repository/UsersRepository.java b/server/src/main/java/com/plantity/server/repository/UsersRepository.java index 1abaf9d..0c95c73 100644 --- a/server/src/main/java/com/plantity/server/repository/UsersRepository.java +++ b/server/src/main/java/com/plantity/server/repository/UsersRepository.java @@ -4,12 +4,8 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; -import javax.persistence.EntityManager; -import java.util.List; -import java.util.Optional; - @Repository public interface UsersRepository extends JpaRepository { - - public Users findByUserId(Long id); + Users findByUserId(Long id); + Boolean existsByUserId(Long userId); }