From 38dea3037b6fe487ab6ccf50545c48739ba3eb35 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sun, 12 Nov 2023 03:26:31 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[feat]=20=EC=9C=A0=EC=A0=80=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4(+=EA=B0=80=EC=9E=85=20=ED=9B=84=20=EA=B2=BD=EA=B3=BC?= =?UTF-8?q?=20=EA=B8=B0=EA=B0=84)=20API=20=EC=99=84=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserController.java | 17 ++++++----- .../user/dto/response/GetUserResponseDto.java | 15 ++++++++++ .../farmususer/user/service/UserService.java | 15 ++++++++++ .../farmususer/user/util/TimeCalculator.java | 29 +++++++++++++++++++ 4 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 src/main/java/modernfarmer/server/farmususer/user/dto/response/GetUserResponseDto.java create mode 100644 src/main/java/modernfarmer/server/farmususer/user/util/TimeCalculator.java diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index 69e2f8f..4e7fc56 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -35,6 +35,16 @@ public class UserController { // // } + @GetMapping + public BaseResponseDto getUser(HttpServletRequest request){ + + String userId = jwtTokenProvider.getUserId(request); + + return userService.getUser(Long.valueOf(userId)); + } + + + @PostMapping(value = "/nickname") public BaseResponseDto emitNickname(HttpServletRequest request, @RequestBody ProduceNicknameRequest produceNicknameRequest){ @@ -91,11 +101,6 @@ public BaseResponseDto deleteUser(HttpServletRequest request){ return responseDto; } - - - - - @DeleteMapping("/logout") public BaseResponseDto logout(HttpServletRequest request) { @@ -135,6 +140,4 @@ public BaseResponseDto specificUser(@RequestParam("userId") Long userId) { return userService.specificUser(userId); } - - } diff --git a/src/main/java/modernfarmer/server/farmususer/user/dto/response/GetUserResponseDto.java b/src/main/java/modernfarmer/server/farmususer/user/dto/response/GetUserResponseDto.java new file mode 100644 index 0000000..a773ad2 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/dto/response/GetUserResponseDto.java @@ -0,0 +1,15 @@ +package modernfarmer.server.farmususer.user.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@AllArgsConstructor(staticName = "of") +@Getter +public class GetUserResponseDto { + + private String nickName; + private String userImageUrl; + private long dDay; +} diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 32a515a..92467e4 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -9,6 +9,7 @@ import modernfarmer.server.farmususer.user.entity.User; import modernfarmer.server.farmususer.user.repository.UserRepository; import modernfarmer.server.farmususer.user.util.JwtTokenProvider; +import modernfarmer.server.farmususer.user.util.TimeCalculator; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -30,6 +31,7 @@ public class UserService { private final RedisTemplate redisTemplate; private final UserRepository userRepository; private final S3Uploader s3Uploader; + private final TimeCalculator timeCalculator; // public BaseResponseDto emitProfileImage(Long userId, MultipartFile multipartFile) throws IOException { @@ -42,6 +44,19 @@ public class UserService { // return BaseResponseDto.of(SuccessMessage.SUCCESS,null); // } + public BaseResponseDto getUser(Long userId){ + + Optional user = userRepository.findById(userId); + + if(user.isEmpty()){ + return BaseResponseDto.of(ErrorMessage.NO_USER_DATA); + } + + long dDay = timeCalculator.calFromToday(user.get().getCreatedAt()); + + return BaseResponseDto.of(SuccessMessage.SUCCESS, GetUserResponseDto.of(user.get().getNickname(),user.get().getProfileImage(),dDay)); + } + public BaseResponseDto emitNickname(Long userId, String nickName){ diff --git a/src/main/java/modernfarmer/server/farmususer/user/util/TimeCalculator.java b/src/main/java/modernfarmer/server/farmususer/user/util/TimeCalculator.java new file mode 100644 index 0000000..f0bf2f4 --- /dev/null +++ b/src/main/java/modernfarmer/server/farmususer/user/util/TimeCalculator.java @@ -0,0 +1,29 @@ +package modernfarmer.server.farmususer.user.util; + +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; +import org.springframework.stereotype.Component; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; + + +@Component +public class TimeCalculator { + + public long calFromToday(LocalDateTime date){ + + LocalDateTime currentDateTime = LocalDateTime.now(); + + // 날짜 차이 계산 + long daysDifference = ChronoUnit.DAYS.between(date.toLocalDate(), currentDateTime.toLocalDate()); + + + return daysDifference; + + } + + +} From c0588d9398ffe20eea4aca4b6f34e5aa678b2c67 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sun, 12 Nov 2023 15:34:00 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[fix]=20=EC=9C=A0=EC=A0=80=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=95=84=20=EC=82=AC=EC=A7=84=20=EB=93=B1=EB=A1=9D=20?= =?UTF-8?q?=EC=8B=9C=20null=20=EC=B2=98=EB=A6=AC=20=EC=97=90=EB=9F=AC=20?= =?UTF-8?q?=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/actions.yml | 2 +- .../server/farmususer/user/controller/UserController.java | 4 ++-- .../server/farmususer/user/service/UserService.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 8b0be59..d743e92 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -2,7 +2,7 @@ name: ModernFarmer CI/CD on: push: - branches: ["feature_21/-유저-오픈-페인-API"] + branches: ["feature_25/유저-정보-조회"] pull_request: branches: ["dev"] diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index 4e7fc56..f329e32 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -57,10 +57,10 @@ public BaseResponseDto emitNickname(HttpServletRequest request, @RequestBody Pro } @PostMapping(value = "/select-information", produces = MediaType.APPLICATION_JSON_VALUE) - public BaseResponseDto selectProfileImageAndNickname(HttpServletRequest request, @RequestParam(value = "file", required = false) MultipartFile multipartFile, @RequestParam("nickName")String nickName) throws IOException { + public BaseResponseDto selectProfileImageAndNickname(HttpServletRequest request, @RequestPart(value = "file", required = false) MultipartFile multipartFile, @RequestParam("nickName")String nickName) throws IOException { String userId = jwtTokenProvider.getUserId(request); - log.info(userId); + BaseResponseDto responseDto = userService.selectProfileImageAndNickname(Long.valueOf(userId), multipartFile,nickName); return responseDto; diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 92467e4..997e95e 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -66,7 +66,7 @@ public BaseResponseDto emitNickname(Long userId, String nickName){ return BaseResponseDto.of(SuccessMessage.SUCCESS,null); } - public BaseResponseDto selectProfileImageAndNickname(Long userId,MultipartFile multipartFile, + public BaseResponseDto selectProfileImageAndNickname(Long userId, MultipartFile multipartFile, String nickName) throws IOException { if(multipartFile.isEmpty()){ From 93d5f89bfce4c9a19933264437d28e87a0e30371 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Tue, 14 Nov 2023 01:52:04 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[feat]=20=EC=9C=A0=EC=A0=80=20=ED=94=84?= =?UTF-8?q?=EB=A1=9C=ED=95=84=20=EC=82=AD=EC=A0=9C=20API=20=EC=99=84?= =?UTF-8?q?=EB=A3=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../farmususer/user/controller/UserController.java | 9 +++++++++ .../farmususer/user/repository/UserRepository.java | 4 ++++ .../server/farmususer/user/service/UserService.java | 9 +++++++++ 3 files changed, 22 insertions(+) diff --git a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java index f329e32..79f4a3f 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java +++ b/src/main/java/modernfarmer/server/farmususer/user/controller/UserController.java @@ -127,6 +127,15 @@ public BaseResponseDto reissueToken(HttpServletRequest request) { return reissueTokenResponseDto; } + @PatchMapping(value = "/delete/user-profile") + public BaseResponseDto deleteUserProfile(HttpServletRequest request) { + + String userId = jwtTokenProvider.getUserId(request); + + return userService.deleteUserProfile(Long.valueOf(userId)); + } + + @GetMapping(value = "/all-user") public BaseResponseDto allUser() { diff --git a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java index 599e401..eb2dd76 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java +++ b/src/main/java/modernfarmer/server/farmususer/user/repository/UserRepository.java @@ -33,6 +33,10 @@ public interface UserRepository extends JpaRepository { @Query("update User as u set u.early = 0 where u.id = :userId") void updateEarly( @Param("userId") Long userId); + @Modifying + @Query("update User as u set u.profileImage = null where u.id = :userId") + void updateUserProfileDefault( @Param("userId") Long userId); + // @Modifying // @Query("update User as u set u.profileImage = :profileImage where u.id = :userId") diff --git a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java index 997e95e..d12b9b4 100644 --- a/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java +++ b/src/main/java/modernfarmer/server/farmususer/user/service/UserService.java @@ -120,6 +120,15 @@ public BaseResponseDto allUser() { } + public BaseResponseDto deleteUserProfile(Long userId) { + + userRepository.updateUserProfileDefault(userId); + + log.info("유저 프로필 삭제 완료"); + return BaseResponseDto.of(SuccessMessage.SUCCESS, null); + + } + public BaseResponseDto specificUser(Long userId) {