Skip to content

Commit

Permalink
Merge pull request #229 from swm-nodriversomabus/BUS-225-MVP2-API-test
Browse files Browse the repository at this point in the history
feat(BE): 친구 목록에 차단한 사용자 미표시 BUS-225-MVP2-API-test
  • Loading branch information
Lemonade255 authored Nov 22, 2023
2 parents e4c98ef + a2fba57 commit 3ae45a9
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ public class BlockListController {
private final GetListUsecase getListUsecase;
private final ReleaseBlockUsecase releaseBlockUsecase;

@Operation(summary = "add Block User", description = "차단할 유저 추가")
/**
* 사용자 차단
* @param addBlockDto (데이터)
*/
@Operation(summary = "Block user", description = "사용자를 차단한다.")
@PostMapping("/block")
public void addBlockUser(@Valid @RequestBody AddBlockDto addBlockDto) {
SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication();
Expand All @@ -42,7 +46,12 @@ public void addBlockUser(@Valid @RequestBody AddBlockDto addBlockDto) {
addBlockUsecase.addBlockUser(addBlockDto, securityUser.getUserId());
}

@Operation(summary = "get List block User", description = "차단한 유저 리스트제공")
/**
* 차단한 사용자 목록 조회
* @param pageable (데이터)
* @return blocked user list
*/
@Operation(summary = "Get blocked user list", description = "차단한 사용자 목록을 조회한다.")
@GetMapping("/block")
public List<BlockUser> getBlockList(@PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC, size = 30) Pageable pageable) {
SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication();
Expand All @@ -53,7 +62,11 @@ public List<BlockUser> getBlockList(@PageableDefault(sort = "createdAt", directi
return getListUsecase.getBlockList(pageable, securityUser.getUserId());
}

@Operation(summary = "release block user", description = "차단한 유저 해제")
/**
* 사용자 차단 해제
* @param deleteBlockDto (데이터)
*/
@Operation(summary = "Release blocked user", description = "사용자 차단을 해제한다.")
@DeleteMapping("/block")
public void releaseBlockUser(@Valid @RequestBody DeleteBlockDto deleteBlockDto) {
SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
public class BlockListEntity extends BaseEntity {
@Id
private UUID userId;


@Id
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(nullable = false, name="blocklist_userid", foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@ToString.Exclude
@Id
private UserEntity blocklistUserId;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

@Repository
Expand All @@ -26,6 +27,11 @@ public class BlockUserPersistentAdapter implements AddBlockUserPort, GetBlockLis
public void addBlockUser(BlockList blockList) {
blockListRepository.save(blockMapperInterface.toEntity(blockList));
}

@Override
public Optional<BlockListEntity> getBlockUser(UUID userId, UUID blockedUserId) {
return blockListRepository.getByUserIdAndBlocklistUserId_UserId(userId, blockedUserId);
}

@Override
public List<BlockList> getBlockUserList(UUID userId, Pageable pageable) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.example.api.blocklist.application.port.out;

import com.example.api.blocklist.adapter.out.persistence.BlockListEntity;
import com.example.api.blocklist.domain.BlockList;
import org.springframework.data.domain.Pageable;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

public interface GetBlockListPort {
Optional<BlockListEntity> getBlockUser(UUID userId, UUID blockedUserId);
List<BlockList> getBlockUserList(UUID userId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.query.Param;

import java.util.Optional;
import java.util.UUID;

public interface BlockListRepository extends JpaRepository<BlockListEntity, BlockListPK> {
void deleteByUserIdAndBlocklistUserId_UserId(UUID userId, UUID blockListUserId);

Optional<BlockListEntity> getByUserIdAndBlocklistUserId_UserId(UUID userId, UUID blockedUserId);
void deleteByUserIdAndBlocklistUserId_UserId(UUID userId, UUID blockedUserId);
@EntityGraph(attributePaths = {"blocklistUserId"})
Page<BlockListEntity> findAllByUserId(@Param("userId") UUID userId, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@

public interface FriendRepository extends JpaRepository<FriendEntity, FriendPK> {
List<FriendEntity> getByUserId(UUID userId);

Optional<FriendEntity> getByUserIdAndFriendId(UUID userId, UUID friendId);
}
14 changes: 10 additions & 4 deletions src/main/java/com/example/api/friend/service/FriendService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.api.friend.service;

import com.example.api.blocklist.application.port.out.GetBlockListPort;
import com.example.api.friend.adapter.out.persistence.FriendEntity;
import com.example.api.friend.adapter.out.persistence.FriendMapperInterface;
import com.example.api.friend.application.port.in.AddFriendUsecase;
Expand All @@ -10,6 +11,7 @@
import com.example.api.friend.application.port.out.FindFriendPort;
import com.example.api.friend.domain.Friend;
import com.example.api.friend.dto.FriendDto;
import com.example.api.user.adapter.out.persistence.UserEntity;
import com.example.api.user.adapter.out.persistence.UserMapperInterface;
import com.example.api.user.application.port.out.FindUserPort;
import com.example.api.user.dto.FindUserDto;
Expand All @@ -28,12 +30,13 @@
@Slf4j
@Transactional(readOnly = true)
public class FriendService implements AddFriendUsecase, FindFriendUsecase, DeleteFriendUsecase {
private final UserMapperInterface userMapper;
private final FriendMapperInterface friendMapper;
private final FindUserPort findUserPort;
private final AddFriendPort addFriendPort;
private final FindFriendPort findFriendPort;
private final DeleteFriendPort deleteFriendPort;
private final GetBlockListPort getBlockListPort;
private final UserMapperInterface userMapper;
private final FriendMapperInterface friendMapper;

@Override
@Transactional
Expand All @@ -44,7 +47,7 @@ public FriendDto addFriend(FriendDto friendDto) {

@Override
public Boolean findFriend(UUID userId, UUID friendId) {
Optional<FriendEntity> friend = findFriendPort.findFriend(userId,friendId);
Optional<FriendEntity> friend = findFriendPort.findFriend(userId, friendId);
return friend.isPresent();
}

Expand All @@ -53,7 +56,10 @@ public List<FindUserDto> getFriendList(UUID userId) {
List<FindUserDto> friendList = new ArrayList<>();
List<FriendEntity> friendPairList = findFriendPort.getFriendList(userId);
for (FriendEntity friendPair: friendPairList) {
friendList.add(userMapper.toDto(findUserPort.getByUserId(friendPair.getFriendId()).orElseThrow()));
Optional<UserEntity> userEntity = findUserPort.getByUserId(friendPair.getFriendId());
if (userEntity.isPresent() && getBlockListPort.getBlockUser(userId, userEntity.get().getUserId()).isEmpty()) {
friendList.add(userMapper.toDto(userEntity.get()));
}
}
return friendList;
}
Expand Down

0 comments on commit 3ae45a9

Please sign in to comment.