Skip to content

Commit

Permalink
Merge pull request #183 from kSideProject/dev
Browse files Browse the repository at this point in the history
syn
  • Loading branch information
yudonggeun authored Jun 18, 2024
2 parents f97c231 + 12f7acf commit 9beabb0
Show file tree
Hide file tree
Showing 142 changed files with 3,593 additions and 1,107 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: CI

on:
push:
branches: [ main ] # push 되었을 때, 실행

jobs:
cd:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

# jdk 21 환경 구성
- name: set up jdk 21
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '21'

# Gradle wrapper 파일 실행 권한주기
- name: Grant execute permission for gradlew
run: chmod +x gradlew

# Gradle jib를 통한 이미지 배포
- name: update image using jib
run: ./gradlew --info jib
14 changes: 11 additions & 3 deletions auth/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ tasks.asciidoctor {
dependsOn(tasks.test)
}

val hostname = "kpring.duckdns.org"

openapi3 {
setServer("http://localhost/auth")
setServer("http://$hostname/auth")
title = "Auth API"
description = "API document"
version = "0.1.0"
Expand All @@ -82,11 +84,17 @@ openapi3 {
jib {
from {
image = "eclipse-temurin:21-jre"
platforms {
platform {
architecture = "arm64"
os = "linux"
}
}
}
to {
image = "localhost:5000/auth-application"
image = "youdong98/kpring-auth-application"
setAllowInsecureRegistries(true)
tags = setOf("latest")
tags = setOf("latest", version.toString())
}
container {
jvmFlags = listOf("-Xms512m", "-Xmx512m")
Expand Down
25 changes: 24 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.springframework.boot.gradle.tasks.bundling.BootJar
import java.io.IOException

plugins {
id("org.springframework.boot") version "3.2.4"
Expand All @@ -17,7 +18,7 @@ repositories {

allprojects {
group = "com.sideproject"
version = "0.0.1-SNAPSHOT"
version = "git rev-parse --short=8 HEAD".runCommand(workingDir = rootDir)

repositories {
mavenCentral()
Expand Down Expand Up @@ -53,3 +54,25 @@ subprojects {
debug.set(true)
}
}

/**
* cli 실행 결과를 반환한기 위한 함수
*/
fun String.runCommand(
workingDir: File = File("."),
timeoutAmount: Long = 60,
timeoutUnit: TimeUnit = TimeUnit.SECONDS,
): String =
ProcessBuilder(split("\\s(?=(?:[^'\"`]*(['\"`])[^'\"`]*\\1)*[^'\"`]*$)".toRegex()))
.directory(workingDir)
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
.start()
.apply { waitFor(timeoutAmount, timeoutUnit) }
.run {
val error = errorStream.bufferedReader().readText().trim()
if (error.isNotEmpty()) {
throw IOException(error)
}
inputStream.bufferedReader().readText().trim()
}
3 changes: 3 additions & 0 deletions chat/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ dependencies {
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")

// non-blocking redis
implementation("org.springframework.boot:spring-boot-starter-data-redis")

// test
testImplementation(project(":test"))
testImplementation("org.springframework.boot:spring-boot-starter-test")
Expand Down
17 changes: 13 additions & 4 deletions chat/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,17 @@ services:
image: mongo:latest
container_name: mongo
ports:
- "27017:27017"
- "27018:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: 58155815
MONGO_INITDB_DATABASE: mongodb
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: testpassword1234
MONGO_INITDB_DATABASE: mongodb

redis:
image: redis:alpine
container_name: redis_link
ports:
- "6379:6379"
environment:
- REDIS_PASSWORD = "testpassword1234"
command: [ "redis-server","--requirepass","${REDIS_PASSWORD}" ]
2 changes: 2 additions & 0 deletions chat/src/main/kotlin/kpring/chat/ChatApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package kpring.chat

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.data.mongodb.config.EnableMongoAuditing

@EnableMongoAuditing
@SpringBootApplication
class ChatApplication

Expand Down
41 changes: 35 additions & 6 deletions chat/src/main/kotlin/kpring/chat/chat/api/v1/ChatController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import kpring.chat.global.exception.GlobalException
import kpring.core.auth.client.AuthClient
import kpring.core.chat.chat.dto.request.ChatType
import kpring.core.chat.chat.dto.request.CreateChatRequest
import kpring.core.chat.chat.dto.request.UpdateChatRequest
import kpring.core.global.dto.response.ApiResponse
import kpring.core.server.client.ServerClient
import kpring.core.server.dto.request.GetServerCondition
Expand All @@ -18,8 +19,8 @@ import org.springframework.web.bind.annotation.*
@RequestMapping("/api/v1")
class ChatController(
private val chatService: ChatService,
val authClient: AuthClient,
val serverClient: ServerClient,
private val authClient: AuthClient,
private val serverClient: ServerClient,
) {
@PostMapping("/chat")
fun createChat(
Expand All @@ -39,24 +40,52 @@ class ChatController(

@GetMapping("/chat")
fun getChats(
@RequestParam("type") type: String,
@RequestParam("type") type: ChatType,
@RequestParam("id") id: String,
@RequestParam("page") page: Int,
@RequestHeader("Authorization") token: String,
): ResponseEntity<*> {
val userId = authClient.getTokenInfo(token).data!!.userId
val result =
when (type) {
ChatType.Room.toString() -> chatService.getRoomChats(id, userId, page)
ChatType.Server.toString() ->
ChatType.Room -> chatService.getRoomChats(id, userId, page)
ChatType.Server ->
chatService.getServerChats(
id,
userId,
page,
serverClient.getServerList(token, GetServerCondition()).body!!.data!!,
)
else -> throw GlobalException(ErrorCode.INVALID_CHAT_TYPE)
}
return ResponseEntity.ok().body(ApiResponse(data = result, status = 200))
}

@PatchMapping("/chat")
fun updateChat(
@Validated @RequestBody request: UpdateChatRequest,
@RequestHeader("Authorization") token: String,
): ResponseEntity<*> {
val userId = authClient.getTokenInfo(token).data!!.userId
val result =
when (request.type) {
ChatType.Room -> chatService.updateRoomChat(request, userId)
ChatType.Server -> chatService.updateServerChat(request, userId)
}
return ResponseEntity.ok().body(ApiResponse<Nothing>(status = 200))
}

@DeleteMapping("/chat/{chatId}")
fun deleteChat(
@RequestParam("type") type: ChatType,
@PathVariable("chatId") chatId: String,
@RequestHeader("Authorization") token: String,
): ResponseEntity<*> {
val userId = authClient.getTokenInfo(token).data!!.userId
val result =
when (type) {
ChatType.Room -> chatService.deleteRoomChat(chatId, userId)
ChatType.Server -> chatService.deleteServerChat(chatId, userId)
}
return ResponseEntity.ok().body(ApiResponse<Nothing>(status = 200))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@ import org.springframework.data.mongodb.core.mapping.Document

@NoArg
@Document(collection = "chats")
class RoomChat(
class Chat(
@Id
val id: String? = null,
val userId: String,
val roomId: String,
val content: String,
// roomId or serverId
val contextId: String,
var content: String,
) : BaseTime() {
@Id
var id: String? = null

fun isEdited(): Boolean {
return !createdAt.equals(updatedAt)
}

fun updateContent(content: String) {
this.content = content
}
}
21 changes: 0 additions & 21 deletions chat/src/main/kotlin/kpring/chat/chat/model/ServerChat.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package kpring.chat.chat.repository

import kpring.chat.chat.model.RoomChat
import kpring.chat.chat.model.Chat
import org.springframework.data.domain.Pageable
import org.springframework.data.mongodb.repository.MongoRepository
import org.springframework.data.querydsl.QuerydslPredicateExecutor
import org.springframework.stereotype.Repository

@Repository
interface RoomChatRepository : MongoRepository<RoomChat, String>, QuerydslPredicateExecutor<RoomChat> {
fun findAllByRoomId(
roomId: String,
interface RoomChatRepository : MongoRepository<Chat, String>, QuerydslPredicateExecutor<Chat> {
fun findAllByContextId(
contextId: String,
pageable: Pageable,
): List<RoomChat>
): List<Chat>
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package kpring.chat.chat.repository

import kpring.chat.chat.model.ServerChat
import kpring.chat.chat.model.Chat
import org.springframework.data.domain.Pageable
import org.springframework.data.mongodb.repository.MongoRepository
import org.springframework.data.querydsl.QuerydslPredicateExecutor
import org.springframework.stereotype.Repository

@Repository
interface ServerChatRepository : MongoRepository<ServerChat, String>, QuerydslPredicateExecutor<ServerChat> {
fun findAllByServerId(
interface ServerChatRepository : MongoRepository<Chat, String>, QuerydslPredicateExecutor<Chat> {
fun findAllByContextId(
serverId: String,
pageable: Pageable,
): List<ServerChat>
): List<Chat>
}
Loading

0 comments on commit 9beabb0

Please sign in to comment.