Skip to content

Commit

Permalink
[feat] #29 - 내식물 조회하기 API 완료
Browse files Browse the repository at this point in the history
- postman 성공
- plantLog가 null로 나옴
- need to refactor
  • Loading branch information
abi-hong committed Sep 13, 2022
1 parent db6796e commit 40329ab
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -99,9 +102,14 @@ public ResponseEntity<MyPlantUpdateResponse> putLook(@PathVariable Long userId,
return MyPlantUpdateResponse.newResponse(UPDATE_LOOKPLANTLOG_SUCCESS);
}

@GetMapping("/plant/{userId}")
public List<MyPlant> check(@PathVariable Long userId) {
usersRepository.findByUserId(userId);
return myPlantRepository.findAll();
// myPlant 상세 정보 조회
@GetMapping("/plant/{userId}/{myPlantId}")
public ResponseEntity<MyPlantResponse> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,10 @@ private MyPlantResponse(Boolean success, String msg, MyPlantResponseDto data) {
this.data = data;
}


public static ResponseEntity<MyPlantResponse> newResponse(SuccessCode code, MyPlantResponseDto data) {
MyPlantResponse response = new MyPlantResponse(true, code.getMsg(), data);
return new ResponseEntity(response, code.getStatus());
}


}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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(
Expand Down

0 comments on commit 40329ab

Please sign in to comment.