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
118 changes: 105 additions & 13 deletions src/main/java/com/example/prdoit/controller/CommentController.java
Original file line number Diff line number Diff line change
@@ -1,51 +1,143 @@
package com.example.prdoit.controller;

import com.example.prdoit.dto.comment.*;
import com.example.prdoit.exception.CustomException;
import com.example.prdoit.service.comment.CommentService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/comments")
@RequestMapping("/comments")
@CrossOrigin(origins = "*", allowedHeaders = "*")
public class CommentController {

private final CommentService commentService;

// 1. 댓글 조회
@GetMapping("/content/{contentId}")
public ResponseEntity<List<CommentResponseDto>> getComments(@PathVariable String contentId) {
return ResponseEntity.ok(commentService.getCommentList(contentId));
public ResponseEntity<Object> getComments(@PathVariable String contentId) {
try {
return ResponseEntity.ok(commentService.getCommentList(contentId));
} catch (CustomException e){
return ResponseEntity.badRequest().body("댓글 조회에 실패했습니다.");
} catch (Exception e) {
return ResponseEntity.internalServerError().body("댓글 조회에 실패했습니다.");
}
}

// 2. 댓글 작성
@PostMapping()
public ResponseEntity<String> createComment(@RequestBody CommentRequestDto commentRequestDto) {
commentService.postComment(commentRequestDto);
return ResponseEntity.ok("댓글이 성공적으로 작성되었습니다!");
public ResponseEntity<Object> createComment(@RequestBody CommentRequestDto commentRequestDto) {
try {
commentService.postComment(commentRequestDto);
return ResponseEntity.ok("댓글이 성공적으로 작성되었습니다!");
} catch (CustomException e) {
return ResponseEntity.badRequest().body("댓글 작성에 실패했습니다.");
} catch (Exception e) {
return ResponseEntity.internalServerError().body("댓글 작성에 실패했습니다.");
}
}

// 3. 대댓글 작성
@PostMapping("/reply")
public ResponseEntity<String> createReply(@RequestBody CommentReplyRequestDto commentReplyRequestDto) {
commentService.postCommentReply(commentReplyRequestDto);
return ResponseEntity.ok("대댓글이 성공적으로 작성되었습니다!");
public ResponseEntity<Object> createReply(@RequestBody CommentReplyRequestDto commentReplyRequestDto) {
try {
commentService.postCommentReply(commentReplyRequestDto);
return ResponseEntity.ok("대댓글이 성공적으로 작성되었습니다!");
} catch (CustomException e) {
return ResponseEntity.badRequest().body("대댓글 작성에 실패했습니다.");
} catch (Exception e) {
return ResponseEntity.internalServerError().body("대댓글 작성에 실패했습니다.");
}
}

// 4. 댓글 수정
@PatchMapping
public ResponseEntity<String> updateComment(@RequestBody CommentPatchDto commentPatchDto) {
commentService.patchComment(commentPatchDto);
return ResponseEntity.ok("댓글이 성공적으로 수정되었습니다!");
try {
commentService.patchComment(commentPatchDto);
return ResponseEntity.ok("댓글이 성공적으로 수정되었습니다!");
} catch (CustomException e) {
return ResponseEntity.badRequest().body("댓글 수정에 실패했습니다.");
} catch (Exception e) {
return ResponseEntity.internalServerError().body("댓글 수정에 실패했습니다.");
}
}

// 5.대댓글 수정
@PatchMapping("/reply")
public ResponseEntity<String> updateReply(@RequestBody CommentReplyPatchDto commentReplyPatchDto) {
commentService.patchCommentReply(commentReplyPatchDto);
return ResponseEntity.ok("대댓글이 성공적으로 수정되었습니다!");
try {
commentService.patchCommentReply(commentReplyPatchDto);
return ResponseEntity.ok("대댓글이 성공적으로 수정되었습니다!");
} catch (CustomException e) {
return ResponseEntity.badRequest().body("대댓글 수정에 실패했습니다.");
} catch (Exception e) {
return ResponseEntity.internalServerError().body("대댓글 수정에 실패했습니다.");
}
}

@GetMapping("/community/{communityId}")
public ResponseEntity<Object> getCommunityComments(@PathVariable String communityId) {
try {
return ResponseEntity.ok(commentService.getCommunityCommentList(communityId));
} catch (CustomException e){
return ResponseEntity.badRequest().body("댓글 조회에 실패했습니다.");
} catch (Exception e) {
return ResponseEntity.internalServerError().body("댓글 조회에 실패했습니다.");
}
}

@PostMapping("/community")
public ResponseEntity<Object> createCommunityComment(@RequestBody CommunityCommentPostDto communityCommentPostDto) {
try {
commentService.postCommunityComment(communityCommentPostDto);
return ResponseEntity.ok("댓글이 성공적으로 작성되었습니다!");
} catch (CustomException e) {
return ResponseEntity.badRequest().body("댓글 작성에 실패했습니다.");
} catch (Exception e) {
return ResponseEntity.internalServerError().body("댓글 작성에 실패했습니다.");
}
}

@PostMapping("/community/reply")
public ResponseEntity<Object> createCommunityReply(@RequestBody CommunityCommentReplyPostDto communityCommentReplyPostDto) {
try {
commentService.postCommunityCommentReply(communityCommentReplyPostDto);
return ResponseEntity.ok("대댓글이 성공적으로 작성되었습니다!");
} catch (CustomException e) {
return ResponseEntity.badRequest().body("대댓글 작성에 실패했습니다.");
} catch (Exception e) {
return ResponseEntity.internalServerError().body("대댓글 작성에 실패했습니다.");
}
}

@PatchMapping("/community")
public ResponseEntity<String> updateCommunityComment(@RequestBody CommunityCommentPatchDto communityCommentPatchDto) {
try {
commentService.patchCommunityComment(communityCommentPatchDto);
return ResponseEntity.ok("댓글이 성공적으로 수정되었습니다!");
} catch (CustomException e) {
return ResponseEntity.badRequest().body("댓글 수정에 실패했습니다.");
} catch (Exception e) {
return ResponseEntity.internalServerError().body("댓글 수정에 실패했습니다.");
}
}

@PatchMapping("/community/reply")
public ResponseEntity<String> updateCommunityReply(@RequestBody CommunityCommentReplyPatchDto communityCommentReplyPatchDto) {
try {
commentService.patchCommunityCommentReply(communityCommentReplyPatchDto);
return ResponseEntity.ok("대댓글이 성공적으로 수정되었습니다!");
} catch (CustomException e) {
return ResponseEntity.badRequest().body("대댓글 수정에 실패했습니다.");
} catch (Exception e) {
return ResponseEntity.internalServerError().body("대댓글 수정에 실패했습니다.");
}
}
}
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("좋아요에 실패했습니다.");
}
}

}
11 changes: 11 additions & 0 deletions src/main/java/com/example/prdoit/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,15 @@ public ResponseEntity<Object> getNotificationList(@PathVariable String userId) {
}
}

@GetMapping("/Information/{userId}")
public ResponseEntity<Object> getInformation(@PathVariable String userId) {
log.info("[getInformation] 회원 정보 조회 시작 - User ID: {}", userId);

try {
return ResponseEntity.ok(userService.getInformation(userId));
} catch (CustomException e) {
log.error("[getInformation] 회원 정보 조회 실패 - 이유: {}", e.getMessage());
return ResponseEntity.badRequest().body(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public class CommentReplyRequestDto {

private int commentId; // 대댓글이 달릴 원본 댓글 ID
private String commentReplyContent; // 대댓글 내용
private String commentReplyNickname; // 대댓글 작성자 닉네임
private String userId;
private LocalDateTime commentReplyDate; // 대댓글 작성 날짜
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public class CommentReplyResponseDto {
private String commentReplyContent; // 대댓글 내용
private String commentReplyNickname; // 작성자 닉네임
private LocalDateTime commentReplyDate; // 대댓글 작성 날짜
private String userId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ public class CommentRequestDto {

private String contentId; // 댓글 달릴 게시글 ID
private String commentContent; // 댓글 내용
private String commentNickname; // 댓글 작성자 닉네임
private String userId; // 댓글 작성자 닉네임
private LocalDateTime commentDate; // 댓글 작성 날짜
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public class CommentResponseDto {
private String commentContent; // 댓글 내용
private String commentNickname; // 작성자 닉네임
private LocalDateTime commentDate; // 댓글 작성 날짜
private List<CommentReplyResponseDto> commentReplyResponseDtoList; // 대댓글 리스트
private List<CommentReplyResponseDto> commentReplyResponseDtoList;
private String userId;// 대댓글 리스트
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.prdoit.dto.comment;

import lombok.*;

import java.time.LocalDateTime;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CommunityCommentPatchDto {

private int commentId;
private String commentContent;
private LocalDateTime commentDate;

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

import lombok.*;

import java.time.LocalDateTime;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CommunityCommentPostDto {

private String communityId;
private String commentContent;
private String userId;
private LocalDateTime commentDate;

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

import lombok.*;

import java.time.LocalDateTime;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CommunityCommentReplyPatchDto {

private int commentReplyId;
private String commentReplyContent;
private LocalDateTime commentReplyDate;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.example.prdoit.dto.comment;

import lombok.*;

import java.time.LocalDateTime;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CommunityCommentReplyPostDto {

private int commentId;
private String commentReplyContent;
private String userId;
private LocalDateTime commentReplyDate;

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


import lombok.*;

import java.time.LocalDateTime;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CommunityCommentReplyResponseDto {

private int commentReplyId;
private String commentReplyContent;
private String commentReplyNickname;
private String userId;
private LocalDateTime commentReplyDate;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.prdoit.dto.comment;

import lombok.*;

import java.time.LocalDateTime;
import java.util.List;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class CommunityCommentResponseDto {

private int commentId;
private String commentContent;
private String userId;
private String commentNickname;
private LocalDateTime commentDate;
private List<CommunityCommentReplyResponseDto> communityCommentReplyResponseDtoList;

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ public class NotificationResponseDto {
private String userId;
private int isRead;
private int isContent;
private String contentTitle;
}
16 changes: 16 additions & 0 deletions src/main/java/com/example/prdoit/dto/user/InformationDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.example.prdoit.dto.user;

import lombok.*;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class InformationDto {

private String id;
private String name;
private String email;
private String nickname;
}
2 changes: 2 additions & 0 deletions src/main/java/com/example/prdoit/model/NotificationTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class NotificationTable {

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 @@ -15,4 +15,15 @@ public interface CommentService {
void patchComment(CommentPatchDto commentPatchDto);

void patchCommentReply(CommentReplyPatchDto commentReplyPatchDto);

List<CommunityCommentResponseDto> getCommunityCommentList(String communityId);

void postCommunityComment(CommunityCommentPostDto communityCommentPostDto);

void postCommunityCommentReply(CommunityCommentReplyPostDto communityCommentReplyPostDto);

void patchCommunityComment(CommunityCommentPatchDto communityCommentPatchDto);

void patchCommunityCommentReply(CommunityCommentReplyPatchDto communityCommentReplyPatchDto);

}
Loading