Skip to content

Commit

Permalink
[FEAT]/#35-알림 조회 기본 틀 구성
Browse files Browse the repository at this point in the history
  • Loading branch information
koojun99 committed Mar 1, 2024
1 parent c9f59fb commit c37cc8e
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,42 @@
package org.example.tree.domain.notification.controller;

import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;
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));
}

}
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();
}
}
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 {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
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 {
public class Notification extends BaseDateTimeEntity {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -22,4 +24,10 @@ public class Notification {
private String title;

private String message;

private boolean readStatus = false;

@ManyToOne
@JoinColumn(name = "receiver_id")
private Member receiver; // 알림을 받는 사용자
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package org.example.tree.domain.notification.entity;

public enum NotificationType {
INVITATION, COMMENT, LIKE
INVITATION, COMMENT, REACTION
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.example.tree.domain.notification.service;

public class NotificationCommandService {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.example.tree.domain.notification.service;

public class NotificationQueryService {
}
Original file line number Diff line number Diff line change
@@ -1,9 +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) {
}
}

0 comments on commit c37cc8e

Please sign in to comment.