-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
570 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
= Chat API 문서 | ||
:doctype: book | ||
:icons: font | ||
:source-highlighter: highlightjs | ||
:toc: left | ||
:toclevels: 3 | ||
|
||
== 사용자의 채팅 내역을 모두 반환한다. (GET /api/chats) | ||
|
||
=== Request | ||
|
||
include::{snippets}/chat-room-controller-test/find_all_my_chatting_rooms/request-headers.adoc[] | ||
include::{snippets}/chat-room-controller-test/find_all_my_chatting_rooms/http-request.adoc[] | ||
|
||
=== Response | ||
|
||
include::{snippets}/chat-room-controller-test/find_all_my_chatting_rooms/response-fields.adoc[] | ||
include::{snippets}/chat-room-controller-test/find_all_my_chatting_rooms/http-response.adoc[] | ||
|
||
== 구매자가 채팅을 신청해서 채팅방을 생성한다. (POST /api/products/{productId}/chats) | ||
|
||
=== Request | ||
|
||
include::{snippets}/chat-room-controller-test/create_new_chatting_room/request-headers.adoc[] | ||
include::{snippets}/chat-room-controller-test/create_new_chatting_room/path-parameters.adoc[] | ||
include::{snippets}/chat-room-controller-test/create_new_chatting_room/request-fields.adoc[] | ||
include::{snippets}/chat-room-controller-test/create_new_chatting_room/http-request.adoc[] | ||
|
||
=== Response | ||
|
||
include::{snippets}/chat-room-controller-test/create_new_chatting_room/response-headers.adoc[] | ||
include::{snippets}/chat-room-controller-test/create_new_chatting_room/http-response.adoc[] | ||
|
||
== 채팅방 내역을 반환한다 (GET /api/products/{productId}/chats/{chattingRoomId}?chatId=:&pageSize=:) | ||
|
||
=== Request | ||
|
||
include::{snippets}/chat-room-controller-test/find_chatting_history/request-headers.adoc[] | ||
include::{snippets}/chat-room-controller-test/find_chatting_history/path-parameters.adoc[] | ||
include::{snippets}/chat-room-controller-test/find_chatting_history/query-parameters.adoc[] | ||
include::{snippets}/chat-room-controller-test/find_chatting_history/request-body.adoc[] | ||
include::{snippets}/chat-room-controller-test/find_chatting_history/http-request.adoc[] | ||
|
||
=== Response | ||
|
||
include::{snippets}/chat-room-controller-test/find_chatting_history/response-fields.adoc[] | ||
include::{snippets}/chat-room-controller-test/find_chatting_history/http-response.adoc[] | ||
|
||
== 채팅 방법 | ||
|
||
- endpoint : `ws://localhost:8080/ws-stomp` | ||
- subscribe url : `ws://localhost:8080/ws-stomp/sub/chats/{chattingRoomId}` | ||
- publish url : `ws://localhost:8080/ws-stomp/pub/chats/{chattingRoomId}/messages` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,3 +20,5 @@ include::member.adoc[] | |
include::product.adoc[] | ||
|
||
include::voucher.adoc[] | ||
|
||
include::chat.adoc[] |
28 changes: 28 additions & 0 deletions
28
market-api/src/main/java/com/server/market/application/chat/ChatRoomQueryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.server.market.application.chat; | ||
|
||
import com.server.market.domain.chat.ChatRepository; | ||
import com.server.market.domain.chat.ChattingRoomRepository; | ||
import com.server.market.domain.chat.dto.ChatHistoryResponse; | ||
import com.server.market.domain.chat.dto.ChattingRoomSimpleResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
@Service | ||
public class ChatRoomQueryService { | ||
|
||
private final ChatRepository chatRepository; | ||
private final ChattingRoomRepository chattingRoomRepository; | ||
|
||
public List<ChattingRoomSimpleResponse> findAllMyChats(final Long authId) { | ||
return chattingRoomRepository.findMyChattingRooms(authId); | ||
} | ||
|
||
public List<ChatHistoryResponse> findChattingHistoryByChatId(final Long authId, final Long chattingRoomId, final Long chatId, final Integer pageSize) { | ||
return chatRepository.findChattingHistoryByChatId(authId, chattingRoomId, chatId, pageSize); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
|
||
public record ChatMessageRequest( | ||
Long senderId, | ||
String senderName, | ||
String message | ||
) { | ||
} |
9 changes: 9 additions & 0 deletions
9
...t-api/src/main/java/com/server/market/application/chat/dto/ChattingRoomCreateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.server.market.application.chat.dto; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
|
||
public record ChattingRoomCreateRequest( | ||
@NotNull(message = "판매자 id가 들어와야 합니다.") | ||
Long sellerId | ||
) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
market-api/src/main/java/com/server/market/domain/chat/ChatRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
package com.server.market.domain.chat; | ||
|
||
import com.server.market.domain.chat.dto.ChatHistoryResponse; | ||
|
||
import java.util.List; | ||
|
||
public interface ChatRepository { | ||
|
||
Chat save(Chat chat); | ||
|
||
List<ChatHistoryResponse> findChattingHistoryByChatId(Long authId, Long chattingRoomId, Long chatId, Integer pageSize); | ||
} |
58 changes: 58 additions & 0 deletions
58
market-api/src/main/java/com/server/market/domain/chat/ChattingRoom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.server.market.domain.chat; | ||
|
||
import com.server.global.domain.BaseEntity; | ||
import com.server.market.domain.chat.vo.ChattingStatus; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Builder | ||
@EqualsAndHashCode(of = "id", callSuper = false) | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Entity | ||
@Table(name = "chatting_room") | ||
public class ChattingRoom extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private Long productId; | ||
|
||
@Column(nullable = false) | ||
private Long buyerId; | ||
|
||
@Column(nullable = false) | ||
private Long sellerId; | ||
|
||
@Column(nullable = false) | ||
@Enumerated(EnumType.STRING) | ||
private ChattingStatus chattingStatus; | ||
|
||
public static ChattingRoom createNewChattingRoom(final Long productId, final Long buyerId, final Long sellerId) { | ||
return ChattingRoom.builder() | ||
.productId(productId) | ||
.buyerId(buyerId) | ||
.sellerId(sellerId) | ||
.chattingStatus(ChattingStatus.PROCESS) | ||
.build(); | ||
} | ||
|
||
public void done() { | ||
this.chattingStatus = ChattingStatus.DONE; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
market-api/src/main/java/com/server/market/domain/chat/ChattingRoomRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.server.market.domain.chat; | ||
|
||
import com.server.market.domain.chat.dto.ChattingRoomSimpleResponse; | ||
|
||
import java.util.List; | ||
|
||
public interface ChattingRoomRepository { | ||
|
||
ChattingRoom save(ChattingRoom chattingRoom); | ||
|
||
List<ChattingRoomSimpleResponse> findMyChattingRooms(Long authId); | ||
} |
14 changes: 14 additions & 0 deletions
14
market-api/src/main/java/com/server/market/domain/chat/dto/ChatHistoryResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.server.market.domain.chat.dto; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record ChatHistoryResponse( | ||
Long chatRoomId, | ||
Long chattingId, | ||
Long senderId, | ||
String senderNickname, | ||
String message, | ||
Boolean isSendByMe, | ||
LocalDateTime sendTime | ||
) { | ||
} |
13 changes: 13 additions & 0 deletions
13
market-api/src/main/java/com/server/market/domain/chat/dto/ChattingRoomSimpleResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.server.market.domain.chat.dto; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record ChattingRoomSimpleResponse( | ||
String productName, | ||
Long productId, | ||
Long chattingRoomId, | ||
Long sellerId, | ||
String sellerNickname, | ||
LocalDateTime lastChattingTime | ||
) { | ||
} |
7 changes: 7 additions & 0 deletions
7
market-api/src/main/java/com/server/market/domain/chat/vo/ChattingStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.server.market.domain.chat.vo; | ||
|
||
public enum ChattingStatus { | ||
|
||
PROCESS, | ||
DONE | ||
} |
66 changes: 66 additions & 0 deletions
66
market-api/src/main/java/com/server/market/infrastructure/chat/ChatQueryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package com.server.market.infrastructure.chat; | ||
|
||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import com.server.market.domain.chat.dto.ChatHistoryResponse; | ||
import com.server.market.domain.chat.dto.ChattingRoomSimpleResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
import static com.querydsl.core.types.Projections.constructor; | ||
import static com.server.market.domain.chat.QChat.chat; | ||
import static com.server.market.domain.chat.QChattingRoom.chattingRoom; | ||
import static com.server.market.domain.product.QProduct.product; | ||
import static com.server.member.domain.member.QMember.member; | ||
|
||
@RequiredArgsConstructor | ||
@Repository | ||
public class ChatQueryRepository { | ||
|
||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
public List<ChattingRoomSimpleResponse> findMyChattingRooms(final Long authId) { | ||
return jpaQueryFactory.select(constructor(ChattingRoomSimpleResponse.class, | ||
product.description.title, | ||
product.id, | ||
chattingRoom.id, | ||
chattingRoom.sellerId, | ||
member.nickname, | ||
chattingRoom.createdAt | ||
)).from(chattingRoom) | ||
.join(product).on(chattingRoom.productId.eq(product.id)) | ||
.join(member).on(chattingRoom.sellerId.eq(member.id)) | ||
.where(chattingRoom.buyerId.eq(authId)) | ||
.fetch(); | ||
} | ||
|
||
public List<ChatHistoryResponse> findChattingHistoryByChatId(final Long authId, final Long chattingRoomId, final Long chatId, final Integer pageSize) { | ||
return jpaQueryFactory.select(constructor(ChatHistoryResponse.class, | ||
chat.chatRoomId, | ||
chat.id, | ||
chat.senderId, | ||
member.nickname, // join | ||
chat.message, | ||
chat.senderId.eq(authId), // 보낸 사람이 인증된 사용자인지 여부 | ||
chat.createdAt | ||
)).from(chat) | ||
.leftJoin(member).on(member.id.eq(chat.senderId)) // 이 부분이 잘못됨 | ||
.where( | ||
chat.chatRoomId.eq(chattingRoomId), | ||
ltChatId(chatId) | ||
) | ||
.orderBy(chat.createdAt.desc()) | ||
.limit(pageSize) | ||
.fetch(); | ||
} | ||
|
||
private BooleanExpression ltChatId(final Long chatId) { | ||
if (chatId == null) { | ||
return null; | ||
} | ||
|
||
return chat.id.lt(chatId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.