Skip to content

Commit

Permalink
Merge pull request #230 from swm-nodriversomabus/dev
Browse files Browse the repository at this point in the history
main 머지
  • Loading branch information
Lemonade255 authored Nov 22, 2023
2 parents 99ded85 + 3ae45a9 commit dabb1ef
Show file tree
Hide file tree
Showing 29 changed files with 240 additions and 41 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 @@ -37,11 +37,14 @@ public class ChatRoomController {
@Operation(summary = "Create chatroom", description = "새로운 채팅방을 생성한다.")
@PostMapping("/chatroom")
public UUID createChatroom(@RequestBody @Valid CreateChatRoomDto createChatRoomDto) {

SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication();
if (securityUser == null) {
log.error("ChatRoomController::createChatroom: Login is needed");
throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE);
}

createChatRoomDto.setMasterId(securityUser.getUserId());
ChatRoom chatRoom = createChatRoomUsecase.createRoom(createChatRoomDto);
return chatRoom.getChatroomId();
}
Expand All @@ -64,12 +67,7 @@ public List<ChatRoom> chatRoomList(@PageableDefault(sort = "createdAt", directio

@Operation(summary = "Delete chatroom", description = "채팅방을 삭제한다.")
@DeleteMapping("/chatroom/{chatRoomId}")
public void outChatRoom(@PathVariable UUID chatRoomId) {
SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication();
if (securityUser == null) {
log.error("ChatRoomController::outChatroom: Login is needed");
throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE);
}
public void outChatRoom(@PathVariable UUID chatRoomId){
log.info("chatroom = {}", chatRoomId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
import com.example.api.chatroom.type.ChatRoomEnum;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.UUID;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CreateChatRoomDto {
@NotNull
private UUID masterId; // TODO 추후 jwt에서 얻을 수 있어 삭제 가능
// @NotNull
private UUID masterId;

@NotBlank
private String chatroomName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

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

@RestController
@RequiredArgsConstructor
Expand All @@ -39,6 +41,7 @@ public FriendDto addFriend(@RequestBody FriendDto friendDto) {
log.error("FriendController::addFriend: Login is needed");
throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE);
}
friendDto.setUserId(securityUser.getUserId());
return addFriendUsecase.addFriend(friendDto);
}

Expand Down Expand Up @@ -71,4 +74,17 @@ public void deleteFriend(FriendDto friendDto) {
}
deleteFriendUsecase.deleteFriend(friendDto);
}

@Operation(summary = "check friend", description = "친구 여부 확인")
@GetMapping("/friend/{friendId}")
public ResponseEntity<Boolean> findFriend(@PathVariable UUID friendId){
SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication();
if (securityUser == null) {
log.error("FriendController::findFriend: Login is needed");
throw new CustomException(ErrorCodeEnum.LOGIN_IS_NOT_DONE);
}
Boolean res = findFriendUsecase.findFriend(securityUser.getUserId(), friendId);
return ResponseEntity.ok(res);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.UUID;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class FriendPK implements Serializable {
private UUID userId;
private UUID friendId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.springframework.stereotype.Repository;

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

@Repository
Expand All @@ -34,4 +35,9 @@ public List<FriendEntity> getFriendList(UUID userId) {
public void deleteFriend(Friend friend) {
friendRepository.delete(friendMapper.toEntity(friend));
}

@Override
public Optional<FriendEntity> findFriend(UUID userId, UUID friendId) {
return friendRepository.getByUserIdAndFriendId(userId, friendId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@

public interface FindFriendUsecase {
List<FindUserDto> getFriendList(UUID userId);
Boolean findFriend(UUID userId, UUID friendId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import org.springframework.stereotype.Component;

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

@Component
public interface FindFriendPort {
List<FriendEntity> getFriendList(UUID userId);

Optional<FriendEntity> findFriend(UUID userId, UUID friendId);
}
2 changes: 1 addition & 1 deletion src/main/java/com/example/api/friend/dto/FriendDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@NoArgsConstructor
@AllArgsConstructor
public class FriendDto {
@NotNull
// @NotNull
private UUID userId;

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import org.springframework.data.jpa.repository.JpaRepository;

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

public interface FriendRepository extends JpaRepository<FriendEntity, FriendPK> {
List<FriendEntity> getByUserId(UUID userId);
Optional<FriendEntity> getByUserIdAndFriendId(UUID userId, UUID friendId);
}
21 changes: 17 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 @@ -20,33 +22,44 @@

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

@Service
@RequiredArgsConstructor
@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
public FriendDto addFriend(FriendDto friendDto) {
Friend friend = addFriendPort.addFriend(friendMapper.toDomain(friendDto));
return friendMapper.toDto(friend);
}


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

@Override
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.getUserId()).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
Loading

0 comments on commit dabb1ef

Please sign in to comment.