Skip to content
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

[5기 최정은, 권효승] Spring Boot JPA 게시판 구현 미션 제출합니다. #275

Open
wants to merge 51 commits into
base: jehs
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
6027063
init: init project
hyoguoo Nov 22, 2023
b223165
config: yaml 파일 데이터베이스 연결 설정
hyoguoo Nov 22, 2023
63b5c68
feat: BaseEntity 추가
hyoguoo Nov 22, 2023
b923f63
feat: User Entity 추가
hyoguoo Nov 22, 2023
8fd8a61
feat: Post Entity 추가
hyoguoo Nov 22, 2023
e2e231b
feat: Entity가 생성 시, 생성/수정 시간 자동 설정
JeongeunChoi Nov 22, 2023
bd6a35d
feat: 엔터티 setter 삭제 및 builder 설정
JeongeunChoi Nov 22, 2023
46d5028
feat: Post, User Repository 추가
JeongeunChoi Nov 22, 2023
65b60c6
feat: 게시글 생성 서비스 로직 추가
JeongeunChoi Nov 22, 2023
190bae6
feat: 게시글 페이지 조회 및 특정 게시글 조회 서비스 로직 추가
JeongeunChoi Nov 22, 2023
33aa13b
feat: 게시글 수정 서비스 로직 추가
JeongeunChoi Nov 22, 2023
b59bdb8
feat: 게시글 관련 Rest API 추가
JeongeunChoi Nov 22, 2023
f4fb87a
chore: 실행을 위한 임시 값 수정
JeongeunChoi Nov 22, 2023
51da029
feat: BaseEntity Getter 추가
hyoguoo Nov 23, 2023
10217c9
chore: 코드 복구
hyoguoo Nov 23, 2023
3b68d6c
feat: Post 조회 Response 추가
hyoguoo Nov 23, 2023
2ed642c
feat: User 조회 Response 추가
hyoguoo Nov 23, 2023
b449a6e
mod: Post 도메인 그대로 노출되는 것 변경(PostResponse 적용)
hyoguoo Nov 23, 2023
44117f5
feat: 성공 메시지 클래스 추가
JeongeunChoi Nov 23, 2023
edfb18a
feat: ResponseEntity 적용
JeongeunChoi Nov 23, 2023
8a7334e
feat: User, Post 커스텀 예외 메시지 및 클래스 생성
JeongeunChoi Nov 23, 2023
94151db
feat: User, Post 커스텀 예외 적용
JeongeunChoi Nov 23, 2023
1921dc3
feat: 예외 처리 컨트롤러 어드바이스 추가
JeongeunChoi Nov 23, 2023
1a9c44d
mod: Post fetch join 적용
JeongeunChoi Nov 23, 2023
a98c640
config: database default user insert 쿼리 추가
hyoguoo Nov 23, 2023
f793dec
feat: Post Controller API 통합 테스트 추가
hyoguoo Nov 23, 2023
ad00ca4
chore: restdocs adoc 파일 설정
JeongeunChoi Nov 24, 2023
9d47d3f
feat: PostControllerTest restdocs 추가
JeongeunChoi Nov 24, 2023
4becb69
feat: 요청 및 응답값 prettyPrint 설정
hyoguoo Nov 24, 2023
0f3fae6
feat: RestDocs request/response fields 추가
hyoguoo Nov 24, 2023
6aaabf5
feat: 에러 발생 시 로깅 추가
hyoguoo Nov 24, 2023
e31ae94
feat: 전체 Exception 대상 Handler 추가
hyoguoo Nov 24, 2023
e1621ed
feat: Cursor 기반 Post 리스트 조회 구현
hyoguoo Nov 26, 2023
2781796
mod: Cursor 기반 조회 시 Slice 타입으로 변경
hyoguoo Nov 26, 2023
7226a2a
feat: User isSameName 메서드 구현 및 적용
hyoguoo Dec 4, 2023
6ba889b
chore: code reformat 적용
hyoguoo Dec 4, 2023
5be79c1
mod: RequestMapping 제거
hyoguoo Dec 4, 2023
fb847a5
mod: RequestMapping 제거 및 SuccessMessage 제네릭 적용
hyoguoo Dec 4, 2023
c4f934b
mod: 알 수 없는 에러 발생 시 상세 에러 정보 반환하지 않도록 변경
hyoguoo Dec 4, 2023
eeb45ff
chore: 게시글 생성 메서드 Transational 어노테이션 적용
hyoguoo Dec 4, 2023
6232a38
mod: Post 리스트 조회 시 Pageable 객체 대신 필요한 값만 받도록 변경 및 Post 리스트 조회 Respons…
hyoguoo Dec 4, 2023
f1cbbe7
mod: 업데이트 시간 애플리케이션 레벨에서 관리되도록 수정
hyoguoo Dec 4, 2023
6d5d2f5
feat: postType ColumnName 명시 추가
hyoguoo Dec 4, 2023
de7046e
fix: 정렬 옵션 제거
hyoguoo Dec 4, 2023
c6a8683
fix: PagesResponse 명세로 변경
hyoguoo Dec 4, 2023
88c16dd
mod: Post 리스트 조회 시 Slice 객체 대신 필요한 값만 받도록 변경 및 Post 리스트 조회 Response 적용
JeongeunChoi Dec 6, 2023
c4ab0e0
chore: 코드 리포멧
hyoguoo Dec 6, 2023
245af97
mod: @EnableJpaAuditing 제거
JeongeunChoi Dec 11, 2023
680e343
refactor: List 조회 Response DTO 제네릭 클래스로 변경
hyoguoo Dec 12, 2023
dfc083b
feat: User 엔티티 age 값 객체 생성 및 검증 로직 추가
hyoguoo Dec 12, 2023
6d76b2f
chore: 불필요한 Rest Docs 관련 그래들 설정 삭제
JeongeunChoi Dec 12, 2023
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
@@ -1,12 +1,8 @@
package jehs.springbootboardjpa.controller;

import jehs.springbootboardjpa.dto.PostCreateRequest;
import jehs.springbootboardjpa.dto.PostResponse;
import jehs.springbootboardjpa.dto.PostUpdateRequest;
import jehs.springbootboardjpa.dto.PostsResponse;
import jehs.springbootboardjpa.dto.*;
import jehs.springbootboardjpa.service.PostService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Slice;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand Down Expand Up @@ -40,7 +36,7 @@ public ResponseEntity<SuccessMessage<PostsResponse>> getAllPosts(@RequestParam(n
}

@GetMapping("/api/v1/posts/cursor")
public ResponseEntity<SuccessMessage<Slice<PostResponse>>> getAllPostsByCursor(@RequestParam(name = "size") int size, @RequestParam(name = "cursorId") Long cursorId) {
public ResponseEntity<SuccessMessage<PostsCursorResponse>> getAllPostsByCursor(@RequestParam(name = "size") int size, @RequestParam(name = "cursorId") Long cursorId) {
return new ResponseEntity<>(
new SuccessMessage<>(
"성공적으로 모든 게시글이 조회되었습니다.",
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/jehs/springbootboardjpa/dto/PostsCursorResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package jehs.springbootboardjpa.dto;

import jehs.springbootboardjpa.entity.Post;
import lombok.Getter;
import org.springframework.data.domain.Slice;

import java.util.List;

@Getter
public class PostsCursorResponse {

private final List<PostResponse> content;
private final boolean hasNext;
Comment on lines +10 to +13

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

커서도 공통화할 수 있을지 고민해보면 좋을 것 같네요 👍
그리고 슬라이스를 활용하는 방법이 괜찮을지 고민해봐주세요.

  • 슬라이스는 이전에 말씀드린대로 오프셋 기반으로 가져오지만 카운트 쿼리를 별도로 날리지 않은 형태에요.
  • 실제 구현은 jpql로 커서 방식으로 하지만 slice 활용으로 인해 혼란을 줄 수 있을 것 같아요.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"실제 구현은 jpql 커서 방식으로 진행하지만 반환값이 Slice라는 점이 혼란을 줄 수 있을 것 같다." 라고 이해했는데, 여기서는 Slice의 hasNext 값을 가져오기 위해 사용해보았는데, 보통 Slice 객체를 반환하지 않는 편인가요?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 Slice 객체를 반환하지 않는 편이에요.
nextCursor와 데이터를 내려주는 편입니다.


public PostsCursorResponse(Slice<Post> postSlice) {
this.content = postSlice.getContent().stream().map(PostResponse::new).toList();
this.hasNext = postSlice.hasNext();
}
}
14 changes: 6 additions & 8 deletions src/main/java/jehs/springbootboardjpa/service/PostService.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package jehs.springbootboardjpa.service;

import jehs.springbootboardjpa.dto.PostCreateRequest;
import jehs.springbootboardjpa.dto.PostResponse;
import jehs.springbootboardjpa.dto.PostUpdateRequest;
import jehs.springbootboardjpa.dto.PostsResponse;
import jehs.springbootboardjpa.dto.*;
import jehs.springbootboardjpa.entity.Post;
import jehs.springbootboardjpa.entity.User;
import jehs.springbootboardjpa.exception.PostErrorMessage;
import jehs.springbootboardjpa.exception.PostException;
import jehs.springbootboardjpa.repository.PostRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.*;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -53,8 +50,9 @@ public PostsResponse getAllPostsWithUser(int page, int size) {
}

@Transactional(readOnly = true)
public Slice<PostResponse> getAllPostsWithUserByCursor(int size, Long cursorId) {
return postRepository.findAllWithUserByCursor(cursorId, PageRequest.of(0, size))
.map(PostResponse::new);
public PostsCursorResponse getAllPostsWithUserByCursor(int size, Long cursorId) {
return new PostsCursorResponse(
postRepository.findAllWithUserByCursor(cursorId, PageRequest.of(0, size))
);
}
}