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 @@ -11,18 +11,19 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/comments")
@CrossOrigin(origins = "*", allowedHeaders = "*")
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
14 changes: 14 additions & 0 deletions src/main/java/com/example/prdoit/controller/ContentController.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,18 @@ public ResponseEntity<Object> getTotalContent(@PathVariable String userId,
}
}

@PostMapping("/like/{contentId}")
public ResponseEntity<Object> likeContent(@PathVariable String contentId) {
try {
contentService.likeContent(contentId);
return ResponseEntity.ok("좋아요 성공");
} catch (CustomException e) {
log.error("[likeContent] 좋아요 실패", e);
return ResponseEntity.badRequest().body(e.getMessage());
} catch (Exception e) {
log.error("[likeContent] 좋아요 실패", e);
return ResponseEntity.internalServerError().body("좋아요에 실패했습니다.");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public class NotificationResponseDto {
private String contentId;
private String userId;
private int isRead;
private int isContent;
private String contentTitle;
}
4 changes: 4 additions & 0 deletions src/main/java/com/example/prdoit/model/NotificationTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public class NotificationTable {

private int isRead;

private int isContent;

private String contentTitle;

@ManyToOne
@JoinColumn(name = "userId")
private IdTable userId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public void postComment(CommentRequestDto commentRequestDto) {
.contentId(contentTable.getContentId())
.userId(contentTable.getUserId())
.isRead(0)
.isContent(1)
.build());

log.info("[postComment] 댓글 등록을 완료했습니다.");
Expand All @@ -98,6 +99,7 @@ public void postCommentReply(CommentReplyRequestDto commentReplyRequestDto) {
.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
Expand Up @@ -20,4 +20,6 @@ public interface ContentService {

TotalContentDto getTotalContent(String userId, int size, int page);

void likeContent(String contentId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,18 @@ public TotalContentDto getTotalContent(String userId, int size, int page){
}
}

@Override
public void likeContent(String contentId){
log.info("[likeContent] 컨텐츠 좋아요 로직 시작");
try {
ContentTable contentTable = contentRepository.findById(contentId).orElseThrow
(() -> new RuntimeException("존재하지 않는 컨텐츠입니다."));
contentTable.setContentLike(contentTable.getContentLike() + 1);
contentRepository.save(contentTable);
} catch (Exception e) {
log.error(e.getMessage());
throw new RuntimeException(e.getMessage());
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public List<NotificationResponseDto> getNotificationList(String userId) {
.contentId(notificationTable.getContentId())
.userId(notificationTable.getUserId().getId())
.isRead(notificationTable.getIsRead())
.isContent(notificationTable.getIsContent())
.build()).toList();
for(NotificationTable notificationTable : idTable.getNotificationTable()) {
notificationTable.setIsRead(1);
Expand Down