Skip to content

Commit

Permalink
Merge pull request #45 from Plantity/feature/#44/fix_myplant_detail
Browse files Browse the repository at this point in the history
Feature/#44/fix myplant detail
  • Loading branch information
OliviaYJH authored Nov 22, 2022
2 parents f4ddc97 + 51cfaa4 commit 731ac97
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 오류
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -136,6 +133,23 @@ public BaseResponse2<List<MyPlantResponseDto>> myPlantInfo(@PathVariable Long us
return new BaseResponse2<>(myPlantResponseDtos);
}

// 내 식물 상세 보기
@GetMapping("/{userId}/{myPlantId}")
public BaseResponse2<MyPlantDetailRes> 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);
}

// 식물 로그 상세 조회
/*
@GetMapping("/plantLog/{userId}/{myPlantId}/{plantLogId}")
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
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;

import java.util.List;

public interface MyPlantRepository extends JpaRepository<MyPlant, Long> {
List<MyPlantResponseDto> findAllByUserIdx(Long userId);
MyPlantDetailRes findByMyPlantId(Long myPlantId);
Boolean existsByMyPlantId(Long myPlantId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Users, Long> {

public Users findByUserId(Long id);
Users findByUserId(Long id);
Boolean existsByUserId(Long userId);
}

0 comments on commit 731ac97

Please sign in to comment.