Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
c298124
mod: PagingInfoDTO 수정
wnsgud0310 Oct 21, 2024
7afde53
Merge branch 'feature/5' of https://github.com/SmashStudy/ESquad-BE i…
wnsgud0310 Oct 22, 2024
11edd57
mod: qnaboard Exception 파일 경로 수정
wnsgud0310 Oct 22, 2024
fcdb87d
mod: BookQnaLike 클래스 수정
wnsgud0310 Oct 22, 2024
af54a4a
mod: CommentService 클래스 수정
wnsgud0310 Oct 22, 2024
8d0eee2
mod: QnaBoardController 수정
wnsgud0310 Oct 22, 2024
b107cac
mod: QuestionService 클래스 수정
wnsgud0310 Oct 22, 2024
1fc6685
remove: BookQnaLikeRepository 제거
wnsgud0310 Oct 22, 2024
7a86219
mod: BookQnaReply 엔티티 수정
wnsgud0310 Oct 22, 2024
6e56822
mod: CommentController 수정
wnsgud0310 Oct 22, 2024
746b27d
remove: CommentLikeRepository 제거
wnsgud0310 Oct 22, 2024
9d7d28a
mod: CommentService 클래스 수정
wnsgud0310 Oct 22, 2024
4f1a009
add: LikeRepository 생성
wnsgud0310 Oct 22, 2024
6c587fc
mod: QnaBoardController 수정
wnsgud0310 Oct 22, 2024
3429c5c
add: QnaLikeController 생성
wnsgud0310 Oct 22, 2024
9e0a6ff
add: QnaLikeService 생성
wnsgud0310 Oct 22, 2024
780f2f0
mod: QuestionService 수정
wnsgud0310 Oct 22, 2024
027d61c
mod: QnaLikeController 수정
wnsgud0310 Oct 22, 2024
1ffb549
add: CommentLikeRepository 생성
wnsgud0310 Oct 22, 2024
c140a87
mod: BookQnaReplyLike 수정
wnsgud0310 Oct 22, 2024
180def0
add: CommentLikeService 생성
wnsgud0310 Oct 22, 2024
072b15f
add: CommentLikeController 생성
wnsgud0310 Oct 22, 2024
d5267e5
mod: CommentRepository 수정
wnsgud0310 Oct 22, 2024
cb4e27e
rename: Qna->Question 클래스명 수정
wnsgud0310 Oct 22, 2024
c2e30ad
Merge branch 'feature/5' of https://github.com/SmashStudy/ESquad-BE i…
wnsgud0310 Oct 22, 2024
13d1a21
mod: QnaBoardController 수정
wnsgud0310 Oct 22, 2024
9e3de6c
mod: QnaRequestDTO 수정
wnsgud0310 Oct 22, 2024
582a067
mod: QuestionService 수정
wnsgud0310 Oct 22, 2024
efc544d
mod: QnaBoardResponseDTO 수정
wnsgud0310 Oct 22, 2024
f2a6edb
remove: Exception 예외 클래스 제거
wnsgud0310 Oct 22, 2024
46be736
test: UserUpdateTest 수정후 테스트
wnsgud0310 Oct 22, 2024
119ba7d
mod: QnaBoardController 수정
wnsgud0310 Oct 22, 2024
37abbb1
mod: QuestionService 수정
wnsgud0310 Oct 22, 2024
02f4edb
test: QuestionServiceTest 수정후 테스트
wnsgud0310 Oct 22, 2024
5a90b2a
refactor: QnaLikeController 좋아요 로직 리팩토링
wnsgud0310 Oct 22, 2024
206d8ba
mod: QnaBoardController 수정
wnsgud0310 Oct 22, 2024
3c9b7f0
mod: CommentLikeService 주석 제거
wnsgud0310 Oct 22, 2024
f02fb31
mod: 게시판 서비스 코드 주석 제거
wnsgud0310 Oct 22, 2024
d9b295f
mod: QuestionService 수정
wnsgud0310 Oct 22, 2024
4cf1aa0
mod: QuestionService 수정
wnsgud0310 Oct 22, 2024
f11d5a7
mod: QnaBoardResponseDTO 수정
wnsgud0310 Oct 22, 2024
601a0c8
mod: QuestionService 수정
wnsgud0310 Oct 22, 2024
8bbe970
mod: CommentLikeService 수정
wnsgud0310 Oct 23, 2024
50221d5
mod: QnaBoardController 수정
wnsgud0310 Oct 23, 2024
af907c4
mod: QuestionService 수정
wnsgud0310 Oct 23, 2024
556e17c
mod: QnaRequestDTO 수정
wnsgud0310 Oct 23, 2024
81f43ee
mod: QuestionService 수정
wnsgud0310 Oct 23, 2024
c21aa82
test: QuestionServiceTest 수정후 테스트
wnsgud0310 Oct 23, 2024
1e6c157
mod: QnaRequestDTO 수정
wnsgud0310 Oct 23, 2024
97facc0
mod: QnaRequestDTO 수정
wnsgud0310 Oct 23, 2024
70a4fc2
mod: QnaBoardController 수정
wnsgud0310 Oct 23, 2024
3f0c438
mod: QuestionService 수정
wnsgud0310 Oct 23, 2024
6209eee
test: QuestionServiceTest 테스트
wnsgud0310 Oct 23, 2024
f9c80e0
mod: QnaBoardController 수정
wnsgud0310 Oct 23, 2024
8653b8e
mod: QnaBoardController 수정
wnsgud0310 Oct 23, 2024
e8ef712
mod: QnaBoardController 수정
wnsgud0310 Oct 24, 2024
c8907f0
mod: QuestionService 수정
wnsgud0310 Oct 24, 2024
ebe07c5
add: BookNotFoundException 예외클래스 생성
wnsgud0310 Oct 24, 2024
52c0c2a
add: QnaErrorCode 질문 게시판 예외 클래스 생성
wnsgud0310 Oct 24, 2024
1fc68fd
add: QuestionNotFoundException 예외 클래스 생성
wnsgud0310 Oct 24, 2024
e9965fb
test: 질문게시판 테스트 수정 후 테스트
wnsgud0310 Oct 24, 2024
47225d8
mod: QuestionService 수정
wnsgud0310 Oct 24, 2024
1ce5671
remove: 안쓰는 예외클래스 제거
wnsgud0310 Oct 24, 2024
e7b5aa7
mod: QnaErrorCode 수정
wnsgud0310 Oct 24, 2024
648489d
add: CommentNotFoundException 생성
wnsgud0310 Oct 24, 2024
aa3ce60
test: QuestionServiceTest 수정 후 테스트
wnsgud0310 Oct 24, 2024
2d66a15
mod: CommentDTO 수정
wnsgud0310 Oct 24, 2024
758538a
remove: CommentDTO 제거
wnsgud0310 Oct 24, 2024
4c5569a
add: CommentRequestDTO 생성
wnsgud0310 Oct 24, 2024
057e377
add: CommentResponseDTO 생성
wnsgud0310 Oct 24, 2024
eb59d0f
mod: CommentNotFoundException 수정
wnsgud0310 Oct 24, 2024
5c46772
mod: CommentController 수정
wnsgud0310 Oct 24, 2024
b3927d9
mod: CommentController 수정
wnsgud0310 Oct 24, 2024
f69af31
mod: CommentRepository 수정
wnsgud0310 Oct 24, 2024
7730223
mod: CommentRequestDTO 수정
wnsgud0310 Oct 24, 2024
521a7a7
mod: CommentService 수정
wnsgud0310 Oct 24, 2024
946c937
test: CommentServiceTest 수정후 테스트
wnsgud0310 Oct 24, 2024
a2ce570
remove: 게시판 좋아요 관련 클래스 제거
wnsgud0310 Oct 24, 2024
e53570c
remove: 게시판 좋아요 관련 클래스 제거
wnsgud0310 Oct 24, 2024
936fb07
Merge branch 'refactor/39' of https://github.com/SmashStudy/ESquad-BE…
wnsgud0310 Oct 24, 2024
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

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,64 +1,60 @@
package com.esquad.esquadbe.qnaboard.controller;

import com.esquad.esquadbe.qnaboard.dto.CommentDTO;
import com.esquad.esquadbe.qnaboard.dto.CommentRequestDTO;
import com.esquad.esquadbe.qnaboard.dto.CommentResponseDTO;
import com.esquad.esquadbe.qnaboard.service.CommentService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.security.Principal;
import java.util.List;

@RequiredArgsConstructor
@RestController
@RequestMapping("/api/comments")
@RequestMapping("/api/questions/{boardId}/comments")
public class CommentController {

private final CommentService commentService;

// 댓글 생성
@PostMapping
public ResponseEntity<CommentDTO> createComment(
@RequestParam("boardId") Long boardId,
@RequestParam("writerId") Long writerId,
@RequestParam("content") String content,
@RequestParam("replyFlag") boolean replyFlag) {
CommentDTO createdComment = commentService.createComment(boardId, writerId, content, replyFlag);
return ResponseEntity.ok(createdComment);
}
public ResponseEntity<String> createComment(@PathVariable Long boardId,
@RequestBody CommentRequestDTO requestDTO,
Principal principal) {

// 댓글 수정
@PutMapping("/{commentId}")
public ResponseEntity<CommentDTO> updateComment(
@PathVariable Long commentId,
@RequestParam("writerId") Long writerId,
@RequestParam("content") String content) {
CommentDTO updatedComment = commentService.updateComment(commentId, writerId, content);
return ResponseEntity.ok(updatedComment);
}
CommentResponseDTO createdComment = commentService.createComment(boardId, requestDTO, principal.getName());

// 댓글 삭제
@DeleteMapping("/{commentId}")
public ResponseEntity<Void> deleteComment(
@PathVariable Long commentId,
@RequestParam("writerId") Long writerId) {
commentService.deleteComment(commentId, writerId);
return ResponseEntity.noContent().build();
String responseMessage = String.format("게시글 %d에 댓글 %d이(가) 생성되었습니다.", boardId, createdComment.getId());
return ResponseEntity.ok(responseMessage);
}

// 댓글 조회
@GetMapping
public ResponseEntity<List<CommentDTO>> getCommentsByBoardId(@RequestParam("boardId") Long boardId) {
List<CommentDTO> comments = commentService.getCommentsByBoardId(boardId);
public ResponseEntity<List<CommentResponseDTO>> getCommentsByBoard(@PathVariable Long boardId) {
List<CommentResponseDTO> comments = commentService.getCommentsByBoardId(boardId);
return ResponseEntity.ok(comments);
}


// 댓글 좋아요 추가/취소
@PostMapping("/like/{commentId}")
public ResponseEntity<String> likeComment(
@PathVariable Long commentId,
@RequestParam("userId") Long userId) {
String result = commentService.likeComment(commentId, userId);
return ResponseEntity.ok(result);
@PutMapping("/{commentId}")
public ResponseEntity<String> updateComment(@PathVariable Long boardId,
@PathVariable Long commentId,
@RequestBody CommentRequestDTO requestDTO,
Principal principal) {

CommentResponseDTO updatedComment = commentService.updateComment(commentId, requestDTO, principal.getName());

String responseMessage = String.format("게시글 %d의 댓글 %d이(가) 수정되었습니다.", boardId, updatedComment.getId());
return ResponseEntity.ok(responseMessage);
}


@DeleteMapping("/{commentId}")
public ResponseEntity<String> deleteComment(@PathVariable Long boardId,
@PathVariable Long commentId,
Principal principal) {
commentService.deleteComment(commentId, principal.getName());

String responseMessage = String.format("게시글 %d의 댓글 %d이(가) 삭제되었습니다.", boardId, commentId);
return ResponseEntity.ok(responseMessage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
import com.esquad.esquadbe.qnaboard.dto.QnaBoardResponseDTO;
import com.esquad.esquadbe.qnaboard.dto.QnaRequestDTO;
import com.esquad.esquadbe.qnaboard.service.QuestionService;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.security.Principal;

@RequiredArgsConstructor
@RestController
@RequestMapping("/api/questions")
Expand All @@ -19,69 +20,57 @@ public class QnaBoardController {

private final QuestionService questionService;

// 전체 게시글 조회

@GetMapping
public Page<QnaBoardResponseDTO> getAllQuestions(
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size) {
return questionService.getAllQuestions(page, size);
}

// 특정 ID의 게시글 조회 (게시글번호)

@GetMapping("/{id}")
public QnaBoardResponseDTO getQuestionById(@PathVariable Long id) {
return questionService.getQuestionById(id);
}

// 새로운 질문 생성

@PostMapping
public QnaBoardResponseDTO createQuestion(
@RequestBody QnaRequestDTO qnaForm,
@ModelAttribute QnaRequestDTO qnaForm,
@RequestParam(required = false) MultipartFile file) {
return questionService.createQuestion(qnaForm, file);
}


// 특정 제목의 게시글 조회
@GetMapping("/search")
public Page<QnaBoardResponseDTO> getQuestionsByTitle(
@RequestParam("title") String title,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size) {
log.info("Searching for questions with title: " + title);
return questionService.getQuestionsByTitle(title, page, size);
}

// 특정 작성자의 게시글 조회

@GetMapping("/by-writer")
public Page<QnaBoardResponseDTO> getQuestionsByWriter(
@RequestParam("userId") Long userId,
Principal principal,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size) {
log.info("Searching for questions by writer: " + userId);
return questionService.getQuestionsByWriter(userId, page, size);
return questionService.getQuestionsByWriter(principal.getName(), page, size);
}

// 게시글 수정

@PutMapping("/{id}")
public QnaBoardResponseDTO updateQuestion(@PathVariable Long id, @RequestBody QnaRequestDTO updateForm) {
return questionService.updateQuestion(id, updateForm);
}


// 게시글 삭제
@DeleteMapping("/{id}")
public ResponseEntity<String> deleteQuestion(@PathVariable Long id) {
questionService.deleteQuestion(id);
public ResponseEntity<String> deleteQuestion(@PathVariable Long id, Principal principal) {
questionService.deleteQuestion(id, principal.getName());
return ResponseEntity.ok("게시글이 삭제되었습니다");
}

// 좋아요 추가/취소
@PostMapping("/like/{boardId}")
public ResponseEntity<String> boardLike(@PathVariable Long boardId, @RequestParam Long userId) {
String result = questionService.boardLike(boardId, userId);
return ResponseEntity.ok(result);
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.esquad.esquadbe.qnaboard.dto;

import com.esquad.esquadbe.qnaboard.entity.BookQnaBoard;
import com.esquad.esquadbe.qnaboard.entity.BookQnaReply;
import com.esquad.esquadbe.user.entity.User;
import lombok.Builder;

@Builder
public record CommentRequestDTO(
Long id,
String content,
boolean replyFlag
) {

public BookQnaReply toEntity(User writer, BookQnaBoard board) {
return BookQnaReply.builder()
.content(content)
.writer(writer)
.board(board)
.replyFlag(replyFlag)
.likes(0)
.depth(0)
.orderNo(0)
.deletedFlag(false)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,42 +1,37 @@
package com.esquad.esquadbe.qnaboard.dto;


import com.esquad.esquadbe.qnaboard.entity.BookQnaReply;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

import java.time.format.DateTimeFormatter;

import java.time.LocalDateTime;

@Getter
@Setter
@Builder
public class CommentDTO {
@Getter
public class CommentResponseDTO {
private Long id;
private Long boardId;
private Long writerId;
private String writerName;
private String content;
private Integer likes;
private String createdAt;
private String modifiedAt;
private boolean replyFlag; // 대댓글 여부
private LocalDateTime createdAt;
private LocalDateTime modifiedAt;
private boolean replyFlag;
private boolean deletedFlag;

// 엔티티에서 DTO로 변환하는 메서드
public static CommentDTO from(BookQnaReply reply) {
return CommentDTO.builder()
public static CommentResponseDTO from(BookQnaReply reply) {
return CommentResponseDTO.builder()
.id(reply.getId())
.boardId(reply.getBoard().getId())
.writerId(reply.getWriter().getId())
.writerName(reply.getWriter().getNickname())
.content(reply.getContent())
.likes(reply.getLikes())
.createdAt(reply.getCreatedAt().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
.modifiedAt(reply.getModifiedAt() != null
? reply.getModifiedAt().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
: null)
.createdAt(reply.getCreatedAt())
.modifiedAt(reply.getModifiedAt())
.replyFlag(reply.isReplyFlag())
.deletedFlag(reply.isDeletedFlag())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Builder
public class PagingInfoDTO {
private int totalPosts; // 모든 글 개수
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
import lombok.Builder;
import lombok.Getter;

import java.time.format.DateTimeFormatter;

@Builder
@Getter
public class QnaBoardResponseDTO {
public class QnaBoardResponseDTO {
private Long id;
private String title;
private Long userId;
Expand All @@ -18,8 +16,6 @@ public class QnaBoardResponseDTO {
private Long teamSpaceId;
private String teamSpaceName;
private String content;
private String createdAt;
private String modifiedAt;
private Integer likes;

// 정적 팩토리 메서드
Expand All @@ -34,14 +30,8 @@ public static QnaBoardResponseDTO from(BookQnaBoard bookQnaBoard) {
.teamSpaceId(bookQnaBoard.getTeamSpace().getId())
.teamSpaceName(bookQnaBoard.getTeamSpace().getTeamName())
.content(bookQnaBoard.getContent())
.createdAt(bookQnaBoard.getCreatedAt().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
.modifiedAt(bookQnaBoard.getModifiedAt() != null
? bookQnaBoard.getModifiedAt().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
: null)
.likes(bookQnaBoard.getLikes())
.build();
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public record QnaRequestDTO(
Long id,
String title,
String content,
Long userId,
String username,
Long bookId,
Long teamSpaceId
) {
Expand Down
33 changes: 0 additions & 33 deletions src/main/java/com/esquad/esquadbe/qnaboard/entity/BookQnaLike.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,4 @@ public class BookQnaReply extends BasicEntity {

@Column(name = "DELETED_FLAG", columnDefinition = "TINYINT(1) DEFAULT 0")
private boolean deletedFlag;

// @OneToMany(mappedBy = "parentReply", orphanRemoval = true)
// private List<BookQnaReply> childReplies;
}
Loading