Skip to content

Commit

Permalink
refactor(ExternalBoardHashtag): external 패키지 아래에 위치했던 boardHashtag 관련…
Browse files Browse the repository at this point in the history
… usecase와 service board 패키지 아래로 이동
  • Loading branch information
mingmingmon committed Dec 22, 2024
1 parent 0a53dd5 commit 991b9a1
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package page.clab.api.external.community.board.application.port;
package page.clab.api.domain.community.board.application.port.in;

import page.clab.api.domain.community.board.application.dto.request.BoardHashtagRequestDto;

public interface ExternalRegisterBoardHashtagUseCase {
public interface RegisterBoardHashtagUseCase {
Long registerBoardHashtag(BoardHashtagRequestDto requestDto);
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package page.clab.api.external.community.board.application.port;
package page.clab.api.domain.community.board.application.port.in;

import java.util.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import page.clab.api.domain.community.board.application.dto.response.BoardHashtagResponseDto;
import page.clab.api.domain.community.board.domain.BoardHashtag;

public interface ExternalRetrieveBoardHashtagUseCase {
public interface RetrieveBoardHashtagUseCase {
List<BoardHashtagResponseDto> getBoardHashtagInfoByBoardId(Long boardId);

List<BoardHashtag> getAllByBoardId(Long boardId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,15 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import page.clab.api.domain.community.board.adapter.out.persistence.BoardHashtagJpaEntity;
import page.clab.api.domain.community.board.application.dto.mapper.BoardDtoMapper;
import page.clab.api.domain.community.board.application.dto.mapper.BoardHashtagDtoMapper;
import page.clab.api.domain.community.board.application.dto.response.BoardDetailsResponseDto;
import page.clab.api.domain.community.board.application.dto.response.BoardEmojiCountResponseDto;
import page.clab.api.domain.community.board.application.dto.response.BoardHashtagResponseDto;
import page.clab.api.domain.community.board.application.port.in.RetrieveBoardDetailsUseCase;
import page.clab.api.domain.community.board.application.port.out.RetrieveBoardEmojiPort;
import page.clab.api.domain.community.board.application.port.out.RetrieveBoardPort;
import page.clab.api.domain.community.board.domain.Board;
import page.clab.api.domain.community.board.domain.BoardHashtag;
import page.clab.api.domain.memberManagement.member.application.dto.shared.MemberDetailedInfoDto;
import page.clab.api.external.community.board.application.service.ExternalBoardHashtagRetrieveService;
import page.clab.api.external.hashtag.application.port.ExternalRetrieveHashtagUseCase;
import page.clab.api.external.memberManagement.member.application.port.ExternalRetrieveMemberUseCase;

import java.util.List;
Expand All @@ -30,7 +25,7 @@ public class BoardDetailsRetrievalService implements RetrieveBoardDetailsUseCase
private final RetrieveBoardPort retrieveBoardPort;
private final RetrieveBoardEmojiPort retrieveBoardEmojiPort;
private final ExternalRetrieveMemberUseCase externalRetrieveMemberUseCase;
private final ExternalBoardHashtagRetrieveService externalBoardHashtagRetrieveService;
private final BoardHashtagRetrieveService boardHashtagRetrieveService;
private final BoardDtoMapper boardDtoMapper;

@Transactional
Expand All @@ -41,7 +36,7 @@ public BoardDetailsResponseDto retrieveBoardDetails(Long boardId) {
MemberDetailedInfoDto memberInfo = externalRetrieveMemberUseCase.getMemberDetailedInfoById(board.getMemberId());
boolean isOwner = board.isOwner(currentMemberInfo.getMemberId());
List<BoardEmojiCountResponseDto> emojiInfos = getBoardEmojiCountResponseDtoList(boardId, currentMemberInfo.getMemberId());
List<BoardHashtagResponseDto> boardHashtagInfos = externalBoardHashtagRetrieveService.getBoardHashtagInfoByBoardId(boardId);
List<BoardHashtagResponseDto> boardHashtagInfos = boardHashtagRetrieveService.getBoardHashtagInfoByBoardId(boardId);
return boardDtoMapper.toDto(board, memberInfo, isOwner, emojiInfos, boardHashtagInfos);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package page.clab.api.external.community.board.application.service;
package page.clab.api.domain.community.board.application.service;

import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import page.clab.api.domain.community.board.application.dto.mapper.BoardHashtagDtoMapper;
import page.clab.api.domain.community.board.application.dto.request.BoardHashtagRequestDto;
import page.clab.api.external.community.board.application.port.ExternalRegisterBoardHashtagUseCase;
import page.clab.api.domain.community.board.application.port.in.RegisterBoardHashtagUseCase;
import page.clab.api.domain.community.board.application.port.out.RegisterBoardHashtagPort;
import page.clab.api.domain.community.board.domain.BoardHashtag;
import page.clab.api.external.hashtag.application.port.ExternalRetrieveHashtagUseCase;
import page.clab.api.global.exception.NotFoundException;

@Service
@RequiredArgsConstructor
public class ExternalBoardHashtagRegisterService implements ExternalRegisterBoardHashtagUseCase {
public class BoardHashtagRegisterService implements RegisterBoardHashtagUseCase {

private final RegisterBoardHashtagPort registerBoardHashtagPort;
private final ExternalRetrieveHashtagUseCase externalRetrieveHashtagUseCase;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package page.clab.api.external.community.board.application.service;
package page.clab.api.domain.community.board.application.service;

import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import page.clab.api.domain.community.board.application.dto.mapper.BoardHashtagDtoMapper;
import page.clab.api.domain.community.board.application.dto.response.BoardHashtagResponseDto;
import page.clab.api.domain.community.board.application.port.out.RetrieveBoardHashtagPort;
import page.clab.api.domain.community.board.domain.BoardHashtag;
import page.clab.api.external.community.board.application.port.ExternalRetrieveBoardHashtagUseCase;
import page.clab.api.domain.community.board.application.port.in.RetrieveBoardHashtagUseCase;
import page.clab.api.external.hashtag.application.port.ExternalRetrieveHashtagUseCase;

@Service
@RequiredArgsConstructor
public class ExternalBoardHashtagRetrieveService implements ExternalRetrieveBoardHashtagUseCase {
public class BoardHashtagRetrieveService implements RetrieveBoardHashtagUseCase {

private final RetrieveBoardHashtagPort retrieveBoardHashtagPort;
private final ExternalRetrieveHashtagUseCase externalRetrieveHashtagUseCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.coyote.BadRequestException;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -14,7 +13,7 @@
import page.clab.api.domain.community.board.application.port.out.RegisterBoardPort;
import page.clab.api.domain.community.board.domain.Board;
import page.clab.api.domain.memberManagement.member.application.dto.shared.MemberDetailedInfoDto;
import page.clab.api.external.community.board.application.port.ExternalRegisterBoardHashtagUseCase;
import page.clab.api.domain.community.board.application.port.in.RegisterBoardHashtagUseCase;
import page.clab.api.external.memberManagement.member.application.port.ExternalRetrieveMemberUseCase;
import page.clab.api.external.memberManagement.notification.application.port.ExternalSendNotificationUseCase;
import page.clab.api.global.common.file.application.UploadedFileService;
Expand All @@ -31,7 +30,7 @@ public class BoardRegisterService implements RegisterBoardUseCase {
private final RegisterBoardPort registerBoardPort;
private final ExternalRetrieveMemberUseCase externalRetrieveMemberUseCase;
private final ExternalSendNotificationUseCase externalSendNotificationUseCase;
private final ExternalRegisterBoardHashtagUseCase externalRegisterBoardHashtagUseCase;
private final RegisterBoardHashtagUseCase registerBoardHashtagUseCase;
private final UploadedFileService uploadedFileService;
private final ApplicationEventPublisher eventPublisher;
private final BoardDtoMapper boardDtoMapper;
Expand Down Expand Up @@ -71,7 +70,7 @@ public String registerBoard(BoardRequestDto requestDto) throws PermissionDeniedE
throw new InvalidBoardCategoryHashtagException("개발질문 게시판에만 해시태그를 등록할 수 있습니다.");
}
if (savedBoard.isDevelopmentQna() && requestDto.getHashtagIdList() != null) {
externalRegisterBoardHashtagUseCase.registerBoardHashtag(boardHashtagDtoMapper.toDto(savedBoard.getId(), requestDto.getHashtagIdList()));
registerBoardHashtagUseCase.registerBoardHashtag(boardHashtagDtoMapper.toDto(savedBoard.getId(), requestDto.getHashtagIdList()));
}
return savedBoard.getCategory().getKey();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import page.clab.api.domain.community.board.application.port.out.RetrieveBoardPort;
import page.clab.api.domain.community.board.domain.Board;
import page.clab.api.domain.memberManagement.member.application.dto.shared.MemberDetailedInfoDto;
import page.clab.api.external.community.board.application.port.ExternalRetrieveBoardHashtagUseCase;
import page.clab.api.domain.community.board.application.port.in.RetrieveBoardHashtagUseCase;
import page.clab.api.external.community.comment.application.port.ExternalRetrieveCommentUseCase;
import page.clab.api.external.memberManagement.member.application.port.ExternalRetrieveMemberUseCase;
import page.clab.api.global.common.dto.PagedResponseDto;
Expand All @@ -26,7 +26,7 @@ public class BoardRetrievalService implements RetrieveBoardUseCase {
private final RetrieveBoardPort retrieveBoardPort;
private final ExternalRetrieveCommentUseCase externalRetrieveCommentUseCase;
private final ExternalRetrieveMemberUseCase externalRetrieveMemberUseCase;
private final ExternalRetrieveBoardHashtagUseCase externalRetrieveBoardHashtagUseCase;
private final RetrieveBoardHashtagUseCase retrieveBoardHashtagUseCase;
private final BoardDtoMapper mapper;

@Transactional
Expand All @@ -49,7 +49,7 @@ private MemberDetailedInfoDto getMemberDetailedInfoByBoard(Board board) {
@NotNull
private BoardListResponseDto mapToBoardListResponseDto(Board board, MemberDetailedInfoDto memberInfo) {
Long commentCount = externalRetrieveCommentUseCase.countByBoardId(board.getId());
List<BoardHashtagResponseDto> boardHashtagInfos = externalRetrieveBoardHashtagUseCase.getBoardHashtagInfoByBoardId(board.getId());
List<BoardHashtagResponseDto> boardHashtagInfos = retrieveBoardHashtagUseCase.getBoardHashtagInfoByBoardId(board.getId());
return mapper.toListDto(board, memberInfo, commentCount, boardHashtagInfos);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.Arrays;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -19,8 +18,8 @@
import page.clab.api.domain.community.board.domain.Board;
import page.clab.api.domain.community.board.domain.BoardHashtag;
import page.clab.api.domain.memberManagement.member.application.dto.shared.MemberDetailedInfoDto;
import page.clab.api.external.community.board.application.port.ExternalRegisterBoardHashtagUseCase;
import page.clab.api.external.community.board.application.port.ExternalRetrieveBoardHashtagUseCase;
import page.clab.api.domain.community.board.application.port.in.RegisterBoardHashtagUseCase;
import page.clab.api.domain.community.board.application.port.in.RetrieveBoardHashtagUseCase;
import page.clab.api.external.memberManagement.member.application.port.ExternalRetrieveMemberUseCase;
import page.clab.api.global.exception.PermissionDeniedException;

Expand All @@ -32,8 +31,8 @@ public class BoardUpdateService implements UpdateBoardUseCase {
private final RegisterBoardPort registerBoardPort;
private final RegisterBoardHashtagPort registerBoardHashtagPort;
private final ExternalRetrieveMemberUseCase externalRetrieveMemberUseCase;
private final ExternalRetrieveBoardHashtagUseCase externalRetrieveBoardHashtagUseCase;
private final ExternalRegisterBoardHashtagUseCase externalRegisterBoardHashtagUseCase;
private final RetrieveBoardHashtagUseCase retrieveBoardHashtagUseCase;
private final RegisterBoardHashtagUseCase registerBoardHashtagUseCase;
private final ApplicationEventPublisher eventPublisher;
private final BoardHashtagDtoMapper boardHashtagDtoMapper;

Expand All @@ -44,7 +43,7 @@ public String updateBoard(Long boardId, BoardUpdateRequestDto requestDto) throws
Board board = retrieveBoardPort.getById(boardId);
board.validateAccessPermission(currentMemberInfo);
board.update(requestDto);
updateBoardHashtag(board, requestDto.getHashtagIdList(), externalRetrieveBoardHashtagUseCase.getAllIncludingDeletedByBoardId(boardId));
updateBoardHashtag(board, requestDto.getHashtagIdList(), retrieveBoardHashtagUseCase.getAllIncludingDeletedByBoardId(boardId));
eventPublisher.publishEvent(new BoardUpdatedEvent(this, board.getId()));
registerBoardPort.save(board);
return board.getCategory().getKey();
Expand All @@ -56,7 +55,7 @@ public void updateBoardHashtag(Board board, List<Long> newHashtagIds, List<Board
throw new InvalidBoardCategoryHashtagException("개발질문 게시판에만 해시태그를 적용할 수 있습니다.");
}

List<Long> currentHashtagIds = externalRetrieveBoardHashtagUseCase.extractAllHashtagId(currentBoardHashtags);
List<Long> currentHashtagIds = retrieveBoardHashtagUseCase.extractAllHashtagId(currentBoardHashtags);
List<Long> hashtagsToRemove = currentHashtagIds.stream()
.filter(id -> !newHashtagIds.contains(id))
.toList();
Expand Down Expand Up @@ -97,7 +96,7 @@ private void addHashtag(Long boardId, Long hashtagId, List<BoardHashtag> current
registerBoardHashtagPort.save(boardHashtag);
},
() -> {
externalRegisterBoardHashtagUseCase.registerBoardHashtag(
registerBoardHashtagUseCase.registerBoardHashtag(
boardHashtagDtoMapper.toDto(boardId, new ArrayList<>(Arrays.asList(hashtagId)))
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import page.clab.api.domain.community.board.domain.Board;
import page.clab.api.domain.community.board.domain.BoardCategory;
import page.clab.api.domain.memberManagement.member.application.dto.shared.MemberDetailedInfoDto;
import page.clab.api.external.community.board.application.port.ExternalRetrieveBoardHashtagUseCase;
import page.clab.api.domain.community.board.application.port.in.RetrieveBoardHashtagUseCase;
import page.clab.api.external.community.comment.application.port.ExternalRetrieveCommentUseCase;
import page.clab.api.external.memberManagement.member.application.port.ExternalRetrieveMemberUseCase;
import page.clab.api.global.common.dto.PagedResponseDto;
Expand All @@ -26,7 +26,7 @@ public class BoardsByCategoryRetrievalService implements RetrieveBoardsByCategor
private final RetrieveBoardPort retrieveBoardPort;
private final ExternalRetrieveMemberUseCase externalRetrieveMemberUseCase;
private final ExternalRetrieveCommentUseCase externalRetrieveCommentUseCase;
private final ExternalRetrieveBoardHashtagUseCase externalRetrieveBoardHashtagUseCase;
private final RetrieveBoardHashtagUseCase retrieveBoardHashtagUseCase;
private final BoardDtoMapper mapper;

@Transactional
Expand All @@ -35,7 +35,7 @@ public PagedResponseDto<BoardOverviewResponseDto> retrieveBoardsByCategory(Board
Page<Board> boards = retrieveBoardPort.findAllByCategory(category, pageable);
return new PagedResponseDto<>(boards.map(board -> {
long commentCount = externalRetrieveCommentUseCase.countByBoardId(board.getId());
List<BoardHashtagResponseDto> boardHashtagInfos = externalRetrieveBoardHashtagUseCase.getBoardHashtagInfoByBoardId(board.getId());
List<BoardHashtagResponseDto> boardHashtagInfos = retrieveBoardHashtagUseCase.getBoardHashtagInfoByBoardId(board.getId());
return mapper.toCategoryDto(board, getMemberDetailedInfoByBoard(board), commentCount, boardHashtagInfos);
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.util.ArrayList;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import page.clab.api.domain.community.board.application.dto.mapper.BoardDtoMapper;
Expand All @@ -13,7 +11,7 @@
import page.clab.api.domain.community.board.application.port.in.RetrieveBoardsByHashtagUseCase;
import page.clab.api.domain.community.board.domain.Board;
import page.clab.api.domain.memberManagement.member.application.dto.shared.MemberDetailedInfoDto;
import page.clab.api.external.community.board.application.port.ExternalRetrieveBoardHashtagUseCase;
import page.clab.api.domain.community.board.application.port.in.RetrieveBoardHashtagUseCase;
import page.clab.api.external.community.board.application.port.ExternalRetrieveBoardUseCase;
import page.clab.api.external.community.comment.application.port.ExternalRetrieveCommentUseCase;
import page.clab.api.external.hashtag.application.port.ExternalRetrieveHashtagUseCase;
Expand All @@ -28,7 +26,7 @@ public class BoardsByHashtagRetrievalService implements RetrieveBoardsByHashtagU
private final ExternalRetrieveHashtagUseCase externalRetrieveHashtagUseCase;
private final ExternalRetrieveCommentUseCase externalRetrieveCommentUseCase;
private final ExternalRetrieveMemberUseCase externalRetrieveMemberUseCase;
private final ExternalRetrieveBoardHashtagUseCase externalRetrieveBoardHashtagUseCase;
private final RetrieveBoardHashtagUseCase retrieveBoardHashtagUseCase;
private final ExternalRetrieveBoardUseCase externalRetrieveBoardUseCase;
private final BoardDtoMapper mapper;

Expand All @@ -39,7 +37,7 @@ public PagedResponseDto<BoardOverviewResponseDto> retrieveBoardsByHashtag(List<S
hashtagIds.add(externalRetrieveHashtagUseCase.getByName(hashtag).getId());
}

List<Long> boardIds = externalRetrieveBoardHashtagUseCase.getBoardIdsByHashTagId(hashtagIds);
List<Long> boardIds = retrieveBoardHashtagUseCase.getBoardIdsByHashTagId(hashtagIds);

List<Board> boards = boardIds.stream()
.map(externalRetrieveBoardUseCase::getById)
Expand All @@ -48,7 +46,7 @@ public PagedResponseDto<BoardOverviewResponseDto> retrieveBoardsByHashtag(List<S
List<BoardOverviewResponseDto> boardOverviewResponseDtos =
boards.stream().map(board -> {
long commentCount = externalRetrieveCommentUseCase.countByBoardId(board.getId());
List<BoardHashtagResponseDto> boardHashtagInfos = externalRetrieveBoardHashtagUseCase.getBoardHashtagInfoByBoardId(board.getId());
List<BoardHashtagResponseDto> boardHashtagInfos = retrieveBoardHashtagUseCase.getBoardHashtagInfoByBoardId(board.getId());
return mapper.toCategoryDto(board, getMemberDetailedInfoByBoard(board), commentCount, boardHashtagInfos);
}).toList();

Expand Down
Loading

0 comments on commit 991b9a1

Please sign in to comment.