-
Notifications
You must be signed in to change notification settings - Fork 3
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
[feat] 게시물 목록 기능 구현 #30
Conversation
# Conflicts: # src/main/java/wanted/media/post/controller/PostController.java # src/main/java/wanted/media/post/domain/Post.java
|
||
//System.out.println("PostDtos: " + postDtos); | ||
|
||
return postDtos; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
헉 보내고 나니 ResponseEntity로 구현하는게 기억나서..나중에 다시 코드 리뷰 받고 refactor로 다시 고치겠습니다 죄송합니다 😭
|
||
@Service | ||
public class PostService { | ||
@Autowired |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Autowired
빼고 @Service
어노테이션 밑에 @RequiredArgsConstructor
사용해주시면 더 깔끔할 것 같슴당
|
||
return postRepository.findBySearchContaining(account, type, searchBy, search, pageable); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
불필요한 공백 제거해주세요~
Sort sort = Sort.by(Sort.Direction.fromString(sortDirection), orderBy); | ||
Pageable pageable = PageRequest.of(page, pageCount, sort); | ||
|
||
// if (search == null || search.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
주석처리한 로직은 사용하지 않으시는건가요?
.map(PostDto::allPosts) | ||
.collect(Collectors.toList()); | ||
|
||
//System.out.println("PostDtos: " + postDtos); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
사용하지 않는 로직은 제거해서 올려주시면 됩니당 41라인 공백도 제거해 주세요~!
// 예시: 검색 조건에 맞는 게시물이 없는 경우 예외 처리 | ||
Page<Post> posts = postRepository.findBySearchContaining(account, type, searchBy, search, pageable); | ||
if (posts.isEmpty()) { | ||
throw new CustomException(ErrorCode.ENTITY_NOT_FOUND); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기는 CustomException보단 NotFoundException을 사용하시는게 맞는것같아요
35라인에 불필요한 공백 제거해주세요!
src/main/resources/data.sql
Outdated
INSERT INTO contents(like_count, type, title, content, hashtags, view_count, share_count, updated_at, created_at, | ||
user_id) | ||
VALUES (30, 'INSTAGRAM', '판교 나들이', '오늘은 판교에 와보았어요. 미래의 직장이 될 곳들이 많이...', 'wanted', 24, 7, '2024-08-23', '2024-08-20', | ||
'wanted'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EOL이 안지켜졌네요 !
List<PostDto> posts = responseEntity.getBody(); | ||
assertThat(posts).isNotEmpty(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기도 EOL이 안지켜졌네요!
|
||
// 예시: 검색 조건에 맞는 게시물이 없는 경우 예외 처리 | ||
Page<Post> posts = postRepository.findBySearchContaining(account, type, searchBy, search, pageable); | ||
if (posts.isEmpty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
해당 게시물이 없으면 에러를 던지는게 아니라 그냥 빈 Post를 반환하는것도 좋은거 같은데 어떻게 생각하세용?
|
||
@Service | ||
public class PostService { | ||
@Autowired |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기도 @Autowired
를 제거하고 @RequiredArgsConstructor
를 달아주시면 좋을 것 같습니당
@NoArgsConstructor | ||
@Getter | ||
@Setter | ||
public class PostDto { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
record 클래스로 바꾸시면 더 깔끔할 것 같습니다!
public record PostDto(
String id,
Long likeCount,
Type type,
String title,
String content,
String hashtags,
Long viewCount,
Long shareCount,
LocalDateTime updatedAt,
LocalDateTime createdAt,
String account) {
public static PostDto allPosts(Post post) {
return new PostDto(
post.getId(),
post.getLikeCount(),
post.getType(),
post.getTitle(),
post.getContent(),
post.getHashtags(),
post.getViewCount(),
post.getShareCount(),
post.getUpdatedAt(),
post.getCreatedAt(),
post.getUser().getAccount()
);
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
수고하셨습니다!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다!
public class PostService { | ||
private PostRepository postRepository; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final을 붙여주셔야 @RequiredArgsConstructor
가 동작하는 걸로 알고 있어용
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다!
Issue
PR 타입(하나 이상의 PR 타입을 선택해주세요)
반영 브랜치
feat/content_list_search -> dev
변경 사항
테스트 결과
Request
Response : 성공시
Response : 실패시
500 에러
잘못된 정렬 기준, 정렬 방향일 때
404 에러
존재하지 않는 account, 검색어 일 때
페이지 수가 너무 클 때