-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: FCM 알림 기능 #86
Open
wonslee
wants to merge
14
commits into
develop
Choose a base branch
from
feature/notification
base: develop
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
feat: FCM 알림 기능 #86
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
aba9622
chore: gitignore firebase key file
wonslee 914c0d9
Merge branch 'develop' into feature/notification
wonslee ce3608d
chore: gitignore spy.log
wonslee 0f9f7e6
chore: gitignore spy.log
wonslee aeeeaa3
chore: fcm 의존성 추가
wonslee c9d7693
feat: fcm 초기 설정
wonslee af14da1
Merge branch 'develop' into feature/notification
wonslee a79d062
feat: Notification 엔티티 컬럼 수정
wonslee 9c03483
feat: FCM 알림 전송 로직
wonslee a651897
feat: 댓글 작성시 FCM 알림 전송
wonslee 7eb193c
fix: Notification id 컬럼명 수정
wonslee 1f68243
feat: 나의 알림 리스트 조회
wonslee 8b990b0
feat: 알림 읽음 처리
wonslee cfb688c
style: remove unused import statements
wonslee 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
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
37 changes: 37 additions & 0 deletions
37
.../java/com/shy_polarbear/server/domain/notification/controller/NotificationController.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,37 @@ | ||
package com.shy_polarbear.server.domain.notification.controller; | ||
|
||
import com.shy_polarbear.server.domain.notification.dto.NotificationReadResponse; | ||
import com.shy_polarbear.server.domain.notification.dto.NotificationResponse; | ||
import com.shy_polarbear.server.domain.notification.service.NotificationService; | ||
import com.shy_polarbear.server.global.auth.security.PrincipalDetails; | ||
import com.shy_polarbear.server.global.common.dto.ApiResponse; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/notifications") | ||
public class NotificationController { | ||
private final NotificationService notificationService; | ||
|
||
@GetMapping("/users/me") | ||
public ApiResponse<List<NotificationResponse>> getMyNotifications( | ||
@AuthenticationPrincipal PrincipalDetails principalDetails) { | ||
return ApiResponse.success(notificationService.getMyNotifications(principalDetails.getUser().getId())); | ||
} | ||
|
||
@PutMapping("/{notificationId}/read") | ||
public ApiResponse<NotificationReadResponse> readNotification( | ||
@PathVariable Long notificationId, | ||
@AuthenticationPrincipal PrincipalDetails principalDetails) { | ||
return ApiResponse.success( | ||
notificationService.readNotification(notificationId, principalDetails.getUser().getId()) | ||
); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/shy_polarbear/server/domain/notification/dto/NotificationReadResponse.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,15 @@ | ||
package com.shy_polarbear.server.domain.notification.dto; | ||
|
||
import com.shy_polarbear.server.domain.notification.model.Notification; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record NotificationReadResponse ( | ||
Long notificationId | ||
){ | ||
public static NotificationReadResponse of(Notification notification) { | ||
return NotificationReadResponse.builder() | ||
.notificationId(notification.getId()) | ||
.build(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/shy_polarbear/server/domain/notification/dto/NotificationResponse.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,33 @@ | ||
package com.shy_polarbear.server.domain.notification.dto; | ||
|
||
import com.shy_polarbear.server.domain.notification.model.Notification; | ||
import com.shy_polarbear.server.domain.notification.model.NotificationType; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record NotificationResponse ( | ||
Long notificationId, | ||
NotificationType notificationType, | ||
String redirectTarget, | ||
Long redirectTargetId, | ||
String title, | ||
String content, | ||
String createdDate, | ||
boolean isRead | ||
){ | ||
public static NotificationResponse of(Notification notification) { | ||
NotificationType notificationType = notification.getNotificationType(); | ||
String target = notificationType.getRedirectTargetClass().getSimpleName(); | ||
|
||
return NotificationResponse.builder() | ||
.notificationId(notification.getId()) | ||
.notificationType(notificationType) | ||
.redirectTarget(target) | ||
.redirectTargetId(notification.getRedirectTargetId()) | ||
.title(notification.getTitle()) | ||
.content(notification.getContent()) | ||
.createdDate(notification.getCreatedDate()) | ||
.isRead(notification.isRead()) | ||
.build(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...in/java/com/shy_polarbear/server/domain/notification/exception/NotificationException.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,11 @@ | ||
package com.shy_polarbear.server.domain.notification.exception; | ||
|
||
import com.shy_polarbear.server.global.exception.CustomException; | ||
import com.shy_polarbear.server.global.exception.ExceptionStatus; | ||
|
||
public class NotificationException extends CustomException { | ||
public NotificationException(ExceptionStatus exceptionStatus) { | ||
super(exceptionStatus); | ||
} | ||
|
||
} |
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
5 changes: 5 additions & 0 deletions
5
...ain/java/com/shy_polarbear/server/domain/notification/model/NotificationReceiverType.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,5 @@ | ||
package com.shy_polarbear.server.domain.notification.model; | ||
|
||
enum NotificationReceiverType { | ||
COMMON, AUTHOR | ||
} |
15 changes: 14 additions & 1 deletion
15
src/main/java/com/shy_polarbear/server/domain/notification/model/NotificationType.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 |
---|---|---|
@@ -1,5 +1,18 @@ | ||
package com.shy_polarbear.server.domain.notification.model; | ||
|
||
import com.shy_polarbear.server.domain.comment.model.Comment; | ||
import com.shy_polarbear.server.domain.feed.model.Feed; | ||
import com.shy_polarbear.server.global.common.model.BaseEntity; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Getter | ||
public enum NotificationType { | ||
COMMENT, CHILD_COMMENT, LIMIT | ||
NEW_FEED_COMMENT(NotificationReceiverType.AUTHOR, Feed.class), | ||
NEW_COMMENT_CHILD_COMMENT(NotificationReceiverType.AUTHOR, Feed.class); | ||
// LIMIT(NotificationReceiverType.COMMON, User.class); | ||
|
||
private final NotificationReceiverType notificationReceiverType; | ||
private final Class<? extends BaseEntity> redirectTargetClass; | ||
} |
8 changes: 8 additions & 0 deletions
8
.../java/com/shy_polarbear/server/domain/notification/repository/NotificationRepository.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.shy_polarbear.server.domain.notification.repository; | ||
|
||
import com.shy_polarbear.server.domain.notification.model.Notification; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface NotificationRepository extends JpaRepository<Notification, Long>, NotificationRepositoryCustom { | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...com/shy_polarbear/server/domain/notification/repository/NotificationRepositoryCustom.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,14 @@ | ||
package com.shy_polarbear.server.domain.notification.repository; | ||
|
||
import com.shy_polarbear.server.domain.notification.model.Notification; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface NotificationRepositoryCustom { | ||
// 특정 알림 조회 | ||
Optional<Notification> findByIdAndReceiverId(Long notificationId, Long receiverId); | ||
|
||
// 내 알림 조회 | ||
List<Notification> findAllByReceiverId(Long userId); | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...a/com/shy_polarbear/server/domain/notification/repository/NotificationRepositoryImpl.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,35 @@ | ||
package com.shy_polarbear.server.domain.notification.repository; | ||
|
||
import static com.shy_polarbear.server.domain.notification.model.QNotification.notification; | ||
|
||
import com.querydsl.jpa.impl.JPAQuery; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import com.shy_polarbear.server.domain.notification.model.Notification; | ||
import com.shy_polarbear.server.global.common.constants.BusinessLogicConstants; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
public class NotificationRepositoryImpl implements NotificationRepositoryCustom { | ||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public List<Notification> findAllByReceiverId(Long userId) { | ||
JPAQuery<Notification> query = queryFactory.selectFrom(notification) | ||
.where(notification.receiver.id.eq(userId)) | ||
.orderBy(notification.id.desc()) | ||
.limit(BusinessLogicConstants.RECENT_NOTIFICATION_LIMIT); | ||
|
||
return query.fetch(); | ||
} | ||
|
||
@Override | ||
public Optional<Notification> findByIdAndReceiverId(Long notificationId, Long receiverId) { | ||
JPAQuery<Notification> query = queryFactory.selectFrom(notification) | ||
.where(notification.id.eq(notificationId) | ||
.and(notification.receiver.id.eq(receiverId))); | ||
return Optional.ofNullable(query.fetchOne()); | ||
} | ||
|
||
} |
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.
알림 받는 사람이 왜 받는지 쉽게 알게 하려고 enum 만드신거 맞죠!?