Skip to content
This repository has been archived by the owner on May 19, 2024. It is now read-only.

Commit

Permalink
[WEAV-124] 유저 JPA 어댑터 getById 구현 (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
waterfogSW authored Jan 30, 2024
1 parent 8b81372 commit 85da70e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,34 @@ 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.common.exception.PersistenceExceptionType
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 com.studentcenter.weave.support.common.exception.CustomException
import org.springframework.stereotype.Component
import java.util.*

@Component
class UserJpaAdapter (
class UserJpaAdapter(
private val userJpaRepository: UserJpaRepository
): UserRepository {
) : UserRepository {

override fun save(user: User) {
val userJpaEntity: UserJpaEntity = user.toJpaEntity()
userJpaRepository.save(userJpaEntity)
}

override fun getById(id: UUID): User {
TODO("Not yet implemented")
return userJpaRepository
.findById(id)
.orElseThrow {
throw CustomException(
type = PersistenceExceptionType.RESOURCE_NOT_FOUND,
message = "유저(id: $id)를 찾을 수 없습니다."
)
}
.toDomain()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.studentcenter.weave.infrastructure.persistence.common.exception

import com.studentcenter.weave.support.common.exception.CustomExceptionType

enum class PersistenceExceptionType(override val code: String): CustomExceptionType {
RESOURCE_NOT_FOUND("PERSISTENCE-001"),
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class UserJpaEntity(
private set

companion object {

fun User.toJpaEntity(): UserJpaEntity {
return UserJpaEntity(
id = id,
Expand All @@ -97,4 +98,20 @@ class UserJpaEntity(
}
}

fun toDomain(): User {
return User(
id = id,
nickname = nickname,
email = email,
gender = gender,
mbti = mbti,
birthYear = birthYear,
universityId = universityId,
majorId = majorId,
avatar = avatar,
registeredAt = registeredAt,
updatedAt = updatedAt,
)
}

}

0 comments on commit 85da70e

Please sign in to comment.