Skip to content
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
34 changes: 34 additions & 0 deletions src/main/java/com/example/RealMatch/oauth/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
import com.example.RealMatch.oauth.dto.request.SignupCompleteRequest;
import com.example.RealMatch.user.application.util.NicknameValidator;
import com.example.RealMatch.user.domain.entity.ContentCategory;
import com.example.RealMatch.user.domain.entity.NotificationSetting;
import com.example.RealMatch.user.domain.entity.SignupPurpose;
import com.example.RealMatch.user.domain.entity.Term;
import com.example.RealMatch.user.domain.entity.User;
import com.example.RealMatch.user.domain.entity.UserContentCategory;
import com.example.RealMatch.user.domain.entity.UserSignupPurpose;
import com.example.RealMatch.user.domain.entity.UserTerm;
import com.example.RealMatch.user.domain.entity.enums.Role;
import com.example.RealMatch.user.domain.entity.enums.TermName;
import com.example.RealMatch.user.domain.repository.ContentCategoryRepository;
import com.example.RealMatch.user.domain.repository.NotificationSettingRepository;
import com.example.RealMatch.user.domain.repository.SignupPurposeRepository;
import com.example.RealMatch.user.domain.repository.TermRepository;
import com.example.RealMatch.user.domain.repository.UserContentCategoryRepository;
Expand All @@ -43,6 +46,7 @@ public class AuthService {
private final UserContentCategoryRepository userContentCategoryRepository;
private final JwtProvider jwtProvider;
private final NicknameValidator nicknameValidator;
private final NotificationSettingRepository notificationSettingRepository;

public OAuthTokenResponse completeSignup(Long userId, String providerId, SignupCompleteRequest request) {
// 유저 조회
Expand Down Expand Up @@ -74,6 +78,9 @@ public OAuthTokenResponse completeSignup(Long userId, String providerId, SignupC
// 콘텐츠 카테고리 저장
saveContentCategories(user, request.contentCategoryIds());

// 마케팅 알림 동의 시 알림 설정 처리
handleNotificationSettings(user, request.terms());

String currentRole = user.getRole().name();

String accessToken = jwtProvider.createAccessToken(user.getId(), providerId, currentRole, user.getEmail());
Expand Down Expand Up @@ -182,4 +189,31 @@ private void saveContentCategories(User user, List<Long> contentCategoryIds) {
userContentCategoryRepository.saveAll(userContentCategories);
}
}

/**
* 마케팅 알림 동의 시 알림 설정 생성/업데이트
*/
private void handleNotificationSettings(
User user,
List<SignupCompleteRequest.TermAgreementDto> terms
) {
boolean marketingNotificationAgreed = terms.stream()
.anyMatch(term ->
term.type() == TermName.MARKETING_NOTIFICATION
&& term.agreed()
);

NotificationSetting notificationSetting =
notificationSettingRepository.findByUserId(user.getId())
.orElseGet(() -> NotificationSetting.builder()
.user(user)
.build());

notificationSetting.update(
marketingNotificationAgreed,
marketingNotificationAgreed
);

notificationSettingRepository.save(notificationSetting);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package com.example.RealMatch.user.domain.entity;

import com.example.RealMatch.global.common.BaseEntity;
import com.example.RealMatch.user.domain.entity.enums.NotificationChannel;
import com.example.RealMatch.user.domain.entity.enums.NotificationType;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.Builder;
Expand All @@ -30,34 +26,29 @@ public class NotificationSetting extends BaseEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false)
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id", nullable = false, unique = true)
private User user;

@Enumerated(EnumType.STRING)
@Column(length = 30)
private NotificationType type;
@Column(name = "app_push_enabled", nullable = false)
private boolean appPushEnabled;

@Enumerated(EnumType.STRING)
@Column(length = 30)
private NotificationChannel channel;

@Column(name = "is_enabled", nullable = false)
private boolean isEnabled;
@Column(name = "email_enabled", nullable = false)
private boolean emailEnabled;

@Builder
public NotificationSetting(User user, NotificationType type, NotificationChannel channel, boolean isEnabled) {
public NotificationSetting(
User user,
boolean appPushEnabled,
boolean emailEnabled
) {
this.user = user;
this.type = type;
this.channel = channel;
this.isEnabled = isEnabled;
}

public void enable() {
this.isEnabled = true;
this.appPushEnabled = appPushEnabled;
this.emailEnabled = emailEnabled;
}

public void disable() {
this.isEnabled = false;
public void update(boolean appPushEnabled, boolean emailEnabled) {
this.appPushEnabled = appPushEnabled;
this.emailEnabled = emailEnabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public enum TermName {
SERVICE_TERMS,
PRIVACY_COLLECTION,
PRIVACY_THIRD_PARTY,
MARKETING_CONSENT,
MARKETING_PRIVACY_COLLECTION,
MARKETING_NOTIFICATION
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
package com.example.RealMatch.user.domain.repository;

import java.util.List;
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;

import com.example.RealMatch.user.domain.entity.NotificationSetting;
import com.example.RealMatch.user.domain.entity.enums.NotificationChannel;
import com.example.RealMatch.user.domain.entity.enums.NotificationType;

public interface NotificationSettingRepository extends JpaRepository<NotificationSetting, Long> {

List<NotificationSetting> findByUserId(Long userId);

Optional<NotificationSetting> findByUserIdAndTypeAndChannel(Long userId, NotificationType type, NotificationChannel channel);

List<NotificationSetting> findByUserIdAndIsEnabled(Long userId, boolean isEnabled);
Optional<NotificationSetting> findByUserId(Long userId);
}
Loading