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 69e2f8f..79f4a3f 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){ @@ -47,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; @@ -91,11 +101,6 @@ public BaseResponseDto deleteUser(HttpServletRequest request){ return responseDto; } - - - - - @DeleteMapping("/logout") public BaseResponseDto logout(HttpServletRequest request) { @@ -122,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() { @@ -135,6 +149,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/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 32a515a..d12b9b4 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){ @@ -51,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()){ @@ -105,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) { 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; + + } + + +}