Skip to content

Commit

Permalink
[feat] 차단 유저 정보 보기 #37
Browse files Browse the repository at this point in the history
  • Loading branch information
wjdtkdgns committed Jul 16, 2023
1 parent df69b7f commit a4aaf95
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,6 +21,7 @@
public class BlockController {
private final CreateBlockUseCase createBlockUseCase;
private final DeleteBlockUseCase deleteBlockUseCase;
private final GetBlockUseCase getBlockUseCase;

@Operation(summary = "유저를 차단합니다.")
@PostMapping()
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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<BlockUserVo> users;

@Builder
private BlockUsersResponse(List<BlockUserVo> users) {
this.users = users;
}

public static BlockUsersResponse from(List<BlockUserVo> users) {
return BlockUsersResponse.builder()
.users(users)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -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<BlockUserVo> toBlockUserVoList(List<Block> blockList, List<User> 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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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<Block> blockList = blockAdaptor.findByBlockFrom(userId);
List<Long> userIds = blockList.stream().map(Block::getBlockUser).toList();
List<User> users = userAdaptor.findAllByIdIn(userIds);
return BlockUsersResponse.from(blockMapper.toBlockUserVoList(blockList, users));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import allchive.server.domain.domains.user.repository.UserRepository;
import lombok.RequiredArgsConstructor;

import java.util.List;

@Adaptor
@RequiredArgsConstructor
public class UserAdaptor {
Expand All @@ -34,4 +36,8 @@ public User queryUserById(Long userId) {
public Boolean existsByNickname(String nickname) {
return userRepository.existsByNickname(nickname);
}

public List<User> findAllByIdIn(List<Long> userIds) {
return userRepository.findAllByIdIn(userIds);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@

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;

public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByOauthInfo(OauthInfo oauthInfo);

boolean existsByNickname(String nickname);

List<User> findAllByIdIn(List<Long> userIds);
}

0 comments on commit a4aaf95

Please sign in to comment.