-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/26 notification #29
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 all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
1045338
feat: FCM ์๋ฒ ์ด๊ธฐํ ๋ฐ ์ฐ๊ฒฐ
316bff2
feat: Fcm, APNS Config ์ค์
7c0393e
feat: FCM Token ๊ด๋ฆฌ ๊ธฐ๋ฅ
00db9fb
feat: ์๋ฆผ ์์ฒญ Dto
09e2908
feat: FCM์๋ฒ๋ก ๋ฉ์์ง ์ ์ก
14f4ac8
chore: ์๋ฌ ์ฝ๋ ์ ๋ฆฌ, ์ถ๊ฐ
8ae5ce7
feat: notification์ ์๋ฆผ ํ์คํ ๋ฆฌ ๊ธฐ๋ก
57cf92c
feat: Facade๋ก ๋ถ๋ฆฌํด ์๋น์ค ์ฒ๋ฆฌ
6a83c21
feat: ์๋ฆผ ๋ฉ์์ง ์์ฑ ๋ก์ง
4005cbc
feat: ์๋ฆผ ํ์
Enum
afb29c2
chore: ํจํค์ง ์ด๋ฆ ๋ณ๊ฒฝ
949c2ec
chore: dto ์ ๋ฆฌ
b63056d
feat: party ์๋ฆผ ๊ธฐ๋ฅ
4e39954
feat: chat ์๋ฆผ ๊ธฐ๋ฅ, title๋ ์๋ฆผ ํ
์ด๋ธ์ ํฌํจ๋๊ฒ ์์
f5e4606
chore: ํฌํผ ๋ฉ์๋ ์ค๋ณต ๋ถ๋ฆฌ
13dddd2
feat: FCM ์๋ต ๊ธฐ๋ฐ ํ ํฐ ๋นํ์ฑํ ์ฒ๋ฆฌ
c9d1c76
feat: ๋นํ์ฑํ ํฐ ์ค์ผ์ค๋ฌ ์ญ์ ์ฒ๋ฆฌ
6438f78
chore: ํจํค์ง ๊ตฌ์กฐ ์ ๋ฆฌ
ddb6905
chore: fcm ํ๊ฒฝ ์ค์
3d75048
fix: ๋ฆฌ๋ทฐ ๋ฐ์
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 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
29 changes: 29 additions & 0 deletions
29
src/main/java/ita/tinybite/domain/notification/controller/FcmTokenController.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,29 @@ | ||
| package ita.tinybite.domain.notification.controller; | ||
|
|
||
| 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.RequestHeader; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| import ita.tinybite.domain.notification.dto.request.FcmTokenRequest; | ||
| import ita.tinybite.domain.notification.service.FcmTokenService; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/v1/fcm") | ||
| public class FcmTokenController { | ||
|
|
||
| private final FcmTokenService fcmTokenService; | ||
|
|
||
| // token ์ด๋ฏธ ์กด์ฌ ์ ์ ๋ฐ์ดํธ ํด์ค | ||
| @PostMapping("/token") | ||
| public ResponseEntity<Void> registerToken(@RequestBody @Valid FcmTokenRequest request, | ||
| @RequestHeader(name = "User-ID") Long currentUserId) { | ||
| fcmTokenService.saveOrUpdateToken(currentUserId, request.token()); | ||
| return ResponseEntity.noContent().build(); | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
src/main/java/ita/tinybite/domain/notification/converter/NotificationLogConverter.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,23 @@ | ||
| package ita.tinybite.domain.notification.converter; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import ita.tinybite.domain.notification.entity.Notification; | ||
| import ita.tinybite.domain.notification.enums.NotificationType; | ||
|
|
||
| @Component | ||
| public class NotificationLogConverter { | ||
|
|
||
| public Notification toEntity(Long targetUserId, String type, String title,String detail) { | ||
|
|
||
| NotificationType notificationType = NotificationType.valueOf(type); | ||
|
|
||
| return Notification.builder() | ||
| .userId(targetUserId) | ||
| .notificationType(notificationType) | ||
| .notificationTitle(title) | ||
| .notificationDetail(detail) | ||
| .isRead(false) | ||
| .build(); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
src/main/java/ita/tinybite/domain/notification/converter/NotificationRequestConverter.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,26 @@ | ||
| package ita.tinybite.domain.notification.converter; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import ita.tinybite.domain.notification.dto.request.NotificationMulticastRequest; | ||
|
|
||
| @Component | ||
| public class NotificationRequestConverter { | ||
|
|
||
| public NotificationMulticastRequest toMulticastRequest( | ||
| List<String> tokens, | ||
| String title, | ||
| String body, | ||
| Map<String, String> data) { | ||
|
|
||
| return NotificationMulticastRequest.builder() | ||
| .tokens(tokens) | ||
| .title(title) | ||
| .body(body) | ||
| .data(data) | ||
| .build(); | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
src/main/java/ita/tinybite/domain/notification/dto/request/FcmTokenRequest.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,8 @@ | ||
| package ita.tinybite.domain.notification.dto.request; | ||
|
|
||
| import jakarta.validation.constraints.NotNull; | ||
|
|
||
| public record FcmTokenRequest( | ||
| @NotNull(message = "FCM ํ ํฐ์ ํ์์ ๋๋ค.") | ||
| String token | ||
| ) {} |
43 changes: 43 additions & 0 deletions
43
src/main/java/ita/tinybite/domain/notification/dto/request/NotificationMulticastRequest.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,43 @@ | ||
| package ita.tinybite.domain.notification.dto.request; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import com.google.firebase.internal.NonNull; | ||
| import com.google.firebase.messaging.MulticastMessage; | ||
| import com.google.firebase.messaging.Notification; | ||
|
|
||
| import lombok.Builder; | ||
|
|
||
| @Builder | ||
| public record NotificationMulticastRequest( | ||
| @NonNull List<String> tokens, | ||
| String title, | ||
| String body, | ||
| Map<String, String> data | ||
| ) implements NotificationRequest { | ||
|
|
||
| public MulticastMessage.Builder buildSendMessage() { | ||
| MulticastMessage.Builder builder = MulticastMessage.builder() | ||
| .setNotification(toNotification()) | ||
| .addAllTokens(tokens); | ||
|
|
||
| if (this.data != null && !this.data.isEmpty()) { | ||
| builder.putAllData(this.data); | ||
| } | ||
|
|
||
| return builder; | ||
| } | ||
|
|
||
| public Notification toNotification() { | ||
| return Notification.builder() | ||
| .setTitle(title) | ||
| .setBody(body) | ||
| .build(); | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, String> data() { | ||
| return this.data; | ||
| } | ||
| } |
12 changes: 12 additions & 0 deletions
12
src/main/java/ita/tinybite/domain/notification/dto/request/NotificationRequest.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,12 @@ | ||
| package ita.tinybite.domain.notification.dto.request; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import com.google.firebase.messaging.Notification; | ||
|
|
||
| public interface NotificationRequest { | ||
| String title(); | ||
| String body(); | ||
| Notification toNotification(); | ||
| Map<String, String> data(); | ||
| } |
42 changes: 42 additions & 0 deletions
42
src/main/java/ita/tinybite/domain/notification/dto/request/NotificationSingleRequest.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,42 @@ | ||
| package ita.tinybite.domain.notification.dto.request; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import com.google.firebase.internal.NonNull; | ||
| import com.google.firebase.messaging.Message; | ||
| import com.google.firebase.messaging.Notification; | ||
|
|
||
| import lombok.Builder; | ||
|
|
||
| @Builder | ||
| public record NotificationSingleRequest( | ||
| @NonNull String token, | ||
| String title, | ||
| String body, | ||
| Map<String, String> data | ||
| ) implements NotificationRequest { | ||
|
|
||
| public Message.Builder buildMessage() { | ||
| Message.Builder builder = Message.builder() | ||
| .setToken(token) | ||
| .setNotification(toNotification()); | ||
|
|
||
| if (this.data != null && !this.data.isEmpty()) { | ||
| builder.putAllData(this.data); | ||
| } | ||
|
|
||
| return builder; | ||
| } | ||
|
|
||
| public Notification toNotification() { | ||
| return Notification.builder() | ||
| .setTitle(title) | ||
| .setBody(body) | ||
| .build(); | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, String> data() { | ||
| return this.data; | ||
| } | ||
| } |
42 changes: 42 additions & 0 deletions
42
src/main/java/ita/tinybite/domain/notification/entity/FcmToken.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,42 @@ | ||
| package ita.tinybite.domain.notification.entity; | ||
|
|
||
| import ita.tinybite.global.entity.BaseEntity; | ||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.Table; | ||
| import lombok.AccessLevel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @AllArgsConstructor | ||
| @Table(name = "fcm_tokens") | ||
| public class FcmToken extends BaseEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(name = "user_id", nullable = false) | ||
| private Long userId; | ||
|
|
||
| @Column(name = "token", nullable = false) | ||
| private String token; | ||
|
|
||
| @Builder.Default | ||
| @Column(name = "is_active", nullable = false) | ||
| private Boolean isActive = Boolean.TRUE; | ||
|
|
||
| public void updateToken(String newToken) { | ||
| this.token = newToken; | ||
| this.isActive = Boolean.TRUE; | ||
| } | ||
| } | ||
54 changes: 54 additions & 0 deletions
54
src/main/java/ita/tinybite/domain/notification/entity/Notification.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,54 @@ | ||
| package ita.tinybite.domain.notification.entity; | ||
|
|
||
| import ita.tinybite.domain.notification.enums.NotificationType; | ||
| import ita.tinybite.global.entity.BaseEntity; | ||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.EnumType; | ||
| import jakarta.persistence.Enumerated; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.Table; | ||
| import lombok.AccessLevel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Entity | ||
| @Getter | ||
| @Builder | ||
| @NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
| @AllArgsConstructor | ||
| @Table(name = "notification") | ||
| public class Notification extends BaseEntity { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @Column(name = "id") | ||
| private Long id; | ||
|
|
||
| @Column(name = "user_id", nullable = false) | ||
| private Long userId; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| @Column(name = "notification_type", nullable = false) | ||
| private NotificationType notificationType; | ||
|
|
||
| @Column(name = "notification_title", nullable = false) | ||
| private String notificationTitle; | ||
|
|
||
| @Column(name = "notification_detail", columnDefinition = "TEXT") | ||
| private String notificationDetail; | ||
|
|
||
| @Builder.Default | ||
| @Column(name = "is_read", nullable = false) | ||
| private Boolean isRead = Boolean.FALSE; | ||
|
|
||
| public void markAsRead() { | ||
| if (Boolean.FALSE.equals(this.isRead)) { | ||
| this.isRead = Boolean.TRUE; | ||
| } | ||
| } | ||
| } |
32 changes: 32 additions & 0 deletions
32
src/main/java/ita/tinybite/domain/notification/enums/NotificationType.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,32 @@ | ||
| package ita.tinybite.domain.notification.enums; | ||
|
|
||
| import lombok.AccessLevel; | ||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor(access = AccessLevel.PROTECTED) | ||
| public enum NotificationType { | ||
| // ์ฑํ | ||
| CHAT_NEW_MESSAGE, | ||
| CHAT_UNREAD_REMINDER, | ||
|
|
||
| // ํํฐ ์ฐธ์ฌ | ||
| PARTY_APPROVAL, | ||
| PARTY_REJECTION, | ||
| PARTY_AUTO_CLOSE, | ||
| PARTY_ORDER_COMPLETE, | ||
| PARTY_DELIVERY_REMINDER, | ||
| PARTY_COMPLETE, | ||
|
|
||
| // ํํฐ ์ด์ | ||
| PARTY_NEW_REQUEST, | ||
| PARTY_MEMBER_LEAVE, | ||
| PARTY_MANAGER_DELIVERY_REMINDER, | ||
|
|
||
| // ๋ง์ผํ ์๋ฆผ | ||
| MARKETING_LOCAL_NEW_PARTY, | ||
| MARKETING_WEEKLY_POPULAR, | ||
| MARKETING_PROMOTION_EVENT; | ||
|
|
||
| } |
32 changes: 32 additions & 0 deletions
32
src/main/java/ita/tinybite/domain/notification/infra/creator/APNsConfigCreator.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,32 @@ | ||
| package ita.tinybite.domain.notification.infra.creator; | ||
|
|
||
| import com.google.firebase.messaging.ApnsConfig; | ||
| import com.google.firebase.messaging.Aps; | ||
|
|
||
| import lombok.AccessLevel; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
| public class APNsConfigCreator { | ||
|
|
||
| public static ApnsConfig createDefaultConfig() { | ||
| return ApnsConfig.builder() | ||
| .setAps(Aps.builder() | ||
| .setSound("default") | ||
| .setBadge(1) | ||
| .build() | ||
| ) | ||
| .build(); | ||
| } | ||
|
|
||
| // ์ด๋ฒคํธ๋ณ๋ก ๋์ ์ธ ๋ฑ์ง ์ซ์ ์ค์ | ||
| public static ApnsConfig createConfigWithBadge(int badgeCount) { | ||
| return ApnsConfig.builder() | ||
| .setAps(Aps.builder() | ||
| .setSound("default") | ||
| .setBadge(badgeCount) | ||
| .build() | ||
| ) | ||
| .build(); | ||
| } | ||
| } |
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.
๐ ๏ธ Refactor suggestion | ๐ Major
ํ ํฐ ๋นํ์ฑํ๋ฅผ ์ํ ๋ฉ์๋๋ฅผ ์ถ๊ฐํ์ธ์.
updateToken์ ํ ํฐ์ ํญ์ ํ์ฑํํ์ง๋ง, ๋ฐ๋ ๋์์ ์ํํ๋ ๋ฉ์๋๊ฐ ์์ต๋๋ค. PR ์ค๋ช ์ ๋ฐ๋ฅด๋ฉด NotificationTransactionHelper๊ฐ ์ ํจํ์ง ์์ ํ ํฐ์ ๋นํ์ฑํํ๋ค๊ณ ๋ช ์๋์ด ์์ผ๋ฏ๋ก, ์ํฐํฐ์ ๋ช ์์ ์ธ ๋นํ์ฑํ ๋ฉ์๋๋ฅผ ์ถ๊ฐํ๋ ๊ฒ์ด ์ข์ต๋๋ค.public void updateToken(String newToken) { this.token = newToken; this.isActive = Boolean.TRUE; } + + public void markInactive() { + this.isActive = Boolean.FALSE; + }๐ค Prompt for AI Agents