Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public class CommentController {
private final CommentService commentService;

// 1. 댓글 조회
@GetMapping("/{contentId}")
@GetMapping("/content/{contentId}")
public ResponseEntity<List<CommentResponseDto>> getComments(@PathVariable String contentId) {
return ResponseEntity.ok(commentService.getCommentList(contentId));
}

// 2. 댓글 작성
@PostMapping
@PostMapping()
public ResponseEntity<String> createComment(@RequestBody CommentRequestDto commentRequestDto) {
commentService.postComment(commentRequestDto);
return ResponseEntity.ok("댓글이 성공적으로 작성되었습니다!");
Expand Down
15 changes: 0 additions & 15 deletions src/main/java/com/example/prdoit/controller/ProjectController.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,4 @@ public ResponseEntity<Object> deleteProject(@PathVariable String projectId) {
return ResponseEntity.badRequest().body("프로젝트 삭제에 실패했습니다.");
}
}

/*
@PutMapping("/product")
public ResponseEntity<Object> putBacklog(@RequestBody BacklogPutDto backlogPutDto) {
log.info("[putBacklog] 백로그 이동 요청");
try{
projectService.putBacklog(backlogPutDto);
return ResponseEntity.ok("백로그 이동에 성공했습니다.");
} catch (RuntimeException e){
log.error("[putBacklog] {}", e.getMessage());
return ResponseEntity.badRequest().body("백로그 이동에 실패했습니다.");
}
}

*/
}
14 changes: 14 additions & 0 deletions src/main/java/com/example/prdoit/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.example.prdoit.dto.user.LoginDto;
import com.example.prdoit.dto.user.UserDto;
import com.example.prdoit.exception.CustomException;
import com.example.prdoit.service.notification.NotificationService;
import com.example.prdoit.service.user.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -20,6 +21,7 @@
public class UserController {

private final UserService userService;
private final NotificationService notificationService;

@PostMapping("/signup")
public ResponseEntity<Object> signUp(@RequestBody UserDto userDto) {
Expand Down Expand Up @@ -141,4 +143,16 @@ public ResponseEntity<Object> checkPassword(@RequestBody LoginDto loginDto) {
}
}

@GetMapping("/notification/{userId}")
public ResponseEntity<Object> getNotificationList(@PathVariable String userId) {
log.info("[getNotificationList] 알림 목록 조회 시작 - User ID: {}", userId);

try {
return ResponseEntity.ok(notificationService.getNotificationList(userId));
} catch (CustomException e) {
log.error("[getNotificationList] 알림 목록 조회 실패 - 이유: {}", e.getMessage());
return ResponseEntity.badRequest().body(e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.prdoit.dto.notification;

import lombok.*;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class NotificationResponseDto {
private int notificationId;
private String notificationContent;
private String contentId;
private String userId;
private int isRead;
private int isContent;
}
8 changes: 4 additions & 4 deletions src/main/java/com/example/prdoit/model/IdTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ public class IdTable {
@JsonIgnore
private List<SurveyTable> surveyTable;

@OneToMany(mappedBy = "id", cascade = CascadeType.REMOVE, orphanRemoval = true, fetch = FetchType.EAGER)
@JsonIgnore
private List<ReadTable> readTable;

@OneToMany(mappedBy = "id", cascade = CascadeType.REMOVE, orphanRemoval = true, fetch = FetchType.EAGER)
@JsonIgnore
private List<CommunityTable> communityTable;
Expand All @@ -47,4 +43,8 @@ public class IdTable {
@JsonIgnore
private List<ContentTable> contentTable;

@OneToMany(mappedBy = "userId", cascade = CascadeType.REMOVE, orphanRemoval = true, fetch = FetchType.EAGER)
@JsonIgnore
private List<NotificationTable> notificationTable;

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,22 @@
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ReadTable {
public class NotificationTable {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int readId;
private int notificationId;

private int readContentId;
private String notificationContent;

private String contentId;

private int isRead;

private int isContent;

@ManyToOne
@JoinColumn(name = "id")
private IdTable id;
@JoinColumn(name = "userId")
private IdTable userId;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.prdoit.repository;

import com.example.prdoit.model.NotificationTable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface NotificationTableRepository extends JpaRepository<NotificationTable, Integer> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
import com.example.prdoit.model.CommentCommentTable;
import com.example.prdoit.model.CommentTable;
import com.example.prdoit.model.ContentTable;
import com.example.prdoit.repository.CommentCommentTableRepository;
import com.example.prdoit.repository.CommentTableRepository;
import com.example.prdoit.repository.ContentTableRepository;
import com.example.prdoit.model.NotificationTable;
import com.example.prdoit.repository.*;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand All @@ -25,6 +24,8 @@ public class CommentServiceImpl implements CommentService {
private final CommentTableRepository commentTableRepository;
private final CommentCommentTableRepository commentCommentTableRepository;
private final ContentTableRepository contentTableRepository;
private final NotificationTableRepository notificationTableRepository;
private final IdTableRepository idTableRepository;

// 1. 댓글 목록 조회 (GET)
@Override
Expand Down Expand Up @@ -67,6 +68,14 @@ public void postComment(CommentRequestDto commentRequestDto) {
.contentId(contentTable)
.build());

notificationTableRepository.save(NotificationTable.builder()
.notificationContent("댓글이 작성되었습니다.")
.contentId(contentTable.getContentId())
.userId(contentTable.getUserId())
.isRead(0)
.isContent(1)
.build());

log.info("[postComment] 댓글 등록을 완료했습니다.");
}

Expand All @@ -85,6 +94,14 @@ public void postCommentReply(CommentReplyRequestDto commentReplyRequestDto) {
.commentId(parentComment)
.build());

notificationTableRepository.save(NotificationTable.builder()
.notificationContent("대댓글이 작성되었습니다.")
.contentId(parentComment.getContentId().getContentId())
.userId(idTableRepository.findByNickname(parentComment.getCommentNickname()))
.isRead(0)
.isContent(1)
.build());

log.info("[postCommentReply] 대댓글 등록을 완료했습니다.");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.prdoit.service.notification;

import com.example.prdoit.dto.notification.NotificationResponseDto;

import java.util.List;

public interface NotificationService {
List<NotificationResponseDto> getNotificationList(String userId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.example.prdoit.service.notification;

import com.example.prdoit.dto.notification.NotificationResponseDto;
import com.example.prdoit.model.IdTable;
import com.example.prdoit.model.NotificationTable;
import com.example.prdoit.repository.IdTableRepository;
import com.example.prdoit.repository.NotificationTableRepository;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@AllArgsConstructor
@Slf4j
public class NotificationServiceImpl implements NotificationService {

private final IdTableRepository idTableRepository;
private final NotificationTableRepository notificationTableRepository;

@Override
public List<NotificationResponseDto> getNotificationList(String userId) {
log.info("[getNotificationList] 알림 목록 조회 시작 - User ID: {}", userId);

IdTable idTable = idTableRepository.findById(userId).orElseThrow(() -> new IllegalArgumentException("해당 유저가 없습니다. ID = " + userId));
try {
List<NotificationResponseDto> notificationResponseDtoList = idTable.getNotificationTable().stream().map(notificationTable -> NotificationResponseDto.builder()
.notificationId(notificationTable.getNotificationId())
.notificationContent(notificationTable.getNotificationContent())
.contentId(notificationTable.getContentId())
.userId(notificationTable.getUserId().getId())
.isRead(notificationTable.getIsRead())
.isContent(notificationTable.getIsContent())
.build()).toList();
for(NotificationTable notificationTable : idTable.getNotificationTable()) {
notificationTable.setIsRead(1);
}
notificationTableRepository.saveAll(idTable.getNotificationTable());
return notificationResponseDtoList;
} catch (Exception e) {
throw new IllegalArgumentException("알림 목록 조회 중 문제가 발생했습니다.");
}
}
}