Skip to content

Commit

Permalink
Merge pull request #128 from UMC-CommonPlant/main
Browse files Browse the repository at this point in the history
[Build] user, place, plant
  • Loading branch information
hweyoung authored May 29, 2024
2 parents 3ad1fae + 5cf3753 commit 903a262
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 21 deletions.
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

0 comments on commit 903a262

Please sign in to comment.