diff --git a/src/main/java/com/umc/commonplant/domain/belong/entity/BelongRepository.java b/src/main/java/com/umc/commonplant/domain/belong/entity/BelongRepository.java index d06afcb..ec43bd1 100644 --- a/src/main/java/com/umc/commonplant/domain/belong/entity/BelongRepository.java +++ b/src/main/java/com/umc/commonplant/domain/belong/entity/BelongRepository.java @@ -19,4 +19,7 @@ public interface BelongRepository extends JpaRepository { Integer countUserOnPlace(String uuid, String code); String countUserByPlace(Place place); + + @Query("select b from Belong b where b.user.uuid=?1") + List getPlaceBelongUser(User user); } diff --git a/src/main/java/com/umc/commonplant/domain/oauth/OAuthProvider.java b/src/main/java/com/umc/commonplant/domain/oauth/OAuthProvider.java new file mode 100644 index 0000000..9c0aa23 --- /dev/null +++ b/src/main/java/com/umc/commonplant/domain/oauth/OAuthProvider.java @@ -0,0 +1,5 @@ +package com.umc.commonplant.domain.oauth; + +public enum OAuthProvider { + KAKAO, APPLE +} diff --git a/src/main/java/com/umc/commonplant/domain/oauth/controller/OAuthController.java b/src/main/java/com/umc/commonplant/domain/oauth/controller/OAuthController.java new file mode 100644 index 0000000..86211e2 --- /dev/null +++ b/src/main/java/com/umc/commonplant/domain/oauth/controller/OAuthController.java @@ -0,0 +1,30 @@ +package com.umc.commonplant.domain.oauth.controller; + +import com.umc.commonplant.domain.oauth.service.OAuthService; +import com.umc.commonplant.global.dto.JsonResponse; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@Slf4j +@RequiredArgsConstructor +@RestController +public class OAuthController { + private final OAuthService oAuthService; + + @GetMapping("/login/{provider}") + public ResponseEntity login(@RequestParam("accessToken") String accessToken, @PathVariable String provider){ + log.info("accessToken : " + accessToken); + String token = oAuthService.oAuthLogin(accessToken, provider); + String email = oAuthService.kakaoLogin(accessToken); + if(token != null){ + return ResponseEntity.ok(new JsonResponse(true, 200, "login", token)); + }else{ + return ResponseEntity.ok(new JsonResponse(true, 2001, "no User Info", email)); + } + } +} diff --git a/src/main/java/com/umc/commonplant/domain/user/dto/KakaoProfile.java b/src/main/java/com/umc/commonplant/domain/oauth/dto/KakaoProfile.java similarity index 87% rename from src/main/java/com/umc/commonplant/domain/user/dto/KakaoProfile.java rename to src/main/java/com/umc/commonplant/domain/oauth/dto/KakaoProfile.java index 6441478..65d7281 100644 --- a/src/main/java/com/umc/commonplant/domain/user/dto/KakaoProfile.java +++ b/src/main/java/com/umc/commonplant/domain/oauth/dto/KakaoProfile.java @@ -1,4 +1,4 @@ -package com.umc.commonplant.domain.user.dto; +package com.umc.commonplant.domain.oauth.dto; import lombok.Data; @@ -11,7 +11,7 @@ public class KakaoProfile { @Data public static class Properties{ - private String name; + private String nickname; private String profile_image; private String thumbnail_image; } @@ -29,7 +29,7 @@ public static class KakaoAccount{ @Data public static class Profile{ - private String name; + private String nickname; private String profile_image_url; private boolean is_default_image; } diff --git a/src/main/java/com/umc/commonplant/domain/user/service/OAuthService.java b/src/main/java/com/umc/commonplant/domain/oauth/service/OAuthService.java similarity index 85% rename from src/main/java/com/umc/commonplant/domain/user/service/OAuthService.java rename to src/main/java/com/umc/commonplant/domain/oauth/service/OAuthService.java index ff45026..adabf1b 100644 --- a/src/main/java/com/umc/commonplant/domain/user/service/OAuthService.java +++ b/src/main/java/com/umc/commonplant/domain/oauth/service/OAuthService.java @@ -1,11 +1,13 @@ -package com.umc.commonplant.domain.user.service; +package com.umc.commonplant.domain.oauth.service; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.umc.commonplant.domain.Jwt.JwtService; -import com.umc.commonplant.domain.user.dto.KakaoProfile; +import com.umc.commonplant.domain.oauth.dto.KakaoProfile; import com.umc.commonplant.domain.user.entity.User; import com.umc.commonplant.domain.user.repository.UserRepository; +import com.umc.commonplant.global.exception.BadRequestException; +import com.umc.commonplant.global.exception.ErrorResponseStatus; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpEntity; @@ -17,6 +19,9 @@ import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; + +import static com.umc.commonplant.global.exception.ErrorResponseStatus.*; + @Slf4j @Service @RequiredArgsConstructor @@ -29,12 +34,13 @@ public String oAuthLogin(String accessToken, String provider){ String email = ""; email = kakaoLogin(accessToken); - if(userRepository.countUserByEmail(email, provider) > 0){ + if(userRepository.countUserByEmail(email, provider) > 0){ // 로그인 성공 User user = userRepository.findByEmail(email, provider); String token = jwtService.createToken(user.getUuid()); return token; - }else{ - throw new IllegalArgumentException(email); + } + else{ + return null; } } public String kakaoLogin(String accessToken){ diff --git a/src/main/java/com/umc/commonplant/domain/place/controller/PlaceContoller.java b/src/main/java/com/umc/commonplant/domain/place/controller/PlaceContoller.java index 2c48c9a..07cd48c 100644 --- a/src/main/java/com/umc/commonplant/domain/place/controller/PlaceContoller.java +++ b/src/main/java/com/umc/commonplant/domain/place/controller/PlaceContoller.java @@ -99,4 +99,25 @@ public ResponseEntity getMyGarden(){ return ResponseEntity.ok(new JsonResponse(true, 200, "getMyGarden", mainPage)); } + + // 사용자가 속한 장소 리스트 + @GetMapping("/user") + public ResponseEntity getPlaceBelongUser(){ + String uuid = jwtService.resolveToken(); + User user = userService.getUser(uuid); + + List placeList = placeService.getPlaceBelongUser(user); + return ResponseEntity.ok(new JsonResponse(true, 200, "getPlaceBelongUser",placeList)); + } + + // 친구 리스트 조회 + @GetMapping("/{code}/friends") + public ResponseEntity getPlaceFriends(@PathVariable String code){ + String uuid = jwtService.resolveToken(); + User user = userService.getUser(uuid); + + placeService.userOnPlace(user, code); + List userList = placeService.getPlaceFriends(code); + return ResponseEntity.ok(new JsonResponse(true, 200, "getPlaceFriends", userList)); + } } diff --git a/src/main/java/com/umc/commonplant/domain/place/dto/PlaceDto.java b/src/main/java/com/umc/commonplant/domain/place/dto/PlaceDto.java index 05ed886..ff05328 100644 --- a/src/main/java/com/umc/commonplant/domain/place/dto/PlaceDto.java +++ b/src/main/java/com/umc/commonplant/domain/place/dto/PlaceDto.java @@ -7,6 +7,7 @@ import lombok.Data; import lombok.NoArgsConstructor; +import java.time.LocalDateTime; import java.util.List; public class PlaceDto { @@ -99,4 +100,28 @@ public static class getMainPage{ private List placeList; private List plantList; } + + @NoArgsConstructor + @AllArgsConstructor + public static class getPlaceBelongUser { + private String imgUrl; + private String name; + private LocalDateTime createdAt; + } + + public static class getPlaceFriends { + private boolean isLeader = false; + private String image; + private String name; + + public getPlaceFriends(String image, String name) { + this.image = image; + this.name = name; + } + + public void setLeader(boolean leader) { + isLeader = leader; + } + } + } diff --git a/src/main/java/com/umc/commonplant/domain/place/entity/Place.java b/src/main/java/com/umc/commonplant/domain/place/entity/Place.java index 6d26dec..3726c84 100644 --- a/src/main/java/com/umc/commonplant/domain/place/entity/Place.java +++ b/src/main/java/com/umc/commonplant/domain/place/entity/Place.java @@ -1,5 +1,6 @@ package com.umc.commonplant.domain.place.entity; +import com.umc.commonplant.domain.BaseTime; import com.umc.commonplant.domain.user.entity.User; import lombok.Builder; import lombok.Getter; @@ -13,7 +14,7 @@ @Table(name = "place") @NoArgsConstructor @Entity -public class Place { +public class Place extends BaseTime { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "place_idx") diff --git a/src/main/java/com/umc/commonplant/domain/place/service/PlaceService.java b/src/main/java/com/umc/commonplant/domain/place/service/PlaceService.java index 4f238cc..a5c849e 100644 --- a/src/main/java/com/umc/commonplant/domain/place/service/PlaceService.java +++ b/src/main/java/com/umc/commonplant/domain/place/service/PlaceService.java @@ -135,6 +135,33 @@ public Optional getFriends(String inputName) { return users; } + public List getPlaceBelongUser(User user) { + List belongs = belongRepository.getPlaceBelongUser(user); + List belongList = new ArrayList<>(); + for(Belong b : belongs){ + PlaceDto.getPlaceBelongUser belongUser = new PlaceDto.getPlaceBelongUser( + b.getPlace().getImgUrl(), + b.getPlace().getName(), + b.getPlace().getCreatedAt()); + belongList.add(belongUser); + } + return belongList; + } + + public List getPlaceFriends(String code) { + Place place = placeRepository.getPlaceByCode(code).orElseThrow(() -> new BadRequestException(NOT_FOUND_PLACE_CODE)); + List userList = belongRepository.getUserListByPlaceCode(code).orElseThrow(() -> new BadRequestException(NOT_FOUND_PLACE_CODE)); + + List friends = new ArrayList<>(); + for(User u : userList){ + PlaceDto.getPlaceFriends user = new PlaceDto.getPlaceFriends(u.getImgUrl(), u.getName()); + if(place.getOwner().getUuid().equals(u.getUuid())) + user.setLeader(true); + friends.add(user); + } + return friends; + } + // ----- API 외 메서드 ----- public void belongUserOnPlace(User user, String code) @@ -143,10 +170,6 @@ public void belongUserOnPlace(User user, String code) throw new BadRequestException(NOT_FOUND_USER_ON_PLACE); } - public void IsUserOnPlace(User user, String code){ - - } - public Place getPlaceByCode(String code){ return placeRepository.getPlaceByCode(code).orElseThrow(() -> new BadRequestException(NOT_FOUND_PLACE_CODE)); } diff --git a/src/main/java/com/umc/commonplant/domain/plant/controller/PlantController.java b/src/main/java/com/umc/commonplant/domain/plant/controller/PlantController.java index 97a1e60..c833759 100644 --- a/src/main/java/com/umc/commonplant/domain/plant/controller/PlantController.java +++ b/src/main/java/com/umc/commonplant/domain/plant/controller/PlantController.java @@ -33,9 +33,6 @@ public class PlantController { @PostMapping("/plant/add") public ResponseEntity createPlant(@RequestPart("plant") PlantDto.createPlantReq createPlantReq, @RequestPart("image") MultipartFile file) { - - // log.info("=============CREATE PLANT==============="); - String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid); @@ -50,9 +47,6 @@ public ResponseEntity createPlant(@RequestPart("plant") PlantDto.c */ @GetMapping("/plant/{plantIdx}") public ResponseEntity getPlantCard(@PathVariable Long plantIdx) { - - // log.info("=============GET PLANT==============="); - String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid); @@ -68,9 +62,6 @@ public ResponseEntity getPlantCard(@PathVariable Long plantIdx) { */ @GetMapping("/user/plantList") public ResponseEntity getPlantList() { - - // log.info("=============GET PLANT LIST==============="); - String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid); @@ -86,9 +77,6 @@ public ResponseEntity getPlantList() { // */ // @GetMapping("/place/plantList/{placeCode}") // public ResponseEntity getMyGardenPlantList(@PathVariable String placeCode) { -// -// // log.info("=============GET PLANT LIST==============="); -// // String uuid = jwtService.resolveToken(); // User user = userService.getUser(uuid); // @@ -107,24 +95,20 @@ public ResponseEntity getPlantList() { */ @PutMapping("/plant/update/wateredDate/{plantIdx}") public ResponseEntity updateWateredDate(@PathVariable Long plantIdx){ - - // System.out.println("=============UPDATE PLANT WATERED DATE==============="); - String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid); - String nickname = plantService.updateWateredDate(plantIdx, user); + String nickname = plantService.updateWateredDate(user, plantIdx); return ResponseEntity.ok(new JsonResponse(true, 200, "updateWateredDate", nickname)); } /** * [GET] /plant/update - * @return 수정할 식물의 애칭 + * @return 수정하기 전 식물의 애칭 */ @GetMapping("/plant/update/{plantIdx}") public ResponseEntity getUpdatedPlant(@PathVariable Long plantIdx){ - String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid); @@ -141,15 +125,27 @@ public ResponseEntity getUpdatedPlant(@PathVariable Long plantIdx) public ResponseEntity updatePlant(@PathVariable Long plantIdx, @RequestPart("nickname") String nickname, @RequestPart("image") MultipartFile file){ + String uuid = jwtService.resolveToken(); + User user = userService.getUser(uuid); - // log.info("=============UPDATE PLANT==============="); + String updatedPlant = plantService.updatePlant(user, plantIdx, nickname, file); + + return ResponseEntity.ok(new JsonResponse(true, 200, "updatePlant", updatedPlant)); + } + /** + * [DELETE] /plant/delete + * @param plantIdx + * @return 삭제한 식물의 닉네임 + */ + @DeleteMapping("/plant/delete/{plantIdx}") + public ResponseEntity deletePlant(@PathVariable Long plantIdx){ String uuid = jwtService.resolveToken(); User user = userService.getUser(uuid); - String updatedPlant = plantService.updatePlant(plantIdx, nickname, file); + String deletedPlant = plantService.deletePlant(user, plantIdx); - return ResponseEntity.ok(new JsonResponse(true, 200, "updatePlant", updatedPlant)); + return ResponseEntity.ok(new JsonResponse(true, 200, "deletePlant", deletedPlant)); } } diff --git a/src/main/java/com/umc/commonplant/domain/plant/service/PlantService.java b/src/main/java/com/umc/commonplant/domain/plant/service/PlantService.java index 1f333b8..c9b874b 100644 --- a/src/main/java/com/umc/commonplant/domain/plant/service/PlantService.java +++ b/src/main/java/com/umc/commonplant/domain/plant/service/PlantService.java @@ -50,6 +50,11 @@ public class PlantService { @Transactional public String createPlant(User user, PlantDto.createPlantReq req, MultipartFile plantImage) { + // 식물 장소 + // TODO: 식물이 있는 장소 -> 장소의 코드로 검색(추후 장소의 이름으로 바뀔 수 있음) + Place plantPlace = placeService.getPlaceByCode(req.getPlace()); + placeService.belongUserOnPlace(user, plantPlace.getCode()); + // 식물 종 // String plantName = infoService.findInfo(req.getPlantName()).getName(); String plantName = req.getPlantName(); @@ -74,10 +79,6 @@ public String createPlant(User user, PlantDto.createPlantReq req, MultipartFile throw new BadRequestException(ErrorResponseStatus.NO_SELECTED_PLANT_IMAGE); } - // 식물 장소 - // TODO: 식물이 있는 장소 -> 장소의 코드로 검색(추후 장소의 이름으로 바뀔 수 있음) - Place plantPlace = placeService.getPlaceByCode(req.getPlace()); - // 물주기 기간 String waterCycle = null; int castedWaterCycle = 0; @@ -133,17 +134,13 @@ public PlantDto.getPlantRes getPlant(User user, Long plantIdx) { List infoResponse = infoService.getOneInfo(plant.getPlantName()); - // log.info("식물의 고유 정보는:" + infoResponse.getScientific_name() + infoResponse.getHumidity()); - // DateTimeFormatter DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); String parsedCreatedDate = plant.getCreatedAt().format(dateTimeFormatter); - // log.info("========parsedCreatedDate======== " + parsedCreatedDate); LocalDateTime createdDateTime = LocalDate.parse(parsedCreatedDate, dateTimeFormatter).atStartOfDay(); String parsedCurrentDate = LocalDate.now().toString(); - // log.info("========parsedCurrentDate======== " + parsedCurrentDate); LocalDateTime currentDateTime = LocalDate.parse(parsedCurrentDate, dateTimeFormatter).atStartOfDay(); // countDate: 식물이 처음 온 날 @@ -191,20 +188,14 @@ public Long getRemainderDate(Plant plant){ // WateredDate: 마지막으로 물 준 날짜, CurrentDate: 오늘 날짜 String parsedWateredDate = plant.getWateredDate().format(dateTimeFormatter); - // log.info("========parsedWateredDate======== " + parsedWateredDate); LocalDateTime wateredDateTime = LocalDate.parse(parsedWateredDate, dateTimeFormatter).atStartOfDay(); String parsedCurrentDate = LocalDate.now().toString(); - // log.info("========parsedCurrentDate======== " + parsedCurrentDate); LocalDateTime currentDateTime = LocalDate.parse(parsedCurrentDate, dateTimeFormatter).atStartOfDay(); // remainderDate: D-Day - Long remainderDate = (Long) infoResponse.get(0).getWater_day() - - (Long) Duration.between(wateredDateTime, currentDateTime).toDays(); - - // log.info(parsedWateredDate); - // log.info(parsedCurrentDate); - // log.info(String.valueOf(remainderDate)); + Long remainderDate = (long) plant.getWaterCycle() + - (long) Duration.between(wateredDateTime, currentDateTime).toDays(); return remainderDate; } @@ -216,21 +207,18 @@ public Long getRemainderDate(Plant plant){ * @return */ @Transactional - public String updateWateredDate(Long plantIdx, User user) { + public String updateWateredDate(User user, Long plantIdx) { Plant plant = plantRepository.findByPlantIdx(plantIdx) .orElseThrow(() -> new BadRequestException(ErrorResponseStatus.NOT_FOUND_PLANT)); - // log.info(" 물주기 리셋할 식물은: " + plant.getNickname()); + // TODO: 식물이 있는 장소 -> 장소의 코드로 검색(추후 장소의 이름으로 바뀔 수 있음) + Place plantPlace = placeService.getPlaceByCode(plant.getPlace().getCode()); + placeService.belongUserOnPlace(user, plantPlace.getCode()); // TODO: 마지막으로 물 준 날짜 plant.setWateredDate(LocalDateTime.now()); -// getPlantInfo()의 인자는 식물 종 이름: 식물 조회할 때 식물 종 이름을 보내서 검색하면 됨 -// InfoDto.InfoResponse infoResponse = infoService.findInfo(plant.getPlantName()); -// Long resetRemainderDate = -1 * (Long) infoResponse.getWater_day(); -// plant.setRemainderDate(resetRemainderDate); - return plantRepository.save(plant).getNickname(); } @@ -344,11 +332,15 @@ public List getMyGardenPlantList(String placeC * @return */ @Transactional - public String updatePlant(Long plantIdx, String nickname, MultipartFile plantImage) { + public String updatePlant(User user, Long plantIdx, String nickname, MultipartFile plantImage) { Plant plant = plantRepository.findByPlantIdx(plantIdx) .orElseThrow(() -> new BadRequestException(ErrorResponseStatus.NOT_FOUND_PLANT)); + // TODO: 식물이 있는 장소 -> 장소의 코드로 검색(추후 장소의 이름으로 바뀔 수 있음) + Place plantPlace = placeService.getPlaceByCode(plant.getPlace().getCode()); + placeService.belongUserOnPlace(user, plantPlace.getCode()); + // TODO: 식물의 애칭 String plantNickname = null; @@ -386,6 +378,10 @@ public PlantDto.updatePlantRes getUpdatedPlant(User user, Long plantIdx) { Plant plant = plantRepository.findByPlantIdx(plantIdx) .orElseThrow(() -> new BadRequestException(ErrorResponseStatus.NOT_FOUND_PLANT)); + // TODO: 식물이 있는 장소 -> 장소의 코드로 검색(추후 장소의 이름으로 바뀔 수 있음) + Place plantPlace = placeService.getPlaceByCode(plant.getPlace().getCode()); + placeService.belongUserOnPlace(user, plantPlace.getCode()); + return new PlantDto.updatePlantRes( plant.getNickname(), plant.getImgUrl() @@ -404,6 +400,21 @@ public String deletePlant(User user, Long plantIdx) { Plant plant = plantRepository.findByPlantIdx(plantIdx) .orElseThrow(() -> new BadRequestException(ErrorResponseStatus.NOT_FOUND_PLANT)); + // TODO: 식물이 있는 장소 -> 장소의 코드로 검색(추후 장소의 이름으로 바뀔 수 있음) + Place plantPlace = placeService.getPlaceByCode(plant.getPlace().getCode()); + placeService.belongUserOnPlace(user, plantPlace.getCode()); + + List memoList = memoService.getAllMemoByPlant(plantIdx); + + for(MemoDto.GetAllMemo memo : memoList) { + memoService.deleteMemo(user, memo.getMemo_idx()); + } + + imageService.deleteFileInS3(plant.getImgUrl()); + + plantRepository.deleteById(plantIdx); + return plant.getNickname(); } + } diff --git a/src/main/java/com/umc/commonplant/domain/user/controller/UserController.java b/src/main/java/com/umc/commonplant/domain/user/controller/UserController.java index f1419ea..6258848 100644 --- a/src/main/java/com/umc/commonplant/domain/user/controller/UserController.java +++ b/src/main/java/com/umc/commonplant/domain/user/controller/UserController.java @@ -3,7 +3,6 @@ import com.umc.commonplant.domain.Jwt.JwtService; import com.umc.commonplant.domain.user.dto.UserDto; import com.umc.commonplant.domain.user.entity.User; -import com.umc.commonplant.domain.user.service.OAuthService; import com.umc.commonplant.domain.user.service.UserService; import com.umc.commonplant.global.dto.JsonResponse; import lombok.RequiredArgsConstructor; @@ -17,7 +16,6 @@ @RestController public class UserController { private final UserService userService; - private final OAuthService oAuthService; private final JwtService jwtService; @PostMapping("/user") //join @@ -27,18 +25,9 @@ public ResponseEntity join(@RequestPart("user") UserDto.join req, return ResponseEntity.ok(new JsonResponse(true, 200, "join", token)); } - @GetMapping("/login/{provider}") - public ResponseEntity login(@RequestParam("accessToken") String accessToken, @PathVariable String provider){ - log.info("accessToken" + accessToken); -// System.out.println("accessToken: " + accessToken); - String token = oAuthService.oAuthLogin(accessToken, provider); - - return ResponseEntity.ok(new JsonResponse(true, 200, "login", token)); - } @GetMapping("/user/{name}") // 회원정보 조회 - public ResponseEntity getUser(@PathVariable String name){ - //String uuid = jwtService.resolveToken(); - User user = userService.getUser(name); + public ResponseEntity getUserByName(@PathVariable String name){ + User user = userService.getUserByName(name); return ResponseEntity.ok(new JsonResponse(true, 200, "getUser", user)); } diff --git a/src/main/java/com/umc/commonplant/domain/user/service/UserService.java b/src/main/java/com/umc/commonplant/domain/user/service/UserService.java index 149726d..4b2ac6e 100644 --- a/src/main/java/com/umc/commonplant/domain/user/service/UserService.java +++ b/src/main/java/com/umc/commonplant/domain/user/service/UserService.java @@ -2,6 +2,7 @@ import com.google.cloud.grpc.BaseGrpcServiceException; import com.umc.commonplant.domain.Jwt.JwtService; +import com.umc.commonplant.domain.image.service.ImageService; import com.umc.commonplant.domain.user.dto.UserDto; import com.umc.commonplant.domain.user.entity.User; import com.umc.commonplant.domain.user.repository.UserRepository; @@ -21,9 +22,10 @@ public class UserService { private final UserRepository userRepository; private final JwtService jwtService; + private final ImageService imageService; - public User getUser(String name){ // User 조회 - return userRepository.findByname(name).orElseThrow(() -> new BadRequestException((NOT_FOUND_USER))); + public User getUser(String uuid){ // User 조회 + return userRepository.findByUuid(uuid).orElseThrow(() -> new BadRequestException((NOT_FOUND_USER))); } public User saveUser(UserDto.join req){ User user = User.builder() @@ -39,11 +41,11 @@ public String joinUser(UserDto.join req, MultipartFile image){ }else{ //join String uuid = UuidUtil.generateType1UUID(); - //String imageUrl = firebaseService.uploadFiles(uuid, image); + String imageUrl = imageService.saveImage(image); User user = User.builder() .name(req.getName()) - //.imgUrl(imageUrl) + .imgUrl(imageUrl) .uuid(uuid) .email(req.getEmail()) .provider(req.getProvider()). @@ -63,4 +65,8 @@ public boolean checkNameDuplication(String name){ return nameDuplicate; } + public User getUserByName(String name){ + return userRepository.findByname(name).orElseThrow(() -> new BadRequestException(NOT_FOUND_USER)); + } + }