-
Notifications
You must be signed in to change notification settings - Fork 8
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
[BE] feat: 새로운 FCM 등록 기능 추가 (#998) #1002
Open
seokjin8678
wants to merge
4
commits into
dev
Choose a base branch
from
feat/#998
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
This file contains 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 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
52 changes: 0 additions & 52 deletions
52
backend/src/main/java/com/festago/fcm/application/MemberFCMService.java
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
backend/src/main/java/com/festago/fcm/application/command/MemberFCMCommandService.java
This file contains 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,40 @@ | ||
package com.festago.fcm.application.command; | ||
|
||
import com.festago.fcm.domain.MemberFCM; | ||
import com.festago.fcm.domain.MemberFCMExpiredAtPolicy; | ||
import com.festago.fcm.domain.MemberFCMDeleteOldTokensPolicy; | ||
import com.festago.fcm.repository.MemberFCMRepository; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class MemberFCMCommandService { | ||
|
||
private final MemberFCMRepository memberFCMRepository; | ||
private final MemberFCMExpiredAtPolicy memberFCMExpiredAtPolicy; | ||
private final MemberFCMDeleteOldTokensPolicy memberFCMDeleteOldTokensPolicy; | ||
|
||
// TODO 별도의 Service 클래스 생성해서 비즈니스 로직 이관 생각해 볼 것 | ||
public void registerFCM(Long memberId, String fcmToken) { | ||
List<MemberFCM> memberFCMs = memberFCMRepository.findAllByMemberId(memberId); | ||
LocalDateTime expiredAt = memberFCMExpiredAtPolicy.provide(); | ||
memberFCMs.stream() | ||
.filter(memberFCM -> memberFCM.isSameToken(fcmToken)) | ||
.findAny() | ||
.ifPresentOrElse(memberFCM -> { | ||
memberFCM.changeExpiredAt(expiredAt); | ||
}, () -> { | ||
memberFCMDeleteOldTokensPolicy.delete(memberFCMs); | ||
memberFCMRepository.save(new MemberFCM(memberId, fcmToken, expiredAt)); | ||
}); | ||
} | ||
|
||
public void deleteAllMemberFCM(Long memberId) { | ||
memberFCMRepository.deleteAllByMemberId(memberId); | ||
} | ||
} |
This file contains 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
17 changes: 17 additions & 0 deletions
17
backend/src/main/java/com/festago/fcm/domain/MemberFCMDeleteOldTokensPolicy.java
This file contains 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,17 @@ | ||
package com.festago.fcm.domain; | ||
|
||
import com.festago.fcm.repository.MemberFCMRepository; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class MemberFCMDeleteOldTokensPolicy { | ||
|
||
private final MemberFCMRepository memberFCMRepository; | ||
|
||
public void delete(List<MemberFCM> memberFCMs) { | ||
memberFCMRepository.deleteByIn(memberFCMs); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/com/festago/fcm/domain/MemberFCMExpiredAtPolicy.java
This file contains 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,8 @@ | ||
package com.festago.fcm.domain; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public interface MemberFCMExpiredAtPolicy { | ||
|
||
LocalDateTime provide(); | ||
} |
19 changes: 19 additions & 0 deletions
19
backend/src/main/java/com/festago/fcm/domain/MemberFCMExpiredAtPolicyImpl.java
This file contains 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,19 @@ | ||
package com.festago.fcm.domain; | ||
|
||
import java.time.Clock; | ||
import java.time.LocalDateTime; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class MemberFCMExpiredAtPolicyImpl implements MemberFCMExpiredAtPolicy { | ||
|
||
private static final int EXPIRED_DAY_OFFSET = 180; | ||
private final Clock clock; | ||
|
||
@Override | ||
public LocalDateTime provide() { | ||
return LocalDateTime.now(clock).plusDays(EXPIRED_DAY_OFFSET); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
backend/src/main/java/com/festago/fcm/dto/v1/MemberFCMTokenRegisterV1Request.java
This file contains 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,7 @@ | ||
package com.festago.fcm.dto.v1; | ||
|
||
public record MemberFCMTokenRegisterV1Request( | ||
String fcmToken | ||
) { | ||
|
||
} |
36 changes: 0 additions & 36 deletions
36
backend/src/main/java/com/festago/fcm/presentation/MemberFCMController.java
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
backend/src/main/java/com/festago/fcm/presentation/v1/MemberFCMV1Controller.java
This file contains 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,30 @@ | ||
package com.festago.fcm.presentation.v1; | ||
|
||
import com.festago.auth.annotation.MemberAuth; | ||
import com.festago.auth.domain.authentication.MemberAuthentication; | ||
import com.festago.fcm.application.command.MemberFCMCommandService; | ||
import com.festago.fcm.dto.v1.MemberFCMTokenRegisterV1Request; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/api/v1/fcm") | ||
@RequiredArgsConstructor | ||
public class MemberFCMV1Controller { | ||
|
||
private final MemberFCMCommandService memberFCMCommandService; | ||
|
||
@MemberAuth | ||
@PostMapping | ||
public ResponseEntity<Void> registerFCM( | ||
MemberAuthentication memberAuthentication, | ||
@RequestBody MemberFCMTokenRegisterV1Request request | ||
) { | ||
memberFCMCommandService.registerFCM(memberAuthentication.getId(), request.fcmToken()); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
This file contains 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
Oops, something went wrong.
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.
자문자답인 것 같긴 한데..
보통 2학기에 축제가 9월에 열리니.. 내년 5월에 알림을 받으려면 1년 정도로 하는게 좋을 것 같네요. 😂