-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…t-fcm 알림센터 조회 API
- Loading branch information
Showing
14 changed files
with
358 additions
and
31 deletions.
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
23 changes: 0 additions & 23 deletions
23
API-Server/src/main/java/swm/hkcc/LGTM/app/global/notification/dto/NotificationDTO.java
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
.../java/swm/hkcc/LGTM/app/modules/notification/controller/NotificationCenterController.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,29 @@ | ||
package swm.hkcc.LGTM.app.modules.notification.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import swm.hkcc.LGTM.app.global.dto.ApiDataResponse; | ||
import swm.hkcc.LGTM.app.modules.member.domain.Member; | ||
import swm.hkcc.LGTM.app.modules.member.domain.custom.CustomUserDetails; | ||
import swm.hkcc.LGTM.app.modules.notification.dto.NotificationDTO; | ||
import swm.hkcc.LGTM.app.modules.notification.service.NotificationCenterService; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/v1/notification") | ||
@RequiredArgsConstructor | ||
public class NotificationCenterController { | ||
private final NotificationCenterService notificationCenterService; | ||
|
||
@GetMapping | ||
public ApiDataResponse<List<NotificationDTO>> getNotification( | ||
@AuthenticationPrincipal CustomUserDetails customUserDetails | ||
) { | ||
Member member = customUserDetails.getMember(); | ||
return ApiDataResponse.of(notificationCenterService.getNotification(member)); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
API-Server/src/main/java/swm/hkcc/LGTM/app/modules/notification/domain/Notification.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,47 @@ | ||
package swm.hkcc.LGTM.app.modules.notification.domain; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.*; | ||
import org.hibernate.annotations.ColumnDefault; | ||
import swm.hkcc.LGTM.app.global.entity.BaseEntity; | ||
import swm.hkcc.LGTM.app.modules.member.domain.Member; | ||
|
||
import java.io.Serializable; | ||
import java.util.Map; | ||
|
||
@Getter | ||
@Setter | ||
@Builder | ||
@ToString | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Entity | ||
public class Notification extends BaseEntity implements Serializable { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "notification_id") | ||
private Long notificationId; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "member_id") | ||
private Member member; | ||
|
||
private String title; | ||
private String body; | ||
|
||
@ColumnDefault("false") | ||
private boolean isRead; | ||
|
||
public static Notification from( | ||
Member member, | ||
Map<String, String> data | ||
) { | ||
return Notification.builder() | ||
.title(data.getOrDefault("title", "")) | ||
.body(data.getOrDefault("body", "")) | ||
.member(member) | ||
.isRead(false) | ||
.build(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
API-Server/src/main/java/swm/hkcc/LGTM/app/modules/notification/dto/NotificationDTO.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,28 @@ | ||
package swm.hkcc.LGTM.app.modules.notification.dto; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.*; | ||
import org.hibernate.annotations.ColumnDefault; | ||
import swm.hkcc.LGTM.app.modules.member.domain.Member; | ||
import swm.hkcc.LGTM.app.modules.notification.domain.Notification; | ||
|
||
import java.util.Map; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@Builder | ||
public class NotificationDTO { | ||
private Long notificationId; | ||
private String title; | ||
private String body; | ||
private Boolean isRead; | ||
|
||
public static NotificationDTO from(Notification notification) { | ||
return NotificationDTO.builder() | ||
.notificationId(notification.getNotificationId()) | ||
.title(notification.getTitle()) | ||
.body(notification.getBody()) | ||
.isRead(notification.isRead()) | ||
.build(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...c/main/java/swm/hkcc/LGTM/app/modules/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,11 @@ | ||
package swm.hkcc.LGTM.app.modules.notification.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import swm.hkcc.LGTM.app.modules.member.domain.Member; | ||
import swm.hkcc.LGTM.app.modules.notification.domain.Notification; | ||
|
||
import java.util.List; | ||
|
||
public interface NotificationRepository extends JpaRepository<Notification, Long> { | ||
List<Notification> findAllByMember(Member member); | ||
} |
42 changes: 42 additions & 0 deletions
42
...c/main/java/swm/hkcc/LGTM/app/modules/notification/service/NotificationCenterService.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,42 @@ | ||
package swm.hkcc.LGTM.app.modules.notification.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import swm.hkcc.LGTM.app.modules.member.domain.Member; | ||
import swm.hkcc.LGTM.app.modules.notification.domain.Notification; | ||
import swm.hkcc.LGTM.app.modules.notification.dto.NotificationDTO; | ||
import swm.hkcc.LGTM.app.modules.notification.repository.NotificationRepository; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class NotificationCenterService { | ||
private final NotificationRepository notificationRepository; | ||
|
||
@Transactional | ||
public List<NotificationDTO> getNotification(Member member) { | ||
List<Notification> notifications = notificationRepository.findAllByMember(member); | ||
List<Notification> unreadNotifications = new ArrayList<>(); | ||
List<NotificationDTO> notificationDTOList = new ArrayList<>(); | ||
notifications.stream() | ||
.forEach(notification -> { | ||
notificationDTOList.add(NotificationDTO.from(notification)); | ||
if (!notification.isRead()) { | ||
notification.setRead(true); | ||
unreadNotifications.add(notification); | ||
} | ||
}); | ||
|
||
if (!unreadNotifications.isEmpty()) | ||
notificationRepository.saveAll(unreadNotifications); | ||
|
||
return notificationDTOList; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...fication/service/NotificationService.java → ...fication/service/NotificationService.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
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
2 changes: 1 addition & 1 deletion
2
...ce/RegistrationNotificationAopConfig.java → ...ce/RegistrationNotificationAopConfig.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
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
Oops, something went wrong.