Skip to content

Commit

Permalink
Merge pull request #3 from catchroom/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
sungjiwoon authored Jan 12, 2024
2 parents 3a0987b + 1a13450 commit a7f6c39
Show file tree
Hide file tree
Showing 30 changed files with 353 additions and 71 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ build/
!**/src/test/**/build/
!**/src/main/resources

## yml ###
src/main/resources/application.yml

### STS ###
.apt_generated
.classpath
Expand Down
6 changes: 4 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,11 @@ tasks.named('test') {
}



dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-websocket'
implementation 'org.springframework.boot:spring-boot-starter-freemarker'
implementation 'org.springframework.boot:spring-boot-devtools'
implementation 'com.mysql:mysql-connector-j'

//aws secretkey 사용을 위한 의존성 추가
implementation 'org.springframework.cloud:spring-cloud-starter-bootstrap:3.1.3'
Expand All @@ -49,6 +47,10 @@ dependencies {
//mongo
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'

//mysql
implementation 'mysql:mysql-connector-java:8.0.32'
runtimeOnly 'com.mysql:mysql-connector-j'


implementation 'org.webjars.bower:bootstrap:4.3.1'
implementation 'org.webjars.bower:vue:2.5.16'
Expand Down
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)));
}
}
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();
}
}
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();
}
}
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 src/main/java/com/catchroom/chat/chatroom/entity/ChatRoom.java
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;
}

}
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);

}
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 src/main/java/com/catchroom/chat/common/common/ApiResponse.java
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);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.catchroom.chat.config;
package com.catchroom.chat.common.config;

import com.catchroom.chat.config.properties.MongoProperties;
import com.catchroom.chat.common.config.properties.MongoProperties;
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
import lombok.RequiredArgsConstructor;
Expand All @@ -11,7 +11,7 @@

@Configuration
@RequiredArgsConstructor
@EnableMongoRepositories(basePackages = "com.catchroom.chat.repository")
@EnableMongoRepositories(basePackages = "com.catchroom.chat.message.repository")
public class MongoConfig {
private final MongoProperties mongoProperties;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.catchroom.chat.config;
package com.catchroom.chat.common.config;

import com.catchroom.chat.config.properties.RedisProperties;
import com.catchroom.chat.pubsub.RedisSubscriber;
import com.catchroom.chat.common.config.properties.RedisProperties;
import com.catchroom.chat.common.pubsub.RedisSubscriber;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.catchroom.chat.config;
package com.catchroom.chat.common.config;

import com.catchroom.chat.handler.StompHandler;
import com.catchroom.chat.common.handler.StompHandler;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.ChannelRegistration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.catchroom.chat.config.properties;
package com.catchroom.chat.common.config.properties;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.catchroom.chat.config.properties;
package com.catchroom.chat.common.config.properties;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.catchroom.chat.handler;
import com.catchroom.chat.dto.ChatMessageDto;
import com.catchroom.chat.repository.ChatRoomRepository;
import com.catchroom.chat.service.ChatService;
import com.catchroom.chat.type.MessageType;
package com.catchroom.chat.common.handler;
import com.catchroom.chat.message.dto.ChatMessageDto;
import com.catchroom.chat.message.repository.ChatRoomRepository;
import com.catchroom.chat.message.service.ChatService;
import com.catchroom.chat.message.type.MessageType;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.catchroom.chat.pubsub;
package com.catchroom.chat.common.pubsub;

import com.catchroom.chat.dto.ChatMessageDto;
import com.catchroom.chat.message.dto.ChatMessageDto;
import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.listener.ChannelTopic;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.catchroom.chat.pubsub;
package com.catchroom.chat.common.pubsub;

import com.catchroom.chat.dto.ChatMessageDto;
import com.catchroom.chat.message.dto.ChatMessageDto;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.catchroom.chat.controller;
package com.catchroom.chat.message.controller;

import com.catchroom.chat.dto.ChatMessageDto;
import com.catchroom.chat.repository.ChatRoomRepository;
import com.catchroom.chat.service.ChatMongoService;
import com.catchroom.chat.service.ChatService;
import com.catchroom.chat.message.dto.ChatMessageDto;
import com.catchroom.chat.message.repository.ChatRoomRepository;
import com.catchroom.chat.message.service.ChatMongoService;
import com.catchroom.chat.message.service.ChatService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.handler.annotation.MessageMapping;
Expand Down
Loading

0 comments on commit a7f6c39

Please sign in to comment.