Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: infrastructure 유닛테스트, comment 유닛테스트 리팩토링 * test: Post 관련 유닛테스트 리팩토링 * test: Post application 레이어 관련 테스트 리팩토링 * test: Post 인수 테스트 리팩토링 * test: PostControllerTest 리팩토링 추가 * test: post builder를 사용하도록 변경 * refactor: 리베이스 후 깨지는 테스트 수정 및 누락된 테스트 추가 refactor: Post의 Tag관련 비즈니스 로직 PostTags로 이동 (#259) 이동과 함께 Post의 Build 패턴 적용과 리팩토링. refactor: PostService와 PostController의 책임 분리. 및 s3Storage 파일 저장 방식 추가 (#259) feed관련과, 게시물 관련으로 분리하여 관심사를 맞춤. refactor: 전체적인 import 정리 (#259) refactor: 패키지 정리 (#259) refactor: Post의 getImageUrl 중복 메서드 제거 (#259) refactor: CommentResponse의 도메인 참조 제거 및 DtoAssembler 리팩토링 (#259) refactor: Feed관련 컨트롤러, 서비스, PostDto어셈블러 리팩토링, 레이어에 맞지 않는 DTO 이동 (#259) refactor: CommentRequestDto 패키지 변경 및 PostController 리팩토링 (#259) refactor: PostResponseDto가 presentation~presentation까지 사용되던것을 분리 (#259) refactor: showRepositories -> userRepositories 메서드명 변경 (#259) refactor: RepositoryResponse, domain -> controller까지 사용 되던것을 분리 (#259) style: domain을 제외한 레이어의 구글 컨벤션 체크 (#259) refactor: PostImageUrlResponseDto Builder 사용하도록 변경 refactor: Post 컨벤션 및 메서드 순서 정리 (#259) refactor: Post user 관련 메서드명 author로 변경 및 필드, 메서드 정리 (#249) refactor: PostTag equals getId()로 변경 및 필드 순서 정리 (#249) refactor: Like를 VO로 취급, Likes를 컨테이너로 취급하도록 변경 (#249) refactor: Image VO로 취급 및 도움 메서드 네이밍 변경, PostContent validation로직 변경 (#249) refactor: CommentContent VO 취급, comment 도움메서드 이름 변경 및 책임 변경 (#249) refactor: Post equals getter를 사용하도록 변경 (#249) refactor: 연관관계 도움 메서드 반환깂 없도록 변경 (#249) style: 구글 컨벤션 적용 (#249) refactor: 추상화 수준 평탄화 작업 (#249)
- Loading branch information
Showing
71 changed files
with
1,958 additions
and
771 deletions.
There are no files selected for viewing
2 changes: 0 additions & 2 deletions
2
...it/src/main/java/com/woowacourse/pickgit/authentication/application/JwtTokenProvider.java
This file contains 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 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 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
...end/pick-git/src/main/java/com/woowacourse/pickgit/common/network/RestTemplateClient.java
This file contains 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 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 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 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
82 changes: 58 additions & 24 deletions
82
...end/pick-git/src/main/java/com/woowacourse/pickgit/post/application/PostDtoAssembler.java
This file contains 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 |
---|---|---|
@@ -1,46 +1,80 @@ | ||
package com.woowacourse.pickgit.post.application; | ||
|
||
import com.woowacourse.pickgit.authentication.domain.user.AppUser; | ||
import com.woowacourse.pickgit.post.application.dto.CommentResponse; | ||
import static java.util.stream.Collectors.toList; | ||
|
||
import com.woowacourse.pickgit.post.application.dto.response.CommentResponseDto; | ||
import com.woowacourse.pickgit.post.application.dto.response.PostResponseDto; | ||
import com.woowacourse.pickgit.post.domain.Post; | ||
import com.woowacourse.pickgit.post.domain.comment.Comment; | ||
import com.woowacourse.pickgit.tag.domain.Tag; | ||
import com.woowacourse.pickgit.user.domain.User; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.function.Function; | ||
|
||
public class PostDtoAssembler { | ||
|
||
private PostDtoAssembler() { | ||
} | ||
|
||
public static List<PostResponseDto> assembleFrom(AppUser appUser, List<Post> posts) { | ||
public static List<PostResponseDto> assembleFrom( | ||
User requestUser, | ||
boolean isGuest, | ||
List<Post> posts | ||
) { | ||
return posts.stream() | ||
.map(post -> convertFrom(post, appUser)) | ||
.collect(Collectors.toList()); | ||
.map(post -> convertFrom(requestUser, isGuest, post)) | ||
.collect(toList()); | ||
} | ||
|
||
private static PostResponseDto convertFrom(User requestUser, boolean isGuest, Post post) { | ||
List<String> tags = createTagsFrom(post); | ||
List<CommentResponseDto> comments = createCommentResponsesFrom(post); | ||
|
||
return PostResponseDto.builder() | ||
.id(post.getId()) | ||
.imageUrls(post.getImageUrls()) | ||
.githubRepoUrl(post.getGithubRepoUrl()) | ||
.content(post.getContent()) | ||
.authorName(post.getAuthorName()) | ||
.profileImageUrl(post.getAuthorProfileImage()) | ||
.likesCount(post.getLikeCounts()) | ||
.tags(tags) | ||
.createdAt(post.getCreatedAt()) | ||
.updatedAt(post.getUpdatedAt()) | ||
.comments(comments) | ||
.isLiked(isLikedBy(requestUser, post, isGuest)) | ||
.build(); | ||
} | ||
|
||
private static PostResponseDto convertFrom(Post post, AppUser appUser) { | ||
User postWriter = post.getUser(); | ||
List<String> tags = post.getTags() | ||
private static List<CommentResponseDto> createCommentResponsesFrom(Post post) { | ||
return post.getComments() | ||
.stream() | ||
.map(Tag::getName) | ||
.collect(Collectors.toList()); | ||
List<CommentResponse> comments = post.getComments() | ||
.map(toCommentResponse()) | ||
.collect(toList()); | ||
} | ||
|
||
private static Function<Comment, CommentResponseDto> toCommentResponse() { | ||
return comment -> CommentResponseDto.builder() | ||
.id(comment.getId()) | ||
.profileImageUrl(comment.getProfileImageUrl()) | ||
.authorName(comment.getAuthorName()) | ||
.content(comment.getContent()) | ||
.isLiked(false) | ||
.build(); | ||
} | ||
|
||
private static List<String> createTagsFrom(Post post) { | ||
return post.getTags() | ||
.stream() | ||
.map(CommentResponse::from) | ||
.collect(Collectors.toList()); | ||
|
||
if (appUser.isGuest()) { | ||
return new PostResponseDto(post.getId(), post.getImageUrls(), post.getGithubRepoUrl(), | ||
post.getContent(), postWriter.getName(), postWriter.getImage(), | ||
post.getLikeCounts(), | ||
tags, post.getCreatedAt(), post.getUpdatedAt(), comments, null); | ||
.map(Tag::getName) | ||
.collect(toList()); | ||
} | ||
|
||
private static Boolean isLikedBy(User requestUser, Post post, boolean isGuest) { | ||
if (isGuest) { | ||
return null; | ||
} | ||
|
||
return new PostResponseDto(post.getId(), post.getImageUrls(), post.getGithubRepoUrl(), | ||
post.getContent(), postWriter.getName(), postWriter.getImage(), | ||
post.getLikeCounts(), | ||
tags, post.getCreatedAt(), post.getUpdatedAt(), comments, post.isLikedBy(appUser.getUsername())); | ||
return post.isLikedBy(requestUser); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
backend/pick-git/src/main/java/com/woowacourse/pickgit/post/application/PostFeedService.java
This file contains 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,82 @@ | ||
package com.woowacourse.pickgit.post.application; | ||
|
||
import com.woowacourse.pickgit.exception.authentication.UnauthorizedException; | ||
import com.woowacourse.pickgit.exception.user.UserNotFoundException; | ||
import com.woowacourse.pickgit.post.application.dto.request.HomeFeedRequestDto; | ||
import com.woowacourse.pickgit.post.application.dto.response.PostResponseDto; | ||
import com.woowacourse.pickgit.post.domain.Post; | ||
import com.woowacourse.pickgit.post.domain.repository.PostRepository; | ||
import com.woowacourse.pickgit.user.domain.User; | ||
import com.woowacourse.pickgit.user.domain.UserRepository; | ||
import java.util.List; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
public class PostFeedService { | ||
|
||
private final PostRepository postRepository; | ||
private final UserRepository userRepository; | ||
|
||
public PostFeedService(PostRepository postRepository, UserRepository userRepository) { | ||
this.postRepository = postRepository; | ||
this.userRepository = userRepository; | ||
} | ||
|
||
public List<PostResponseDto> homeFeed(HomeFeedRequestDto homeFeedRequestDto) { | ||
return readFeed(homeFeedRequestDto, Optional.empty()); | ||
} | ||
|
||
public List<PostResponseDto> myFeed(HomeFeedRequestDto homeFeedRequestDto) { | ||
String userName = homeFeedRequestDto.getRequestUserName(); | ||
|
||
if (Objects.isNull(userName)) { | ||
throw new UnauthorizedException(); | ||
} | ||
|
||
return readFeed(homeFeedRequestDto, Optional.of(userName)); | ||
} | ||
|
||
public List<PostResponseDto> userFeed(HomeFeedRequestDto homeFeedRequestDto, String userName) { | ||
return readFeed(homeFeedRequestDto, Optional.of(userName)); | ||
} | ||
|
||
private List<PostResponseDto> readFeed( | ||
HomeFeedRequestDto homeFeedRequestDto, | ||
Optional<String> userName | ||
) { | ||
var page = homeFeedRequestDto.getPage().intValue(); | ||
var limit = homeFeedRequestDto.getLimit().intValue(); | ||
var requestUserName = homeFeedRequestDto.getRequestUserName(); | ||
var isGuest = homeFeedRequestDto.isGuest(); | ||
|
||
Pageable pageable = PageRequest.of(page, limit); | ||
List<Post> result = getPostsBy(userName, pageable); | ||
|
||
User requestUser = findUserByName(requestUserName); | ||
|
||
return PostDtoAssembler.assembleFrom(requestUser, isGuest, result); | ||
} | ||
|
||
private List<Post> getPostsBy(Optional<String> userName, Pageable pageable) { | ||
return userName | ||
.map(this::findUserByName) | ||
.map(target -> postRepository.findAllPostsByUser(target, pageable)) | ||
.orElse(postRepository.findAllPosts(pageable)); | ||
} | ||
|
||
private User findUserByName(String userName) { | ||
if(Objects.isNull(userName)) { | ||
return null; | ||
} | ||
|
||
return userRepository | ||
.findByBasicProfile_Name(userName) | ||
.orElseThrow(UserNotFoundException::new); | ||
} | ||
} |
Oops, something went wrong.