-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from catchroom/develop
Develop
- Loading branch information
Showing
30 changed files
with
353 additions
and
71 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
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
26 changes: 26 additions & 0 deletions
26
src/main/java/com/catchroom/chat/chatroom/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,26 @@ | ||
package com.catchroom.chat.chatroom.controller; | ||
|
||
import com.catchroom.chat.chatroom.dto.ChatRoomCreateRequest; | ||
import com.catchroom.chat.chatroom.service.ChatRoomService; | ||
import com.catchroom.chat.common.common.ApiResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequestMapping("/v1/chat/room") | ||
@RequiredArgsConstructor | ||
public class ChatRoomController { | ||
private final ChatRoomService chatRoomService; | ||
@GetMapping("/{userId}") | ||
public ResponseEntity<?> findChatRoomListByMemberId(@PathVariable Long userId) { | ||
return ResponseEntity.ok( | ||
ApiResponse.create(6000, chatRoomService.findChatRoomListByMemberId(userId))); | ||
} | ||
|
||
@PostMapping("/create") | ||
public ResponseEntity<?> createRoom(@RequestBody ChatRoomCreateRequest chatRoomCreateRequest) { | ||
return ResponseEntity.ok( | ||
ApiResponse.create(6002,chatRoomService.createChatRoom(chatRoomCreateRequest))); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/catchroom/chat/chatroom/dto/ChatRoomCreateRequest.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,23 @@ | ||
package com.catchroom.chat.chatroom.dto; | ||
|
||
import com.catchroom.chat.chatroom.entity.ChatRoom; | ||
import lombok.*; | ||
|
||
@Builder | ||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class ChatRoomCreateRequest { | ||
|
||
private Long buyerId; | ||
private Long sellerId; | ||
private Long productId; | ||
|
||
public ChatRoom toEntity() { | ||
return ChatRoom.builder() | ||
.buyerId(buyerId) | ||
.sellerId(sellerId) | ||
.productId(productId) | ||
.build(); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/catchroom/chat/chatroom/dto/ChatRoomCreateResponse.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,21 @@ | ||
package com.catchroom.chat.chatroom.dto; | ||
|
||
import com.catchroom.chat.chatroom.entity.ChatRoom; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Builder | ||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class ChatRoomCreateResponse { | ||
private String ChatRoomNumber; | ||
|
||
public static ChatRoomCreateResponse fromEntity(ChatRoom chatRoom) { | ||
return ChatRoomCreateResponse.builder() | ||
.ChatRoomNumber(chatRoom.getChatRoomNumber()) | ||
.build(); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/catchroom/chat/chatroom/dto/ChatRoomListGetResponse.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,25 @@ | ||
package com.catchroom.chat.chatroom.dto; | ||
|
||
import com.catchroom.chat.chatroom.entity.ChatRoom; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@Builder | ||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class ChatRoomListGetResponse { | ||
private List<ChatRoom> ChatRoomListUserIsBuyer; | ||
private List<ChatRoom> ChatRoomListUserIsSeller; | ||
|
||
public static ChatRoomListGetResponse of(List<ChatRoom> ChatRoomListUserIsBuyer, List<ChatRoom> ChatRoomListUserIsSeller) { | ||
return ChatRoomListGetResponse.builder() | ||
.ChatRoomListUserIsBuyer(ChatRoomListUserIsBuyer) | ||
.ChatRoomListUserIsSeller(ChatRoomListUserIsSeller) | ||
.build(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/catchroom/chat/chatroom/entity/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,39 @@ | ||
package com.catchroom.chat.chatroom.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.UUID; | ||
|
||
@Entity | ||
@Getter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class ChatRoom { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
private Long sellerId; | ||
private Long buyerId; | ||
private Long productId; | ||
private String chatRoomNumber; | ||
|
||
public ChatRoom(Long sellerId, Long buyerId, Long productId, String chatRoomNumber) { | ||
this.sellerId = sellerId; | ||
this.buyerId = buyerId; | ||
this.productId = productId; | ||
this.chatRoomNumber = chatRoomNumber; | ||
} | ||
|
||
public static ChatRoom create(Long sellerId, Long buyerId, Long productId) { | ||
String chatRoomNumber = UUID.randomUUID().toString(); | ||
ChatRoom chatRoom = new ChatRoom(sellerId,buyerId,productId,chatRoomNumber); | ||
return chatRoom; | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/catchroom/chat/chatroom/repository/ChatRoomRepositoryJPA.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.catchroom.chat.chatroom.repository; | ||
|
||
import com.catchroom.chat.chatroom.entity.ChatRoom; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface ChatRoomRepositoryJPA extends JpaRepository<ChatRoom,Long> { | ||
List<ChatRoom> findAllByBuyerId(Long buyerId); | ||
List<ChatRoom> findAllBySellerId(Long sellerId); | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
src/main/java/com/catchroom/chat/chatroom/service/ChatRoomService.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,42 @@ | ||
package com.catchroom.chat.chatroom.service; | ||
|
||
import com.catchroom.chat.chatroom.dto.ChatRoomCreateRequest; | ||
import com.catchroom.chat.chatroom.dto.ChatRoomCreateResponse; | ||
import com.catchroom.chat.chatroom.dto.ChatRoomListGetResponse; | ||
import com.catchroom.chat.chatroom.entity.ChatRoom; | ||
import com.catchroom.chat.chatroom.repository.ChatRoomRepositoryJPA; | ||
import jakarta.annotation.Resource; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.redis.core.HashOperations; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class ChatRoomService { | ||
private final ChatRoomRepositoryJPA chatRoomRepository; | ||
@Resource(name = "redisTemplate") //redisTemplate bean 주입. | ||
private HashOperations<String, String, ChatRoom> opsHashChatRoom; | ||
private static final String CHAT_ROOMS = "CHAT_ROOM_REDIS"; | ||
|
||
@Transactional(readOnly = true) | ||
public ChatRoomListGetResponse findChatRoomListByMemberId(Long userId) { | ||
List<ChatRoom> ChatRoomListUserIsBuyer = chatRoomRepository.findAllByBuyerId(userId); | ||
|
||
List<ChatRoom> ChatRoomListUserIsSeller = chatRoomRepository.findAllBySellerId(userId); | ||
return ChatRoomListGetResponse.of(ChatRoomListUserIsBuyer, ChatRoomListUserIsSeller); | ||
} | ||
|
||
@Transactional | ||
public ChatRoomCreateResponse createChatRoom(ChatRoomCreateRequest chatRoomCreateRequest) { | ||
ChatRoom chatRoom = ChatRoom.create( | ||
chatRoomCreateRequest.getSellerId(), | ||
chatRoomCreateRequest.getBuyerId(), | ||
chatRoomCreateRequest.getProductId()); | ||
chatRoomRepository.save(chatRoom); | ||
opsHashChatRoom.put(CHAT_ROOMS, chatRoom.getChatRoomNumber(), chatRoom); | ||
return ChatRoomCreateResponse.fromEntity(chatRoom); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/catchroom/chat/common/common/ApiResponse.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,15 @@ | ||
package com.catchroom.chat.common.common; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class ApiResponse<T> { | ||
private final Integer code; // 사용자 정의 코드 | ||
private final T data; // API에서 반환되는 데이터 | ||
|
||
public static <T> ApiResponse<T> create(int code, T data) { | ||
return new ApiResponse<>(code, data); | ||
} | ||
} |
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: 3 additions & 3 deletions
6
...om/catchroom/chat/config/RedisConfig.java → ...hroom/chat/common/config/RedisConfig.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
4 changes: 2 additions & 2 deletions
4
...atchroom/chat/config/WebSocketConfig.java → ...m/chat/common/config/WebSocketConfig.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
2 changes: 1 addition & 1 deletion
2
...at/config/properties/MongoProperties.java → ...on/config/properties/MongoProperties.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
2 changes: 1 addition & 1 deletion
2
...at/config/properties/RedisProperties.java → ...on/config/properties/RedisProperties.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
10 changes: 5 additions & 5 deletions
10
.../catchroom/chat/handler/StompHandler.java → ...oom/chat/common/handler/StompHandler.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
4 changes: 2 additions & 2 deletions
4
...catchroom/chat/pubsub/RedisPublisher.java → ...om/chat/common/pubsub/RedisPublisher.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
4 changes: 2 additions & 2 deletions
4
...atchroom/chat/pubsub/RedisSubscriber.java → ...m/chat/common/pubsub/RedisSubscriber.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
21 changes: 0 additions & 21 deletions
21
src/main/java/com/catchroom/chat/controller/ChatFindController.java
This file was deleted.
Oops, something went wrong.
10 changes: 5 additions & 5 deletions
10
...hroom/chat/controller/ChatController.java → ...at/message/controller/ChatController.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
Oops, something went wrong.