From 32ff728efe1d02b2be9e5c74f440ee8791fa4d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EC=9D=B8=EC=A4=80?= Date: Thu, 28 Nov 2024 14:40:31 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20Interest=20=EB=8F=84=EB=A9=94?= =?UTF-8?q?=EC=9D=B8=20=EB=B0=8F=20=EC=97=94=ED=8B=B0=ED=8B=B0=20=EC=9E=91?= =?UTF-8?q?=EC=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../persistence/user/impl/InterestAdapter.kt | 27 +++++++++++++++ .../user/persist/InterestEntity.kt | 34 +++++++++++++++++++ .../user/persist/InterestRepository.kt | 7 ++++ .../com/pokit/user/port/out/InterestPort.kt | 11 ++++++ .../kotlin/com/pokit/user/model/Interest.kt | 7 ++++ 5 files changed, 86 insertions(+) create mode 100644 adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/user/impl/InterestAdapter.kt create mode 100644 adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/user/persist/InterestEntity.kt create mode 100644 adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/user/persist/InterestRepository.kt create mode 100644 application/src/main/kotlin/com/pokit/user/port/out/InterestPort.kt create mode 100644 domain/src/main/kotlin/com/pokit/user/model/Interest.kt diff --git a/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/user/impl/InterestAdapter.kt b/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/user/impl/InterestAdapter.kt new file mode 100644 index 00000000..6b543941 --- /dev/null +++ b/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/user/impl/InterestAdapter.kt @@ -0,0 +1,27 @@ +package com.pokit.out.persistence.user.impl + +import com.pokit.out.persistence.user.persist.InterestEntity +import com.pokit.out.persistence.user.persist.InterestRepository +import com.pokit.out.persistence.user.persist.toDomain +import com.pokit.user.model.Interest +import com.pokit.user.port.out.InterestPort +import org.springframework.stereotype.Repository + +@Repository +class InterestAdapter ( + private val interestRepository: InterestRepository +) : InterestPort { + override fun persist(interest: Interest): Interest { + return interestRepository.save(InterestEntity.of(interest)) + .toDomain() + } + + override fun delete(interest: Interest) { + interestRepository.deleteById(interest.id) + } + + override fun loadByUserId(userId: Long): List { + return interestRepository.findAllByUserId(userId) + .map { it.toDomain() } + } +} diff --git a/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/user/persist/InterestEntity.kt b/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/user/persist/InterestEntity.kt new file mode 100644 index 00000000..232ef7fc --- /dev/null +++ b/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/user/persist/InterestEntity.kt @@ -0,0 +1,34 @@ +package com.pokit.out.persistence.user.persist + +import com.pokit.user.model.Interest +import com.pokit.user.model.InterestType +import jakarta.persistence.* + +@Table(name = "INTEREST") +@Entity +class InterestEntity ( + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long = 0L, + + @Column(name = "user_id") + val userId: Long, + + @Column(name = "interest_type") + @Enumerated(EnumType.STRING) + var interestType: InterestType +) { + companion object { + fun of(interest: Interest) = InterestEntity( + id = interest.id, + userId = interest.userId, + interestType = interest.interestType + ) + } +} + +internal fun InterestEntity.toDomain() = Interest( + id = this.id, + userId = this.userId, + interestType = this.interestType +) diff --git a/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/user/persist/InterestRepository.kt b/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/user/persist/InterestRepository.kt new file mode 100644 index 00000000..2216c297 --- /dev/null +++ b/adapters/out-persistence/src/main/kotlin/com/pokit/out/persistence/user/persist/InterestRepository.kt @@ -0,0 +1,7 @@ +package com.pokit.out.persistence.user.persist + +import org.springframework.data.jpa.repository.JpaRepository + +interface InterestRepository : JpaRepository { + fun findAllByUserId(userId: Long): List +} diff --git a/application/src/main/kotlin/com/pokit/user/port/out/InterestPort.kt b/application/src/main/kotlin/com/pokit/user/port/out/InterestPort.kt new file mode 100644 index 00000000..4c4cd9c3 --- /dev/null +++ b/application/src/main/kotlin/com/pokit/user/port/out/InterestPort.kt @@ -0,0 +1,11 @@ +package com.pokit.user.port.out + +import com.pokit.user.model.Interest + +interface InterestPort { + fun persist(interest: Interest): Interest + + fun delete(interest: Interest) + + fun loadByUserId(userId: Long): List +} diff --git a/domain/src/main/kotlin/com/pokit/user/model/Interest.kt b/domain/src/main/kotlin/com/pokit/user/model/Interest.kt new file mode 100644 index 00000000..c65575ea --- /dev/null +++ b/domain/src/main/kotlin/com/pokit/user/model/Interest.kt @@ -0,0 +1,7 @@ +package com.pokit.user.model + +data class Interest( + val id: Long = 0L, + val userId: Long, + var interestType: InterestType +)