Skip to content

Commit ffe5feb

Browse files
kamiazyaclaude
andcommitted
feat(domain): migrate Scope entity to jMolecules Entity
Changes: - Implement jMolecules Entity<ScopeAggregate, ScopeId> - Add getId(): ScopeId implementation - Use _id private field with public id property (via @JvmName to avoid platform clash) - Update factory methods to use _id parameter - Fix ScopeAggregate.applyEvent() to use _id when creating Scope Technical details: - @JvmName("id") annotation prevents platform declaration clash with getId() since ScopeId is an inline value class that mangles to the same JVM signature - id property delegates to getId() for convenient access - Entity type parameter references ScopeAggregate (the owning aggregate root) Build status: ✅ SUCCESS (with expected deprecation warnings) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent ab57cc9 commit ffe5feb

File tree

2 files changed

+23
-8
lines changed
  • contexts/scope-management/domain/src/main/kotlin/io/github/kamiazya/scopes/scopemanagement/domain

2 files changed

+23
-8
lines changed

contexts/scope-management/domain/src/main/kotlin/io/github/kamiazya/scopes/scopemanagement/domain/aggregate/ScopeAggregate.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import arrow.core.raise.ensureNotNull
77
import io.github.kamiazya.scopes.platform.domain.value.AggregateId
88
import io.github.kamiazya.scopes.platform.domain.value.AggregateVersion
99
import io.github.kamiazya.scopes.platform.domain.value.EventId
10-
import org.jmolecules.ddd.types.AggregateRoot
1110
import io.github.kamiazya.scopes.scopemanagement.domain.entity.Scope
1211
import io.github.kamiazya.scopes.scopemanagement.domain.error.ScopeError
1312
import io.github.kamiazya.scopes.scopemanagement.domain.error.ScopesError
@@ -28,6 +27,7 @@ import io.github.kamiazya.scopes.scopemanagement.domain.valueobject.ScopeId
2827
import io.github.kamiazya.scopes.scopemanagement.domain.valueobject.ScopeTitle
2928
import kotlinx.datetime.Clock
3029
import kotlinx.datetime.Instant
30+
import org.jmolecules.ddd.types.AggregateRoot
3131

3232
/**
3333
* Scope aggregate root implementing event sourcing pattern with jMolecules DDD types.
@@ -145,7 +145,6 @@ data class ScopeAggregate(
145145
initialAggregate.raiseEvent(event)
146146
}
147147

148-
149148
/**
150149
* Creates an empty aggregate for event replay.
151150
* Used when loading an aggregate from the event store.
@@ -194,7 +193,6 @@ data class ScopeAggregate(
194193
this@ScopeAggregate.raiseEvent(event)
195194
}
196195

197-
198196
/**
199197
* Updates the scope description after validation.
200198
*/
@@ -352,7 +350,7 @@ data class ScopeAggregate(
352350
createdAt = event.occurredAt,
353351
updatedAt = event.occurredAt,
354352
scope = Scope(
355-
id = event.scopeId,
353+
_id = event.scopeId,
356354
title = event.title,
357355
description = event.description,
358356
parentId = event.parentId,

contexts/scope-management/domain/src/main/kotlin/io/github/kamiazya/scopes/scopemanagement/domain/entity/Scope.kt

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import arrow.core.Either
44
import arrow.core.NonEmptyList
55
import arrow.core.raise.either
66
import arrow.core.raise.ensure
7+
import io.github.kamiazya.scopes.scopemanagement.domain.aggregate.ScopeAggregate
78
import io.github.kamiazya.scopes.scopemanagement.domain.error.ScopesError
89
import io.github.kamiazya.scopes.scopemanagement.domain.valueobject.AspectKey
910
import io.github.kamiazya.scopes.scopemanagement.domain.valueobject.AspectValue
@@ -13,24 +14,40 @@ import io.github.kamiazya.scopes.scopemanagement.domain.valueobject.ScopeId
1314
import io.github.kamiazya.scopes.scopemanagement.domain.valueobject.ScopeStatus
1415
import io.github.kamiazya.scopes.scopemanagement.domain.valueobject.ScopeTitle
1516
import kotlinx.datetime.Instant
17+
import org.jmolecules.ddd.types.Entity
1618

1719
/**
1820
* Core domain entity representing a unified "Scope" that can be a project, epic, or task.
1921
* This implements the recursive structure where all entities share the same operations.
2022
* Follows functional DDD principles with immutability and pure functions.
23+
* Implements jMolecules Entity to explicitly express DDD building blocks.
2124
*
2225
* Note: Aspects are temporarily included here but should be managed in aspect-management context.
2326
*/
2427
data class Scope(
25-
val id: ScopeId,
28+
private val _id: ScopeId,
2629
val title: ScopeTitle,
2730
val description: ScopeDescription? = null,
2831
val parentId: ScopeId? = null,
2932
val status: ScopeStatus = ScopeStatus.default(),
3033
val createdAt: Instant,
3134
val updatedAt: Instant,
3235
val aspects: Aspects = Aspects.empty(),
33-
) {
36+
) : Entity<ScopeAggregate, ScopeId> {
37+
38+
/**
39+
* jMolecules Entity identifier accessor.
40+
*/
41+
override fun getId(): ScopeId = _id
42+
43+
/**
44+
* Convenience property to access id directly.
45+
* Note: Uses @JvmName to avoid platform declaration clash with getId()
46+
* since ScopeId is an inline value class.
47+
*/
48+
@get:JvmName("id")
49+
val id: ScopeId get() = getId()
50+
3451
companion object {
3552
/**
3653
* Create a new scope with generated timestamps.
@@ -46,7 +63,7 @@ data class Scope(
4663
val validatedTitle = ScopeTitle.create(title).bind()
4764
val validatedDescription = ScopeDescription.create(description).bind()
4865
Scope(
49-
id = ScopeId.generate(),
66+
_id = ScopeId.generate(),
5067
title = validatedTitle,
5168
description = validatedDescription,
5269
parentId = parentId,
@@ -70,7 +87,7 @@ data class Scope(
7087
aspects: Aspects = Aspects.empty(),
7188
now: Instant,
7289
): Scope = Scope(
73-
id = id,
90+
_id = id,
7491
title = title,
7592
description = description,
7693
parentId = parentId,

0 commit comments

Comments
 (0)