-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from Team-Shaka/feature/35-notification
Feature/35 notification
- Loading branch information
Showing
10 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/main/java/org/example/tree/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,42 @@ | ||
package org.example.tree.domain.notification.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import lombok.RequiredArgsConstructor; | ||
import org.example.tree.domain.notification.dto.NotificationResponseDTO; | ||
import org.example.tree.domain.notification.service.NotificationService; | ||
import org.example.tree.global.common.ApiResponse; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/notifications") | ||
public class NotificationController { | ||
|
||
private final NotificationService notificationService; | ||
|
||
@Operation(summary = "알림 생성 테스트") | ||
@PostMapping("/test") | ||
public ApiResponse<NotificationResponseDTO.sendNotification> sendNotification( | ||
@RequestBody final NotificationRequestDTO.sendNotification request) | ||
{ | ||
return ApiResponse.onSuccess(notificationService.sendNotification(request)); | ||
} | ||
|
||
@Operation(summary = "전체 알림 조회", description = "유저가 받은 알림들을 조회합니다.") | ||
@GetMapping | ||
public ApiResponse<List<NotificationResponseDTO.getNotification>> getNotifications( | ||
@RequestHeader("Authorization") final String header) | ||
{ | ||
String token = header.replace("Bearer ", ""); | ||
return ApiResponse.onSuccess(notificationService.getUserNotifications(token)); | ||
} | ||
|
||
@Operation(summary = "특정 알림 조회", description = "유저가 받은 알림 중 하나를 조회합니다.") | ||
@GetMapping("/{notificationId}") | ||
public ApiResponse<NotificationResponseDTO.getNotification> getNotification( | ||
@PathVariable final Long notificationId) | ||
{ | ||
return ApiResponse.onSuccess(notificationService.getNotification(notificationId)); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/org/example/tree/domain/notification/converter/NotificationConverter.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,19 @@ | ||
package org.example.tree.domain.notification.converter; | ||
|
||
import org.example.tree.domain.member.entity.Member; | ||
import org.example.tree.domain.notification.entity.Notification; | ||
import org.example.tree.domain.notification.entity.NotificationType; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class NotificationConverter { | ||
|
||
public Notification toNotification(String title, String message, String type, Member receiver) { | ||
return Notification.builder() | ||
.title(title) | ||
.message(message) | ||
.type(NotificationType.valueOf(type)) | ||
.receiver(receiver) | ||
.build(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/example/tree/domain/notification/dto/NotificationRequestDTO.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,9 @@ | ||
package org.example.tree.domain.notification.dto; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
|
||
public class NotificationRequestDTO { | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/org/example/tree/domain/notification/dto/NotificationResponseDTO.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 org.example.tree.domain.notification.dto; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public class NotificationResponseDTO { | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/org/example/tree/domain/notification/entity/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,33 @@ | ||
package org.example.tree.domain.notification.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.example.tree.common.BaseDateTimeEntity; | ||
import org.example.tree.domain.member.entity.Member; | ||
|
||
@Entity | ||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class Notification extends BaseDateTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
private NotificationType type; | ||
|
||
private String title; | ||
|
||
private String message; | ||
|
||
private boolean readStatus = false; | ||
|
||
@ManyToOne | ||
@JoinColumn(name = "receiver_id") | ||
private Member receiver; // 알림을 받는 사용자 | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/org/example/tree/domain/notification/entity/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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.example.tree.domain.notification.entity; | ||
|
||
public enum NotificationType { | ||
INVITATION, COMMENT, REACTION | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/example/tree/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,9 @@ | ||
package org.example.tree.domain.notification.repository; | ||
|
||
import org.example.tree.domain.notification.entity.Notification; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
public interface NotificationRepository extends JpaRepository<Notification, Long> { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/org/example/tree/domain/notification/service/NotificationCommandService.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,4 @@ | ||
package org.example.tree.domain.notification.service; | ||
|
||
public class NotificationCommandService { | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/org/example/tree/domain/notification/service/NotificationQueryService.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,4 @@ | ||
package org.example.tree.domain.notification.service; | ||
|
||
public class NotificationQueryService { | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/org/example/tree/domain/notification/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.example.tree.domain.notification.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.example.tree.domain.member.entity.Member; | ||
import org.example.tree.domain.notification.converter.NotificationConverter; | ||
import org.example.tree.domain.notification.entity.Notification; | ||
import org.example.tree.domain.notification.repository.NotificationRepository; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class NotificationService { | ||
|
||
private final NotificationRepository notificationRepository; | ||
private final NotificationCommandService notificationCommandService; | ||
private final NotificationQueryService notificationQueryService; | ||
private final NotificationConverter notificationConverter; | ||
|
||
public Notification sendNotification(String title, String message, String type, Member receiver) { | ||
} | ||
|
||
public List<Notification> getUserNotifications(String token) { | ||
} | ||
} |