diff --git a/Api/src/main/java/allchive/server/api/block/controller/BlockController.java b/Api/src/main/java/allchive/server/api/block/controller/BlockController.java index deddfb66..6ad67635 100644 --- a/Api/src/main/java/allchive/server/api/block/controller/BlockController.java +++ b/Api/src/main/java/allchive/server/api/block/controller/BlockController.java @@ -3,8 +3,10 @@ import allchive.server.api.block.model.dto.request.BlockRequest; import allchive.server.api.block.model.dto.response.BlockResponse; +import allchive.server.api.block.model.dto.response.BlockUsersResponse; import allchive.server.api.block.service.CreateBlockUseCase; import allchive.server.api.block.service.DeleteBlockUseCase; +import allchive.server.api.block.service.GetBlockUseCase; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; @@ -19,6 +21,7 @@ public class BlockController { private final CreateBlockUseCase createBlockUseCase; private final DeleteBlockUseCase deleteBlockUseCase; + private final GetBlockUseCase getBlockUseCase; @Operation(summary = "유저를 차단합니다.") @PostMapping() @@ -31,4 +34,10 @@ public BlockResponse createBlock(@RequestBody BlockRequest blockRequest) { public BlockResponse deleteBlock(@RequestBody BlockRequest blockRequest) { return deleteBlockUseCase.execute(blockRequest); } + + @Operation(summary = "차단한 유저 정보를 가져옵니다.") + @GetMapping() + public BlockUsersResponse getBlock() { + return getBlockUseCase.execute(); + } } diff --git a/Api/src/main/java/allchive/server/api/block/model/dto/response/BlockUsersResponse.java b/Api/src/main/java/allchive/server/api/block/model/dto/response/BlockUsersResponse.java new file mode 100644 index 00000000..3353559c --- /dev/null +++ b/Api/src/main/java/allchive/server/api/block/model/dto/response/BlockUsersResponse.java @@ -0,0 +1,23 @@ +package allchive.server.api.block.model.dto.response; + +import allchive.server.api.block.model.vo.BlockUserVo; +import lombok.Builder; +import lombok.Getter; + +import java.util.List; + +@Getter +public class BlockUsersResponse { + List users; + + @Builder + private BlockUsersResponse(List users) { + this.users = users; + } + + public static BlockUsersResponse from(List users) { + return BlockUsersResponse.builder() + .users(users) + .build(); + } +} diff --git a/Api/src/main/java/allchive/server/api/block/model/mapper/BlockMapper.java b/Api/src/main/java/allchive/server/api/block/model/mapper/BlockMapper.java index fc070b91..725a3369 100644 --- a/Api/src/main/java/allchive/server/api/block/model/mapper/BlockMapper.java +++ b/Api/src/main/java/allchive/server/api/block/model/mapper/BlockMapper.java @@ -1,12 +1,28 @@ package allchive.server.api.block.model.mapper; +import allchive.server.api.block.model.vo.BlockUserVo; import allchive.server.core.annotation.Mapper; +import allchive.server.core.error.exception.InternalServerError; import allchive.server.domain.domains.block.domain.Block; +import allchive.server.domain.domains.user.domain.User; + +import java.util.List; @Mapper public class BlockMapper { public Block toEntity(Long blockFrom, Long blockUser) { return Block.of(blockFrom, blockUser); } + + public List toBlockUserVoList(List blockList, List users) { + return blockList.stream() + .map(block -> { + User user = users.stream() + .filter(u -> u.getId().equals(block.getBlockUser())) + .findFirst() + .orElseThrow(); + return BlockUserVo.of(user.getNickname(), block.getBlockUser()); + }).toList(); + } } diff --git a/Api/src/main/java/allchive/server/api/block/model/vo/BlockUserVo.java b/Api/src/main/java/allchive/server/api/block/model/vo/BlockUserVo.java new file mode 100644 index 00000000..9f8c7fe0 --- /dev/null +++ b/Api/src/main/java/allchive/server/api/block/model/vo/BlockUserVo.java @@ -0,0 +1,27 @@ +package allchive.server.api.block.model.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; +import lombok.Getter; + +@Getter +public class BlockUserVo { + @Schema(defaultValue = "닉네임", description = "차단한 유저의 닉네임") + private String nickname; + + @Schema(defaultValue = "1", description = "차단한 유저의 고유번호") + private Long id; + + @Builder + private BlockUserVo(String nickname, Long id) { + this.nickname = nickname; + this.id = id; + } + + public static BlockUserVo of(String nickname, Long id) { + return BlockUserVo.builder() + .nickname(nickname) + .id(id) + .build(); + } +} diff --git a/Api/src/main/java/allchive/server/api/block/service/GetBlockUseCase.java b/Api/src/main/java/allchive/server/api/block/service/GetBlockUseCase.java new file mode 100644 index 00000000..c344b437 --- /dev/null +++ b/Api/src/main/java/allchive/server/api/block/service/GetBlockUseCase.java @@ -0,0 +1,31 @@ +package allchive.server.api.block.service; + +import allchive.server.api.block.model.dto.response.BlockUsersResponse; +import allchive.server.api.block.model.mapper.BlockMapper; +import allchive.server.api.config.security.SecurityUtil; +import allchive.server.core.annotation.UseCase; +import allchive.server.domain.domains.block.adaptor.BlockAdaptor; +import allchive.server.domain.domains.block.domain.Block; +import allchive.server.domain.domains.user.adaptor.UserAdaptor; +import allchive.server.domain.domains.user.domain.User; +import lombok.RequiredArgsConstructor; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@UseCase +@RequiredArgsConstructor +public class GetBlockUseCase { + private final BlockAdaptor blockAdaptor; + private final BlockMapper blockMapper; + private final UserAdaptor userAdaptor; + + @Transactional(readOnly = true) + public BlockUsersResponse execute() { + Long userId = SecurityUtil.getCurrentUserId(); + List blockList = blockAdaptor.findByBlockFrom(userId); + List userIds = blockList.stream().map(Block::getBlockUser).toList(); + List users = userAdaptor.findAllByIdIn(userIds); + return BlockUsersResponse.from(blockMapper.toBlockUserVoList(blockList, users)); + } +} diff --git a/Domain/src/main/java/allchive/server/domain/domains/user/adaptor/UserAdaptor.java b/Domain/src/main/java/allchive/server/domain/domains/user/adaptor/UserAdaptor.java index 135d202f..01fbe90e 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/user/adaptor/UserAdaptor.java +++ b/Domain/src/main/java/allchive/server/domain/domains/user/adaptor/UserAdaptor.java @@ -8,6 +8,8 @@ import allchive.server.domain.domains.user.repository.UserRepository; import lombok.RequiredArgsConstructor; +import java.util.List; + @Adaptor @RequiredArgsConstructor public class UserAdaptor { @@ -34,4 +36,8 @@ public User queryUserById(Long userId) { public Boolean existsByNickname(String nickname) { return userRepository.existsByNickname(nickname); } + + public List findAllByIdIn(List userIds) { + return userRepository.findAllByIdIn(userIds); + } } diff --git a/Domain/src/main/java/allchive/server/domain/domains/user/repository/UserRepository.java b/Domain/src/main/java/allchive/server/domain/domains/user/repository/UserRepository.java index af39a107..7a2e24af 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/user/repository/UserRepository.java +++ b/Domain/src/main/java/allchive/server/domain/domains/user/repository/UserRepository.java @@ -3,6 +3,8 @@ import allchive.server.domain.domains.user.domain.User; import allchive.server.domain.domains.user.domain.enums.OauthInfo; + +import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; @@ -10,4 +12,6 @@ public interface UserRepository extends JpaRepository { Optional findByOauthInfo(OauthInfo oauthInfo); boolean existsByNickname(String nickname); + + List findAllByIdIn(List userIds); }