-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
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
23 changes: 23 additions & 0 deletions
23
Api/src/main/java/allchive/server/api/block/model/dto/response/BlockUsersResponse.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,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(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
Api/src/main/java/allchive/server/api/block/model/mapper/BlockMapper.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,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(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
Api/src/main/java/allchive/server/api/block/model/vo/BlockUserVo.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,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(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
Api/src/main/java/allchive/server/api/block/service/GetBlockUseCase.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,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)); | ||
} | ||
} |
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