Skip to content

Commit

Permalink
Merge pull request #129 from grida-diary/main
Browse files Browse the repository at this point in the history
prod
  • Loading branch information
wwan13 authored Aug 26, 2024
2 parents a734dc6 + 5bf428a commit 6cafd37
Show file tree
Hide file tree
Showing 57 changed files with 252 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ import org.springframework.boot.context.properties.ConstructorBinding
@ConfigurationProperties("kakao")
data class KakaoProperties(
val appKey: String,
val redirectUri: String
)
val baseUri: String,
val apiPath: String
) {
val redirectUri: String = baseUri + apiPath
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
spring:
config:
activate:
on-profile: dev
kakao:
appKey: ${KAKAO_APP_KEY}
base-uri: http://localhost:8080
api-path: ${KAKAO_REDIRECT_URL}

---
spring:
config:
activate:
on-profile: prod
kakao:
appKey: ${KAKAO_APP_KEY}
base-uri: https://grida.today
api-path: ${KAKAO_REDIRECT_URL}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
openai:
secret-key: ${OPEN_AI_SECRET_KEY}

---
spring:
config:
activate:
on-profile: dev

---
spring:
config:
activate:
on-profile: prod

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package org.grida

import com.amazonaws.AmazonClientException
import com.amazonaws.services.s3.AmazonS3
import org.grida.config.StorageClientProperties
import org.grida.config.S3ClientProperties
import org.grida.error.FileUploadFail
import org.grida.error.GridaException
import org.springframework.stereotype.Component
import java.io.File

@Component
class StorageClient(
private val properties: StorageClientProperties,
class S3Client(
private val properties: S3ClientProperties,
private val amazonS3: AmazonS3,
) {
fun uploadFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import org.springframework.context.annotation.Configuration

@Configuration
@ConfigurationPropertiesScan
class StorageClientConfig(
private val properties: StorageClientProperties,
class S3ClientConfig(
private val properties: S3ClientProperties,
) {
@Bean
fun amazonS3Client(properties: StorageClientProperties): AmazonS3 {
fun amazonS3Client(properties: S3ClientProperties): AmazonS3 {
val credential = BasicAWSCredentials(properties.accessKey, properties.secretKey)

return AmazonS3ClientBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.springframework.boot.context.properties.ConstructorBinding

@ConstructorBinding
@ConfigurationProperties("storage.aws")
data class StorageClientProperties(
data class S3ClientProperties(
val accessKey: String,
val secretKey: String,
val region: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
storage:
aws:
access-key: ${S3_ACCESS_KEY}
secret-key: ${S3_SECRET_KEY}
region: ${S3_REGION}
bucket: ${S3_BUCKET}
host: ${CDN_HOST}
---
spring:
config:
activate:
on-profile: dev

---
spring:
config:
activate:
on-profile: prod

This file was deleted.

19 changes: 19 additions & 0 deletions grida-common/src/main/kotlin/org/grida/api/dto/ListResponse.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.grida.api.dto

data class ListResponse<T>(
val count: Int,
val list: List<T>
) {

companion object {
fun <T> from(
list: List<T>,
mapAction: () -> T
): ListResponse<T> {
return ListResponse(
list.size,
list.map { mapAction.invoke() }
)
}
}
}
Empty file.
10 changes: 4 additions & 6 deletions grida-core/core-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ plugins {
dependencies {
// module dependencies
implementation(project(":grida-core:core-domain"))
implementation(project(":grida-database:database-rds"))
implementation(project(":grida-storage:rds-storage"))
implementation(project(":grida-clients:kakao-client"))
implementation(project(":grida-support:logging"))
implementation(project(":grida-support:monitoring"))

// web
implementation("org.springframework.boot:spring-boot-starter-web")
Expand All @@ -18,15 +20,11 @@ dependencies {
implementation("com.github.wwan13:winter-security:0.0.10")

// logging-request
implementation("com.github.wwan13:spring-request-logger:0.0.3")
implementation("com.github.wwan13:spring-request-logger:0.0.7")

// api docs
testImplementation("org.springframework.restdocs:spring-restdocs-mockmvc")
testImplementation("com.github.wwan13.kotlin-dsl-rest-docs:impl-mockmvc:1.2.9")

// monitoring
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("io.micrometer:micrometer-registry-prometheus")
}

tasks {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,8 @@
package org.grida.config

import io.wwan13.springrequestlogger.configure.EnableLoggingRequest
import io.wwan13.springrequestlogger.configure.LogMessageConfigurer
import io.wwan13.springrequestlogger.context.RequestContext
import org.springframework.boot.context.properties.ConfigurationPropertiesScan
import org.springframework.context.annotation.Configuration
import java.util.function.Function

@Configuration
@ConfigurationPropertiesScan
@EnableLoggingRequest
class CoreApiConfig : LogMessageConfigurer {

override fun format(): Function<RequestContext, String> {
return Function { context ->
"""
|
| ${context.method} '${context.uri}' - ${context.status} (${context.elapsed} s)
| >> Request Headers : ${context.requestHeaders}
| >> Request Params : ${context.requestParams}
| >> Request Body : ${context.requestBody}
| >> Response Body : ${context.responseBody}
""".trimMargin()
}
}
}
class CoreApiConfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.grida.config

import io.wwan13.springrequestlogger.configure.EnableLoggingRequest
import io.wwan13.springrequestlogger.configure.LogMessageConfigurer
import org.springframework.context.annotation.Configuration

@Configuration
@EnableLoggingRequest
class RequestLoggingConfig : LogMessageConfigurer {

override fun excludePathPatterns(): List<String> {
return listOf("/api/actuator/**")
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.http.converter.HttpMessageNotReadableException
import org.springframework.web.HttpRequestMethodNotSupportedException
import org.springframework.web.bind.MissingServletRequestParameterException
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.RestControllerAdvice
import org.springframework.web.servlet.NoHandlerFoundException
Expand Down Expand Up @@ -98,6 +99,15 @@ class ApiControllerAdvice {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response)
}

@ExceptionHandler(MissingServletRequestParameterException::class)
fun handleMissingServletRequestParameterException(
e: MissingServletRequestParameterException
): ResponseEntity<ApiResponse<ErrorResponse>> {
log.info(e.message)
val response = ApiResponse.error("HTTP_400", "요청에 필요한 쿼리 파라미터 ${e.parameterName}가 없습니다.")
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(response)
}

@ExceptionHandler(HttpMessageNotReadableException::class)
fun handleHttpMessageNotReadableException(
e: HttpMessageNotReadableException
Expand Down
64 changes: 14 additions & 50 deletions grida-core/core-api/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,24 @@
spring:
profiles:
active: dev
include:
- rds-storage
- kakao-client
- openai-client
- s3-client
- logging
- monitoring
mvc:
throw-exception-if-no-handler-found: true
web:
resources:
add-mappings: false
datasource:
url: ${DATASOURCE_URL}
username: ${DATABASE_USERNAME}
password: ${DATABASE_PASSWORD}
driver-class-name: com.mysql.cj.jdbc.Driver
jpa:
hibernate:
ddl-auto: update
properties:
hibernate:
format_sql: false
show_sql: false
default_batch_fetch_size: 1000
open-in-view: false
servlet:
multipart:
max-file-size: 100MB
max-request-size: 100MB
servlet:
multipart:
max-file-size: 100MB
max-request-size: 100MB

jwt:
secret-key: ${JWT_SECRET_KEY}
access-token-expired: ${ACCESS_TOKEN_EXPIRED}
refresh-token-expired: ${REFRESH_TOKEN_EXPIRED}

openai:
secret-key: ${OPEN_AI_SECRET_KEY}

storage:
aws:
access-key: ${S3_ACCESS_KEY}
secret-key: ${S3_SECRET_KEY}
region: ${S3_REGION}
bucket: ${S3_BUCKET}
host: ${CDN_HOST}

kakao:
appKey: ${KAKAO_APP_KEY}
redirectUri: ${KAKAO_REDIRECT_URL}

management:
endpoints:
web:
base-path: /api/actuator
exposure:
include: "prometheus"

server:
tomcat:
mbeanregistry:
enabled: true

logging:
level:
root: INFO
refresh-token-expired: ${REFRESH_TOKEN_EXPIRED}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class AuthApiDocsTest(
** live : https://kauth.kakao.com/oauth/authorize?client_id=e32f0cc35368a69966b54698b193a794&
redirect_uri=https://grida.today/api/v1/auth/login/kakao&response_type=code<br/>
""".trimIndent()
.lineSequence()
.map { it.trimEnd() }
.joinToString("")
)
queryParameters("code" whichMeans "카카오 인증 토큰")
responseFields(
Expand Down
2 changes: 1 addition & 1 deletion grida-core/core-domain/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ dependencies {
implementation("org.springframework:spring-tx:6.1.0")

implementation(project(":grida-clients:openai-client"))
implementation(project(":grida-clients:storage-client"))
implementation(project(":grida-clients:s3-client"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package org.grida.domain.base
import org.grida.error.GridaException
import org.grida.error.InvalidEnumValue

interface BaseEnum<T : Enum<T>> {
interface ValueEnum<T : Enum<T>> {
val value: String

companion object {
inline fun <reified T : Enum<T>> resolve(value: String): T {
val entries = enumValues<T>()
return entries
.firstOrNull { (it as BaseEnum<*>).value == value }
?: throw GridaException(InvalidEnumValue(enumValues<T>()))
return enumValues<T>()
.singleOrNull { (it as ValueEnum<*>).value == value }
?: throw GridaException(InvalidEnumValue(entries.map { (it as ValueEnum<*>).value }))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package org.grida.domain.diary

enum class DiaryScope {
PUBLIC, FRIENDS_ONLY, PRIVATE
import org.grida.domain.base.ValueEnum

enum class DiaryScope(
override val value: String
) : ValueEnum<DiaryScope> {
PUBLIC("공개"),
FRIENDS_ONLY("친구 공개"),
PRIVATE("비공개");
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package org.grida.domain.image

enum class ImageStatus {
ACTIVATE, DEACTIVATE
import org.grida.domain.base.ValueEnum

enum class ImageStatus(
override val value: String
) : ValueEnum<ImageStatus> {
ACTIVATE("활성화"),
DEACTIVATE("비활성화");
}
Loading

0 comments on commit 6cafd37

Please sign in to comment.