Skip to content

Commit

Permalink
Merge pull request #52 from Team-Shaka/feature/35-notification
Browse files Browse the repository at this point in the history
Feature/35 notification
  • Loading branch information
koojun99 authored Mar 1, 2024
2 parents a8c44c0 + c37cc8e commit 06745c6
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 0 deletions.
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));
}

}
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
@@ -0,0 +1,8 @@
package org.example.tree.domain.notification.dto;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class NotificationResponseDTO {
}
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; // 알림을 받는 사용자
}
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
}
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> {
}
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
@@ -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) {
}
}

0 comments on commit 06745c6

Please sign in to comment.