-
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.
- Loading branch information
Showing
38 changed files
with
1,308 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,17 @@ | ||
package db.domain.chat.enums; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum ChatRoomStatus { | ||
|
||
ACTIVE(1, "νμ±ν μ±ν λ°©", "νμ±νλ μ±ν λ°©μ λλ€."), | ||
INACTIVE(2, "λΉνμ±ν μ±ν λ°©", "λΉνμ±νλ μ±ν λ°©μ λλ€.") | ||
; | ||
|
||
private final int current; | ||
private final String status; | ||
private final String description; | ||
} |
39 changes: 39 additions & 0 deletions
39
db/src/main/java/db/domain/chat/message/ChatMessageEntity.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 db.domain.chat.message; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import java.io.Serial; | ||
import java.io.Serializable; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Entity | ||
@Table(name = "chat_message") | ||
@SuperBuilder | ||
public class ChatMessageEntity implements Serializable { | ||
|
||
@Serial | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Id | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private String message; // λ©μμ§ λ΄μ© | ||
|
||
@Column(nullable = false) | ||
private Long chatRoomId; // λ°© ID | ||
|
||
@Column(nullable = false) | ||
private Long userId; // λ°μ μ ID | ||
|
||
private String createdAt; | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
db/src/main/java/db/domain/chat/message/ChatMessageRepository.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,10 @@ | ||
package db.domain.chat.message; | ||
|
||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ChatMessageRepository extends JpaRepository<ChatMessageEntity, Long> { | ||
|
||
List<ChatMessageEntity> findAllByChatRoomId(Long chatRoomId); | ||
|
||
} |
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,45 @@ | ||
package db.domain.chat.room; | ||
|
||
import db.domain.chat.enums.ChatRoomStatus; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import java.io.Serial; | ||
import java.io.Serializable; | ||
import java.time.LocalDateTime; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.experimental.SuperBuilder; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Entity | ||
@Table(name = "chat_room") | ||
@SuperBuilder | ||
public class ChatRoomEntity implements Serializable { | ||
|
||
@Serial | ||
private static final long serialVersionUID = 1L; | ||
|
||
@Id | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private Long userId; // ꡬ맀μ id | ||
|
||
@Column(nullable = false) | ||
|
||
private Long usedGoodsId; // μ€κ³ ν맀 κΈ ID | ||
|
||
@Column(nullable = false) | ||
@Enumerated(EnumType.STRING) | ||
private ChatRoomStatus status; | ||
|
||
private LocalDateTime createdAt; | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
db/src/main/java/db/domain/chat/room/ChatRoomRepository.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 db.domain.chat.room; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ChatRoomRepository extends JpaRepository<ChatRoomEntity,Long> { | ||
|
||
Optional<ChatRoomEntity> findFirstByUsedGoodsIdAndUserId(Long usedGoodsId, Long userId); | ||
|
||
List<ChatRoomEntity> findAll(); | ||
|
||
void deleteById(Long id); | ||
|
||
Optional<ChatRoomEntity> findFirstById(Long id); | ||
|
||
List<ChatRoomEntity> findByUsedGoodsIdIn(List<Long> usedGoodsId); | ||
|
||
List<ChatRoomEntity> findByUserId(Long userid); | ||
|
||
} |
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
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
52 changes: 52 additions & 0 deletions
52
warehouse/src/main/java/warehouse/common/config/redis/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package warehouse.common.config.redis; | ||
|
||
import db.domain.chat.message.ChatMessageEntity; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.listener.RedisMessageListenerContainer; | ||
import org.springframework.data.redis.serializer.GenericToStringSerializer; | ||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
@RequiredArgsConstructor | ||
@Configuration | ||
public class RedisConfig { | ||
|
||
/** | ||
* redis pub/sub λ©μμ§λ₯Ό μ²λ¦¬νλ listener μ€μ | ||
*/ | ||
@Bean | ||
public RedisMessageListenerContainer redisMessageListener( | ||
RedisConnectionFactory connectionFactory) { | ||
RedisMessageListenerContainer container = new RedisMessageListenerContainer(); | ||
container.setConnectionFactory(connectionFactory); | ||
return container; | ||
} | ||
|
||
/** | ||
* ChatRoom μ¬μ©ν redisTemplate μ€μ | ||
*/ | ||
@Bean | ||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) { | ||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>(); | ||
redisTemplate.setConnectionFactory(connectionFactory); | ||
redisTemplate.setKeySerializer(new StringRedisSerializer()); | ||
redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<>(String.class)); // λͺ¨λ Objectλ₯Ό JSONμΌλ‘ μ§λ ¬ν | ||
return redisTemplate; | ||
} | ||
|
||
/** | ||
* ChatMessage μ¬μ©ν redisTemplate μ€μ | ||
*/ | ||
@Bean | ||
public RedisTemplate<Long, ChatMessageEntity> chatMessageRedisTemplate(RedisConnectionFactory connectionFactory) { | ||
RedisTemplate<Long, ChatMessageEntity> redisTemplate = new RedisTemplate<>(); | ||
redisTemplate.setConnectionFactory(connectionFactory); | ||
redisTemplate.setKeySerializer(new GenericToStringSerializer<>(Long.class)); | ||
redisTemplate.setValueSerializer(new Jackson2JsonRedisSerializer<>(ChatMessageEntity.class)); | ||
return redisTemplate; | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
warehouse/src/main/java/warehouse/common/config/websocket/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package warehouse.common.config.websocket; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.messaging.simp.config.MessageBrokerRegistry; | ||
import org.springframework.web.socket.config.annotation.EnableWebSocket; | ||
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker; | ||
import org.springframework.web.socket.config.annotation.StompEndpointRegistry; | ||
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
@EnableWebSocketMessageBroker | ||
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer { | ||
|
||
@Override | ||
public void configureMessageBroker(MessageBrokerRegistry registry) { | ||
registry.enableSimpleBroker("/sub"); | ||
registry.setApplicationDestinationPrefixes("/pub"); | ||
} | ||
|
||
@Override | ||
public void registerStompEndpoints(StompEndpointRegistry registry) { | ||
registry.addEndpoint("/chatting").setAllowedOrigins("*"); | ||
//.withSockJS(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
warehouse/src/main/java/warehouse/common/error/ChatErrorCode.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,24 @@ | ||
package warehouse.common.error; | ||
|
||
import global.errorcode.ErrorCodeIfs; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum ChatErrorCode implements ErrorCodeIfs { | ||
|
||
CHAT_ROOM_NOT_FOUND(HttpStatus.NOT_FOUND.value(), 1700, "μ±ν λ°©μ΄ μ‘΄μ¬νμ§ μμ΅λλ€."), | ||
CHAT_MESSAGE_NOT_FOUND(HttpStatus.NOT_FOUND.value(), 1701, "μ±ν λ©μμ§κ° μ‘΄μ¬νμ§ μμ΅λλ€."), | ||
CHAT_ROOM_EXISTS(HttpStatus.BAD_REQUEST.value(), 1702, "μ΄λ―Έ μ‘΄μ¬νλ μ±ν λ°© μ λλ€."), | ||
SELLER_AND_BUYER_SAME(HttpStatus.BAD_REQUEST.value(), 1703, "ν맀μλ μμ μ μνμ λν΄ μ±ν λ°©μ μμ±ν μ μμ΅λλ€."), | ||
CHAT_ROOM_INACTIVE(HttpStatus.BAD_REQUEST.value(), 1704, "μ±ν λ°©μ΄ λΉνμ±ν λμ΄ μ±ν μ μ‘μ΄ λΆκ°λ₯ν©λλ€."), | ||
CHAT_ROOM_ACCESS_DENIED(HttpStatus.BAD_REQUEST.value(), 1705, "μ±ν λ°© μ κ·Ό κΆνμ΄ μ‘΄μ¬νμ§ μμ΅λλ€.") | ||
; | ||
|
||
private final Integer httpCode; | ||
private final Integer errorCode; | ||
private final String description; | ||
|
||
} |
Oops, something went wrong.