Skip to content

Commit

Permalink
feat : Interest 도메인 및 엔티티 작업
Browse files Browse the repository at this point in the history
  • Loading branch information
dlswns2480 committed Nov 28, 2024
1 parent 40f748c commit 32ff728
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<Interest> {
return interestRepository.findAllByUserId(userId)
.map { it.toDomain() }
}
}
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pokit.out.persistence.user.persist

import org.springframework.data.jpa.repository.JpaRepository

interface InterestRepository : JpaRepository<InterestEntity, Long> {
fun findAllByUserId(userId: Long): List<InterestEntity>
}
Original file line number Diff line number Diff line change
@@ -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<Interest>
}
7 changes: 7 additions & 0 deletions domain/src/main/kotlin/com/pokit/user/model/Interest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.pokit.user.model

data class Interest(
val id: Long = 0L,
val userId: Long,
var interestType: InterestType
)

0 comments on commit 32ff728

Please sign in to comment.