Skip to content

Commit

Permalink
Merge branch 'dev' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Jyuung committed Aug 24, 2024
2 parents 91c6ab4 + 6cc4d2c commit 9b152c0
Show file tree
Hide file tree
Showing 38 changed files with 1,308 additions and 3 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules/delivery/baobab.delivery.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules/global/baobab.global.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules/warehouse/baobab.warehouse.main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions db/src/main/java/db/domain/chat/enums/ChatRoomStatus.java
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 db/src/main/java/db/domain/chat/message/ChatMessageEntity.java
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 db/src/main/java/db/domain/chat/message/ChatMessageRepository.java
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);

}
45 changes: 45 additions & 0 deletions db/src/main/java/db/domain/chat/room/ChatRoomEntity.java
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 db/src/main/java/db/domain/chat/room/ChatRoomRepository.java
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);

}
3 changes: 3 additions & 0 deletions db/src/main/java/db/domain/usedgoods/UsedGoodsRepository.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package db.domain.usedgoods;

import db.domain.usedgoods.enums.UsedGoodsStatus;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

Expand All @@ -10,4 +11,6 @@ public interface UsedGoodsRepository extends JpaRepository<UsedGoodsEntity, Long

Optional<UsedGoodsEntity> findFirstById(Long usedGoodsId);

List<UsedGoodsEntity> findByUserId(Long userId);

}
4 changes: 4 additions & 0 deletions warehouse/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ dependencies {

implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'

implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.boot:spring-boot-starter-websocket'


implementation 'io.jsonwebtoken:jjwt-api:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.11.5'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5'
Expand Down
2 changes: 2 additions & 0 deletions warehouse/src/main/java/warehouse/WarehouseApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.scheduling.annotation.EnableScheduling;
import warehouse.domain.image.properties.FileStorageProperties;

@OpenAPIDefinition(servers = {@Server(url = "https://baobab.run/warehouse/", description = "Baobab Dev Server API")})
@SpringBootApplication
@EnableConfigurationProperties({
FileStorageProperties.class
})
@EnableScheduling
public class WarehouseApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import java.util.concurrent.Executor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@EnableAsync
@Configuration
public class AsyncConfig {

@Primary
@Bean(name = "imageUploadExecutor")
public Executor imageUploadExecutor() {

Expand Down
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class SecurityConfig {
private final TokenService tokenService;

private final List<String> WHITE_LIST = List.of("/swagger-ui.html", "/swagger-ui/**",
"/v3/api-docs/**", "/open-api/**");
"/v3/api-docs/**", "/open-api/**", "/chatting/**");

@Bean
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
Expand Down
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 warehouse/src/main/java/warehouse/common/error/ChatErrorCode.java
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;

}
Loading

0 comments on commit 9b152c0

Please sign in to comment.