-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/create user #38
Changes from all commits
d607c48
faecbe0
ade090e
c0aed98
bb16061
79ca470
1405032
587362b
96d321d
28599f2
e3d84d6
333b360
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.hanghae.commerce.user.application | ||
|
||
import com.hanghae.commerce.user.domain.User | ||
import com.hanghae.commerce.user.domain.UserType | ||
import com.hanghae.commerce.user.domain.UserWriter | ||
import com.hanghae.commerce.user.presentation.dto.* | ||
Check failure on line 6 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/application/CustomerWriterService.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/application/CustomerWriterService.kt#L6 <standard:no-wildcard-imports>
Raw output
|
||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class CustomerWriterService( | ||
private val userWriter: UserWriter, | ||
) { | ||
|
||
Check failure on line 13 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/application/CustomerWriterService.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/application/CustomerWriterService.kt#L13 <standard:no-empty-first-line-in-class-body>
Raw output
|
||
fun createCustomer(request: CreateCustomerRequest): CreateCustomerResponse { | ||
val savedUserId = userWriter.save( | ||
Check failure on line 15 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/application/CustomerWriterService.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/application/CustomerWriterService.kt#L15 <standard:multiline-expression-wrapping>
Raw output
|
||
User.of( | ||
name = request.name, | ||
age = request.age, | ||
email = request.email, | ||
address = request.address, | ||
userType = UserType.CUSTOMER, | ||
), | ||
) | ||
|
||
return CreateCustomerResponse(id = savedUserId) | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.hanghae.commerce.user.application | ||
|
||
import com.hanghae.commerce.user.domain.User | ||
import com.hanghae.commerce.user.domain.UserType | ||
import com.hanghae.commerce.user.domain.UserWriter | ||
import com.hanghae.commerce.user.presentation.dto.* | ||
Check failure on line 6 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/application/SellerWriterService.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/application/SellerWriterService.kt#L6 <standard:no-wildcard-imports>
Raw output
|
||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class SellerWriterService( | ||
private val userWriter: UserWriter, | ||
) { | ||
|
||
Check failure on line 13 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/application/SellerWriterService.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/application/SellerWriterService.kt#L13 <standard:no-empty-first-line-in-class-body>
Raw output
|
||
fun createSeller(request: CreateSellerRequest): CreateSellerResponse { | ||
val savedUserId = userWriter.save( | ||
Check failure on line 15 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/application/SellerWriterService.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/application/SellerWriterService.kt#L15 <standard:multiline-expression-wrapping>
Raw output
|
||
User.of( | ||
name = request.name, | ||
age = request.age, | ||
email = request.email, | ||
address = request.address, | ||
userType = UserType.SELLER, | ||
), | ||
) | ||
|
||
return CreateSellerResponse(id = savedUserId) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.hanghae.commerce.user.application | ||
|
||
import com.hanghae.commerce.user.domain.UserReader | ||
import com.hanghae.commerce.user.presentation.dto.GetUserResponse | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class UserReaderService( | ||
private val userReader: UserReader, | ||
) { | ||
|
||
Check failure on line 11 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/application/UserReaderService.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/application/UserReaderService.kt#L11 <standard:no-empty-first-line-in-class-body>
Raw output
|
||
fun getUserById(userId: Long): GetUserResponse { | ||
val user = userReader.read(userId) ?: throw IllegalArgumentException() | ||
return GetUserResponse.of(user) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,28 @@ | ||
package com.hanghae.commerce.user.domain | ||
|
||
class User( | ||
var id: Long? = null, | ||
val name: String, | ||
) | ||
val age: Int, | ||
val email: String, | ||
val address: String, | ||
val userType: UserType, | ||
var id: Long? = null, | ||
) { | ||
init { | ||
if (name.isBlank()) { | ||
throw IllegalArgumentException("이름은 비어 있을 수 없습니다") | ||
} | ||
if (email.isBlank()) { | ||
throw IllegalArgumentException("이메일은 비어 있을 수 없습니다") | ||
} | ||
if (address.isBlank()) { | ||
throw IllegalArgumentException("주소는 비어 있을 수 없습니다") | ||
} | ||
} | ||
Comment on lines
+11
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 프로퍼티들에 대한 유효성 검사 로직을 User 도메인 모델 안에 정의함으로써 응집도를 높일 수 있는 것 같아 좋은 것 같습니다. |
||
|
||
companion object { | ||
fun of(name: String, age: Int, email: String, address: String, userType: UserType): User { | ||
Check failure on line 24 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/domain/User.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/domain/User.kt#L24 <standard:function-signature>
Raw output
Check failure on line 24 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/domain/User.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/domain/User.kt#L24 <standard:function-signature>
Raw output
Check failure on line 24 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/domain/User.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/domain/User.kt#L24 <standard:function-signature>
Raw output
Check failure on line 24 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/domain/User.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/domain/User.kt#L24 <standard:function-signature>
Raw output
Check failure on line 24 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/domain/User.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/domain/User.kt#L24 <standard:function-signature>
Raw output
Check failure on line 24 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/domain/User.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/domain/User.kt#L24 <standard:function-signature>
Raw output
|
||
return User(name, age, email, address, userType) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
package com.hanghae.commerce.user.domain | ||
|
||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
interface UserRepository { | ||
fun save(user: User) | ||
fun save(user: User): Long | ||
fun read(id: Long): User? | ||
fun allDelete() | ||
Check failure on line 9 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/domain/UserRepository.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/domain/UserRepository.kt#L9 <standard:blank-line-before-declaration>
Raw output
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.hanghae.commerce.user.domain | ||
|
||
enum class UserType { | ||
CUSTOMER, | ||
SELLER, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.hanghae.commerce.user.domain | ||
|
||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class UserWriter( | ||
private val userRepository: UserRepository, | ||
) { | ||
fun save(user: User): Long { | ||
return userRepository.save(user) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.hanghae.commerce.user.presentation | ||
|
||
import com.hanghae.commerce.user.application.CustomerWriterService | ||
import com.hanghae.commerce.user.presentation.dto.* | ||
Check failure on line 4 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/CustomerController.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/CustomerController.kt#L4 <standard:no-wildcard-imports>
Raw output
|
||
import org.springframework.web.bind.annotation.* | ||
Check failure on line 5 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/CustomerController.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/CustomerController.kt#L5 <standard:no-wildcard-imports>
Raw output
|
||
|
||
@RestController | ||
@RequestMapping("/customer") | ||
class CustomerController( | ||
private val customerWriterService: CustomerWriterService, | ||
) { | ||
|
||
Check failure on line 12 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/CustomerController.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/CustomerController.kt#L12 <standard:no-empty-first-line-in-class-body>
Raw output
|
||
@PostMapping | ||
fun createCustomer(@RequestBody createCustomerRequest: CreateCustomerRequest): CreateCustomerResponse { | ||
Check failure on line 14 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/CustomerController.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/CustomerController.kt#L14 <standard:parameter-list-wrapping>
Raw output
Check failure on line 14 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/CustomerController.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/CustomerController.kt#L14 <standard:function-signature>
Raw output
Check failure on line 14 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/CustomerController.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/CustomerController.kt#L14 <standard:parameter-list-wrapping>
Raw output
Check failure on line 14 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/CustomerController.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/CustomerController.kt#L14 <standard:function-signature>
Raw output
|
||
return customerWriterService.createCustomer(createCustomerRequest) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.hanghae.commerce.user.presentation | ||
|
||
import com.hanghae.commerce.user.application.SellerWriterService | ||
import com.hanghae.commerce.user.presentation.dto.* | ||
Check failure on line 4 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/SellerController.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/SellerController.kt#L4 <standard:no-wildcard-imports>
Raw output
|
||
import org.springframework.web.bind.annotation.* | ||
Check failure on line 5 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/SellerController.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/SellerController.kt#L5 <standard:no-wildcard-imports>
Raw output
|
||
|
||
@RestController | ||
@RequestMapping("/seller") | ||
class SellerController( | ||
private val sellerService: SellerWriterService, | ||
) { | ||
|
||
Check failure on line 12 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/SellerController.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/SellerController.kt#L12 <standard:no-empty-first-line-in-class-body>
Raw output
|
||
@PostMapping | ||
fun createSeller(@RequestBody createSellerRequest: CreateSellerRequest): CreateSellerResponse { | ||
Check failure on line 14 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/SellerController.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/SellerController.kt#L14 <standard:parameter-list-wrapping>
Raw output
Check failure on line 14 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/SellerController.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/SellerController.kt#L14 <standard:function-signature>
Raw output
Check failure on line 14 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/SellerController.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/SellerController.kt#L14 <standard:parameter-list-wrapping>
Raw output
Check failure on line 14 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/SellerController.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/SellerController.kt#L14 <standard:function-signature>
Raw output
|
||
return sellerService.createSeller(createSellerRequest) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,17 @@ | ||
package com.hanghae.commerce.user.presentation | ||
|
||
import org.springframework.web.bind.annotation.RestController | ||
import com.hanghae.commerce.user.application.UserReaderService | ||
import com.hanghae.commerce.user.presentation.dto.GetUserResponse | ||
import org.springframework.web.bind.annotation.* | ||
Check failure on line 5 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/UserController.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/UserController.kt#L5 <standard:no-wildcard-imports>
Raw output
|
||
|
||
@RestController | ||
class UserController | ||
@RequestMapping("/user") | ||
class UserController( | ||
private val userService: UserReaderService, | ||
) { | ||
|
||
Check failure on line 12 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/UserController.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/UserController.kt#L12 <standard:no-empty-first-line-in-class-body>
Raw output
|
||
@GetMapping("/{userId}") | ||
fun getUser(@PathVariable userId: Long): GetUserResponse { | ||
Check failure on line 14 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/UserController.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/UserController.kt#L14 <standard:parameter-list-wrapping>
Raw output
Check failure on line 14 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/UserController.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/UserController.kt#L14 <standard:function-signature>
Raw output
Check failure on line 14 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/UserController.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/UserController.kt#L14 <standard:parameter-list-wrapping>
Raw output
Check failure on line 14 in commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/UserController.kt GitHub Actions / ktlint[ktlint] commerce-api/src/main/kotlin/com/hanghae/commerce/user/presentation/UserController.kt#L14 <standard:function-signature>
Raw output
|
||
return userService.getUserById(userId) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.hanghae.commerce.user.presentation.dto | ||
|
||
import jakarta.validation.constraints.NotBlank | ||
|
||
data class CreateCustomerRequest( | ||
@field:NotBlank(message = "이름을 공백으로 할 수 없습니다.") | ||
val name: String, | ||
val age: Int, | ||
@field:NotBlank(message = "이메일을 공백으로 할 수 없습니다.") | ||
val email: String, | ||
@field:NotBlank(message = "주소를 공백으로 할 수 없습니다.") | ||
val address: String, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.hanghae.commerce.user.presentation.dto | ||
|
||
data class CreateCustomerResponse( | ||
val id: Long, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.hanghae.commerce.user.presentation.dto | ||
|
||
import jakarta.validation.constraints.NotBlank | ||
|
||
data class CreateSellerRequest( | ||
@field:NotBlank(message = "이름을 공백으로 할 수 없습니다.") | ||
val name: String, | ||
val age: Int, | ||
@field:NotBlank(message = "이메일을 공백으로 할 수 없습니다.") | ||
val email: String, | ||
@field:NotBlank(message = "주소를 공백으로 할 수 없습니다.") | ||
val address: String, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.hanghae.commerce.user.presentation.dto | ||
|
||
data class CreateSellerResponse( | ||
val id: Long, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.hanghae.commerce.user.presentation.dto | ||
|
||
import com.hanghae.commerce.user.domain.User | ||
import com.hanghae.commerce.user.domain.UserType | ||
|
||
data class GetUserResponse( | ||
val name: String, | ||
val age: Int, | ||
val email: String, | ||
val address: String, | ||
val id: Long, | ||
val userType: UserType, | ||
) { | ||
companion object { | ||
fun of(user: User): GetUserResponse { | ||
return GetUserResponse( | ||
name = user.name, | ||
age = user.age, | ||
email = user.email, | ||
address = user.address, | ||
userType = user.userType, | ||
id = user.id!!, | ||
) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,5 @@ spring: | |
config: | ||
activate: | ||
on-profile: develop | ||
|
||
|
||
import: | ||
- logging.yml |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ spring: | |
config: | ||
activate: | ||
on-profile: local | ||
import: | ||
- logging.yml |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,5 @@ spring: | |
config: | ||
activate: | ||
on-profile: prod | ||
import: | ||
- logging.yml |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,5 +7,4 @@ spring: | |
|
||
config: | ||
import: | ||
- logging.yml | ||
- db-main.yml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.hanghae.commerce.user.application | ||
|
||
import com.hanghae.commerce.testconfiguration.IntegrationTest | ||
import com.hanghae.commerce.user.domain.UserRepository | ||
import com.hanghae.commerce.user.presentation.dto.CreateCustomerRequest | ||
import org.assertj.core.api.Assertions | ||
import org.junit.jupiter.api.AfterEach | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.beans.factory.annotation.Autowired | ||
|
||
@IntegrationTest | ||
class CustomerWriterServiceTest( | ||
@Autowired | ||
private val customerWriterService: CustomerWriterService, | ||
@Autowired | ||
private val userRepository: UserRepository, | ||
) { | ||
|
||
Check failure on line 18 in commerce-api/src/test/kotlin/com/hanghae/commerce/user/application/CustomerWriterServiceTest.kt GitHub Actions / ktlint[ktlint] commerce-api/src/test/kotlin/com/hanghae/commerce/user/application/CustomerWriterServiceTest.kt#L18 <standard:no-empty-first-line-in-class-body>
Raw output
|
||
@AfterEach | ||
fun tearDown() { | ||
userRepository.allDelete() | ||
} | ||
|
||
@Test | ||
fun createCustomer() { | ||
// given | ||
val request = CreateCustomerRequest( | ||
Check failure on line 27 in commerce-api/src/test/kotlin/com/hanghae/commerce/user/application/CustomerWriterServiceTest.kt GitHub Actions / ktlint[ktlint] commerce-api/src/test/kotlin/com/hanghae/commerce/user/application/CustomerWriterServiceTest.kt#L27 <standard:multiline-expression-wrapping>
Raw output
|
||
name = "sangmin", | ||
age = 20, | ||
email = "hanghae001@gmail.com", | ||
address = "seoul", | ||
) | ||
|
||
// when | ||
val result = customerWriterService.createCustomer(request) | ||
|
||
// then | ||
Assertions.assertThat(result.id).isNotNull | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id 를 var와 Nullable 타입으로 선언하신 이유가 궁금합니다! id는 Null을 허용하지 않고 재할당될 수 없는 프로퍼티라고 생각합니다.
UUID 혹은 ULID를 활용하면 DB의 시퀀스나 auto-increment를 사용하지않고 객체 생성 시점에 ID에 값을 할당할 수 있습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
말씀해주신대로 값 변경이 안되도록 val 타입을 사용하는게 맞는것 같습니다. id값을 UUID로 사용하면 nullable 타입으로 사용안해도 괜찮을 것 같네요