Repository navigation
[Feat/#105] 회원 FCM 토큰 등록 API 추가 #106
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| package kr.ac.kookmin.stream.api.app.core.member.request; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.Pattern; | ||
| import jakarta.validation.constraints.Size; | ||
|
|
||
| public record FcmTokenUpdateRequest( | ||
| // FCM 등록 토큰({인스턴스 ID}:APA91b...)과 FID 모두 base64url 문자와 ':'만 쓴다. 길이는 members.fcm_token 컬럼에 맞춘다 | ||
| @NotBlank(message = "FCM 토큰을 입력해 주세요.") | ||
| @Size(max = 255, message = "FCM 토큰은 255자 이하여야 합니다.") | ||
| @Pattern(regexp = "^[A-Za-z0-9_:-]+$", message = "FCM 토큰 형식이 올바르지 않습니다.") | ||
| String fcmToken | ||
| ) {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,6 +83,18 @@ public boolean isSignedUp(Long memberId) { | |
| return isSignedUp(getById(memberId)); | ||
| } | ||
|
|
||
| // 한 기기를 다른 계정으로 쓰게 되면 이전 회원의 알림이 새 사용자에게 가지 않도록, 다른 회원에게 남은 같은 토큰을 지운다. | ||
| // 이미 중복이 들어 있는 데이터도 정리하려고 자기 토큰이 그대로여도 매번 지운다 | ||
| @Override | ||
| @Transactional | ||
| public void updateFcmToken(Long memberId, String fcmToken) { | ||
| Member member = getById(memberId); | ||
| memberRepository.clearFcmTokenOfOthers(memberId, fcmToken); | ||
| if (member.updateFcmToken(fcmToken)) { | ||
| memberRepository.save(member); | ||
|
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. 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift 토큰 변경 시 회원 전체 행을 저장하지 마세요.
🤖 Prompt for AI AgentsSource: Learnings |
||
| } | ||
| } | ||
|
|
||
| // 전화번호와 필수 약관 동의가 모두 있어야 가입을 마친 것으로 본다 | ||
| private boolean isSignedUp(Member member) { | ||
| return member.hasPhoneNumber() && memberTermService.hasAgreedRequiredTerms(member.getId()); | ||
|
|
||
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.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: billilge/stream-server
Length of output: 23942
🏁 Script executed:
Repository: billilge/stream-server
Length of output: 7139
🏁 Script executed:
Repository: billilge/stream-server
Length of output: 9460
동시 등록에서도 FCM 토큰의 단일 소유자를 보장하세요.
updateFcmToken은 회원을 조회한 뒤 다른 회원의 같은 토큰을 삭제하고 현재 회원을 저장합니다. 두 회원이 같은 토큰을 동시에 등록하면 두 bulk update가 저장 전에 끝날 수 있습니다. 현재 스키마에는fcm_token유일성 제약도 없으므로 두 회원이 같은 토큰을 저장할 수 있습니다.토큰 소유권 변경을 직렬화하거나
fcm_token에 유일성 제약을 추가하여 중복 저장을 막으세요.🤖 Prompt for AI Agents