Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Build] user, place, plant #128

Merged
merged 8 commits into from
May 29, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class PlaceContoller implements PlaceSwagger{

@GetMapping("/health")
public ResponseEntity<String> healthCheck(){
log.info("[API] healthCheck");
return ResponseEntity.ok("health check ok");
}

Expand All @@ -42,6 +43,7 @@ public ResponseEntity<String> healthCheck(){
consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<JsonResponse> createPlace(@RequestPart("place") PlaceDto.createPlaceReq req, @RequestPart(value = "image", required = false) MultipartFile image)
{
log.info("[API] createPlace");
String uuid = jwtService.resolveToken();
User user = userService.getUser(uuid);
String placeCode = placeService.create(user, req, image);
Expand All @@ -51,6 +53,7 @@ public ResponseEntity<JsonResponse> createPlace(@RequestPart("place") PlaceDto.c
@GetMapping("/{code}")
public ResponseEntity<JsonResponse> getPlace(@PathVariable("code") String code)
{
log.info("[API] getPlace");
String uuid = jwtService.resolveToken();
User user = userService.getUser(uuid);
placeService.userOnPlace(user, code);
Expand All @@ -62,6 +65,7 @@ public ResponseEntity<JsonResponse> getPlace(@PathVariable("code") String code)
@GetMapping("/weather/{code}")
public ResponseEntity<JsonResponse> getPlaceWeather(@PathVariable("code") String code)
{
log.info("[API] getPlaceWeather");
String uuid = jwtService.resolveToken();
User user = userService.getUser(uuid);
PlaceDto.getPlaceGridRes placeGrid = placeService.getPlaceGrid(user, code);
Expand All @@ -71,6 +75,7 @@ public ResponseEntity<JsonResponse> getPlaceWeather(@PathVariable("code") String
// //친ꡬ μš”μ²­
@PostMapping("/friends")
public ResponseEntity<JsonResponse> newFriends(@RequestBody PlaceDto.newFriendsReq req){
log.info("[API] newFriends");
String uuid = jwtService.resolveToken();
User user = userService.getUser(uuid);

Expand All @@ -93,6 +98,7 @@ public ResponseEntity<JsonResponse> newFriends(@RequestBody PlaceDto.newFriendsR
// λ©”μΈνŽ˜μ΄μ§€
@GetMapping("/myGarden")
public ResponseEntity<JsonResponse> getMyGarden(){
log.info("[API] getMyGarden");
String uuid = jwtService.resolveToken();
User user = userService.getUser(uuid);
String name = user.getName();
Expand All @@ -110,6 +116,7 @@ public ResponseEntity<JsonResponse> getMyGarden(){
// μ‚¬μš©μžκ°€ μ†ν•œ μž₯μ†Œ 리슀트
@GetMapping("/user")
public ResponseEntity<JsonResponse> getPlaceBelongUser(){
log.info("[API] getPlaceBelongUser");
String uuid = jwtService.resolveToken();
User user = userService.getUser(uuid);

Expand All @@ -121,6 +128,7 @@ public ResponseEntity<JsonResponse> getPlaceBelongUser(){
// 친ꡬ 리슀트 쑰회
@GetMapping("/{code}/friends")
public ResponseEntity<JsonResponse> getPlaceFriends(@PathVariable String code){
log.info("[API] getPlaceFriends");
String uuid = jwtService.resolveToken();
User user = userService.getUser(uuid);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,28 +99,28 @@ public ResponseEntity<JsonResponse> updateWateredDate(@PathVariable Long plantId
String uuid = jwtService.resolveToken();
User user = userService.getUser(uuid);

String nickname = plantService.updateWateredDate(user, plantIdx);
PlantDto.updateWateredDateRes wateredDateUpdatedPlant = plantService.updateWateredDate(user, plantIdx);

return ResponseEntity.ok(new JsonResponse(true, 200, "updateWateredDate", nickname));
return ResponseEntity.ok(new JsonResponse(true, 200, "wateredDateUpdatedPlant", wateredDateUpdatedPlant));
}

/**
* [GET] /plant/update
* @return μˆ˜μ •ν•˜κΈ° μ „ μ‹λ¬Όμ˜ μ• μΉ­
* @return μˆ˜μ •ν•˜κΈ° μ „ μ‹λ¬Όμ˜ 정보
*/
@GetMapping("/plant/update/{plantIdx}")
public ResponseEntity<JsonResponse> getUpdatedPlant(@PathVariable Long plantIdx){
String uuid = jwtService.resolveToken();
User user = userService.getUser(uuid);

String nickname = plantService.getUpdatedPlant(user, plantIdx).getNickname();
PlantDto.updatePlantRes beforeUpdatedPlant = plantService.getUpdatedPlant(user, plantIdx);

return ResponseEntity.ok(new JsonResponse(true, 200, "getUpdatedPlant", nickname));
return ResponseEntity.ok(new JsonResponse(true, 200, "beforeUpdatedPlant", beforeUpdatedPlant));
}

/**
* [PUT] /plant/update
* @return μˆ˜μ •ν•œ μ‹λ¬Όμ˜ μ• μΉ­
* @return μˆ˜μ •ν•œ μ‹λ¬Όμ˜ 정보
*/
@PutMapping(value = "/plant/update/{plantIdx}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<JsonResponse> updatePlant(@PathVariable Long plantIdx,
Expand All @@ -129,7 +129,7 @@ public ResponseEntity<JsonResponse> updatePlant(@PathVariable Long plantIdx,
String uuid = jwtService.resolveToken();
User user = userService.getUser(uuid);

String updatedPlant = plantService.updatePlant(user, plantIdx, updatePlantReq, file);
PlantDto.updatePlantRes updatedPlant = plantService.updatePlant(user, plantIdx, updatePlantReq, file);

return ResponseEntity.ok(new JsonResponse(true, 200, "updatePlant", updatedPlant));
}
Expand Down
43 changes: 40 additions & 3 deletions src/main/java/com/umc/commonplant/domain/plant/dto/PlantDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,49 @@ public static class createPlantReq{
@NoArgsConstructor
@Getter
public static class getPlantRes{
private Long plantIdx;
@Schema(description = "식물도감에 μ €μž₯된 μ‹λ¬Όμ˜ μ’… 이름(ν•™μˆ λͺ…)", example = "λͺ¬μŠ€ν…ŒλΌ μΉ΄μŠ€ν…Œλ‹ˆμ•ˆ")
private String name;
@Schema(description = "μ‹λ¬Όμ˜ λ‹‰λ„€μž„", example = "λͺ¬ν…Œ")
private String nickname;

@Schema(description = "식물이 μžˆλŠ” μž₯μ†Œμ˜ 이름", example = "카페")
private String place;

@Schema(description = "μ‹λ¬Όμ˜ 이미지 url λ¬Έμžμ—΄")
private String imgUrl;

@Schema(description = "식물과 ν•¨κ»˜ν•œ λ‚ μ§œ", example = "1")
private Long countDate;
@Schema(description = "λ‹€μŒ λ¬Όμ£ΌκΈ° D-Day κΉŒμ§€ 남은 λ‚ μ§œ", example = "10")
private Long remainderDate;

// Memo
@Schema(description = "식물에 μž‘μ„±λœ λ©”λͺ¨ 리슀트")
private List<MemoDto.GetAllMemo> memoList;

// Info
@Schema(description = "ν•™μˆ λͺ…", example = "Monstera carstenianum")
private String scientificName;
@Schema(description = "μ‹λ¬Όμ˜ λ¬Όμ£ΌλŠ” μ£ΌκΈ° (Information 에 μ €μž₯된 ꢌμž₯ μ£ΌκΈ°)", example = "10")
private Long waterDay;
@Schema(description = "λΉ›μ˜ 강도", example = "밝은 곳을 μ’‹μ•„ν•΄μš”!")
private String sunlight;
@Schema(description = "μ΅œμ € μ˜¨λ„", example = "16")
private Long tempMin;
@Schema(description = "졜고 μ˜¨λ„", example = "20")
private Long tempMax;
@Schema(description = "μŠ΅λ„", example = "70% 이상")
private String humidity;

@Schema(
description = "식물이 λ“±λ‘λœ λ‚ μ§œ",
example = "2024.01.29"
)
@JsonFormat(pattern = "yyyy.MM.dd")
private LocalDateTime createdAt;

@Schema(
description = "μ‚¬μš©μžκ°€ λ§ˆμ§€λ§‰μœΌλ‘œ 물을 μ€€ λ‚ μ§œ",
example = "2024.01.29"
)
@JsonFormat(pattern = "yyyy.MM.dd")
private LocalDateTime wateredDate;
}
Expand All @@ -78,6 +97,7 @@ public static class getPlantRes{
@NoArgsConstructor
@Getter
public static class getPlantListRes{
private Long plantIdx;
private String nickname;
private String imgUrl;
private String place;
Expand All @@ -86,6 +106,7 @@ public static class getPlantListRes{

@Builder
public getPlantListRes(Plant plant, String place, String member, Long remainderDate){
this.plantIdx = plant.getPlantIdx();
this.nickname = plant.getNickname();
this.imgUrl = plant.getImgUrl();
this.place = place;
Expand All @@ -101,6 +122,7 @@ public getPlantListRes(Plant plant, String place, String member, Long remainderD
@NoArgsConstructor
@Getter
public static class getMyGardenPlantListRes{
private Long plantIdx;
private String plantName;
private String nickname;
private String imgUrl;
Expand All @@ -111,6 +133,7 @@ public static class getMyGardenPlantListRes{

@Builder
public getMyGardenPlantListRes(Plant plant, Long remainderDate, String recentMemo){
this.plantIdx = plant.getPlantIdx();
this.plantName = plant.getPlantName();
this.nickname = plant.getNickname();
this.imgUrl = plant.getImgUrl();
Expand All @@ -124,6 +147,7 @@ public getMyGardenPlantListRes(Plant plant, Long remainderDate, String recentMem
@NoArgsConstructor
@Data
public static class updatePlantReq{
private Long plantIdx;
private String nickname;
}

Expand All @@ -134,7 +158,20 @@ public static class updatePlantReq{
@NoArgsConstructor
@Getter
public static class updatePlantRes{
private Long plantIdx;
private String nickname;
private String imgUrl;
}

/**
* 식물 D-Day μ—…λ°μ΄νŠΈ
*/
@AllArgsConstructor
@NoArgsConstructor
@Getter
public static class updateWateredDateRes{
private Long plantIdx;
private Long remainderDate;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class PlantService {

/**
* createPlant: 식물 μΆ”κ°€
* @param user
* @param req
* @param plantImage
* @return
Expand Down Expand Up @@ -122,8 +123,8 @@ public String createPlant(User user, PlantDto.createPlantReq req, MultipartFile

/**
* getPlant: 식물 쑰회
* @param plantIdx
* @param user
* @param plantIdx
* @return
*/
@Transactional
Expand Down Expand Up @@ -154,6 +155,7 @@ public PlantDto.getPlantRes getPlant(User user, Long plantIdx) {
// log.info("getMemoList: " + getAllMemoList);

PlantDto.getPlantRes getPlantRes = new PlantDto.getPlantRes(
plant.getPlantIdx(),
plant.getPlantName(),
plant.getNickname(),
plant.getPlace().getName(),
Expand Down Expand Up @@ -202,12 +204,12 @@ public Long getRemainderDate(Plant plant){

/**
* updateWateredDate: μ‹λ¬Όμ˜ D-Day μ—…λ°μ΄νŠΈ
* @param plantIdx
* @param user
* @param plantIdx
* @return
*/
@Transactional
public String updateWateredDate(User user, Long plantIdx) {
public PlantDto.updateWateredDateRes updateWateredDate(User user, Long plantIdx) {

Plant plant = plantRepository.findByPlantIdx(plantIdx)
.orElseThrow(() -> new BadRequestException(ErrorResponseStatus.NOT_FOUND_PLANT));
Expand All @@ -218,8 +220,14 @@ public String updateWateredDate(User user, Long plantIdx) {

// TODO: λ§ˆμ§€λ§‰μœΌλ‘œ λ¬Ό μ€€ λ‚ μ§œ
plant.setWateredDate(LocalDateTime.now());
plantRepository.save(plant);

Long remainderDate = getRemainderDate(plant);

return plantRepository.save(plant).getNickname();
return new PlantDto.updateWateredDateRes(
plant.getPlantIdx(),
remainderDate
);
}

/**
Expand Down Expand Up @@ -326,13 +334,14 @@ public List<PlantDto.getMyGardenPlantListRes> getMyGardenPlantList(String placeC

/**
* updatePlant: 식물 μˆ˜μ •
* @param user
* @param plantIdx
* @param nickname
* @param req
* @param plantImage
* @return
*/
@Transactional
public String updatePlant(User user, Long plantIdx, PlantDto.updatePlantReq req, MultipartFile plantImage) {
public PlantDto.updatePlantRes updatePlant(User user, Long plantIdx, PlantDto.updatePlantReq req, MultipartFile plantImage) {

Plant plant = plantRepository.findByPlantIdx(plantIdx)
.orElseThrow(() -> new BadRequestException(ErrorResponseStatus.NOT_FOUND_PLANT));
Expand Down Expand Up @@ -362,8 +371,13 @@ public String updatePlant(User user, Long plantIdx, PlantDto.updatePlantReq req,
}

plant.updatePlant(imgUrl, plantNickname);
plantRepository.save(plant);

return plantRepository.save(plant).getNickname();
return new PlantDto.updatePlantRes(
plant.getPlantIdx(),
plantNickname,
imgUrl
);
}

/**
Expand All @@ -372,7 +386,7 @@ public String updatePlant(User user, Long plantIdx, PlantDto.updatePlantReq req,
* @param plantIdx
* @return
*/
@Transactional
@Transactional(readOnly = true)
public PlantDto.updatePlantRes getUpdatedPlant(User user, Long plantIdx) {

Plant plant = plantRepository.findByPlantIdx(plantIdx)
Expand All @@ -383,6 +397,7 @@ public PlantDto.updatePlantRes getUpdatedPlant(User user, Long plantIdx) {
placeService.belongUserOnPlace(user, plantPlace.getCode());

return new PlantDto.updatePlantRes(
plant.getPlantIdx(),
plant.getNickname(),
plant.getImgUrl()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ public String joinUser(UserDto.join req, MultipartFile image){
}else{
//join
String uuid = UuidUtil.generateType1UUID();
String imageUrl = imageService.saveImage(image);
String imageUrl = "";
if(!image.isEmpty())
imageUrl = imageService.saveImage(image);

// String uuid = UuidUtil.generateType1UUID();
// String imageUrl = imageService.saveImage(image);

User user = User.builder()
.name(req.getName())
Expand All @@ -63,12 +68,12 @@ public String joinUser(UserDto.join req, MultipartFile image){
}
@Transactional(readOnly = true)
public boolean checkNameDuplication(String name){
boolean nameDuplicate = userRepository.existsByname(name);
boolean nameDuplicate = userRepository.existsByname(name); // κ²€μƒ‰μ•ˆλ˜λ©΄ false (μ‚¬μš©κ°€λŠ₯ν•œ 이름)
if(nameDuplicate)
throw new BadRequestException(EXIST_NAME);
if(name.length() < 2 || name.length() > 10)
throw new BadRequestException(NOT_VALID_LENGTH);
return nameDuplicate;
return !nameDuplicate;
}

public User getUserByName(String name){
Expand Down
Loading