-
Notifications
You must be signed in to change notification settings - Fork 1
[FEAT] 알림 토큰 생성, 삭제 API 구현 #296
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 10 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
0146241
chore : FCM 의존성 추가
Daae-Kim 8d45b9c
remove : fcmEntity 삭제
Daae-Kim 887c07e
feat : memberPushTokenEntity, model 생성
Daae-Kim c0e3f7d
feat : 알림 provider enum 생성, 제공자 NotFound 예외 추가
Daae-Kim 1073813
feat : 알림토큰 삭제 권한, not found 예외 작성
Daae-Kim 2afc1cc
feat : request dto, controller, swagger 구현
Daae-Kim 4f5f7ff
feat : usecase, model, converter, service 구현
Daae-Kim 8ddd568
feat : entity, repository, jpaRepository 구현
Daae-Kim aa4fcd5
chore : notification api security 체인 등록
Daae-Kim b7c8b39
chore : spotless apply
Daae-Kim 82642b7
refactor : NotBlank 사용
Daae-Kim 4b61f34
refactor : 불필요한 component 삭제
Daae-Kim bb95894
refactor : status, 에러메세지 수정
Daae-Kim 8890a5f
refactor : unique 제약조건 추가
Daae-Kim 412629b
refactor : 패키지 오타 수정
Daae-Kim ae39fe3
refactor : 패키지 오타 수정
Daae-Kim df6033f
refactor : sl4j 삭제, delete 반환값 void 변경
Daae-Kim 711cc76
chore : spotlessApply
Daae-Kim 99acb17
feat : lastActiveAt 필드 추가
Daae-Kim ee5b4d7
feat : 토큰 생성 로직 수정
Daae-Kim f568b5e
chore : spotlessApply
Daae-Kim a6a5df2
refactor : 중복 토큰 조회 메서드 수정
Daae-Kim 17bafe1
chore : spotlessApply
Daae-Kim 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
Some comments aren't visible on the classic Files Changed page.
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
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
16 changes: 16 additions & 0 deletions
16
...java/com/blackcompany/eeos/notification/application/dto/CreateMemberPushTokenRequest.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,16 @@ | ||
| package com.blackcompany.eeos.notification.application.dto; | ||
|
|
||
| import jakarta.validation.constraints.NotNull; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @Builder(toBuilder = true) | ||
| public class CreateMemberPushTokenRequest { | ||
| @NotNull private String pushToken; | ||
| @NotNull private String provider; | ||
| } | ||
15 changes: 15 additions & 0 deletions
15
...java/com/blackcompany/eeos/notification/application/dto/DeleteMemberPushTokenRequest.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,15 @@ | ||
| package com.blackcompany.eeos.notification.application.dto; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| @Builder(toBuilder = true) | ||
| public class DeleteMemberPushTokenRequest { | ||
| @NotBlank private String pushToken; | ||
| } | ||
Daae-Kim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
17 changes: 17 additions & 0 deletions
17
.../blackcompany/eeos/notification/application/exception/DeniedDeletePushTokenException.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,17 @@ | ||
| package com.blackcompany.eeos.notification.application.exception; | ||
|
|
||
| import com.blackcompany.eeos.common.exception.BusinessException; | ||
| import org.springframework.http.HttpStatus; | ||
|
|
||
| public class DeniedDeletePushTokenException extends BusinessException { | ||
| private static final String FAIL_CODE = "5008"; | ||
|
|
||
| public DeniedDeletePushTokenException() { | ||
| super(FAIL_CODE, HttpStatus.UNAUTHORIZED); | ||
| } | ||
|
|
||
| @Override | ||
| public String getMessage() { | ||
| return "토큰 수정 권한이 없습니다."; | ||
| } | ||
| } | ||
Daae-Kim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
20 changes: 20 additions & 0 deletions
20
...ompany/eeos/notification/application/exception/NotFoundNotificationProviderException.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,20 @@ | ||
| package com.blackcompany.eeos.notification.application.exception; | ||
|
|
||
| import com.blackcompany.eeos.common.exception.BusinessException; | ||
| import org.springframework.http.HttpStatus; | ||
|
|
||
| public class NotFoundNotificationProviderException extends BusinessException { | ||
|
|
||
| private static final String FAIL_CODE = "5006"; | ||
| private final String provider; | ||
|
|
||
| public NotFoundNotificationProviderException(String provider) { | ||
| super(FAIL_CODE, HttpStatus.NOT_FOUND); | ||
| this.provider = provider; | ||
| } | ||
|
|
||
| @Override | ||
| public String getMessage() { | ||
| return String.format("%s 는 존재하지 않는 외부 제공자 입니다.", provider); | ||
| } | ||
| } |
21 changes: 21 additions & 0 deletions
21
.../com/blackcompany/eeos/notification/application/exception/NotFoundPushTokenException.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,21 @@ | ||
| package com.blackcompany.eeos.notification.application.exception; | ||
|
|
||
| import com.blackcompany.eeos.common.exception.BusinessException; | ||
| import org.springframework.http.HttpStatus; | ||
|
|
||
| public class NotFoundPushTokenException extends BusinessException { | ||
|
|
||
| private static final String FAIL_CODE = "5007"; | ||
| private final String pushToken; | ||
|
|
||
| public NotFoundPushTokenException(String pushToken) { | ||
|
|
||
| super(FAIL_CODE, HttpStatus.NOT_FOUND); | ||
| this.pushToken = pushToken; | ||
| } | ||
|
|
||
| @Override | ||
| public String getMessage() { | ||
| return String.format("%s 는 존재하지 않는 알림토큰 입니다.", pushToken); | ||
| } | ||
Daae-Kim marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
18 changes: 18 additions & 0 deletions
18
.../main/java/com/blackcompany/eeos/notification/application/model/MemberPushTokenModel.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,18 @@ | ||
| package com.blackcompany.eeos.notification.application.model; | ||
|
|
||
| import com.blackcompany.eeos.common.support.AbstractModel; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @Builder | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| public class MemberPushTokenModel implements AbstractModel { | ||
| private Long id; | ||
| private Long memberId; | ||
| private NotificationProvider notificationProvider; | ||
| private String pushToken; | ||
| } |
24 changes: 24 additions & 0 deletions
24
.../main/java/com/blackcompany/eeos/notification/application/model/NotificationProvider.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,24 @@ | ||
| package com.blackcompany.eeos.notification.application.model; | ||
|
|
||
| import com.blackcompany.eeos.notification.application.exception.NotFoundNotificationProviderException; | ||
| import java.util.Arrays; | ||
| import lombok.Getter; | ||
|
|
||
| @Getter | ||
| public enum NotificationProvider { | ||
| FCM("fcm"), | ||
| ETC("etc"); | ||
|
|
||
| private final String provider; | ||
|
|
||
| NotificationProvider(String provider) { | ||
| this.provider = provider; | ||
| } | ||
|
|
||
| public static NotificationProvider find(String name) { | ||
| return Arrays.stream(NotificationProvider.values()) | ||
| .filter(provider -> provider.name().equalsIgnoreCase(name)) | ||
| .findFirst() | ||
| .orElseThrow(() -> new NotFoundNotificationProviderException(name)); | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
...company/eeos/notification/application/model/converter/MemberPushTokenEntityConverter.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,31 @@ | ||
| package com.blackcompany.eeos.notification.application.model.converter; | ||
|
|
||
| import com.blackcompany.eeos.common.support.converter.AbstractEntityConverter; | ||
| import com.blackcompany.eeos.notification.application.model.MemberPushTokenModel; | ||
| import com.blackcompany.eeos.notification.persistence.MemberPushTokenEntity; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| public class MemberPushTokenEntityConverter | ||
| implements AbstractEntityConverter<MemberPushTokenEntity, MemberPushTokenModel> { | ||
|
|
||
| @Override | ||
| public MemberPushTokenModel from(MemberPushTokenEntity source) { | ||
| return MemberPushTokenModel.builder() | ||
| .id(source.getId()) | ||
| .memberId(source.getMemberId()) | ||
| .notificationProvider(source.getProvider()) | ||
| .pushToken(source.getPushToken()) | ||
| .build(); | ||
| } | ||
|
|
||
| @Override | ||
| public MemberPushTokenEntity toEntity(MemberPushTokenModel source) { | ||
| return MemberPushTokenEntity.builder() | ||
| .id(source.getId()) | ||
| .memberId(source.getMemberId()) | ||
| .pushToken(source.getPushToken()) | ||
| .provider(source.getNotificationProvider()) | ||
| .build(); | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
...com/blackcompany/eeos/notification/application/respository/MemberPushTokenRepository.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,24 @@ | ||
| package com.blackcompany.eeos.notification.application.respository; | ||
Daae-Kim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| import com.blackcompany.eeos.notification.application.model.MemberPushTokenModel; | ||
| import com.blackcompany.eeos.notification.application.model.NotificationProvider; | ||
| import java.time.LocalDateTime; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| public interface MemberPushTokenRepository { | ||
| Optional<MemberPushTokenModel> findByPushToken(String pushToken); | ||
|
|
||
| List<MemberPushTokenModel> findByMemberId(Long memberId); | ||
|
|
||
| List<MemberPushTokenModel> findByMemberIdAndProvider( | ||
| Long memberId, NotificationProvider provider); | ||
|
|
||
| void deleteByPushToken(String pushToken); | ||
|
|
||
| int deleteByMemberId(Long memberId); | ||
|
|
||
| int deleteByUpdatedDateBefore(LocalDateTime updatedDate); | ||
|
|
||
| MemberPushTokenModel save(MemberPushTokenModel memberPushToken); | ||
| } | ||
64 changes: 64 additions & 0 deletions
64
...java/com/blackcompany/eeos/notification/application/service/NotificationTokenService.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,64 @@ | ||
| package com.blackcompany.eeos.notification.application.service; | ||
|
|
||
| import com.blackcompany.eeos.notification.application.dto.CreateMemberPushTokenRequest; | ||
| import com.blackcompany.eeos.notification.application.dto.DeleteMemberPushTokenRequest; | ||
| import com.blackcompany.eeos.notification.application.exception.DeniedDeletePushTokenException; | ||
| import com.blackcompany.eeos.notification.application.exception.NotFoundPushTokenException; | ||
| import com.blackcompany.eeos.notification.application.model.MemberPushTokenModel; | ||
| import com.blackcompany.eeos.notification.application.model.NotificationProvider; | ||
| import com.blackcompany.eeos.notification.application.respository.MemberPushTokenRepository; | ||
| import com.blackcompany.eeos.notification.application.usecase.CreateMemberPushTokenUsecase; | ||
| import com.blackcompany.eeos.notification.application.usecase.DeleteAllMemberPushTokensUsecase; | ||
| import com.blackcompany.eeos.notification.application.usecase.DeleteMemberPushTokenUsecase; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| @Slf4j | ||
| public class NotificationTokenService | ||
| implements CreateMemberPushTokenUsecase, | ||
| DeleteAllMemberPushTokensUsecase, | ||
| DeleteMemberPushTokenUsecase { | ||
|
|
||
| private final MemberPushTokenRepository memberPushTokenRepository; | ||
|
|
||
| @Override | ||
| @Transactional | ||
| public void create(Long memberId, CreateMemberPushTokenRequest request) { | ||
|
|
||
| NotificationProvider provider = NotificationProvider.find(request.getProvider()); | ||
| if (memberPushTokenRepository.findByPushToken(request.getPushToken()).isEmpty()) { | ||
| MemberPushTokenModel model = | ||
| MemberPushTokenModel.builder() | ||
| .memberId(memberId) | ||
| .pushToken(request.getPushToken()) | ||
| .notificationProvider(provider) | ||
| .build(); | ||
|
|
||
| memberPushTokenRepository.save(model); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| @Transactional | ||
| public void deleteAllMemberPushTokens(Long memberId) { | ||
| memberPushTokenRepository.deleteByMemberId(memberId); | ||
| } | ||
|
|
||
| @Override | ||
| @Transactional | ||
| public void delete(Long memberId, DeleteMemberPushTokenRequest request) { | ||
| MemberPushTokenModel model = | ||
| memberPushTokenRepository | ||
| .findByPushToken(request.getPushToken()) | ||
| .orElseThrow(() -> new NotFoundPushTokenException(request.getPushToken())); | ||
| if (!model.getMemberId().equals(memberId)) { | ||
| throw new DeniedDeletePushTokenException(); | ||
| } | ||
| memberPushTokenRepository.deleteByPushToken(request.getPushToken()); | ||
| } | ||
| } |
9 changes: 9 additions & 0 deletions
9
.../com/blackcompany/eeos/notification/application/usecase/CreateMemberPushTokenUsecase.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,9 @@ | ||
| package com.blackcompany.eeos.notification.application.usecase; | ||
|
|
||
| import com.blackcompany.eeos.notification.application.dto.CreateMemberPushTokenRequest; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| public interface CreateMemberPushTokenUsecase { | ||
| void create(Long memberId, CreateMemberPushTokenRequest request); | ||
| } |
8 changes: 8 additions & 0 deletions
8
.../blackcompany/eeos/notification/application/usecase/DeleteAllMemberPushTokensUsecase.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 com.blackcompany.eeos.notification.application.usecase; | ||
|
|
||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| public interface DeleteAllMemberPushTokensUsecase { | ||
| void deleteAllMemberPushTokens(Long memberId); | ||
| } | ||
Daae-Kim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
9 changes: 9 additions & 0 deletions
9
.../com/blackcompany/eeos/notification/application/usecase/DeleteMemberPushTokenUsecase.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,9 @@ | ||
| package com.blackcompany.eeos.notification.application.usecase; | ||
|
|
||
| import com.blackcompany.eeos.notification.application.dto.DeleteMemberPushTokenRequest; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| public interface DeleteMemberPushTokenUsecase { | ||
| void delete(Long memberId, DeleteMemberPushTokenRequest request); | ||
| } | ||
Daae-Kim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
28 changes: 28 additions & 0 deletions
28
...ain/java/com/blackcompany/eeos/notification/persistence/JpaMemberPushTokenRepository.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,28 @@ | ||
| package com.blackcompany.eeos.notification.persistence; | ||
|
|
||
| import com.blackcompany.eeos.notification.application.model.NotificationProvider; | ||
| import java.sql.Timestamp; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.data.jpa.repository.Modifying; | ||
| import org.springframework.data.jpa.repository.Query; | ||
| import org.springframework.data.repository.query.Param; | ||
|
|
||
| public interface JpaMemberPushTokenRepository extends JpaRepository<MemberPushTokenEntity, Long> { | ||
|
|
||
| Optional<MemberPushTokenEntity> findByPushToken(String token); | ||
|
|
||
| List<MemberPushTokenEntity> findByMemberId(Long memberId); | ||
|
|
||
| List<MemberPushTokenEntity> findByMemberIdAndProvider( | ||
| Long memberId, NotificationProvider provider); | ||
|
|
||
| @Modifying | ||
| @Query("DELETE FROM MemberPushTokenEntity t WHERE t.memberId = :memberId") | ||
| int deleteByMemberId(@Param("memberId") Long memberId); | ||
|
|
||
| void deleteByPushToken(String token); | ||
|
|
||
| int deleteByUpdatedDateBefore(Timestamp updatedDate); | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.