Skip to content

Commit

Permalink
[fix] refactor. 코드 리팩토링.프로필 정보 추가.
Browse files Browse the repository at this point in the history
  • Loading branch information
dongseoki committed Jan 7, 2024
1 parent 2f1da46 commit 1af0cfe
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ public void deleteAttachesByRefNoAndAttachType(Long refNo, AttachType attachType
}
}

public Map<Long, List<AttachDto>> getAttachListBykeysAndType(List<Long> keys,
AttachType attachType) {
public Map<Long, List<AttachDto>> getAttachInfoMapBykeysAndType(List<Long> keys,
AttachType attachType) {
List<Attach> attachList =
attachRepository.findByRefNoInAndAttachTypeIsAndDelYnIs(keys, attachType,
YesOrNo.N);
Expand All @@ -70,4 +70,16 @@ public Map<Long, List<AttachDto>> getAttachListBykeysAndType(List<Long> keys,
}
return kToAMap;
}

public List<AttachDto> getAttachListBykeyAndType(Long key,
AttachType attachType) {
List<Attach> attachList =
attachRepository.findByRefNoInAndAttachTypeIsAndDelYnIs(List.of(key), attachType,
YesOrNo.N);
List<AttachDto> attachDtos = new ArrayList<>();
for (Attach attach : attachList) {
attachDtos.add(AttachDto.of(attach));
}
return attachDtos;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

@Component
@RequiredArgsConstructor
public class PostManager {
public class PostService {
private final PostRepository postRepository;
private final PostMybatisRepository postMybatisRepository;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.bside.bside_311.component;

import com.bside.bside_311.entity.User;
import com.bside.bside_311.entity.YesOrNo;
import com.bside.bside_311.repository.UserRepository;
import com.bside.bside_311.util.MessageUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

@Slf4j
@Component
@RequiredArgsConstructor
public class UserManager {
private final UserRepository userRepository;

public User getUser(Long userNo) {
if (ObjectUtils.isEmpty(userNo)) {
return null;
}
return userRepository.findByIdAndDelYnIs(userNo, YesOrNo.N).orElseThrow(
() -> new IllegalArgumentException(MessageUtil.USER_NOT_FOUND_MSG));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.bside.bside_311.dto.PostResponseDto;
import com.bside.bside_311.dto.common.ResultDto;
import com.bside.bside_311.entity.Post;
import com.bside.bside_311.service.PostService;
import com.bside.bside_311.service.PostFacade;
import com.bside.bside_311.util.AuthUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
Expand Down Expand Up @@ -49,15 +49,15 @@
@RequestMapping("/posts")
@Tag(name = "게시글", description = "게시글 API")
public class PostController {
private final PostService postService;
private final PostFacade postFacade;

@Operation(summary = "[o]게시글 등록 ", description = "게시글 등록 API")
@UserRequired
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
public AddPostResponseDto addPost(@RequestBody @Valid AddPostRequestDto addPostRequestDto) {
log.info(">>> PostController.addPost");
return postService.addPost(Post.of(addPostRequestDto), addPostRequestDto.getAlcoholNo(),
return postFacade.addPost(Post.of(addPostRequestDto), addPostRequestDto.getAlcoholNo(),
addPostRequestDto.getAlcoholFeature(), addPostRequestDto.getTagList());
}

Expand All @@ -68,15 +68,15 @@ public void editPost(@PathVariable("postNo") Long postNo,
@RequestBody @Valid EditPostRequestDto editPostRequestDto) {
log.info(">>> PostController.editPost");

postService.editPost(postNo, editPostRequestDto);
postFacade.editPost(postNo, editPostRequestDto);
}

@Operation(summary = "[o]게시글 삭제", description = "게시글 삭제 API")
@UserRequired
@DeleteMapping("/{postNo}")
public void deletePost(@PathVariable("postNo") Long postNo) {
log.info(">>> PostController.deletePost");
postService.deletePost(postNo);
postFacade.deletePost(postNo);
}

@Operation(summary = "[o]게시글 목록 조회(v1)", description = "게시글 조회 API")
Expand Down Expand Up @@ -111,7 +111,7 @@ public GetPostResponseDto getPosts(@RequestParam(name = "page", defaultValue = "
} catch (Exception e) {
log.error(">>> PostController.getPost searchUserNos 파싱 에러 Exception", e);
}
return postService.getPosts(page, size, orderColumn, orderType, searchKeyword,
return postFacade.getPosts(page, size, orderColumn, orderType, searchKeyword,
searchUserNoList);
}

Expand Down Expand Up @@ -166,7 +166,7 @@ public Page<PostResponseDto> getPostsV2(
}
}

return postService.getPostsV2(pageable, searchKeyword, searchUserNoList, isLikedByMe,
return postFacade.getPostsV2(pageable, searchKeyword, searchUserNoList, isLikedByMe,
isCommentedByMe, searchAlcoholNoList);
}

Expand All @@ -181,14 +181,14 @@ public ResultDto<Page<PostResponseDto>> getPostsPopular(
@Schema(description = "사이즈", example = "10")
Long size
) {
return postService.getPostsPopular(page, size);
return postFacade.getPostsPopular(page, size);
}

@Operation(summary = "[o]게시글 상세 조회", description = "게시글 상세 조회 API")
@GetMapping("/{postNo}")
public PostResponseDto getPostDetail(@PathVariable("postNo") Long postNo) {
log.info(">>> PostController.getPostDetail");
return postService.getPostDetail(postNo);
return postFacade.getPostDetail(postNo);
}

@Operation(summary = "[o]게시글 댓글 등록", description = "게시글 댓글 등록 API")
Expand All @@ -198,15 +198,15 @@ public PostResponseDto getPostDetail(@PathVariable("postNo") Long postNo) {
public AddCommentResponseDto addComment(@PathVariable("postNo") Long postNo, @Valid @RequestBody
AddCommentRequestDto addCommentRequestDto) {
log.info(">>> PostController.addComment");
return postService.addComment(postNo, addCommentRequestDto);
return postFacade.addComment(postNo, addCommentRequestDto);
}

@Operation(summary = "[o]게시글 댓글 조회", description = "게시글 댓글 조회 API")
@GetMapping("/{postNo}/comments")
@ResponseStatus(HttpStatus.CREATED)
public GetPostCommentsResponseDto getPostComments(@PathVariable("postNo") Long postNo) {
log.info(">>> PostController.getPostComments");
return postService.getPostComments(postNo);
return postFacade.getPostComments(postNo);
}

@Operation(summary = "[o]게시글 댓글 수정", description = "게시글 댓글 수정 API")
Expand All @@ -217,7 +217,7 @@ public void editComment(@PathVariable("postNo") Long postNo,
@Valid @RequestBody
EditCommentRequestDto editCommentRequestDto) {
log.info(">>> PostController.editComment");
postService.editComment(postNo, commentNo, editCommentRequestDto);
postFacade.editComment(postNo, commentNo, editCommentRequestDto);
}

@Operation(summary = "[o]게시글 댓글 삭제", description = "게시글 댓글 삭제 API")
Expand All @@ -226,7 +226,7 @@ public void editComment(@PathVariable("postNo") Long postNo,
public void deleteComment(@PathVariable("postNo") Long postNo,
@PathVariable("commentNo") Long commentNo) {
log.info(">>> PostController.deleteComment");
postService.deleteComment(postNo, commentNo);
postFacade.deleteComment(postNo, commentNo);
}

@Operation(summary = "[o]인용 등록 ", description = "인용 등록 API")
Expand All @@ -239,22 +239,22 @@ public AddQuoteResponseDto addQuote(@PathVariable("postNo")
, @PathVariable("quotedPostNo") @Schema(example = "2", description = "인용하는 포스트 번호")
Long quotedPostNo) {
log.info(">>> PostController.addQuote");
return AddQuoteResponseDto.of(postService.addQuote(postNo, quotedPostNo));
return AddQuoteResponseDto.of(postFacade.addQuote(postNo, quotedPostNo));
}

@Operation(summary = "[o]인용 삭제", description = "인용 삭제 API")
@DeleteMapping("/quotes/{quoteNo}")
@UserRequired
public void deleteQuote(@PathVariable("quoteNo") Long quoteNo) {
log.info(">>> PostController.deleteQuote");
postService.deleteQuote(quoteNo);
postFacade.deleteQuote(quoteNo);
}

@Operation(summary = "[o]인용 복수 조회", description = "인용 복수 조회 API")
@GetMapping("/post-quotes/{postNo}")
public GetQuotesByPostResponseDto getQuotesByPost(@PathVariable("postNo") Long postNo) {
log.info(">>> PostController.getQuoteDetail");
return postService.getQuotesByPost(postNo);
return postFacade.getQuotesByPost(postNo);
}

@Operation(summary = "[o]게시글 좋아요", description = "게시글 좋아요 API")
Expand All @@ -263,7 +263,7 @@ public GetQuotesByPostResponseDto getQuotesByPost(@PathVariable("postNo") Long p
public void likePost(@PathVariable("postNo") Long postNo) {
log.info(">>> PostController.likePost");
Long userNo = AuthUtil.getUserNoFromAuthentication();
postService.likePost(userNo, postNo);
postFacade.likePost(userNo, postNo);
}

@Operation(summary = "[o]게시글 좋아요 취소", description = "게시글 좋아요 취소 API")
Expand All @@ -272,7 +272,7 @@ public void likePost(@PathVariable("postNo") Long postNo) {
public void likeCancelPost(@PathVariable("postNo") Long postNo) {
log.info(">>> PostController.likeCancelPost");
Long userNo = AuthUtil.getUserNoFromAuthentication();
postService.likeCancelPost(userNo, postNo);
postFacade.likeCancelPost(userNo, postNo);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ public class PostResponseDto {
private Long quoteCount;

public static PostResponseDto of(Post post, User user, Alcohol alcohol, List<Tag> tags,
List<Comment> comments, List<AttachDto> attachDtos
List<Comment> comments, List<AttachDto> postAttachDtos,
List<AttachDto> profileAttachDtos
, Boolean isLikedByMe, Boolean isFollowedByMe, Long likeCount, Long quoteCount) {
PostResponseDtoBuilder postResponseDtoBuilder = PostResponseDto.builder();
if (user != null) {
Expand All @@ -74,10 +75,12 @@ public static PostResponseDto of(Post post, User user, Alcohol alcohol, List<Tag
postResponseDtoBuilder.tagList(tagList);
}
// TODO quoteInfo는 나중에.
if (ObjectUtils.isNotEmpty(attachDtos)) {
postResponseDtoBuilder.postAttachUrls(attachDtos);
if (ObjectUtils.isNotEmpty(postAttachDtos)) {
postResponseDtoBuilder.postAttachUrls(postAttachDtos);
}
if (ObjectUtils.isNotEmpty(profileAttachDtos)) {
postResponseDtoBuilder.profileImgUrls(profileAttachDtos);
}

if (ObjectUtils.isNotEmpty(isFollowedByMe)) {
postResponseDtoBuilder.isFollowedByMe(isFollowedByMe);
}
Expand Down
10 changes: 5 additions & 5 deletions server/src/main/java/com/bside/bside_311/init/Initializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ private static void copyInputStreamToFile(InputStream inputStream, File file) th
FileUtils.copyInputStreamToFile(inputStream, file);
}

private void setSecurityContextUserNo(Long userNo) {
SecurityContextHolder.getContext()
.setAuthentication(easyUserRoleAuthenticationFactory(userNo));
}

@PostConstruct
public void init() throws JsonProcessingException {
initAlcoholType();
Expand All @@ -91,6 +86,11 @@ public void init() throws JsonProcessingException {

}

private void setSecurityContextUserNo(Long userNo) {
SecurityContextHolder.getContext()
.setAuthentication(easyUserRoleAuthenticationFactory(userNo));
}

private void initPostQuotes() {
// 인용하기.
// 2번 게시글이 1번 게시글을 인용.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ public Page<Post> searchPagePopular(Long page, Long size) {
// groupBy 행 결과를 query로 받음.
JPAQuery<Integer> prepareCountQuery = queryFactory.selectOne()
.from(post)
.leftJoin(postLike)
.on(postLike.post.eq(post).and(
postLike.delYn.eq(YesOrNo.N)))
.where(notDeleted())
.groupBy(post.id);
return PageableExecutionUtils.getPage(postQueryResults, PageRequest.of(page.intValue(),
Expand Down
Loading

0 comments on commit 1af0cfe

Please sign in to comment.