diff --git a/src/main/java/com/devcard/devcard/auth/repository/MemberRepository.java b/src/main/java/com/devcard/devcard/auth/repository/MemberRepository.java index b4c269e..87d0d10 100644 --- a/src/main/java/com/devcard/devcard/auth/repository/MemberRepository.java +++ b/src/main/java/com/devcard/devcard/auth/repository/MemberRepository.java @@ -1,8 +1,12 @@ package com.devcard.devcard.auth.repository; import com.devcard.devcard.auth.entity.Member; +import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; public interface MemberRepository extends JpaRepository { + Member findByGithubId(String githubId); + + List findByIdIn(List ids); } diff --git a/src/main/java/com/devcard/devcard/card/controller/page/HomeController.java b/src/main/java/com/devcard/devcard/card/controller/page/HomeController.java index 9137f12..d711013 100644 --- a/src/main/java/com/devcard/devcard/card/controller/page/HomeController.java +++ b/src/main/java/com/devcard/devcard/card/controller/page/HomeController.java @@ -2,6 +2,9 @@ import com.devcard.devcard.auth.entity.Member; import com.devcard.devcard.auth.model.OauthMemberDetails; +import com.devcard.devcard.card.dto.CardResponseDto; +import com.devcard.devcard.card.service.CardService; +import java.util.List; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -11,11 +14,29 @@ @Controller public class HomeController { + private final CardService cardService; + + public HomeController(CardService cardService) { + this.cardService = cardService; + } + @GetMapping("/home") public String home(@AuthenticationPrincipal OauthMemberDetails oauthMemberDetails, Model model) { if (oauthMemberDetails != null) { Member member = oauthMemberDetails.getMember(); model.addAttribute("member", member); + + // CardResponseDto 리스트 가져오기 + List cards = cardService.getMyCards(member.getId()); + + // 첫 번째 카드 ID 가져오기 (카드가 존재하는 경우) + if (!cards.isEmpty()) { + Long firstCardId = cards.getFirst().getId(); + model.addAttribute("cardId", firstCardId); + } else { + // 기본 카드 ID 또는 처리 방법 정의 (카드가 없을 경우) + model.addAttribute("cardId", 1); // 기본값으로 1 설정 + } } return "home"; } diff --git a/src/main/java/com/devcard/devcard/card/service/GroupService.java b/src/main/java/com/devcard/devcard/card/service/GroupService.java index 1054034..fd4340b 100644 --- a/src/main/java/com/devcard/devcard/card/service/GroupService.java +++ b/src/main/java/com/devcard/devcard/card/service/GroupService.java @@ -8,9 +8,12 @@ import com.devcard.devcard.card.repository.GroupRepository; import com.devcard.devcard.chat.dto.CreateRoomRequest; import com.devcard.devcard.chat.service.ChatRoomService; +import com.devcard.devcard.chat.service.ChatService; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -19,6 +22,8 @@ @Service public class GroupService { + private static final Logger logger = LoggerFactory.getLogger(ChatService.class); + private final GroupRepository groupRepository; private final CardRepository cardRepository; private final ChatRoomService chatRoomService; @@ -62,6 +67,8 @@ public void addCardToGroup(Long groupId, Long cardId, Member member) { } // 채팅방 생성 + logger.debug( + "Chat room participants: Member ID = " + member.getId() + ", Card Owner ID = " + card.getMember().getId()); CreateRoomRequest createRoomRequest = new CreateRoomRequest(Arrays.asList( member.getId(), card.getMember().getId() diff --git a/src/main/java/com/devcard/devcard/chat/model/ChatRoom.java b/src/main/java/com/devcard/devcard/chat/model/ChatRoom.java index 8a6faec..44a371a 100644 --- a/src/main/java/com/devcard/devcard/chat/model/ChatRoom.java +++ b/src/main/java/com/devcard/devcard/chat/model/ChatRoom.java @@ -2,9 +2,11 @@ import com.devcard.devcard.auth.entity.Member; import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; import jakarta.persistence.JoinTable; import jakarta.persistence.ManyToMany; import jakarta.persistence.Table; @@ -18,8 +20,12 @@ public class ChatRoom { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; - @ManyToMany - @JoinTable(name = "chat_room_participants") + @ManyToMany(fetch = FetchType.EAGER) + @JoinTable( + name = "chat_room_participants", + joinColumns = @JoinColumn(name = "chat_room_id"), + inverseJoinColumns = @JoinColumn(name = "member_id") + ) private List participants; private LocalDateTime createdAt; private String lastMessage = "메세지를 보내보세요."; // 기본값 설정 diff --git a/src/main/java/com/devcard/devcard/chat/repository/ChatUserRepository.java b/src/main/java/com/devcard/devcard/chat/repository/ChatUserRepository.java deleted file mode 100644 index 49aea8a..0000000 --- a/src/main/java/com/devcard/devcard/chat/repository/ChatUserRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.devcard.devcard.chat.repository; - -import com.devcard.devcard.auth.entity.Member; -import java.util.List; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface ChatUserRepository extends JpaRepository { - - List findByIdIn(List participantsId); -} diff --git a/src/main/java/com/devcard/devcard/chat/service/ChatRoomService.java b/src/main/java/com/devcard/devcard/chat/service/ChatRoomService.java index ea58167..4788677 100644 --- a/src/main/java/com/devcard/devcard/chat/service/ChatRoomService.java +++ b/src/main/java/com/devcard/devcard/chat/service/ChatRoomService.java @@ -4,6 +4,7 @@ import static com.devcard.devcard.chat.util.Constants.CHAT_ROOM_NOT_FOUND_BY_PARTICIPANTS; import com.devcard.devcard.auth.entity.Member; +import com.devcard.devcard.auth.repository.MemberRepository; import com.devcard.devcard.chat.dto.ChatMessageResponse; import com.devcard.devcard.chat.dto.ChatRoomListResponse; import com.devcard.devcard.chat.dto.ChatRoomResponse; @@ -14,9 +15,7 @@ import com.devcard.devcard.chat.model.ChatRoom; import com.devcard.devcard.chat.repository.ChatRepository; import com.devcard.devcard.chat.repository.ChatRoomRepository; -import com.devcard.devcard.chat.repository.ChatUserRepository; import java.time.LocalDateTime; -import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import org.springframework.stereotype.Service; @@ -32,16 +31,16 @@ public class ChatRoomService { private final ChatRoomRepository chatRoomRepository; private final ChatRepository chatRepository; - private final ChatUserRepository chatUserRepository; + private final MemberRepository memberRepository; public ChatRoomService( ChatRoomRepository chatRoomRepository, ChatRepository chatRepository, - ChatUserRepository chatUserRepository + MemberRepository memberRepository ) { this.chatRoomRepository = chatRoomRepository; this.chatRepository = chatRepository; - this.chatUserRepository = chatUserRepository; + this.memberRepository = memberRepository; } /** @@ -51,8 +50,9 @@ public ChatRoomService( */ public CreateRoomResponse createChatRoom(CreateRoomRequest createRoomRequest) { // jpa를 이용해 ChatUser 리스트 가져오기 - List participants = chatUserRepository.findByIdIn(createRoomRequest.getParticipantsId()); + List participants = memberRepository.findByIdIn(createRoomRequest.getParticipantsId()); ChatRoom chatRoom = new ChatRoom(participants, LocalDateTime.now()); // chatRoom생성 + chatRoom.getParticipants().addAll(participants); chatRoomRepository.save(chatRoom); // db에 저장 return makeCreateChatRoomResponse(chatRoom); // Response로 변환 } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 5c4ee58..44ccb7a 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -38,3 +38,5 @@ qr.code.directory=src/main/resources/static/qrcodes/ # Kakao Service # application-secret.properties? ????? ?? spring.config.import=optional:classpath:application-secret.properties + +logging.level.com.devcard.devcard=DEBUG diff --git a/src/main/resources/static/css/card/card-manage.css b/src/main/resources/static/css/card/card-manage.css index 0f68789..abb8486 100644 --- a/src/main/resources/static/css/card/card-manage.css +++ b/src/main/resources/static/css/card/card-manage.css @@ -41,6 +41,7 @@ /* 명함 리스트 섹션 */ .card-list-section { + height: 100%; overflow-y: auto; padding: 1rem; display: grid; diff --git a/src/main/resources/templates/card-list.html b/src/main/resources/templates/card-list.html index 8644d5b..912c7eb 100644 --- a/src/main/resources/templates/card-list.html +++ b/src/main/resources/templates/card-list.html @@ -34,7 +34,7 @@

Card Name

Bio

- Profile Picture + Profile Picture
diff --git a/src/main/resources/templates/home.html b/src/main/resources/templates/home.html index 291ade7..65f86b8 100644 --- a/src/main/resources/templates/home.html +++ b/src/main/resources/templates/home.html @@ -16,7 +16,7 @@

My Business Card

-
+