Skip to content

Commit

Permalink
feat: 알림 토큰 엔티티를 직접 수정하도록 변경
Browse files Browse the repository at this point in the history
Related-to : #40
  • Loading branch information
ji-woong-song committed Apr 5, 2024
1 parent d35b995 commit 0c7e6bd
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 32 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.umc5th.muffler.domain.member.repository;

import com.umc5th.muffler.entity.MemberAlarm;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface MemberAlarmRepository extends JpaRepository<MemberAlarm, Long> {
@Query("select ma from MemberAlarm ma where ma.member.id = :memberId")
Optional<MemberAlarm> findByMemberId(@Param("memberId") String memberId);
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.umc5th.muffler.domain.member.dto.AlarmAgreeUpdateRequest;
import com.umc5th.muffler.domain.member.dto.AlarmAgreementResponse;
import com.umc5th.muffler.domain.member.dto.MemberConverter;
import com.umc5th.muffler.domain.member.dto.TokenEnrollRequest;
import com.umc5th.muffler.domain.member.repository.MemberAlarmRepository;
import com.umc5th.muffler.domain.member.repository.MemberRepository;
import com.umc5th.muffler.entity.Member;
import com.umc5th.muffler.entity.MemberAlarm;
Expand All @@ -17,27 +17,30 @@
@RequiredArgsConstructor
public class MemberAlarmService {
private final MemberRepository memberRepository;
private final MemberAlarmRepository memberAlarmRepository;

@Transactional
public void fetchAlarmAgree(String memberId, AlarmAgreeUpdateRequest request) {
Member member = memberRepository.findMemberFetchAlarm(memberId)
MemberAlarm memberAlarm = memberAlarmRepository.findByMemberId(memberId)
.orElseThrow(() -> new MemberException(ErrorCode.MEMBER_NOT_FOUND));
member = MemberConverter.toEntity(member, request);
memberRepository.save(member);
memberAlarm.setIsDailyPlanRemindAgree(request.getDailyPlanRemindAgree());
memberAlarm.setIsTodayEnrollRemindAgree(request.getTodayEnrollRemindAgree());
memberAlarm.setIsGoalEndReportRemindAgree(request.getGoalEndRemindAgree());
memberAlarm.setIsYesterdayEnrollRemindAgree(request.getYesterdayEnrollRemindAgree());
}

@Transactional
public void enrollAlarmToken(String memberId, TokenEnrollRequest request) {
Member member = memberRepository.findMemberFetchAlarm(memberId)
MemberAlarm memberAlarm = memberAlarmRepository.findByMemberId(memberId)
.orElseThrow(() -> new MemberException(ErrorCode.MEMBER_NOT_FOUND));
member.enrollToken(request.getToken());
memberAlarm.enrollToken(request.getToken());
}

@Transactional
public void deleteAlarmToken(String memberId) {
Member member = memberRepository.findMemberFetchAlarm(memberId)
MemberAlarm memberAlarm = memberAlarmRepository.findByMemberId(memberId)
.orElseThrow(() -> new MemberException(ErrorCode.MEMBER_NOT_FOUND));
member.deleteToken();
memberAlarm.deleteToken();
}

@Transactional(readOnly = true)
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/umc5th/muffler/entity/MemberAlarm.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import lombok.*;
import org.hibernate.annotations.ColumnDefault;
import org.hibernate.annotations.DynamicInsert;

Expand All @@ -31,18 +28,22 @@ public class MemberAlarm extends BaseTimeEntity {

@Column(nullable = false)
@ColumnDefault("true")
@Setter
private Boolean isDailyPlanRemindAgree;

@Column(nullable = false)
@ColumnDefault("true")
@Setter
private Boolean isTodayEnrollRemindAgree;

@Column(nullable = false)
@ColumnDefault("true")
@Setter
private Boolean isYesterdayEnrollRemindAgree;

@Column(nullable = false)
@ColumnDefault("true")
@Setter
private Boolean isGoalEndReportRemindAgree;

@OneToOne(mappedBy = "memberAlarm")
Expand Down

0 comments on commit 0c7e6bd

Please sign in to comment.