Skip to content

Commit

Permalink
[FIX] #40 식물 등록 시 관수 설명도 함께 저장
Browse files Browse the repository at this point in the history
  • Loading branch information
OliviaYJH committed Nov 21, 2022
1 parent e74848a commit 4fecdb3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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.plant.detail.PlantDetail;
import com.plantity.server.domain.plantlog.DateMyPlantLogResponseDto;
import com.plantity.server.domain.plantlog.MyPlantLogRequestDto;
import com.plantity.server.domain.plantlog.MyPlantLogResponseDto;
Expand All @@ -22,6 +23,7 @@
import com.plantity.server.dto.res.plantlog.PlantLogResponse;
import com.plantity.server.exception.CustomException;
import com.plantity.server.repository.MyPlantRepository;
import com.plantity.server.repository.PlantDetailRepository;
import com.plantity.server.repository.PlantLogRepository;
import com.plantity.server.repository.UsersRepository;
import com.plantity.server.service.MyPlantService;
Expand Down Expand Up @@ -51,19 +53,26 @@ public class MyPlantApiController {
private final PlantLogRepository plantLogRepository;
private final MyPlantRepository myPlantRepository;
private final UsersRepository usersRepository;
private final PlantDetailRepository plantDetailRepository;

@Value("${cloud.aws.s3.bucket}")
public String bucket;

@PostMapping("/save/{userId}")
public ResponseEntity<MyPlantSaveResponse> save(
@RequestParam String cntntsNo,
@RequestPart(value="image", required=false) MultipartFile multipartFile,
@RequestPart(value = "plantName") String plantName,
@RequestPart(value = "plantNickName") String plantNickName,
@RequestPart(value = "plantAdaptTime") String plantAdaptTime,
@RequestPart(value = "plantType") String plantType,
@PathVariable Long userId) throws IOException {
try{
// cntntsNo로 해당 식물의 관수 설명도 함께 myPlant에 저장
PlantDetail plantDetail = new PlantDetail(plantDetailRepository.findByCntntsNo(cntntsNo)); // 식물 찾기
String watercycleSprngCodeNm= plantDetail.getWatercycleSprngCodeNm(); // 관수설명 찾기


String oriFileName = multipartFile.getOriginalFilename();
String fileName = oriFileName;
String filePath = "postImg/" + fileName;
Expand All @@ -78,7 +87,7 @@ public ResponseEntity<MyPlantSaveResponse> save(

Users users1 = new Users(usersRepository.findByUserId(userId));

MyPlant myPlant = new MyPlant(plantName,plantNickName, plantAdaptTime,plantType, amazonS3.getUrl(bucket, filePath).toString(), users1);
MyPlant myPlant = new MyPlant(plantName,plantNickName, plantAdaptTime,plantType, amazonS3.getUrl(bucket, filePath).toString(), watercycleSprngCodeNm, users1);

//myPlantService.save(myPlantSaveRequestDto);
myPlantRepository.save(myPlant);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,20 @@ public class MyPlant extends BaseTimeEntity {
private String plantType; //식물타입
private String filePath;
private String plantNickName; // 식물 별명
private String watercycleSprngCodeNm; // 관수코드
private Long userIdx;

@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private String plantAdaptTime; //식물입양날짜

@Builder
public MyPlant(String plantName, String plantNickName, String plantAdaptTime, String plantType, String filePath, Users users) {
public MyPlant(String plantName, String plantNickName, String plantAdaptTime, String plantType, String filePath, String watercycleSprngCodeNm, Users users) {
this.plantName = plantName;
this.plantType = plantType;
this.filePath = filePath;
this.plantAdaptTime = plantAdaptTime;
this.plantNickName = plantNickName;
this.watercycleSprngCodeNm = watercycleSprngCodeNm;
this.userIdx = users.getUserId();
}
}

0 comments on commit 4fecdb3

Please sign in to comment.