-
Notifications
You must be signed in to change notification settings - Fork 1
feat(#327): 알림 설정 조회 및 수정 기능 추가 #339
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
db9e7dc
feat(#327): 알림 설정 조회 및 수정 기능 추가
ParkJiYeoung8297 37ea041
chore: Merge branch 'dev' of github.com:RealMatchTeam/BE into dev
ParkJiYeoung8297 e1c78b1
Merge branch 'dev' into feat/#327-alarm-notification-setting
ParkJiYeoung8297 43048dd
chore: 자바 체크 스타일 수정
ParkJiYeoung8297 b27581f
chore: Merge branch 'feat/#327-alarm-notification-setting' of github.…
ParkJiYeoung8297 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
src/main/java/com/example/RealMatch/user/application/service/NotificationSettingService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| package com.example.RealMatch.user.application.service; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import com.example.RealMatch.global.exception.CustomException; | ||
| import com.example.RealMatch.user.domain.entity.NotificationSetting; | ||
| import com.example.RealMatch.user.domain.entity.Term; | ||
| import com.example.RealMatch.user.domain.entity.UserTerm; | ||
| import com.example.RealMatch.user.domain.entity.enums.TermName; | ||
| import com.example.RealMatch.user.domain.repository.NotificationSettingRepository; | ||
| import com.example.RealMatch.user.domain.repository.TermRepository; | ||
| import com.example.RealMatch.user.domain.repository.UserTermRepository; | ||
| import com.example.RealMatch.user.presentation.code.UserErrorCode; | ||
| import com.example.RealMatch.user.presentation.dto.request.NotificationSettingUpdateRequest; | ||
| import com.example.RealMatch.user.presentation.dto.response.NotificationSettingResponse; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional | ||
| public class NotificationSettingService { | ||
|
|
||
| private static final TermName MARKETING_TERM_NAME = TermName.MARKETING_CONSENT; | ||
|
|
||
| private final NotificationSettingRepository notificationSettingRepository; | ||
| private final UserTermRepository userTermRepository; | ||
| private final TermRepository termRepository; | ||
|
|
||
| /** | ||
| * 내 알림 설정 조회 | ||
| */ | ||
| @Transactional(readOnly = true) | ||
| public NotificationSettingResponse getMySetting(Long userId) { | ||
|
|
||
| NotificationSetting setting = notificationSettingRepository | ||
| .findOneByUserId(userId) | ||
| .orElseThrow(() -> | ||
| new CustomException(UserErrorCode.USER_NOTIFICATION_SETTING_NOT_FOUND) | ||
| ); | ||
|
|
||
| boolean marketingConsent = userTermRepository | ||
| .findByUserIdAndTermName(userId, MARKETING_TERM_NAME) | ||
| .isPresent(); // ⭐ 존재 여부로 판단 | ||
|
|
||
| return NotificationSettingResponse.builder() | ||
| .marketingConsent(marketingConsent) | ||
| .appPushEnabled(setting.isAppPushEnabled()) | ||
| .emailEnabled(setting.isEmailEnabled()) | ||
| .build(); | ||
| } | ||
|
|
||
| /** | ||
| * 내 알림 설정 수정 (설정 완료) | ||
| */ | ||
| public void updateSetting(Long userId, NotificationSettingUpdateRequest request) { | ||
|
|
||
| // 1️⃣ 알림 설정 업데이트 | ||
| NotificationSetting setting = notificationSettingRepository | ||
| .findOneByUserId(userId) | ||
| .orElseThrow(() -> | ||
| new CustomException(UserErrorCode.USER_NOTIFICATION_SETTING_NOT_FOUND) | ||
| ); | ||
|
|
||
| setting.update( | ||
| request.isAppPushEnabled(), | ||
| request.isEmailEnabled() | ||
| ); | ||
|
|
||
| Optional<UserTerm> optionalUserTerm = | ||
| userTermRepository.findByUserIdAndTermName(userId, MARKETING_TERM_NAME); | ||
|
|
||
| boolean wantMarketingConsent = request.isMarketingConsent(); | ||
|
|
||
| // Case 1: 동의 안 함 → 기존 row 있으면 삭제 | ||
| if (!wantMarketingConsent) { | ||
| optionalUserTerm.ifPresent(userTermRepository::delete); | ||
| return; | ||
| } | ||
|
|
||
| // Case 2: 동의 함 → 기존 row 없으면 생성 | ||
| if (optionalUserTerm.isEmpty()) { | ||
| Term marketingTerm = termRepository | ||
| .findByName(MARKETING_TERM_NAME) | ||
| .orElseThrow(() -> | ||
| new CustomException(UserErrorCode.INVALID_TERM) | ||
| ); | ||
|
|
||
| UserTerm newUserTerm = UserTerm.builder() | ||
| .user(setting.getUser()) | ||
| .term(marketingTerm) | ||
| .isAgreed(true) | ||
| .build(); | ||
|
|
||
| userTermRepository.save(newUserTerm); | ||
| } | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,5 @@ | |
|
|
||
| public enum NotificationChannel { | ||
| PUSH, | ||
| EMAIL, | ||
| SMS | ||
| } | ||
22 changes: 15 additions & 7 deletions
22
src/main/java/com/example/RealMatch/user/domain/entity/enums/TermName.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,19 @@ | ||
| package com.example.RealMatch.user.domain.entity.enums; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public enum TermName { | ||
| AGE, | ||
| SERVICE_TERMS, | ||
| PRIVACY_COLLECTION, | ||
| PRIVACY_THIRD_PARTY, | ||
| MARKETING_CONSENT, | ||
| MARKETING_PRIVACY_COLLECTION, | ||
| MARKETING_NOTIFICATION | ||
|
|
||
| AGE("만 14세 이상입니다"), | ||
| SERVICE_TERMS("서비스 이용약관에 동의합니다"), | ||
| PRIVACY_COLLECTION("개인정보를 수집하고 이용하는 것에 동의합니다"), | ||
| PRIVACY_THIRD_PARTY("개인정보를 제3자에게 제공하는 것에 동의합니다"), | ||
| MARKETING_CONSENT("이벤트 혜택과 광고성 정보 수신에 동의합니다"), | ||
| MARKETING_PRIVACY_COLLECTION("마케팅 목적의 개인정보 수집과 이용에 동의합니다"), | ||
| MARKETING_NOTIFICATION("이메일과 앱 푸시 알림 수신에 동의합니다"); | ||
|
|
||
| private final String displayName; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,4 +9,6 @@ | |
| public interface NotificationSettingRepository extends JpaRepository<NotificationSetting, Long> { | ||
|
|
||
| Optional<NotificationSetting> findByUserId(Long userId); | ||
| Optional<NotificationSetting> findOneByUserId(Long userId); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...ava/com/example/RealMatch/user/presentation/controller/NotificationSettingController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package com.example.RealMatch.user.presentation.controller; | ||
|
|
||
| import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PutMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import com.example.RealMatch.global.config.jwt.CustomUserDetails; | ||
| import com.example.RealMatch.global.presentation.CustomResponse; | ||
| import com.example.RealMatch.user.application.service.NotificationSettingService; | ||
| import com.example.RealMatch.user.presentation.dto.request.NotificationSettingUpdateRequest; | ||
| import com.example.RealMatch.user.presentation.dto.response.NotificationSettingResponse; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/api/v1/users/me/notification-settings") | ||
| @RequiredArgsConstructor | ||
| public class NotificationSettingController { | ||
|
|
||
| private final NotificationSettingService notificationSettingService; | ||
|
|
||
| /** | ||
| * 내 알림 설정 조회 | ||
| */ | ||
| @GetMapping | ||
| public CustomResponse<NotificationSettingResponse> getMyNotificationSetting( | ||
| @AuthenticationPrincipal CustomUserDetails userDetails | ||
| ) { | ||
| return CustomResponse.ok( | ||
| notificationSettingService.getMySetting(userDetails.getUserId()) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * 내 알림 설정 전체 수정 (설정 완료 버튼) | ||
| */ | ||
| @PutMapping | ||
| public CustomResponse<String> updateMyNotificationSetting( | ||
| @AuthenticationPrincipal CustomUserDetails userDetails, | ||
| @RequestBody NotificationSettingUpdateRequest request | ||
| ) { | ||
| notificationSettingService.updateSetting( | ||
| userDetails.getUserId(), | ||
| request | ||
| ); | ||
| return CustomResponse.ok("알림 설정이 수정되었습니다."); | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
...com/example/RealMatch/user/presentation/dto/request/NotificationSettingUpdateRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package com.example.RealMatch.user.presentation.dto.request; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @NoArgsConstructor | ||
| public class NotificationSettingUpdateRequest { | ||
| private boolean marketingConsent; | ||
| private boolean appPushEnabled; | ||
| private boolean emailEnabled; | ||
|
|
||
| } |
14 changes: 14 additions & 0 deletions
14
...ava/com/example/RealMatch/user/presentation/dto/response/NotificationSettingResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package com.example.RealMatch.user.presentation.dto.response; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| @Builder | ||
| public class NotificationSettingResponse { | ||
| private boolean marketingConsent; | ||
| private boolean appPushEnabled; | ||
| private boolean emailEnabled; | ||
|
|
||
| } | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
마케팅 수신 동의 여부를 처리하는 로직이
return을 사용하여 두 부분으로 나뉘어 있어 흐름을 파악하기 다소 어렵습니다.if-else if구조를 사용하여 동의/비동의 케이스를 명확하게 분리하면 가독성을 높일 수 있습니다.