Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main 머지 #230

Merged
merged 20 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
7c30336
feat(BE): 위치 기준으로 매칭 조회 BUS-229-place-latitude-longitude #221
Lemonade255 Nov 20, 2023
287ccff
feat(BE): 위치 기준으로 매칭 조회 BUS-229-place-latitude-longitude #221
Lemonade255 Nov 20, 2023
e13cee1
feat(BE): 디폴트 위치 추가 BUS-229-place-latitude-longitude #221
Lemonade255 Nov 20, 2023
faccb1f
feat(BE): 매칭 신청 생성/수락/거절 시 알림 표시 BUS-230-matching-application-notific…
Lemonade255 Nov 21, 2023
7623fe7
Merge pull request #224 from swm-nodriversomabus/BUS-229-place-latitu…
Lemonade255 Nov 21, 2023
a443853
Merge pull request #226 from swm-nodriversomabus/BUS-230-matching-app…
Lemonade255 Nov 21, 2023
cd5646f
hotfix(BE): 채팅방 생성시 생기는 오류 체크
namhyo01 Nov 21, 2023
da0812c
hotfix(BE): 친구 추가 오류 수정
namhyo01 Nov 21, 2023
116661f
hotfix(BE): 유저 프로필 사진 불러오기 오류 수정
namhyo01 Nov 22, 2023
3351cfe
hotfix(BE): 친구 추가 오류 수정
namhyo01 Nov 22, 2023
6079c01
hotfix(BE): validator 애러 체크
namhyo01 Nov 22, 2023
fc0100f
hotfix(BE): 친구추가 버그 수정
namhyo01 Nov 22, 2023
c40a881
hotfix(BE): 친구추가 버그 수정
namhyo01 Nov 22, 2023
fc7df82
hotfix(BE): 친구추가 버그 수정
namhyo01 Nov 22, 2023
41f392d
hotfix(BE): 숙소 매칭 등록 안됨 BUS-225-MVP2-API-test
Lemonade255 Nov 22, 2023
0f2b242
Merge pull request #227 from swm-nodriversomabus/BUS-225-MVP2-API-test
Lemonade255 Nov 22, 2023
06085b1
hotfix(BE): 숙소 매칭 조회 오류 BUS-225-MVP2-API-test
Lemonade255 Nov 22, 2023
e4c98ef
Merge pull request #228 from swm-nodriversomabus/BUS-225-MVP2-API-test
Lemonade255 Nov 22, 2023
a2fba57
feat(BE): 친구 목록에 차단한 사용자 미표시 BUS-225-MVP2-API-test
Lemonade255 Nov 22, 2023
3ae45a9
Merge pull request #229 from swm-nodriversomabus/BUS-225-MVP2-API-test
Lemonade255 Nov 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading