-
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
5b9072f
commit a5a4a29
Showing
5 changed files
with
168 additions
and
2 deletions.
There are no files selected for viewing
25 changes: 23 additions & 2 deletions
25
domain/src/main/kotlin/com/threedays/domain/connection/entity/Connection.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 |
---|---|---|
@@ -1,13 +1,34 @@ | ||
package com.threedays.domain.connection.entity | ||
|
||
import com.threedays.domain.user.entity.User | ||
import com.threedays.support.common.base.domain.AggregateRoot | ||
import com.threedays.support.common.base.domain.UUIDTypeId | ||
import java.util.UUID | ||
import java.time.LocalDateTime | ||
import java.util.* | ||
|
||
data class Connection( | ||
override val id: Id, | ||
): AggregateRoot<Connection, Connection.Id>() { | ||
val participant1: Participant, | ||
val participant2: Participant, | ||
val connectedAt: LocalDateTime, | ||
) : AggregateRoot<Connection, Connection.Id>() { | ||
|
||
data class Id(override val value: UUID) : UUIDTypeId(value) | ||
|
||
companion object { | ||
|
||
fun match( | ||
user1: User.Id, | ||
user2: User.Id | ||
): Connection { | ||
return Connection( | ||
id = UUIDTypeId.random(), | ||
participant1 = Participant(user1), | ||
participant2 = Participant(user2), | ||
connectedAt = LocalDateTime.now() | ||
) | ||
} | ||
} | ||
|
||
|
||
} |
25 changes: 25 additions & 0 deletions
25
domain/src/main/kotlin/com/threedays/domain/connection/entity/Participant.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,25 @@ | ||
package com.threedays.domain.connection.entity | ||
|
||
import com.threedays.domain.user.entity.User | ||
import com.threedays.support.common.base.domain.DomainEntity | ||
|
||
/** | ||
* 매칭에 참여하는 유저 | ||
* @param id: 유저의 ID | ||
* @param connectionResponse: 매칭에 대한 응답 | ||
*/ | ||
data class Participant( | ||
override val id: User.Id, | ||
val connectionResponse: ConnectionResponse = ConnectionResponse.NO_RESPONSE | ||
) : DomainEntity<Participant, User.Id>() { | ||
|
||
/** | ||
* 유저의 매칭에 대한 응답 | ||
*/ | ||
enum class ConnectionResponse { | ||
NO_RESPONSE, // 응답하지 않음 | ||
KEEP_CONNECT, // 커넥션 유지 | ||
DISCONNECT, // 연결 끊기 | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
...stence/src/main/kotlin/com/threedays/persistence/connection/entity/ConnectionJpaEntity.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,65 @@ | ||
package com.threedays.persistence.connection.entity | ||
|
||
import com.threedays.domain.connection.entity.Connection | ||
import jakarta.persistence.CascadeType | ||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.FetchType | ||
import jakarta.persistence.Id | ||
import jakarta.persistence.OneToOne | ||
import jakarta.persistence.Table | ||
import java.time.LocalDateTime | ||
import java.util.* | ||
|
||
@Entity | ||
@Table(name = "connection") | ||
class ConnectionJpaEntity( | ||
id: UUID, | ||
participant1: ParticipantJpaEntity, | ||
participant2: ParticipantJpaEntity, | ||
connectedAt: LocalDateTime, | ||
) { | ||
|
||
@Id | ||
var id: UUID = id | ||
private set | ||
|
||
@OneToOne( | ||
fetch = FetchType.EAGER, | ||
cascade = [CascadeType.ALL], | ||
) | ||
var participant1: ParticipantJpaEntity = participant1 | ||
private set | ||
|
||
@OneToOne( | ||
fetch = FetchType.EAGER, | ||
cascade = [CascadeType.ALL], | ||
) | ||
var participant2: ParticipantJpaEntity = participant2 | ||
private set | ||
|
||
@Column(name = "connected_at", nullable = false) | ||
var connectedAt: LocalDateTime = connectedAt | ||
private set | ||
|
||
fun toDomain(): Connection { | ||
return Connection( | ||
id = Connection.Id(id), | ||
participant1 = participant1.toDomain(), | ||
participant2 = participant2.toDomain(), | ||
connectedAt = connectedAt | ||
) | ||
} | ||
|
||
companion object { | ||
|
||
fun from(domain: Connection): ConnectionJpaEntity { | ||
return ConnectionJpaEntity( | ||
id = domain.id.value, | ||
participant1 = ParticipantJpaEntity.from(domain.participant1), | ||
participant2 = ParticipantJpaEntity.from(domain.participant2), | ||
connectedAt = domain.connectedAt | ||
) | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...tence/src/main/kotlin/com/threedays/persistence/connection/entity/ParticipantJpaEntity.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,39 @@ | ||
package com.threedays.persistence.connection.entity | ||
|
||
import com.threedays.domain.connection.entity.Participant | ||
import com.threedays.domain.user.entity.User | ||
import jakarta.persistence.* | ||
import java.util.* | ||
|
||
@Entity | ||
@Table(name = "participant") | ||
class ParticipantJpaEntity( | ||
id: UUID, | ||
connectionResponse: Participant.ConnectionResponse | ||
) { | ||
|
||
@Id | ||
var id: UUID = id | ||
private set | ||
|
||
@Column(name = "connection_response", nullable = false) | ||
@Enumerated(EnumType.STRING) | ||
var connectionResponse: Participant.ConnectionResponse = connectionResponse | ||
private set | ||
|
||
fun toDomain(): Participant { | ||
return Participant( | ||
id = User.Id(id), | ||
connectionResponse = connectionResponse | ||
) | ||
} | ||
|
||
companion object { | ||
fun from(domain: Participant): ParticipantJpaEntity { | ||
return ParticipantJpaEntity( | ||
id = domain.id.value, | ||
connectionResponse = domain.connectionResponse | ||
) | ||
} | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
infrastructure/persistence/src/main/resources/db/migration/V3__init_connection.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,16 @@ | ||
CREATE TABLE participant | ||
( | ||
id BINARY(16) PRIMARY KEY COMMENT '사용자 ID', | ||
connection_response VARCHAR(20) NOT NULL COMMENT '연결 응답 (ACCEPTED, REJECTED, WAITING)' | ||
); | ||
|
||
CREATE TABLE connection | ||
( | ||
id BINARY(16) PRIMARY KEY COMMENT '커넥션 ID', | ||
participant1_id BINARY(16) NOT NULL COMMENT '참가자1 ID', | ||
participant2_id BINARY(16) NOT NULL COMMENT '참가자2 ID', | ||
connected_at DATETIME(6) NOT NULL COMMENT '커넥션 생성 일시', | ||
|
||
INDEX idx_connection_participant1_id (participant1_id), | ||
INDEX idx_connection_participant2_id (participant2_id) | ||
); |