Skip to content
This repository was archived by the owner on Mar 20, 2025. It is now read-only.

feat: user model の追加 #119

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
49 changes: 49 additions & 0 deletions src/main/kotlin/dev/sunabak0/akiyadego/domain/User.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package dev.sunabak0.akiyadego.domain

import dev.sunabak0.akiyadego.openapi.generated.model.Post

/**
* ユーザ
*
* @property id
* @property uuid
* @property name
* @property email
* @property password
* @property createdAt
* @property posts
* @constructor Create empty User
*/
data class User(
val id: Int,
val uuid: String,
val name: String,
val email: String,
val password: String,
val createdAt: String,
val posts: List<Post>,
) {
/**
* Factoryメソッド
*/
companion object {
/**
* Validation 有り
*
*/
fun new(
id: Int,
uuid: String,
name: String,
email: String,
password: String,
createdAt: String,
posts: List<Post>,
): Any {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[memo]
User にすると怒られた。Post だと怒られなかったのに、、

if (name.isEmpty()) {
return IllegalArgumentException("名前が1文字未満です")
}
return User(id, uuid, name, email, password, createdAt, posts)
}
}
}
27 changes: 27 additions & 0 deletions src/test/kotlin/dev/sunabak0/akiyadego/domain/UserTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package dev.sunabak0.akiyadego.domain

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows

class UserTest {
@Test
fun `ユーザの名前の文字数が違反していたユーザの生成に失敗する`() {
/**
* given:
*/

/**
* when:
*/

/**
* then:
* - 名前を検査
*/
val user = assertThrows<IllegalArgumentException> {
User.new(1, "uuid", "", "sample@com", "password", "20230123-12:00:00", listOf())
}
assertEquals(user.message, "名前が入力されていません")
}
}