-
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
40f748c
commit 32ff728
Showing
5 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...rs/out-persistence/src/main/kotlin/com/pokit/out/persistence/user/impl/InterestAdapter.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,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() } | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
.../out-persistence/src/main/kotlin/com/pokit/out/persistence/user/persist/InterestEntity.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,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 | ||
) |
7 changes: 7 additions & 0 deletions
7
...-persistence/src/main/kotlin/com/pokit/out/persistence/user/persist/InterestRepository.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,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> | ||
} |
11 changes: 11 additions & 0 deletions
11
application/src/main/kotlin/com/pokit/user/port/out/InterestPort.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,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> | ||
} |
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,7 @@ | ||
package com.pokit.user.model | ||
|
||
data class Interest( | ||
val id: Long = 0L, | ||
val userId: Long, | ||
var interestType: InterestType | ||
) |