Skip to content

Commit

Permalink
Merge pull request #111 from cussle/weekly/11
Browse files Browse the repository at this point in the history
명함 관련 CSS 수정, 채팅 로직 수정
  • Loading branch information
cussle authored Nov 15, 2024
2 parents 1ca943a + 74a6f56 commit a8eb148
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -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, Long> {

Member findByGithubId(String githubId);

List<Member> findByIdIn(List<Long> ids);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<CardResponseDto> 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";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/devcard/devcard/chat/model/ChatRoom.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Member> participants;
private LocalDateTime createdAt;
private String lastMessage = "메세지를 보내보세요."; // 기본값 설정
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}

/**
Expand All @@ -51,8 +50,9 @@ public ChatRoomService(
*/
public CreateRoomResponse createChatRoom(CreateRoomRequest createRoomRequest) {
// jpa를 이용해 ChatUser 리스트 가져오기
List<Member> participants = chatUserRepository.findByIdIn(createRoomRequest.getParticipantsId());
List<Member> 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로 변환
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/main/resources/static/css/card/card-manage.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

/* 명함 리스트 섹션 */
.card-list-section {
height: 100%;
overflow-y: auto;
padding: 1rem;
display: grid;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/card-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h3 th:text="${card.name}">Card Name</h3>
<p th:text="${card.bio}">Bio</p>
</div>
<div class="card-image">
<img th:src="@{${card.profilePicture}}" alt="Profile Picture">
<img th:src="@{${card.profileImg}}" alt="Profile Picture">
</div>
</a>
<button class="delete-button" th:attr="card-id=${card.id}" onclick="deleteCardFromGroup(this)">삭제</button>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<div class="card-title-container">
<h2 class="title">My Business Card</h2>
<!-- 명함 Card-->
<div th:replace="card :: cardSection(${card?.id ?: 1})"></div>
<div th:replace="card :: cardSection(${cardId})"></div>
</div>

<!-- 하단 네비게이션 바 -->
Expand Down

0 comments on commit a8eb148

Please sign in to comment.