diff --git a/server/src/main/java/com/plantity/server/constants/SuccessCode.java b/server/src/main/java/com/plantity/server/constants/SuccessCode.java index 6684a3a..d76eaf6 100644 --- a/server/src/main/java/com/plantity/server/constants/SuccessCode.java +++ b/server/src/main/java/com/plantity/server/constants/SuccessCode.java @@ -16,7 +16,8 @@ public enum SuccessCode { UPDATE_WATERPLANTLOG_SUCCESS(OK, "물주기 로그 등록하기를 성공했습니다."), UPDATE_LOOKPLANTLOG_SUCCESS(OK, "관찰 로그 등록하기를 성공했습니다."), - USER_INFO_SUCCESS(OK, "유저 프로필 상세 조회를 성공했습니다."); + USER_INFO_SUCCESS(OK, "유저 프로필 상세 조회를 성공했습니다."), + MYPLANT_INFO_SUCCESS(OK, "나의 식물 상세 조회를 성공했습니다."); private final HttpStatus status; private final String msg; 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 f9b3620..65538b9 100644 --- a/server/src/main/java/com/plantity/server/controller/MyPlantApiController.java +++ b/server/src/main/java/com/plantity/server/controller/MyPlantApiController.java @@ -6,9 +6,12 @@ import com.amazonaws.services.s3.model.ObjectMetadata; import com.plantity.server.config.BaseResponse2; 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.plantlog.PlantLog; import com.plantity.server.domain.users.Users; +import com.plantity.server.dto.res.myplant.MyPlantResponse; import com.plantity.server.dto.res.myplant.MyPlantSaveResponse; import com.plantity.server.dto.res.myplant.MyPlantUpdateResponse; import com.plantity.server.repository.MyPlantRepository; @@ -99,9 +102,14 @@ public ResponseEntity putLook(@PathVariable Long userId, return MyPlantUpdateResponse.newResponse(UPDATE_LOOKPLANTLOG_SUCCESS); } - @GetMapping("/plant/{userId}") - public List check(@PathVariable Long userId) { - usersRepository.findByUserId(userId); - return myPlantRepository.findAll(); + // myPlant 상세 정보 조회 + @GetMapping("/plant/{userId}/{myPlantId}") + public ResponseEntity myPlantInfo(@PathVariable Long userId, @PathVariable Long myPlantId) { + + MyPlantRequestDto myPlantRequestDto = MyPlantRequestDto.of(userId, myPlantId); + + MyPlantResponseDto myPlantResponseDto = myPlantService.myPlantInfo(myPlantRequestDto); + + return MyPlantResponse.newResponse(MYPLANT_INFO_SUCCESS, myPlantResponseDto); } } diff --git a/server/src/main/java/com/plantity/server/domain/myPlant/MyPlantRequestDto.java b/server/src/main/java/com/plantity/server/domain/myPlant/MyPlantRequestDto.java new file mode 100644 index 0000000..90b1a9a --- /dev/null +++ b/server/src/main/java/com/plantity/server/domain/myPlant/MyPlantRequestDto.java @@ -0,0 +1,23 @@ +package com.plantity.server.domain.myPlant; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@RequiredArgsConstructor +public class MyPlantRequestDto { + + private Long userIdx; + private Long myPlantId; + + private MyPlantRequestDto(Long userIdx, Long myPlantId) { + this.userIdx = userIdx; + this.myPlantId = myPlantId; + } + + public static MyPlantRequestDto of(Long userIdx, Long myPlantId) { + return new MyPlantRequestDto(userIdx, myPlantId); + } +} diff --git a/server/src/main/java/com/plantity/server/domain/users/UsersRequestDto.java b/server/src/main/java/com/plantity/server/domain/users/UsersRequestDto.java index 901e593..7581769 100644 --- a/server/src/main/java/com/plantity/server/domain/users/UsersRequestDto.java +++ b/server/src/main/java/com/plantity/server/domain/users/UsersRequestDto.java @@ -16,9 +16,6 @@ public class UsersRequestDto { private UsersRequestDto(Long userId){ this.userId = userId; - //this.nickName = nickName; - //this.rating = rating; - //this.score = score; } public static UsersRequestDto of(Long userId) { diff --git a/server/src/main/java/com/plantity/server/dto/res/myplant/MyPlantResponse.java b/server/src/main/java/com/plantity/server/dto/res/myplant/MyPlantResponse.java index d430961..a1ff356 100644 --- a/server/src/main/java/com/plantity/server/dto/res/myplant/MyPlantResponse.java +++ b/server/src/main/java/com/plantity/server/dto/res/myplant/MyPlantResponse.java @@ -19,5 +19,10 @@ private MyPlantResponse(Boolean success, String msg, MyPlantResponseDto data) { this.data = data; } - + public static ResponseEntity newResponse(SuccessCode code, MyPlantResponseDto data) { + MyPlantResponse response = new MyPlantResponse(true, code.getMsg(), data); + return new ResponseEntity(response, code.getStatus()); + } + + } diff --git a/server/src/main/java/com/plantity/server/service/MyPlantService.java b/server/src/main/java/com/plantity/server/service/MyPlantService.java index 6b82183..70eea47 100644 --- a/server/src/main/java/com/plantity/server/service/MyPlantService.java +++ b/server/src/main/java/com/plantity/server/service/MyPlantService.java @@ -1,5 +1,8 @@ package com.plantity.server.service; +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.plantlog.PlantLog; import com.plantity.server.repository.MyPlantRepository; import com.plantity.server.repository.PlantLogRepository; @@ -22,6 +25,14 @@ public Long save(MyPlantSaveRequestDto requestDto) { */ + public MyPlantResponseDto myPlantInfo(MyPlantRequestDto requestDto) { + MyPlant myPlant = myPlantRepository.findById(requestDto.getMyPlantId()).orElseThrow( + () -> new IllegalArgumentException("해당 식물이 없습니다.") + ); + + return MyPlantResponseDto.from(myPlant); + } + @Transactional public Long updateSun(Long userId, Long myPlantId) { PlantLog plantLog = plantLogRepository.findById(myPlantId).orElseThrow(