Skip to content

Commit

Permalink
Merge pull request #142 from swm-nodriversomabus/BUS-202-MVP1-API-test
Browse files Browse the repository at this point in the history
fix(BE): 매칭 신청 등록 오류 BUS-202-MVP1-API-test
  • Loading branch information
Lemonade255 authored Oct 23, 2023
2 parents be3fe58 + 35bc645 commit cb61638
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.query.Param;

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

public interface ChatRepository extends JpaRepository<ChatEntity, Long> {

// entity graph를 활용해 user랑 join
@EntityGraph(attributePaths = {"senderId"})
Page<ChatEntity> findAllByRoomId_ChatroomId(@Param("roomId") UUID roomId, Pageable pageable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
public class ChatRoomController {
private final CreateChatRoomUsecase createChatRoomUsecase;
private final FindChatRomListUsecase findChatRomListUsecase;

/**
* 채팅방 생성
* @param createChatRoomDto (데이터)
Expand All @@ -43,8 +44,8 @@ public UUID createChatroom(@RequestBody @Valid CreateChatRoomDto createChatRoomD
*/
@Operation(summary = "Get chatroom list", description = "사용자의 채팅방 목록을 불러온다.")
@GetMapping("/chatroom")
public List<ChatRoom> chatRoomList(@RequestParam Long userid, @PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable) { //추후 바꾸자함
return findChatRomListUsecase.chatRoomList(pageable, userid);
public List<ChatRoom> chatRoomList(@PageableDefault(sort = "createdAt", direction = Sort.Direction.DESC) Pageable pageable) { //추후 바꾸자함
return findChatRomListUsecase.chatRoomList(pageable);
}

@Operation(summary = "Delete chatroom", description = "채팅방을 삭제한다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
public class ChatRoomPersistenceAdapter implements CreateChatRoomPort, FindChatRoomListPort, RetrieveChatRoomPort {
private final ChatRoomRepository chatRoomRepository;
private final ChatRoomMapper chatRoomMapper;
private final MemberRepository memberRepository;

@Override
public ChatRoom createChatRoom(ChatRoom chatRoom) {
Expand All @@ -36,9 +35,9 @@ public ChatRoom retrieveChatRoom(UUID chatroomId) {
}

@Override
public List<ChatRoom> chatRoomList(Pageable pageable, Long userId) {
public List<ChatRoom> chatRoomList(Pageable pageable, UUID userId) {
Page<ChatRoomEntity> ret = chatRoomRepository.findAllByUserId(pageable, userId);
if(ret != null && ret.hasContent()) {
if (ret != null && ret.hasContent()) {
return chatRoomMapper.fromEntityListToDomain(ret.getContent());
}
return new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
import java.util.List;

public interface FindChatRomListUsecase {
List<ChatRoom> chatRoomList(Pageable pageable, Long userId);
}
List<ChatRoom> chatRoomList(Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import org.springframework.data.domain.Pageable;

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

public interface FindChatRoomListPort {
List<ChatRoom> chatRoomList(Pageable pageable, Long userId);
}
List<ChatRoom> chatRoomList(Pageable pageable, UUID userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@

public interface ChatRoomRepository extends JpaRepository<ChatRoomEntity, UUID> {
@Query(value = "select DISTINCT c from ChatRoomEntity c join fetch c.members e where e.userId = :userid") // n+1 문제 떄문에 fetch join 사용
Page<ChatRoomEntity> findAllByUserId(Pageable pageable, @Param("userid") Long userid);
}
Page<ChatRoomEntity> findAllByUserId(Pageable pageable, @Param("userid") UUID userid);
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.example.api.chatroom.service;

import com.example.api.auth.domain.SecurityUser;
import com.example.api.chat.config.KafkaConsumerConfig;
import com.example.api.chatroom.application.port.in.CreateChatRoomUsecase;
import com.example.api.chatroom.application.port.in.FindChatRomListUsecase;
import com.example.api.chatroom.application.port.out.CreateChatRoomPort;
import com.example.api.chatroom.application.port.out.FindChatRoomListPort;
import com.example.api.chatroom.domain.ChatRoom;
import com.example.api.chatroom.dto.CreateChatRoomDto;
import com.example.api.common.utils.AuthenticationUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.admin.AdminClient;
Expand Down Expand Up @@ -45,8 +47,13 @@ public ChatRoom createRoom(CreateChatRoomDto createChatRoomDto) {
}

@Override
public List<ChatRoom> chatRoomList(Pageable pageable, Long userId) {
return findChatRoomListPort.chatRoomList(pageable, userId);
public List<ChatRoom> chatRoomList(Pageable pageable) {
SecurityUser securityUser = AuthenticationUtils.getCurrentUserAuthentication();
if (securityUser == null) {
log.error("ChatRoomService::charRoomList: Authentication is needed.");
return new ArrayList<>();
}
return findChatRoomListPort.chatRoomList(pageable, securityUser.getUserId());
}

public void createTopic(String chatroomId){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
@NoArgsConstructor
@AllArgsConstructor
public class SaveMatchingApplicationDto {
private UUID userId;

@NotNull
@Min(1)
private Long matchingId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ public ChatRoom createMatchingApplication(SaveMatchingApplicationDto matchingApp
return ChatRoom.builder().build();
}
MatchingApplication matchingApplication = matchingMapper.toDomain(matchingApplicationDto);
log.info("securityUserId: {}", securityUser.getUserId());
if (matchingApplication.getUserId() == null) {
matchingApplication.setUserId(securityUser.getUserId());
}
Expand Down

0 comments on commit cb61638

Please sign in to comment.