From c62093af65b7c8309cfd2fd48fe6e5f402183a6d Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sat, 27 Jul 2024 02:29:35 +0900 Subject: [PATCH 1/4] =?UTF-8?q?[fix]=20User=20=EC=97=94=ED=8B=B0=ED=8B=B0?= =?UTF-8?q?=20=EC=95=8C=EB=A6=BC=20=EC=83=81=ED=83=9C=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=20=EC=BB=AC=EB=9F=BC=20=EC=B6=94=EA=B0=80=20=EB=B0=8F=20create?= =?UTF-8?q?User=20=ED=95=A8=EC=88=98=EC=97=90=20=EB=94=94=ED=8F=B4?= =?UTF-8?q?=ED=8A=B8=20false=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modernfarmer/farmusspring/domain/user/entity/User.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/entity/User.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/entity/User.java index fc0d6003..18d83ac9 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/entity/User.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/entity/User.java @@ -46,6 +46,9 @@ public class User extends BaseEntity { @Column(nullable = true) private String level; + @Column(nullable = false) + private boolean notificationStatus; + @OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL) @Builder.Default @@ -80,6 +83,7 @@ public static User createUser(String role, String userNumber, boolean early){ .role(role) .userNumber(userNumber) .early(early) + .notificationStatus(true) .build(); return newUser; From 9de2eeeef1b715fab5e288ca4b84120e8ad88a0c Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sat, 27 Jul 2024 03:01:11 +0900 Subject: [PATCH 2/4] =?UTF-8?q?[fix]=20User=20=EC=97=94=ED=8B=B0=ED=8B=B0?= =?UTF-8?q?=20=EC=BB=AC=EB=9F=BC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/modernfarmer/farmusspring/domain/user/entity/User.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/entity/User.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/entity/User.java index 18d83ac9..702978d5 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/entity/User.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/entity/User.java @@ -47,7 +47,7 @@ public class User extends BaseEntity { private String level; @Column(nullable = false) - private boolean notificationStatus; + private Boolean notificationStatus; @OneToMany(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.ALL) From b89aa7938bf10c5ff6c3ae76d47d64348a15ab66 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sat, 27 Jul 2024 03:01:28 +0900 Subject: [PATCH 3/4] =?UTF-8?q?[feat]=20User=20=EC=95=8C=EB=A6=BC=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=20=EC=88=98=EC=A0=95=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserController.java | 21 +++++++++++++------ .../domain/user/dto/request/AlarmUpdate.java | 16 ++++++++++++++ .../user/repository/UserRepository.java | 6 ++++-- .../domain/user/service/UserService.java | 10 ++++++++- 4 files changed, 44 insertions(+), 9 deletions(-) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/user/dto/request/AlarmUpdate.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/controller/UserController.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/controller/UserController.java index d0dacfb8..77716a3b 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/controller/UserController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/controller/UserController.java @@ -1,13 +1,11 @@ package com.modernfarmer.farmusspring.domain.user.controller; import com.modernfarmer.farmusspring.domain.auth.entity.CustomUser; -import com.modernfarmer.farmusspring.domain.user.dto.request.SetLevelRequest; -import com.modernfarmer.farmusspring.domain.user.dto.request.UpdateProfileDto; -import com.modernfarmer.farmusspring.domain.user.dto.response.SetLevelResponse; +import com.modernfarmer.farmusspring.domain.user.dto.request.AlarmUpdate; import com.modernfarmer.farmusspring.domain.user.dto.response.UserProfileResponse; import com.modernfarmer.farmusspring.domain.user.service.UserService; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; -import jakarta.servlet.http.HttpServletRequest; +import com.modernfarmer.farmusspring.global.response.SuccessCode; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.MediaType; @@ -28,17 +26,24 @@ public class UserController { @GetMapping(value = "") public BaseResponseDto selectUserProfile(@AuthenticationPrincipal CustomUser user) { - return userService.selectUserProfile(user.getUserId()); } @PatchMapping(value = "/profile-image") public BaseResponseDto deleteProfleImage(@AuthenticationPrincipal CustomUser user) { - return userService.deleteProfleImage(user.getUserId()); } + @PatchMapping("/notification") + public BaseResponseDto modifyNotification(@AuthenticationPrincipal CustomUser user, @Validated @RequestBody AlarmUpdate alarmUpdate) { + log.info(String.valueOf(alarmUpdate.getStatus())); + userService.modifyNotification(user.getUserId(), alarmUpdate.getStatus()); + return BaseResponseDto.of(SuccessCode.SUCCESS, null); + } + + + @PostMapping(value = "/profile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) public BaseResponseDto settingProfile( @AuthenticationPrincipal CustomUser user, @@ -54,4 +59,8 @@ public void initUser( ) { userService.initUser(userId); } + + + + } diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/dto/request/AlarmUpdate.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/dto/request/AlarmUpdate.java new file mode 100644 index 00000000..9dc8fff8 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/dto/request/AlarmUpdate.java @@ -0,0 +1,16 @@ +package com.modernfarmer.farmusspring.domain.user.dto.request; + + +import jakarta.validation.constraints.NotNull; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@AllArgsConstructor +@NoArgsConstructor +public class AlarmUpdate { + + @NotNull(message = "null 값을 가지면 안됩니다.") + private Boolean status; +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/repository/UserRepository.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/repository/UserRepository.java index c0a3005a..e2f37391 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/repository/UserRepository.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/repository/UserRepository.java @@ -31,9 +31,11 @@ public interface UserRepository extends JpaRepository { @Modifying @Query("update user as u set u.profileImage = null where u.id = :userId") - void updateProfileImage( @Param("userId") Long userId); - + void updateProfileImage(@Param("userId") Long userId); + @Modifying + @Query("update user as u set u.notificationStatus = :status where u.id = :userId") + void updateNotification(@Param("userId") Long userId, @Param("status") Boolean status); @Modifying @Query("update user as u set u.profileImage = :profileImage, u.nickname = :nickName where u.id = :userId") void selectProfileAndNickname(@Param("userId") Long userId, @Param("profileImage") String profileImage, @Param("nickName") String nickName); diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java index 59c763ca..84691907 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java @@ -1,5 +1,6 @@ package com.modernfarmer.farmusspring.domain.user.service; +import com.modernfarmer.farmusspring.domain.auth.entity.CustomUser; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Diary; import com.modernfarmer.farmusspring.domain.myveggiegarden.exception.DiaryNotFoundException; import com.modernfarmer.farmusspring.domain.user.dto.response.UserProfileResponse; @@ -12,6 +13,7 @@ import com.modernfarmer.farmusspring.infra.s3.S3Service; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; @@ -46,7 +48,6 @@ public BaseResponseDto selectUserProfile(Long userId) { @Transactional public BaseResponseDto deleteProfleImage(Long userId) { - updateProfileImage(userId); return BaseResponseDto.of(SuccessCode.SUCCESS,null); } @@ -84,6 +85,13 @@ public void initUser(Long userId) { user.initUser(); } + + @Transactional + public void modifyNotification(Long userId, Boolean status) { + log.info(String.valueOf(status)); + userRepository.updateNotification(userId, status); + } + private void updateUserProfileAccordingToProfileImage(MultipartFile multipartFile, String nickName, Long userId) throws IOException { if(multipartFile.isEmpty()){ From 4c246372bca30e4e212fc0be87f23e9eb0023f09 Mon Sep 17 00:00:00 2001 From: seungryeol Date: Sat, 27 Jul 2024 03:14:55 +0900 Subject: [PATCH 4/4] =?UTF-8?q?[feat]=20User=20=EC=95=8C=EB=A6=BC=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=20=EC=A1=B0=ED=9A=8C=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/controller/UserController.java | 8 +++++++- .../domain/user/dto/response/AlarmStatus.java | 14 ++++++++++++++ .../domain/user/service/UserService.java | 10 +++++++++- 3 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/modernfarmer/farmusspring/domain/user/dto/response/AlarmStatus.java diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/controller/UserController.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/controller/UserController.java index 77716a3b..776085f5 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/controller/UserController.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/controller/UserController.java @@ -2,6 +2,7 @@ import com.modernfarmer.farmusspring.domain.auth.entity.CustomUser; import com.modernfarmer.farmusspring.domain.user.dto.request.AlarmUpdate; +import com.modernfarmer.farmusspring.domain.user.dto.response.AlarmStatus; import com.modernfarmer.farmusspring.domain.user.dto.response.UserProfileResponse; import com.modernfarmer.farmusspring.domain.user.service.UserService; import com.modernfarmer.farmusspring.global.response.BaseResponseDto; @@ -37,11 +38,16 @@ public BaseResponseDto deleteProfleImage(@AuthenticationPrincipal CustomUs @PatchMapping("/notification") public BaseResponseDto modifyNotification(@AuthenticationPrincipal CustomUser user, @Validated @RequestBody AlarmUpdate alarmUpdate) { - log.info(String.valueOf(alarmUpdate.getStatus())); userService.modifyNotification(user.getUserId(), alarmUpdate.getStatus()); return BaseResponseDto.of(SuccessCode.SUCCESS, null); } + @GetMapping("/notification") + public BaseResponseDto bringNotification(@AuthenticationPrincipal CustomUser user) { + AlarmStatus result = userService.bringNotification(user.getUserId()); + return BaseResponseDto.of(SuccessCode.SUCCESS, result); + } + @PostMapping(value = "/profile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/dto/response/AlarmStatus.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/dto/response/AlarmStatus.java new file mode 100644 index 00000000..4967dc93 --- /dev/null +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/dto/response/AlarmStatus.java @@ -0,0 +1,14 @@ +package com.modernfarmer.farmusspring.domain.user.dto.response; + + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@AllArgsConstructor(staticName = "of") +@Getter +public class AlarmStatus { + + private Boolean status; +} diff --git a/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java b/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java index 84691907..d39f0ce2 100644 --- a/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java +++ b/src/main/java/com/modernfarmer/farmusspring/domain/user/service/UserService.java @@ -3,6 +3,7 @@ import com.modernfarmer.farmusspring.domain.auth.entity.CustomUser; import com.modernfarmer.farmusspring.domain.myveggiegarden.entity.Diary; import com.modernfarmer.farmusspring.domain.myveggiegarden.exception.DiaryNotFoundException; +import com.modernfarmer.farmusspring.domain.user.dto.response.AlarmStatus; import com.modernfarmer.farmusspring.domain.user.dto.response.UserProfileResponse; import com.modernfarmer.farmusspring.domain.user.entity.User; import com.modernfarmer.farmusspring.domain.user.exception.UserNotFoundException; @@ -88,10 +89,17 @@ public void initUser(Long userId) { @Transactional public void modifyNotification(Long userId, Boolean status) { - log.info(String.valueOf(status)); userRepository.updateNotification(userId, status); } + @Transactional + public AlarmStatus bringNotification(Long userId) { + User user = selectUserById(userId); + return AlarmStatus.of(user.getNotificationStatus()); + } + + + private void updateUserProfileAccordingToProfileImage(MultipartFile multipartFile, String nickName, Long userId) throws IOException { if(multipartFile.isEmpty()){