diff --git a/front-test-bed/README.md b/front-test-bed/README.md new file mode 100644 index 0000000..be2c42e --- /dev/null +++ b/front-test-bed/README.md @@ -0,0 +1,13 @@ +# Websocket Simple Test + +1. ## Click `Edit Configurations...` +![Edit-Configurations](editConfig.png) + +2. ## Input `local` in 'Active profiles' +![Alt text](setProfile.png) + +> local 프로필로 실행하면 h2 db를 사용해 MySQL의 실행 없이 간단한 테스트가 가능합니다. + +3. ## Run! + +4. ## Open `front-test-bed/index.html` \ No newline at end of file diff --git a/front-test-bed/app.js b/front-test-bed/app.js new file mode 100644 index 0000000..8515dcb --- /dev/null +++ b/front-test-bed/app.js @@ -0,0 +1,69 @@ +const stompClient = new StompJs.Client({ + brokerURL: 'ws://localhost:8080/ws-stomp' +}); + +// var channelId = "" + +stompClient.onConnect = (frame) => { + setConnected(true); + console.log('Connected: ' + frame); + stompClient.subscribe('/sub/chat/channel/' + $("#channelId").val(), (message) => { + console.log(JSON.parse(message.body)) + showMessage(JSON.parse(message.body).content); + }); +}; + +stompClient.onWebSocketError = (error) => { + console.error('Error with websocket', error); +}; + +stompClient.onStompError = (frame) => { + console.error('Broker reported error: ' + frame.headers['message']); + console.error('Additional details: ' + frame.body); +}; + +function setConnected(connected) { + $("#connect").prop("disabled", connected); + $("#disconnect").prop("disabled", !connected); + if (connected) { + $("#conversation").show(); + } + else { + $("#conversation").hide(); + } + $("#greetings").html(""); +} + +function connect() { + stompClient.activate(); +} + +function disconnect() { + stompClient.deactivate(); + setConnected(false); + console.log("Disconnected"); +} + +function sendName() { + stompClient.publish({ + destination: "/pub/chat/message", + body: JSON.stringify( + { + "channelId": $("#channelId").val(), + "sender" : $("#name").val(), + "content" : $("#content").val() + } + ) + }); +} + +function showMessage(message) { + $("#greetings").append("" + message + ""); +} + +$(function () { + $("form").on('submit', (e) => e.preventDefault()); + $( "#connect" ).click(() => connect()); + $( "#disconnect" ).click(() => disconnect()); + $( "#send" ).click(() => sendName()); +}); diff --git a/front-test-bed/editConfig.png b/front-test-bed/editConfig.png new file mode 100644 index 0000000..078abf7 Binary files /dev/null and b/front-test-bed/editConfig.png differ diff --git a/front-test-bed/index.html b/front-test-bed/index.html new file mode 100644 index 0000000..00c7909 --- /dev/null +++ b/front-test-bed/index.html @@ -0,0 +1,68 @@ + + + + Hello WebSocket + + + + + + + + +
+
+
+
+
+ + + +
+
+
+
+
+
+ + +
+
+
+
+
+
+ + +
+ +
+
+
+
+
+ + +
+
+
+
+
+
+ + + + + + + + +
Greetings
+
+
+
+ + diff --git a/front-test-bed/setProfile.png b/front-test-bed/setProfile.png new file mode 100644 index 0000000..53d34b9 Binary files /dev/null and b/front-test-bed/setProfile.png differ diff --git a/sns_service/build.gradle.kts b/sns_service/build.gradle.kts index bdeaff5..81b8af9 100644 --- a/sns_service/build.gradle.kts +++ b/sns_service/build.gradle.kts @@ -26,13 +26,16 @@ repositories { dependencies { implementation("org.springframework.boot:spring-boot-starter-web") + implementation("org.springframework.boot:spring-boot-starter-websocket") implementation("com.fasterxml.jackson.module:jackson-module-kotlin") implementation("org.jetbrains.kotlin:kotlin-reflect") implementation("org.springframework.boot:spring-boot-starter-data-jpa") + implementation ("org.springframework.boot:spring-boot-starter-data-redis") implementation("org.springframework.boot:spring-boot-starter-actuator") implementation("io.micrometer:micrometer-registry-prometheus") implementation ("net.logstash.logback:logstash-logback-encoder:7.3") implementation ("io.github.microutils:kotlin-logging:3.0.5") + implementation("it.ozimov:embedded-redis:0.7.2") implementation("org.springframework.kafka:spring-kafka") @@ -40,6 +43,7 @@ dependencies { annotationProcessor("org.projectlombok:lombok") testImplementation("org.springframework.boot:spring-boot-starter-test") runtimeOnly("com.mysql:mysql-connector-j") + runtimeOnly("com.h2database:h2") } tasks.withType { diff --git a/sns_service/src/main/kotlin/joryu/sns_service/SnsServiceApplication.kt b/sns_service/src/main/kotlin/joryu/sns_service/SnsServiceApplication.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/channel/entity/Channel.kt b/sns_service/src/main/kotlin/joryu/sns_service/channel/entity/Channel.kt new file mode 100755 index 0000000..d4f8daf --- /dev/null +++ b/sns_service/src/main/kotlin/joryu/sns_service/channel/entity/Channel.kt @@ -0,0 +1,35 @@ +package joryu.sns_service.channel.entity + +import jakarta.persistence.* +import joryu.sns_service.channel.enums.ChannelType +import java.io.Serializable +import java.util.* + + +@Table(name = "channel") +@Entity +class Channel( + channelName: String = "", + + @Column(name = "channel_type") + val channelType: ChannelType = ChannelType.PERSONAL +) : Serializable { + @Id + @Column(name = "channel_id") + val id: String = UUID.randomUUID().toString() + + @OneToMany(mappedBy = "channel") + val channelProfiles: MutableList = mutableListOf() + + @Column(name = "channel_name") + var channelName: String = channelName + private set + + fun updateChannelName(newName: String) { + channelName = newName + } + + fun addProfileToChannel(profile: ChannelProfile) { + channelProfiles.add(profile) + } +} \ No newline at end of file diff --git a/sns_service/src/main/kotlin/joryu/sns_service/channel/entity/ChannelProfile.kt b/sns_service/src/main/kotlin/joryu/sns_service/channel/entity/ChannelProfile.kt new file mode 100755 index 0000000..2679b9c --- /dev/null +++ b/sns_service/src/main/kotlin/joryu/sns_service/channel/entity/ChannelProfile.kt @@ -0,0 +1,22 @@ +package joryu.sns_service.channel.entity + +import jakarta.persistence.* +import joryu.sns_service.profile.entity.Profile +import java.io.Serializable + +@Table(name = "channel_profile") +@Entity +class ChannelProfile( + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "channel_id") + val channel: Channel = Channel(), + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "profile_id") + val profile: Profile = Profile() +): Serializable { + @Id + @Column(name = "channel_profile_id") + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long = 0 +} diff --git a/sns_service/src/main/kotlin/joryu/sns_service/channel/enums/ChannelType.kt b/sns_service/src/main/kotlin/joryu/sns_service/channel/enums/ChannelType.kt new file mode 100644 index 0000000..c505b36 --- /dev/null +++ b/sns_service/src/main/kotlin/joryu/sns_service/channel/enums/ChannelType.kt @@ -0,0 +1,5 @@ +package joryu.sns_service.channel.enums + +enum class ChannelType { + PERSONAL, GROUP +} \ No newline at end of file diff --git a/sns_service/src/main/kotlin/joryu/sns_service/channel/repository/ChannelProfileRepository.kt b/sns_service/src/main/kotlin/joryu/sns_service/channel/repository/ChannelProfileRepository.kt new file mode 100644 index 0000000..c5e3f72 --- /dev/null +++ b/sns_service/src/main/kotlin/joryu/sns_service/channel/repository/ChannelProfileRepository.kt @@ -0,0 +1,7 @@ +package joryu.sns_service.channel.repository + +import joryu.sns_service.channel.entity.ChannelProfile +import org.springframework.data.jpa.repository.JpaRepository + +interface ChannelProfileRepository: JpaRepository { +} \ No newline at end of file diff --git a/sns_service/src/main/kotlin/joryu/sns_service/channel/repository/ChannelRepository.kt b/sns_service/src/main/kotlin/joryu/sns_service/channel/repository/ChannelRepository.kt new file mode 100644 index 0000000..823686e --- /dev/null +++ b/sns_service/src/main/kotlin/joryu/sns_service/channel/repository/ChannelRepository.kt @@ -0,0 +1,7 @@ +package joryu.sns_service.channel.repository + +import joryu.sns_service.channel.entity.Channel +import org.springframework.data.jpa.repository.JpaRepository + +interface ChannelRepository: JpaRepository { +} \ No newline at end of file diff --git a/sns_service/src/main/kotlin/joryu/sns_service/chat/config/EmbeddedRedisConfig.kt b/sns_service/src/main/kotlin/joryu/sns_service/chat/config/EmbeddedRedisConfig.kt new file mode 100644 index 0000000..e790868 --- /dev/null +++ b/sns_service/src/main/kotlin/joryu/sns_service/chat/config/EmbeddedRedisConfig.kt @@ -0,0 +1,30 @@ +package joryu.sns_service.chat.config + +import jakarta.annotation.PostConstruct +import jakarta.annotation.PreDestroy +import org.springframework.beans.factory.annotation.Value +import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Profile +import redis.embedded.RedisServer + + +@Profile("local") // profile이 local일때만 활성화 +@Configuration +class EmbeddedRedisConfig { + + @Value("\${spring.data.redis.port}") + private val redisPort = 6379 + + private var redisServer: RedisServer? = null + + @PostConstruct + fun redisServer() { + redisServer = RedisServer(redisPort) + redisServer?.start() + } + + @PreDestroy + fun stopRedis() { + redisServer?.stop() + } +} \ No newline at end of file diff --git a/sns_service/src/main/kotlin/joryu/sns_service/chat/config/RedisConfig.kt b/sns_service/src/main/kotlin/joryu/sns_service/chat/config/RedisConfig.kt new file mode 100755 index 0000000..7ec6a56 --- /dev/null +++ b/sns_service/src/main/kotlin/joryu/sns_service/chat/config/RedisConfig.kt @@ -0,0 +1,86 @@ +package joryu.sns_service.chat.config + +import org.springframework.beans.factory.annotation.Qualifier +import org.springframework.beans.factory.annotation.Value +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Primary +import org.springframework.data.redis.connection.MessageListener +import org.springframework.data.redis.connection.RedisConnectionFactory +import org.springframework.data.redis.connection.RedisStandaloneConfiguration +import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory +import org.springframework.data.redis.core.RedisTemplate +import org.springframework.data.redis.listener.ChannelTopic +import org.springframework.data.redis.listener.RedisMessageListenerContainer +import org.springframework.data.redis.listener.adapter.MessageListenerAdapter +import org.springframework.data.redis.repository.configuration.EnableRedisRepositories +import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer +import org.springframework.data.redis.serializer.StringRedisSerializer + + +/** + * 채팅에 사용되는 redis 설정 관리 + */ +@Configuration +@EnableRedisRepositories +class RedisConfig( + @Value("\${spring.data.redis.port:6379}") + private val port: Int, + + @Value("\${spring.data.redis.host:localhost}") + private val host: String +) { + + /** + * ChannelTopic 에 발행된 메시지를 처리하는 Listner 들을 설정한다. + */ + @Bean + @Primary + fun redisMessageListenerContainer( + redisConnectionFactory: RedisConnectionFactory, + chatMessageListenerAdapter: MessageListenerAdapter, + @Qualifier("chatChannelTopic") chatChannelTopic: ChannelTopic + ): RedisMessageListenerContainer { + val container = RedisMessageListenerContainer() + container.setConnectionFactory(redisConnectionFactory) + container.addMessageListener(chatMessageListenerAdapter, chatChannelTopic) + return container + } + + @Bean + fun redisConnectionFactory(): RedisConnectionFactory { + val redisStandaloneConfiguration = RedisStandaloneConfiguration() + redisStandaloneConfiguration.hostName = host + redisStandaloneConfiguration.port = port + return LettuceConnectionFactory(redisStandaloneConfiguration) + } + + /** + * RedisMessageListenerContainer 로부터 메시지를 전달받는다. + * 메시지 처리 비즈니스 로직을 담은 Subscriber Bean 을 추가해준다. + */ + @Bean + fun chatMessageListenerAdapter(listener: MessageListener): MessageListenerAdapter { + return MessageListenerAdapter(listener, "onMessage") + } + + /** + * 채팅 채널 토픽을 반환한다. + */ + @Bean(value = ["chatChannelTopic"]) + fun chatChannelTopic(): ChannelTopic { + return ChannelTopic("chat") + } + + /** + * Redis 데이터에 접근하는 redisTemplate 를 반환한다. + */ + @Bean + fun redisTemplate(connectionFactory: RedisConnectionFactory): RedisTemplate { + val redisTemplate = RedisTemplate() + redisTemplate.connectionFactory = connectionFactory + redisTemplate.keySerializer = StringRedisSerializer() + redisTemplate.valueSerializer = Jackson2JsonRedisSerializer(String::class.java) + return redisTemplate + } +} \ No newline at end of file diff --git a/sns_service/src/main/kotlin/joryu/sns_service/chat/config/WebSocketConfig.kt b/sns_service/src/main/kotlin/joryu/sns_service/chat/config/WebSocketConfig.kt new file mode 100755 index 0000000..b23d260 --- /dev/null +++ b/sns_service/src/main/kotlin/joryu/sns_service/chat/config/WebSocketConfig.kt @@ -0,0 +1,34 @@ +package joryu.sns_service.chat.config + +import org.springframework.context.annotation.Configuration +import org.springframework.messaging.simp.config.MessageBrokerRegistry +import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker +import org.springframework.web.socket.config.annotation.StompEndpointRegistry +import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer + + +/** + * WebSocket 설정을 관리하는 클래스 + */ +@Configuration +@EnableWebSocketMessageBroker +class WebSocketConfig : WebSocketMessageBrokerConfigurer { + + /** + * 목적지 prefix 가 "/sub" 인 메시지를 필터링합니다. (outbound) + * 도착지 prefix 가 "/pub" 인 메시지를 필터링합니다. (inbound) + */ + override fun configureMessageBroker(config: MessageBrokerRegistry) { + config.enableSimpleBroker("/sub") + config.setApplicationDestinationPrefixes("/pub") + } + + /** + * STOMP endpoint 를 설정합니다. + */ + override fun registerStompEndpoints(registry: StompEndpointRegistry) { + registry + .addEndpoint("/ws-stomp") + .setAllowedOriginPatterns("*") + } +} \ No newline at end of file diff --git a/sns_service/src/main/kotlin/joryu/sns_service/chat/controller/ChatMessageController.kt b/sns_service/src/main/kotlin/joryu/sns_service/chat/controller/ChatMessageController.kt new file mode 100644 index 0000000..b21909d --- /dev/null +++ b/sns_service/src/main/kotlin/joryu/sns_service/chat/controller/ChatMessageController.kt @@ -0,0 +1,20 @@ +package joryu.sns_service.chat.controller + +import joryu.sns_service.chat.dto.ChatMessage +import joryu.sns_service.chat.service.ChatPublisher +import org.springframework.messaging.handler.annotation.MessageMapping +import org.springframework.stereotype.Controller + +@Controller +class ChatMessageController( + private val chatPublisher: ChatPublisher +) { + /** + * /pub/chat/message 로 들어오는 메시징을 처리한다. + */ + @MessageMapping("/chat/message") + fun sendMessage(message: ChatMessage) { + + chatPublisher.publish(message) + } +} \ No newline at end of file diff --git a/sns_service/src/main/kotlin/joryu/sns_service/chat/dto/ChatMessage.kt b/sns_service/src/main/kotlin/joryu/sns_service/chat/dto/ChatMessage.kt new file mode 100644 index 0000000..176ba33 --- /dev/null +++ b/sns_service/src/main/kotlin/joryu/sns_service/chat/dto/ChatMessage.kt @@ -0,0 +1,7 @@ +package joryu.sns_service.chat.dto + +data class ChatMessage( + val channelId: String, + val senderProfileId: String, + val content: String = "", +) diff --git a/sns_service/src/main/kotlin/joryu/sns_service/chat/service/ChatListener.kt b/sns_service/src/main/kotlin/joryu/sns_service/chat/service/ChatListener.kt new file mode 100644 index 0000000..c69ec48 --- /dev/null +++ b/sns_service/src/main/kotlin/joryu/sns_service/chat/service/ChatListener.kt @@ -0,0 +1,31 @@ +package joryu.sns_service.chat.service + +import com.fasterxml.jackson.databind.ObjectMapper +import joryu.sns_service.chat.dto.ChatMessage +import mu.KLogger +import mu.KotlinLogging +import org.springframework.data.redis.connection.Message +import org.springframework.data.redis.connection.MessageListener +import org.springframework.data.redis.core.RedisTemplate +import org.springframework.messaging.simp.SimpMessageSendingOperations +import org.springframework.stereotype.Service + +@Service +class ChatListener( + private val objectMapper: ObjectMapper, + private val redisTemplate: RedisTemplate, + private val messagingTemplate: SimpMessageSendingOperations, +): MessageListener { + val log: KLogger = KotlinLogging.logger {} + + override fun onMessage(message: Message, pattern: ByteArray?) { + try { + val publishMessage = redisTemplate.stringSerializer.deserialize(message.body) + val chatMessage = objectMapper.readValue(publishMessage, ChatMessage::class.java) + + messagingTemplate.convertAndSend("/sub/chat/channel/" + chatMessage.channelId, chatMessage) + } catch (e: Exception) { + log.error { e.stackTraceToString() } + } + } +} \ No newline at end of file diff --git a/sns_service/src/main/kotlin/joryu/sns_service/chat/service/ChatPublisher.kt b/sns_service/src/main/kotlin/joryu/sns_service/chat/service/ChatPublisher.kt new file mode 100644 index 0000000..8893756 --- /dev/null +++ b/sns_service/src/main/kotlin/joryu/sns_service/chat/service/ChatPublisher.kt @@ -0,0 +1,16 @@ +package joryu.sns_service.chat.service + +import joryu.sns_service.chat.dto.ChatMessage +import org.springframework.data.redis.core.RedisTemplate +import org.springframework.data.redis.listener.ChannelTopic +import org.springframework.stereotype.Service + +@Service +class ChatPublisher( + private val channelTopic: ChannelTopic, + private val redisTemplate: RedisTemplate, +) { + fun publish(message: ChatMessage) { + redisTemplate.convertAndSend(channelTopic.topic, message) + } +} \ No newline at end of file diff --git a/sns_service/src/main/kotlin/joryu/sns_service/comment/controller/CommentController.kt b/sns_service/src/main/kotlin/joryu/sns_service/comment/controller/CommentController.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/comment/dto/request/CommentCreateRequest.kt b/sns_service/src/main/kotlin/joryu/sns_service/comment/dto/request/CommentCreateRequest.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/comment/dto/request/CommentUpdateRequest.kt b/sns_service/src/main/kotlin/joryu/sns_service/comment/dto/request/CommentUpdateRequest.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/comment/dto/response/CommentResponse.kt b/sns_service/src/main/kotlin/joryu/sns_service/comment/dto/response/CommentResponse.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/comment/entity/Comment.kt b/sns_service/src/main/kotlin/joryu/sns_service/comment/entity/Comment.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/comment/entity/CommentLike.kt b/sns_service/src/main/kotlin/joryu/sns_service/comment/entity/CommentLike.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/comment/repository/CommentLikeRepository.kt b/sns_service/src/main/kotlin/joryu/sns_service/comment/repository/CommentLikeRepository.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/comment/repository/CommentRepository.kt b/sns_service/src/main/kotlin/joryu/sns_service/comment/repository/CommentRepository.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/comment/service/CommentService.kt b/sns_service/src/main/kotlin/joryu/sns_service/comment/service/CommentService.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/common/dto/response/CommonResponseBody.kt b/sns_service/src/main/kotlin/joryu/sns_service/common/dto/response/CommonResponseBody.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/common/entity/BaseEntity.kt b/sns_service/src/main/kotlin/joryu/sns_service/common/entity/BaseEntity.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/follow/controller/FollowController.kt b/sns_service/src/main/kotlin/joryu/sns_service/follow/controller/FollowController.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/follow/dto/request/FollowRequest.kt b/sns_service/src/main/kotlin/joryu/sns_service/follow/dto/request/FollowRequest.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/follow/dto/request/UnFollowRequest.kt b/sns_service/src/main/kotlin/joryu/sns_service/follow/dto/request/UnFollowRequest.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/follow/entity/Follow.kt b/sns_service/src/main/kotlin/joryu/sns_service/follow/entity/Follow.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/follow/repository/FollowRepository.kt b/sns_service/src/main/kotlin/joryu/sns_service/follow/repository/FollowRepository.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/follow/service/FollowService.kt b/sns_service/src/main/kotlin/joryu/sns_service/follow/service/FollowService.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/post/controller/PostController.kt b/sns_service/src/main/kotlin/joryu/sns_service/post/controller/PostController.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/post/controller/PostLikeController.kt b/sns_service/src/main/kotlin/joryu/sns_service/post/controller/PostLikeController.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/post/controller/ShareController.kt b/sns_service/src/main/kotlin/joryu/sns_service/post/controller/ShareController.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/post/dto/request/PostCreateRequest.kt b/sns_service/src/main/kotlin/joryu/sns_service/post/dto/request/PostCreateRequest.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/post/dto/request/PostUpdateRequest.kt b/sns_service/src/main/kotlin/joryu/sns_service/post/dto/request/PostUpdateRequest.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/post/dto/response/PostLikeCountResponse.kt b/sns_service/src/main/kotlin/joryu/sns_service/post/dto/response/PostLikeCountResponse.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/post/dto/response/PostResponse.kt b/sns_service/src/main/kotlin/joryu/sns_service/post/dto/response/PostResponse.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/post/entity/Post.kt b/sns_service/src/main/kotlin/joryu/sns_service/post/entity/Post.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/post/entity/PostLike.kt b/sns_service/src/main/kotlin/joryu/sns_service/post/entity/PostLike.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/post/entity/PostView.kt b/sns_service/src/main/kotlin/joryu/sns_service/post/entity/PostView.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/post/entity/Share.kt b/sns_service/src/main/kotlin/joryu/sns_service/post/entity/Share.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/post/repository/PostLikeRepository.kt b/sns_service/src/main/kotlin/joryu/sns_service/post/repository/PostLikeRepository.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/post/repository/PostRepository.kt b/sns_service/src/main/kotlin/joryu/sns_service/post/repository/PostRepository.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/post/repository/PostViewRepository.kt b/sns_service/src/main/kotlin/joryu/sns_service/post/repository/PostViewRepository.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/post/repository/ShareRepository.kt b/sns_service/src/main/kotlin/joryu/sns_service/post/repository/ShareRepository.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/post/service/PostLikeService.kt b/sns_service/src/main/kotlin/joryu/sns_service/post/service/PostLikeService.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/post/service/PostService.kt b/sns_service/src/main/kotlin/joryu/sns_service/post/service/PostService.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/post/service/ShareService.kt b/sns_service/src/main/kotlin/joryu/sns_service/post/service/ShareService.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/profile/controller/ProfileApiController.kt b/sns_service/src/main/kotlin/joryu/sns_service/profile/controller/ProfileApiController.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/profile/dto/request/ProfileCreateRequest.kt b/sns_service/src/main/kotlin/joryu/sns_service/profile/dto/request/ProfileCreateRequest.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/profile/dto/request/ProfileUpdateRequest.kt b/sns_service/src/main/kotlin/joryu/sns_service/profile/dto/request/ProfileUpdateRequest.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/profile/dto/response/AllFollowerProfileResponse.kt b/sns_service/src/main/kotlin/joryu/sns_service/profile/dto/response/AllFollowerProfileResponse.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/profile/dto/response/ProfileInfoResponse.kt b/sns_service/src/main/kotlin/joryu/sns_service/profile/dto/response/ProfileInfoResponse.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/profile/entity/Profile.kt b/sns_service/src/main/kotlin/joryu/sns_service/profile/entity/Profile.kt old mode 100644 new mode 100755 index 97de07c..bd8cbcc --- a/sns_service/src/main/kotlin/joryu/sns_service/profile/entity/Profile.kt +++ b/sns_service/src/main/kotlin/joryu/sns_service/profile/entity/Profile.kt @@ -1,10 +1,13 @@ package joryu.sns_service.profile.entity import jakarta.persistence.* +import joryu.sns_service.channel.entity.Channel +import joryu.sns_service.channel.entity.ChannelProfile import joryu.sns_service.common.entity.BaseEntity import joryu.sns_service.follow.entity.Follow import joryu.sns_service.profile.dto.request.ProfileUpdateRequest + @Table(name = "profile") @Entity class Profile( @@ -28,6 +31,9 @@ class Profile( constructor() : this(0, "", 0, 0) constructor(name: String) : this(0, name, 0, 0) + @OneToMany(mappedBy = "profile") + val channelProfiles: MutableList = mutableListOf() + fun update(profileUpdateRequest: ProfileUpdateRequest) { this.name = profileUpdateRequest.name } @@ -38,5 +44,9 @@ class Profile( fun addFollowing(following: Follow) { this.followingNumber++ } + + fun addChannel(channel: Channel) { + channelProfiles.add(ChannelProfile(channel, this)) + } } diff --git a/sns_service/src/main/kotlin/joryu/sns_service/profile/exception/ProfileBaseException.kt b/sns_service/src/main/kotlin/joryu/sns_service/profile/exception/ProfileBaseException.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/profile/exception/ProfileExceptionEnums.kt b/sns_service/src/main/kotlin/joryu/sns_service/profile/exception/ProfileExceptionEnums.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/profile/exception/ProfileExceptionHandler.kt b/sns_service/src/main/kotlin/joryu/sns_service/profile/exception/ProfileExceptionHandler.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/kotlin/joryu/sns_service/profile/repository/ProfileRepository.kt b/sns_service/src/main/kotlin/joryu/sns_service/profile/repository/ProfileRepository.kt old mode 100644 new mode 100755 index c9deb84..560e571 --- a/sns_service/src/main/kotlin/joryu/sns_service/profile/repository/ProfileRepository.kt +++ b/sns_service/src/main/kotlin/joryu/sns_service/profile/repository/ProfileRepository.kt @@ -4,4 +4,5 @@ import joryu.sns_service.profile.entity.Profile import org.springframework.data.jpa.repository.JpaRepository interface ProfileRepository : JpaRepository { + fun findAllByIdIn(ids: List): List } \ No newline at end of file diff --git a/sns_service/src/main/kotlin/joryu/sns_service/profile/service/ProfileService.kt b/sns_service/src/main/kotlin/joryu/sns_service/profile/service/ProfileService.kt old mode 100644 new mode 100755 index 4a88b38..3409a2e --- a/sns_service/src/main/kotlin/joryu/sns_service/profile/service/ProfileService.kt +++ b/sns_service/src/main/kotlin/joryu/sns_service/profile/service/ProfileService.kt @@ -38,6 +38,12 @@ class ProfileService( return ProfileInfoResponse(profile) } + @Transactional(readOnly = true) + fun findAllByIdIn(ids: List): List { + return profileRepository.findAllByIdIn(ids) + .map { profile -> ProfileInfoResponse(profile) } + } + @Transactional fun update(id: Long, profileUpdateRequest: ProfileUpdateRequest): ProfileInfoResponse { val profile = profileRepository.findById(id) diff --git a/sns_service/src/main/kotlin/joryu/sns_service/utils/IpUtils.kt b/sns_service/src/main/kotlin/joryu/sns_service/utils/IpUtils.kt old mode 100644 new mode 100755 diff --git a/sns_service/src/main/resources/application.yaml b/sns_service/src/main/resources/application.yaml index 32c79a0..5cddacd 100644 --- a/sns_service/src/main/resources/application.yaml +++ b/sns_service/src/main/resources/application.yaml @@ -4,7 +4,6 @@ spring: password: 1234 url: jdbc:mysql://localhost:33061/sns-db?useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC&useLegacyDatetimeCode=false driver-class-name: com.mysql.cj.jdbc.Driver - jpa: hibernate: ddl-auto: create @@ -13,9 +12,37 @@ spring: show_sql: true format_sql: true dialect: org.hibernate.dialect.MySQL8Dialect + profiles: + group: + dev: "local" + active: local management: endpoints: web: exposure: include: "prometheus" + +--- + +spring: + config: + activate: + on-profile: "local" + datasource: + driver-class-name: org.h2.Driver + url: jdbc:h2:mem:testdb;MODE=MySQL; + username: sa + password: + jpa: + hibernate: + ddl-auto: create-drop + logging.level: + org.hibernate.SQL: debug + properties: + hibernate: + show_sql: true + data: + redis: + host: localhost + port: 6379