This repository has been archived by the owner on May 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7895807
commit bbed23e
Showing
13 changed files
with
193 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...ation/src/main/kotlin/com/studentcenter/weave/application/port/outbound/UserRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.studentcenter.weave.application.port.outbound | ||
|
||
import com.studentcenter.weave.domain.entity.User | ||
|
||
interface UserRepository { | ||
|
||
fun save(user: User) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,8 @@ package com.studentcenter.weave.domain.entity | |
import com.studentcenter.weave.domain.enum.Gender | ||
import com.studentcenter.weave.domain.enum.Mbti | ||
import com.studentcenter.weave.domain.vo.BirthYear | ||
import com.studentcenter.weave.domain.vo.MajorName | ||
import com.studentcenter.weave.domain.vo.Nickname | ||
import com.studentcenter.weave.domain.vo.UniversityName | ||
import com.studentcenter.weave.support.common.uuid.UuidCreator | ||
import com.studentcenter.weave.support.common.vo.Email | ||
import io.kotest.core.spec.style.FunSpec | ||
import io.kotest.matchers.shouldBe | ||
|
@@ -18,8 +17,8 @@ class UserTest : FunSpec({ | |
val email = Email("[email protected]") | ||
val gender = Gender.MAN | ||
val birthYear = BirthYear(1999) | ||
val university = UniversityName("서울대학교") | ||
val major = MajorName("컴퓨터 공학과") | ||
val universityId = UuidCreator.create() | ||
val majorId = UuidCreator.create() | ||
val mbti = Mbti.ENFJ | ||
|
||
// act | ||
|
@@ -29,8 +28,8 @@ class UserTest : FunSpec({ | |
gender = gender, | ||
mbti = mbti, | ||
birthYear = birthYear, | ||
university = university, | ||
major = major, | ||
universityId = universityId, | ||
majorId = majorId, | ||
) | ||
|
||
// assert | ||
|
@@ -39,7 +38,8 @@ class UserTest : FunSpec({ | |
user.gender shouldBe gender | ||
user.mbti shouldBe mbti | ||
user.birthYear shouldBe birthYear | ||
user.major shouldBe major | ||
user.universityId shouldBe universityId | ||
user.majorId shouldBe majorId | ||
} | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
.../main/kotlin/com/studentcenter/weave/infrastructure/persistence/adapter/UserJpaAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.studentcenter.weave.infrastructure.persistence.adapter | ||
|
||
import com.studentcenter.weave.application.port.outbound.UserRepository | ||
import com.studentcenter.weave.domain.entity.User | ||
import com.studentcenter.weave.infrastructure.persistence.entity.UserJpaEntity | ||
import com.studentcenter.weave.infrastructure.persistence.entity.UserJpaEntity.Companion.toJpaEntity | ||
import com.studentcenter.weave.infrastructure.persistence.repository.UserJpaRepository | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class UserJpaAdapter ( | ||
private val userJpaRepository: UserJpaRepository | ||
): UserRepository { | ||
|
||
override fun save(user: User) { | ||
val userJpaEntity: UserJpaEntity = user.toJpaEntity() | ||
userJpaRepository.save(userJpaEntity) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...rc/main/kotlin/com/studentcenter/weave/infrastructure/persistence/entity/UserJpaEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package com.studentcenter.weave.infrastructure.persistence.entity | ||
|
||
import com.studentcenter.weave.domain.entity.User | ||
import com.studentcenter.weave.domain.enum.Gender | ||
import com.studentcenter.weave.domain.enum.Mbti | ||
import com.studentcenter.weave.domain.vo.BirthYear | ||
import com.studentcenter.weave.domain.vo.Nickname | ||
import com.studentcenter.weave.support.common.vo.Email | ||
import com.studentcenter.weave.support.common.vo.Url | ||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.EnumType | ||
import jakarta.persistence.Enumerated | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.Table | ||
import java.time.LocalDateTime | ||
import java.util.* | ||
|
||
@Entity | ||
@Table(name = "`user`") | ||
class UserJpaEntity( | ||
id: UUID, | ||
nickname: Nickname, | ||
email: Email, | ||
gender: Gender, | ||
mbti: Mbti, | ||
birthYear: BirthYear, | ||
universityId: UUID, | ||
majorId: UUID, | ||
avatar: Url? = null, | ||
registeredAt: LocalDateTime, | ||
updatedAt: LocalDateTime, | ||
) { | ||
|
||
@Id | ||
@Column(nullable = false, updatable = false) | ||
var id: UUID = id | ||
private set | ||
|
||
@Column(nullable = false, updatable = false) | ||
var nickname: Nickname = nickname | ||
private set | ||
|
||
@Column(nullable = false, updatable = false) | ||
var email: Email = email | ||
private set | ||
|
||
@Column(nullable = false, updatable = false, columnDefinition = "varchar(255)") | ||
@Enumerated(value = EnumType.STRING) | ||
var gender: Gender = gender | ||
private set | ||
|
||
@Column(nullable = false, columnDefinition = "varchar(255)") | ||
@Enumerated(value = EnumType.STRING) | ||
var mbti: Mbti = mbti | ||
private set | ||
|
||
@Column(nullable = false) | ||
var birthYear: BirthYear = birthYear | ||
private set | ||
|
||
@Column(nullable = false, updatable = false) | ||
var universityId: UUID = universityId | ||
private set | ||
|
||
@Column(nullable = false, updatable = false) | ||
var majorId: UUID = majorId | ||
private set | ||
|
||
@Column() | ||
var avatar: Url? = avatar | ||
private set | ||
|
||
@Column(nullable = false, updatable = false) | ||
var registeredAt: LocalDateTime = registeredAt | ||
private set | ||
|
||
@Column(nullable = false) | ||
var updatedAt: LocalDateTime = updatedAt | ||
private set | ||
|
||
companion object { | ||
fun User.toJpaEntity(): UserJpaEntity { | ||
return UserJpaEntity( | ||
id = id, | ||
nickname = nickname, | ||
email = email, | ||
gender = gender, | ||
mbti = mbti, | ||
birthYear = birthYear, | ||
universityId = universityId, | ||
majorId = majorId, | ||
avatar = avatar, | ||
registeredAt = registeredAt, | ||
updatedAt = updatedAt, | ||
) | ||
} | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...kotlin/com/studentcenter/weave/infrastructure/persistence/repository/UserJpaRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.studentcenter.weave.infrastructure.persistence.repository | ||
|
||
import com.studentcenter.weave.infrastructure.persistence.entity.UserJpaEntity | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.stereotype.Repository | ||
import java.util.UUID | ||
|
||
@Repository | ||
interface UserJpaRepository : JpaRepository<UserJpaEntity, UUID> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
infrastructure/persistence/src/main/resources/db/migration/V3__create_user.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
-- 유저 -- | ||
create table `user` | ||
( | ||
id binary(16) not null, | ||
nickname varchar(255) not null, | ||
email varchar(255) not null, | ||
gender varchar(255) not null, | ||
mbti varchar(255) not null, | ||
birth_year integer not null, | ||
university_id binary(16) not null, | ||
major_id binary(16) not null, | ||
avatar varchar(255), | ||
registered_at datetime(6) not null, | ||
updated_at datetime(6) not null, | ||
primary key (id), | ||
index idx_university_id (university_id), | ||
index idx_major_id (major_id) | ||
) engine = InnoDB | ||
default charset = utf8mb4; |