Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 36/알림 여부 #39

Merged
merged 4 commits into from
Jul 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
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.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;
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;
Expand All @@ -28,17 +27,29 @@ public class UserController {

@GetMapping(value = "")
public BaseResponseDto<UserProfileResponse> selectUserProfile(@AuthenticationPrincipal CustomUser user) {

return userService.selectUserProfile(user.getUserId());
}


@PatchMapping(value = "/profile-image")
public BaseResponseDto<Void> deleteProfleImage(@AuthenticationPrincipal CustomUser user) {

return userService.deleteProfleImage(user.getUserId());
}

@PatchMapping("/notification")
public BaseResponseDto<?> modifyNotification(@AuthenticationPrincipal CustomUser user, @Validated @RequestBody AlarmUpdate alarmUpdate) {
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)
public BaseResponseDto<Void> settingProfile(
@AuthenticationPrincipal CustomUser user,
Expand All @@ -54,4 +65,8 @@ public void initUser(
) {
userService.initUser(userId);
}




}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -80,6 +83,7 @@ public static User createUser(String role, String userNumber, boolean early){
.role(role)
.userNumber(userNumber)
.early(early)
.notificationStatus(true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

커밋 메세지에는 디폴트값이 false라고 써져있는데 코드 내용은 다른 것 같네요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 커밋 메시지를 잘못썼네요...디폴트 true입니다!

.build();

return newUser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ public interface UserRepository extends JpaRepository<User, Long> {

@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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
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.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;
Expand All @@ -12,6 +14,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;
Expand Down Expand Up @@ -46,7 +49,6 @@ public BaseResponseDto<UserProfileResponse> selectUserProfile(Long userId) {

@Transactional
public BaseResponseDto<Void> deleteProfleImage(Long userId) {

updateProfileImage(userId);
return BaseResponseDto.of(SuccessCode.SUCCESS,null);
}
Expand Down Expand Up @@ -84,6 +86,20 @@ public void initUser(Long userId) {
user.initUser();
}


@Transactional
public void modifyNotification(Long userId, Boolean 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()){

Expand Down
Loading