Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/main/kotlin/com/depromeet/makers/config/MongoConfig.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.depromeet.makers.config

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.data.mongodb.MongoDatabaseFactory
import org.springframework.data.mongodb.config.EnableMongoAuditing
import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver
import org.springframework.data.mongodb.core.convert.DefaultMongoTypeMapper
import org.springframework.data.mongodb.core.convert.MappingMongoConverter
import org.springframework.data.mongodb.core.mapping.MongoMappingContext

@Configuration
class MongoConfig {
@Bean
fun mappingMongoConverter(
factory: MongoDatabaseFactory,
context: MongoMappingContext,
) = MappingMongoConverter(DefaultDbRefResolver(factory), context).apply {
setTypeMapper(DefaultMongoTypeMapper(null))
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기본 옵션은 직/역직렬화 할 class 정보를 DB에 저장하는데요, 패키지 정보를 굳이 저장하지 않아도 매핑이 가능해서 제거해주었습니다

}
}
5 changes: 5 additions & 0 deletions src/main/kotlin/com/depromeet/makers/service/TestService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.depromeet.makers.service
import com.depromeet.makers.domain.Test
import com.depromeet.makers.domain.exception.DomainException
import com.depromeet.makers.domain.exception.ErrorCode
import com.depromeet.makers.domain.vo.Age
import com.depromeet.makers.repository.TestRepository
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
Expand All @@ -11,6 +12,10 @@ import org.springframework.stereotype.Service
class TestService(
private val testRepository: TestRepository,
) {
fun create(name: String, age: Age): Test {
return testRepository.save(Test(name = name, age = age))
}

fun getById(id: String): Test {
return testRepository.findByIdOrNull(id) ?: throw DomainException(ErrorCode.TEST_NOT_FOUND)
}
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/application.properties

This file was deleted.

21 changes: 21 additions & 0 deletions src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
spring:
application:
name: depromeet-makers-be
app:
token:
secretKey: ${TOKEN_SECRET_KEY}
expiration:
access: 86400
refresh: 2592000

---
# MongoDB
spring:
data:
mongodb:
host: ${MONGO_HOST}
port: ${MONGO_PORT}
username: ${MONGO_USER}
password: ${MONGO_PASSWORD}
database: ${MONGO_DB}
field-naming-strategy: org.springframework.data.mapping.model.SnakeCaseFieldNamingStrategy
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

몽고디비는 snake_case를 사용해서 데이터 베이스에 스네이크 케이스로 역/직렬화 해주도록 하는 옵션입니다!