-
Notifications
You must be signed in to change notification settings - Fork 3
댓글 기능 추가 / 기존 기능 리팩토링 / 조회수 기능 추가 #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
DongCaprio
wants to merge
45
commits into
GrowingMates:DongCaprio
Choose a base branch
from
DongCaprio:DongCaprio
base: DongCaprio
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 21 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
9407b7a
refactor : 공통 패키지 명에서 board 제거
DongCaprio e644327
refactor : ArticleEntity 에 createdAt 추가
DongCaprio 68ed2a9
feat : 댓글 기능 관련 Entity / Service 개발
DongCaprio 41f37e4
feat : 댓글 삭제 기능 리팩토링(상태true, false로 관리)
DongCaprio 03df248
feat : 댓글 관련 service test 추가
DongCaprio 171ea5f
feat : 댓글 기능 추가(controller, test)
DongCaprio e5ff8ec
test : 댓글 통합테스트 작성
DongCaprio 46653fd
refactor : jwt 패턴 추가(댓글 url)
DongCaprio fd7d7a2
refactor : 개별 게시글 조회때만 내용 보이게 수정
DongCaprio 8d35c9e
feat : 게시글 조회수 기능 추가
DongCaprio d7fc582
refactor : 메서드 명 및 분리 등 리팩토링 진행
DongCaprio db1869a
refactor : 클래스명 더 알맞게 리팩토링
DongCaprio ab235c4
refactor : findAll(여러개) 반환 시 Page 관련 DTO로 반환하도록 수정
DongCaprio 9ce6cf6
refactor : 게시글 포함 안하는 response
DongCaprio 533e160
refactor : sort 기본값(최신순 정렬)로 보이도록 수정
DongCaprio a61a1cc
refactor : 삭제 기능 추가(soft delete)
DongCaprio 08d082e
refactor : 파일 위치(패키지) 변경
DongCaprio f5f6699
feat : SortUtils 클래스 생성(내용 아직 미완성)
DongCaprio e83c64e
feat : 공통 정렬 util 클래스 완성
DongCaprio 2145079
refactor : 로그인 예외처리 더 자세하게 변경
DongCaprio 9410b16
feat : 로그아웃 / 회원탈퇴 기능 추가
DongCaprio 4c253f5
refactor : null 코드에 명시한 부분 제거
DongCaprio 0a33f9f
refactor : boolean 변수명 앞에 is 접두사 붙여 명시적으로 변경
DongCaprio 0eccefb
refactor : 변수명 deleted > isDeleted로 변경했으므로 repository 메서드명도 변경
DongCaprio 4baafc9
refactor : long vs Long 구분해서 더 적절한것으로 변경
DongCaprio 7e08bc7
refactor : requestDTO의 Long 변수에도 유효성 체크 어노테이션 추가
DongCaprio ce53e20
refactor : 공통되는 entity 속성 extends와 @MappedSuperclass 사용하여 공통화
DongCaprio f85e734
refactor : 동등성 어노테이션 추가
DongCaprio 54139ac
refactor : jwt 인증 필요 유무 JwtAuthFilter에서 관리
DongCaprio cb5d446
test : MemberEntity의 @EqualsAndHashCode 추가로 인한 테스트 코드 변경
DongCaprio 07e454c
refactor : 게시글 조회수 증가 -> 동시성 문제로 인한 리팩토링
DongCaprio f0922e9
refactor,test : 통합테스트 커스텀 어노테이션 생성 및 사용
DongCaprio b2e1876
refactor : 비회원도 요청가능한 controller 요청 분리
DongCaprio fd990dd
refactor : jwt가 필요한 경로 및 httpMethod enum으로 분리 진행
DongCaprio 22430a2
refactor : 댓글관련 controller restApi에 맞게 변경
DongCaprio 0b9d34f
refactor : cookie 관련 내용 전부 삭제
DongCaprio df2932a
feat : 리프레시 토큰 기능 추가
DongCaprio fbfff37
refactor : 토큰의 id를 emial -> memberId로 수정
DongCaprio 168e5ef
test, feat : 스프링 컨텍스트 초기화용 어노테이션 추가
DongCaprio 16e145e
feat, build, test : 통합테스트에 @Transactional 제거 후 CleanDatabase 추가
DongCaprio edbb190
test : ddl-auto 속성 변경
DongCaprio 91ea56c
feat : 대댓글 기능 추가
DongCaprio d8cfa32
test : 대댓글 기능 테스트 작성
DongCaprio 90e07f8
feat : Redis 활용하여 조회수 증가 처리 및 조회
DongCaprio e6a552b
refactor : 조회수 증가 Controller > Service로 로직 이동 , 게시글 삭제시 Redis에도 삭제되는 …
DongCaprio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...main/java/com/board/BoardApplication.java → src/main/java/com/BoardApplication.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
src/main/java/com/board/board/dto/response/ArticleResponse.java
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| package com.board.controller; | ||
|
|
||
| import com.board.dto.request.CommentCreateRequest; | ||
| import com.board.dto.request.CommentUpdateRequest; | ||
| import com.board.dto.response.CommentResponse; | ||
| import com.board.entity.CommentEntity; | ||
| import com.board.service.CommentService; | ||
| import com.config.auth.annotation.AuthenticatedMember; | ||
| import com.util.page.PageResponse; | ||
| import com.util.sort.SortUtils; | ||
| import jakarta.validation.Valid; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.PageRequest; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PatchMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @RestController | ||
| @RequestMapping("/comments") | ||
| public class CommentController { | ||
|
|
||
| private final CommentService commentService; | ||
|
|
||
| @GetMapping | ||
| public ResponseEntity<PageResponse<CommentResponse>> findAllComments(@RequestParam Long articleId, | ||
| @RequestParam(defaultValue = "0") int page, | ||
| @RequestParam(defaultValue = "10") int size, | ||
| @RequestParam(defaultValue = "latest") String sort) { | ||
| Pageable pageable = PageRequest.of(page, size, SortUtils.getCommentSort(sort)); | ||
| Page<CommentResponse> commentPage = commentService.findAllComments(articleId, pageable) | ||
| .map(CommentResponse::new); | ||
|
|
||
| return ResponseEntity.ok(PageResponse.from(commentPage)); | ||
| } | ||
|
|
||
| @PostMapping | ||
| public ResponseEntity<CommentResponse> addComment(@Valid @RequestBody CommentCreateRequest request, | ||
| @AuthenticatedMember Long memberId) { | ||
| CommentEntity savedComment = commentService.createComment(request, memberId); | ||
|
|
||
| return ResponseEntity.status(HttpStatus.CREATED) | ||
| .body(new CommentResponse(savedComment)); | ||
| } | ||
|
|
||
| @PatchMapping("/{commentId}") | ||
| public ResponseEntity<CommentResponse> updateComment(@PathVariable long commentId, | ||
sosow0212 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| @Valid @RequestBody CommentUpdateRequest request, | ||
| @AuthenticatedMember Long memberId) { | ||
| request.setCommentId(commentId); | ||
| CommentEntity updatedComment = commentService.updateComment(request, memberId); | ||
| return ResponseEntity.ok() | ||
| .body(new CommentResponse(updatedComment)); | ||
| } | ||
|
|
||
| @DeleteMapping("/{commentId}") | ||
| public ResponseEntity<Void> deleteComment(@PathVariable long commentId, | ||
| @AuthenticatedMember Long memberId) { | ||
| commentService.deleteComment(commentId, memberId); | ||
| return ResponseEntity.noContent() | ||
| .build(); | ||
| } | ||
| } | ||
2 changes: 1 addition & 1 deletion
2
...ard/dto/request/ArticleCreateRequest.java → ...ard/dto/request/ArticleCreateRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ard/dto/request/ArticleUpdateRequest.java → ...ard/dto/request/ArticleUpdateRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/com/board/dto/request/CommentCreateRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.board.dto.request; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| @Getter | ||
| @NoArgsConstructor | ||
| public class CommentCreateRequest { | ||
|
|
||
| @NotBlank(message = "내용을 입력해주세요") | ||
| private String content; | ||
| private Long articleId; | ||
DongCaprio marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| @Builder | ||
| public CommentCreateRequest(String content, Long articleId) { | ||
| this.content = content; | ||
| this.articleId = articleId; | ||
| } | ||
| } | ||
23 changes: 23 additions & 0 deletions
23
src/main/java/com/board/dto/request/CommentUpdateRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| package com.board.dto.request; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @NoArgsConstructor | ||
| public class CommentUpdateRequest { | ||
|
|
||
| @NotBlank(message = "내용을 입력해주세요") | ||
| private String content; | ||
| private Long commentId; | ||
sosow0212 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Builder | ||
| public CommentUpdateRequest(String content, Long commentId) { | ||
| this.content = content; | ||
| this.commentId = commentId; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package com.board.dto.response; | ||
|
|
||
| import com.board.entity.ArticleEntity; | ||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Getter | ||
| public class ArticleResponse { | ||
|
|
||
| private final Long id; | ||
| private final String title; | ||
| private String content; | ||
sosow0212 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| private final Long memberId; | ||
| private final long viewCount; | ||
|
|
||
| @Builder | ||
| public ArticleResponse(Long id, String title, String content, Long memberId, long viewCount) { | ||
| this.id = id; | ||
| this.title = title; | ||
| this.content = content; | ||
| this.memberId = memberId; | ||
| this.viewCount = viewCount; | ||
| } | ||
|
|
||
| public ArticleResponse(ArticleEntity article) { | ||
| this.id = article.getId(); | ||
| this.title = article.getTitle(); | ||
| this.content = article.getContent(); | ||
| this.memberId = article.getMember().getId(); | ||
| this.viewCount = article.getViewCount(); | ||
| } | ||
|
|
||
| public static ArticleResponse withoutContent(ArticleEntity article) { | ||
| return ArticleResponse.builder() | ||
| .id(article.getId()) | ||
| .title(article.getTitle()) | ||
| .content(null) // content 포함 안함 | ||
sosow0212 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .memberId(article.getMember().getId()) | ||
| .viewCount(article.getViewCount()) | ||
| .build(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.board.dto.response; | ||
|
|
||
| import com.board.entity.CommentEntity; | ||
| import java.time.LocalDateTime; | ||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Getter | ||
| public class CommentResponse { | ||
|
|
||
| private final Long id; | ||
| private final String content; | ||
| private final Long authorId; | ||
| private final String authorName; | ||
| private final LocalDateTime createdAt; | ||
| private final boolean deleted; | ||
|
|
||
| public CommentResponse(CommentEntity comment) { | ||
| this.id = comment.getId(); | ||
| this.content = comment.getContent(); | ||
| this.authorId = comment.getMember().getId(); | ||
| this.authorName = comment.getMember().getNickName(); | ||
| this.createdAt = comment.getCreatedAt(); | ||
| this.deleted = comment.isDeleted(); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.