forked from codesquad-members-2023/second-hand-max
-
Notifications
You must be signed in to change notification settings - Fork 1
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
[feat] 채팅방 관련 기능 구현 #143
Merged
The head ref may contain hidden characters: "127-\uCC44\uD305\uBC29-\uAD00\uB828-\uAE30\uB2A5-\uAD6C\uD604"
Merged
[feat] 채팅방 관련 기능 구현 #143
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
24a27c3
chore: build.gradle에 소켓 의존성 추가
jinny-l b8c6f80
feat: 웹소켓 Config 작성
jinny-l 3236791
feat: 채팅방 생성 요청 API 기능 구현
jinny-l 7ea5a68
feat: 채팅방 존재 여부 조회 요청 API 기능 구현
jinny-l 064c281
feat: 채팅방 생성 시 첫번째 메시지 내용을 저장하는 로직 구현
jinny-l 937d668
feat: 채팅방 목록 조회 API 기능 구현
jinny-l 08afc97
feat: 채팅방 메시지 조회 API 기능 구현
jinny-l 969e905
feat: 채팅방 생성 요청 API 요청 형태 수정
jinny-l File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
be/src/main/java/kr/codesquad/secondhand/api/chat/controller/ChatRoomController.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,31 @@ | ||
package kr.codesquad.secondhand.api.chat.controller; | ||
|
||
import static kr.codesquad.secondhand.global.util.HttpAuthorizationUtils.extractMemberId; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import kr.codesquad.secondhand.api.chat.dto.ChatRoomCreateDto; | ||
import kr.codesquad.secondhand.api.chat.service.ChatFacadeService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.validation.annotation.Validated; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class ChatRoomController { | ||
|
||
private final ChatFacadeService chatService; | ||
|
||
@PostMapping("/api/chat/room") | ||
public ResponseEntity<ChatRoomCreateDto.Response> createChatRoom(HttpServletRequest httpServletRequest, | ||
@Validated @RequestBody ChatRoomCreateDto.Request request) { | ||
Long memberId = extractMemberId(httpServletRequest); | ||
ChatRoomCreateDto.Response response = chatService.createChatRoom(memberId, request.getProductId()); | ||
return ResponseEntity | ||
.status(HttpStatus.CREATED) | ||
.body(response); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
be/src/main/java/kr/codesquad/secondhand/api/chat/domain/ChatRoom.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,41 @@ | ||
package kr.codesquad.secondhand.api.chat.domain; | ||
|
||
import java.util.UUID; | ||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.Id; | ||
import javax.persistence.JoinColumn; | ||
import javax.persistence.ManyToOne; | ||
import kr.codesquad.secondhand.api.member.domain.Member; | ||
import kr.codesquad.secondhand.api.product.domain.Product; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class ChatRoom { | ||
|
||
@Id | ||
private String id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "product_id") | ||
private Product product; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "member_id") | ||
private Member member; | ||
|
||
private ChatRoom(String id, Product product, Member member) { | ||
this.id = id; | ||
this.product = product; | ||
this.member = member; | ||
} | ||
|
||
public static ChatRoom create(Product product, Member member) { | ||
String id = UUID.randomUUID().toString(); | ||
return new ChatRoom(id, product, member); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
be/src/main/java/kr/codesquad/secondhand/api/chat/dto/ChatRoomCreateDto.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,39 @@ | ||
package kr.codesquad.secondhand.api.chat.dto; | ||
|
||
import javax.validation.Valid; | ||
import javax.validation.constraints.NotBlank; | ||
import javax.validation.constraints.NotNull; | ||
import lombok.Getter; | ||
|
||
public class ChatRoomCreateDto { | ||
|
||
@Getter | ||
public static class Request { | ||
|
||
@NotNull(message = "생성할 채팅방의 상품 정보가 비어있습니다.") | ||
private Long productId; | ||
|
||
@Valid | ||
private MessageDTO message; | ||
} | ||
|
||
@Getter | ||
private static class MessageDTO { | ||
|
||
@NotNull(message = "생성할 채팅방의 senderId가 비어있습니다.") | ||
private Long senderId; | ||
|
||
@NotBlank(message = "생성할 채팅방의 메시지 내용이 없습니다.") | ||
private String content; | ||
} | ||
|
||
@Getter | ||
public static class Response { | ||
|
||
private final String roomId; | ||
|
||
public Response(String roomId) { | ||
this.roomId = roomId; | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
be/src/main/java/kr/codesquad/secondhand/api/chat/repository/ChatRoomRepositoryImpl.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 kr.codesquad.secondhand.api.chat.repository; | ||
|
||
import kr.codesquad.secondhand.api.chat.domain.ChatRoom; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ChatRoomRepositoryImpl extends JpaRepository<ChatRoom, String> { | ||
} |
29 changes: 29 additions & 0 deletions
29
be/src/main/java/kr/codesquad/secondhand/api/chat/service/ChatFacadeService.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,29 @@ | ||
package kr.codesquad.secondhand.api.chat.service; | ||
|
||
import kr.codesquad.secondhand.api.chat.domain.ChatRoom; | ||
import kr.codesquad.secondhand.api.chat.dto.ChatRoomCreateDto; | ||
import kr.codesquad.secondhand.api.member.domain.Member; | ||
import kr.codesquad.secondhand.api.member.service.MemberService; | ||
import kr.codesquad.secondhand.api.product.domain.Product; | ||
import kr.codesquad.secondhand.api.product.service.ProductService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ChatFacadeService { | ||
|
||
private final ChatService chatService; | ||
private final ProductService productService; | ||
private final MemberService memberService; | ||
|
||
public ChatRoomCreateDto.Response createChatRoom(Long memberId, Long productId) { | ||
Member member = memberService.getMemberReferenceById(memberId); // 없는 경우에 무슨 예외 터지는지 확인 | ||
Product product = productService.findById(productId); | ||
ChatRoom chatRoom = chatService.createChatRoom(product, member); | ||
|
||
// TODO request의 첫 메시지 관련 처리 필요 | ||
return new ChatRoomCreateDto.Response(chatRoom.getId()); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
be/src/main/java/kr/codesquad/secondhand/api/chat/service/ChatService.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,22 @@ | ||
package kr.codesquad.secondhand.api.chat.service; | ||
|
||
import kr.codesquad.secondhand.api.chat.domain.ChatRoom; | ||
import kr.codesquad.secondhand.api.chat.repository.ChatRoomRepositoryImpl; | ||
import kr.codesquad.secondhand.api.member.domain.Member; | ||
import kr.codesquad.secondhand.api.product.domain.Product; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ChatService { | ||
|
||
private final ChatRoomRepositoryImpl chatRoomRepository; | ||
|
||
public ChatRoom createChatRoom(Product product, Member member) { | ||
ChatRoom chatRoom = ChatRoom.create(product, member); | ||
chatRoomRepository.save(chatRoom); | ||
return chatRoom; | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
일부러 프록시 조회, 일반 조회를 혼용하셨나요??