Skip to content
This repository was archived by the owner on Jul 7, 2025. It is now read-only.

Commit a20aa9e

Browse files
committed
ASAP-409 IndexedSpace 제거
1 parent b04c1ad commit a20aa9e

File tree

13 files changed

+115
-193
lines changed

13 files changed

+115
-193
lines changed

Application-Module/src/main/kotlin/com/asap/application/space/port/out/SpaceManagementPort.kt

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.asap.application.space.port.out
22

33
import com.asap.domain.common.DomainId
4-
import com.asap.domain.space.entity.IndexedSpace
54
import com.asap.domain.space.entity.MainSpace
65
import com.asap.domain.space.entity.Space
76

@@ -13,13 +12,6 @@ interface SpaceManagementPort {
1312
spaceId: DomainId,
1413
): Space
1514

16-
fun getIndexedSpaceNotNull(
17-
userId: DomainId,
18-
spaceId: DomainId,
19-
): IndexedSpace
20-
21-
fun getAllIndexedSpace(userId: DomainId): List<IndexedSpace>
22-
2315
fun getAllSpaceBy(
2416
userId: DomainId,
2517
spaceIds: List<DomainId>,
@@ -29,14 +21,9 @@ interface SpaceManagementPort {
2921

3022
fun save(space: Space): Space
3123

32-
fun update(space: Space): Space
33-
34-
fun update(indexedSpace: IndexedSpace): IndexedSpace
24+
fun saveAll(spaces: List<Space>): List<Space>
3525

36-
fun updateIndexes(
37-
userId: DomainId,
38-
orders: List<IndexedSpace>,
39-
)
26+
fun update(space: Space): Space
4027

4128
fun deleteBy(space: Space)
4229

Application-Module/src/main/kotlin/com/asap/application/space/service/SpaceCommandService.kt

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,30 +77,27 @@ class SpaceCommandService(
7777
}
7878

7979
override fun update(command: UpdateSpaceUsecase.Command.Index) {
80-
val indexedSpaces = spaceManagementPort.getAllIndexedSpace(DomainId(command.userId))
80+
val spaces = spaceManagementPort.getAllSpaceBy(DomainId(command.userId))
8181
val changeIndexMap = command.orders.associateBy({ DomainId(it.spaceId) }, { it.index })
8282

8383
try {
8484
spaceIndexValidator.validate(
85-
indexedSpaces = indexedSpaces,
85+
spaces = spaces, // todo: space로 수정하기
8686
validateIndex = changeIndexMap,
8787
)
8888
} catch (e: DefaultException.InvalidArgumentException) {
89-
throw SpaceException.InvalidSpaceUpdateException()
89+
throw SpaceException.InvalidSpaceUpdateException(message = e.message)
9090
}
9191

92-
indexedSpaces.map {
92+
spaces.map {
9393
it.updateIndex(changeIndexMap.getValue(it.id))
9494
}
95-
spaceManagementPort.updateIndexes(
96-
userId = DomainId(command.userId),
97-
orders = indexedSpaces,
98-
)
95+
spaceManagementPort.saveAll(spaces)
9996
}
10097

10198
private fun reIndexingSpaceOrder(userId: DomainId) {
10299
spaceManagementPort
103-
.getAllIndexedSpace(userId)
100+
.getAllSpaceBy(userId)
104101
.sortedBy { it.index }
105102
.forEachIndexed { index, indexedSpace ->
106103
indexedSpace.updateIndex(index)
@@ -109,6 +106,16 @@ class SpaceCommandService(
109106
}
110107

111108
override fun update(command: UpdateSpaceUsecase.Command.Main) {
112-
TODO("Not yet implemented")
109+
val spaces = spaceManagementPort.getAllSpaceBy(
110+
userId = DomainId(command.userId),
111+
).map {
112+
if(it.id.value == command.spaceId){
113+
it.updateToMain()
114+
}else{
115+
it.updateToSub()
116+
}
117+
}
118+
119+
113120
}
114121
}

Application-Module/src/main/kotlin/com/asap/application/space/service/SpaceQueryService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class SpaceQueryService(
3737

3838
override fun getAll(query: GetSpaceUsecase.GetAllQuery): GetSpaceUsecase.GetAllResponse {
3939
val spaces =
40-
spaceManagementPort.getAllIndexedSpace(
40+
spaceManagementPort.getAllSpaceBy(
4141
userId = DomainId(query.userId),
4242
)
4343

Application-Module/src/test/kotlin/com/asap/application/space/service/SpaceCommandServiceTest.kt

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import com.asap.application.space.port.`in`.DeleteSpaceUsecase
66
import com.asap.application.space.port.`in`.UpdateSpaceNameUsecase
77
import com.asap.application.space.port.`in`.UpdateSpaceUsecase
88
import com.asap.application.space.port.out.SpaceManagementPort
9+
import com.asap.domain.SpaceFixture
910
import com.asap.domain.common.DomainId
10-
import com.asap.domain.space.entity.IndexedSpace
1111
import com.asap.domain.space.entity.Space
1212
import io.kotest.assertions.throwables.shouldThrow
1313
import io.kotest.core.spec.style.BehaviorSpec
@@ -122,38 +122,23 @@ class SpaceCommandServiceTest :
122122
UpdateSpaceUsecase.Command.SpaceOrder("spaceId2", 0),
123123
),
124124
)
125-
val indexedSpaces =
125+
val spaces =
126126
listOf(
127-
IndexedSpace(
128-
id = DomainId("spaceId1"),
129-
userId = DomainId("userId"),
130-
name = "space1",
131-
index = 0,
132-
templateType = 1,
127+
SpaceFixture.createSpace(
128+
id = DomainId(spaceUpdateIndexCommand.orders[0].spaceId),
129+
userId = DomainId(spaceUpdateIndexCommand.userId),
133130
),
134-
IndexedSpace(
135-
id = DomainId("spaceId2"),
136-
userId = DomainId("userId"),
137-
name = "space2",
138-
index = 1,
139-
templateType = 1,
131+
SpaceFixture.createSpace(
132+
id = DomainId(spaceUpdateIndexCommand.orders[1].spaceId),
133+
userId = DomainId(spaceUpdateIndexCommand.userId),
140134
),
141135
)
142-
every { spaceManagementPort.getAllIndexedSpace(DomainId(spaceUpdateIndexCommand.userId)) } returns indexedSpaces
136+
every { spaceManagementPort.getAllSpaceBy(DomainId(spaceUpdateIndexCommand.userId)) } returns spaces
143137
`when`("유저 아이디, 스페이스 순서가 주어진다면") {
144138
spaceCommandService.update(spaceUpdateIndexCommand)
145139
then("스페이스 순서를 수정한다") {
146-
indexedSpaces[0].updateIndex(1)
147-
indexedSpaces[1].updateIndex(0)
148140
verify {
149-
spaceManagementPort.updateIndexes(
150-
userId = DomainId(spaceUpdateIndexCommand.userId),
151-
orders =
152-
listOf(
153-
indexedSpaces[0],
154-
indexedSpaces[1],
155-
),
156-
)
141+
spaceManagementPort.saveAll(spaces)
157142
}
158143
}
159144
}
@@ -169,8 +154,8 @@ class SpaceCommandServiceTest :
169154
),
170155
)
171156
every {
172-
spaceManagementPort.getAllIndexedSpace(DomainId(invalidCommand.userId))
173-
} returns indexedSpaces
157+
spaceManagementPort.getAllSpaceBy(DomainId(invalidCommand.userId))
158+
} returns spaces
174159
`when`("인덱스 검증과정에서 예외가 발생한다면") {
175160
then("스페이스 순서를 수정하지 않는다") {
176161
shouldThrow<SpaceException.InvalidSpaceUpdateException> {

Application-Module/src/test/kotlin/com/asap/application/space/service/SpaceQueryServiceTest.kt

Lines changed: 18 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import com.asap.application.space.port.`in`.GetMainSpaceUsecase
55
import com.asap.application.space.port.`in`.GetSpaceUsecase
66
import com.asap.application.space.port.out.SpaceManagementPort
77
import com.asap.application.user.port.out.UserManagementPort
8+
import com.asap.domain.SpaceFixture
89
import com.asap.domain.UserFixture
910
import com.asap.domain.common.DomainId
10-
import com.asap.domain.space.entity.IndexedSpace
1111
import com.asap.domain.space.entity.MainSpace
1212
import com.asap.domain.space.entity.Space
1313
import io.kotest.core.spec.style.BehaviorSpec
@@ -62,41 +62,23 @@ class SpaceQueryServiceTest :
6262
}
6363

6464
given("모든 스페이스 조회 요청이 들어왔을 때") {
65-
val indexedSpaces =
66-
listOf(
67-
IndexedSpace(
68-
id = DomainId.generate(),
69-
name = "name",
70-
index = 0,
71-
userId = DomainId("userId"),
72-
templateType = 1,
73-
),
74-
IndexedSpace(
75-
id = DomainId.generate(),
76-
name = "name",
77-
index = 1,
78-
userId = DomainId("userId"),
79-
templateType = 1,
80-
),
81-
IndexedSpace(
82-
id = DomainId.generate(),
83-
name = "name",
84-
index = 2,
85-
userId = DomainId("userId"),
86-
templateType = 1,
87-
),
65+
val spaces = (0..2).mapIndexed { index, _ ->
66+
SpaceFixture.createSpace(
67+
userId = DomainId("userId"),
68+
index = index,
8869
)
89-
val indexedSpaceMap = indexedSpaces.associateBy { it.id }
70+
}
71+
val indexedSpaceMap = spaces.associateBy { it.id }
9072
val query =
9173
GetSpaceUsecase.GetAllQuery(
9274
userId = "userId",
9375
)
94-
every { spaceManagementPort.getAllIndexedSpace(DomainId(query.userId)) } returns indexedSpaces
76+
every { spaceManagementPort.getAllSpaceBy(DomainId(query.userId)) } returns spaces
9577
every { spaceLetterManagementPort.countSpaceLetterBy(any(), any()) } returns 0
9678
`when`("유저 아이디가 주어진다면") {
9779
val response = spaceQueryService.getAll(query)
9880
then("모든 스페이스를 반환한다") {
99-
response.spaces.size shouldBe indexedSpaces.size
81+
response.spaces.size shouldBe spaces.size
10082
response.spaces.forEach { spaceDetail ->
10183
val indexedSpace = indexedSpaceMap[DomainId(spaceDetail.spaceId)]
10284
indexedSpace.shouldNotBeNull {
@@ -111,42 +93,24 @@ class SpaceQueryServiceTest :
11193
}
11294

11395
given("행성 모두 조회 요청이 들어왔을 때") {
114-
val indexedSpaces =
115-
listOf(
116-
IndexedSpace(
117-
id = DomainId.generate(),
118-
name = "name",
119-
index = 0,
120-
userId = DomainId("userId"),
121-
templateType = 1,
122-
),
123-
IndexedSpace(
124-
id = DomainId.generate(),
125-
name = "name",
126-
index = 1,
127-
userId = DomainId("userId"),
128-
templateType = 1,
129-
),
130-
IndexedSpace(
131-
id = DomainId.generate(),
132-
name = "name",
133-
index = 2,
134-
userId = DomainId("userId"),
135-
templateType = 1,
136-
),
96+
val spaces = (0..2).mapIndexed { index, _ ->
97+
SpaceFixture.createSpace(
98+
userId = DomainId("userId"),
99+
index = index,
137100
)
138-
val indexedSpaceMap = indexedSpaces.associateBy { it.id }
101+
}
102+
val spaceMap = spaces.associateBy { it.id }
139103
val query =
140104
GetSpaceUsecase.GetAllQuery(
141105
userId = "userId",
142106
)
143-
every { spaceManagementPort.getAllIndexedSpace(DomainId(query.userId)) } returns indexedSpaces
107+
every { spaceManagementPort.getAllSpaceBy(DomainId(query.userId)) } returns spaces
144108
`when`("유저 아이디가 주어진다면") {
145109
val response = spaceQueryService.getAll(query)
146110
then("모든 스페이스를 반환한다") {
147-
response.spaces.size shouldBe indexedSpaces.size
111+
response.spaces.size shouldBe spaces.size
148112
response.spaces.forEach { spaceDetail ->
149-
val indexedSpace = indexedSpaceMap[DomainId(spaceDetail.spaceId)]
113+
val indexedSpace = spaceMap[DomainId(spaceDetail.spaceId)]
150114
indexedSpace.shouldNotBeNull {
151115
this.id shouldBe DomainId(spaceDetail.spaceId)
152116
this.name shouldBe spaceDetail.spaceName

Application-Module/src/testFixtures/kotlin/com/asap/application/space/SpaceMockManager.kt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,10 @@ class SpaceMockManager(
1818
templateType = 0,
1919
)
2020
return spaceManagementPort.save(space).also {
21-
spaceManagementPort.getIndexedSpaceNotNull(DomainId(userId), it.id).apply {
21+
spaceManagementPort.getSpaceNotNull(DomainId(userId), it.id).apply {
2222
updateIndex(index)
2323
spaceManagementPort.update(this)
2424
}
2525
}
2626
}
27-
28-
fun getSpaceIndexes(userId: String): List<Pair<String, Int>> =
29-
spaceManagementPort.getAllIndexedSpace(DomainId(userId)).map {
30-
it.id.value to it.index
31-
}
3227
}

Domain-Module/src/main/kotlin/com/asap/domain/space/entity/IndexedSpace.kt

Lines changed: 0 additions & 18 deletions
This file was deleted.

Domain-Module/src/main/kotlin/com/asap/domain/space/entity/Space.kt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class Space(
88
id: DomainId,
99
val userId: DomainId,
1010
var name: String,
11+
var index: Int = 0,
1112
val templateType: Int,
1213
var isMain: Boolean = false,
1314
) : Aggregate<Space>(id) {
@@ -32,6 +33,19 @@ class Space(
3233
this.name = name
3334
}
3435

36+
fun updateToMain() {
37+
this.isMain = true
38+
}
39+
40+
fun updateToSub() {
41+
this.isMain = false
42+
}
43+
44+
fun updateIndex(index: Int) {
45+
check(index >= 0) { "Index must be greater than or equal to 0" }
46+
this.index = index
47+
}
48+
3549
fun delete() {
3650
this.registerEvent(SpaceEvent.SpaceDeletedEvent(this))
3751
}

Domain-Module/src/main/kotlin/com/asap/domain/space/service/SpaceIndexValidator.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@ package com.asap.domain.space.service
22

33
import com.asap.common.exception.DefaultException
44
import com.asap.domain.common.DomainId
5-
import com.asap.domain.space.entity.IndexedSpace
5+
import com.asap.domain.space.entity.Space
66

77
class SpaceIndexValidator {
88

9-
fun validate(indexedSpaces: List<IndexedSpace>, validateIndex: Map<DomainId, Int>){
10-
val indexedSpaceSize = indexedSpaces.size
9+
fun validate(spaces: List<Space>, validateIndex: Map<DomainId, Int>){
10+
val spaceSize = spaces.size
1111
val indexSet = validateIndex.values.toSet()
12-
if (indexSet.size != indexedSpaceSize) {
12+
if (indexSet.size != spaceSize) {
1313
throw DefaultException.InvalidArgumentException("요청 인덱스가 기존 엔덱스와 일치하지 않습니다.")
1414
}
15-
if (indexSet.minOrNull() != 0 || indexSet.maxOrNull() != indexedSpaceSize - 1) {
15+
if (indexSet.minOrNull() != 0 || indexSet.maxOrNull() != spaceSize - 1) {
1616
throw DefaultException.InvalidArgumentException("인덱스 범위가 기존 인덱스 범위와 일치하지 않습니다.")
1717
}
18-
indexedSpaces.forEach {
18+
spaces.forEach {
1919
if(validateIndex.containsKey(it.id).not()){
2020
throw DefaultException.InvalidArgumentException("사용자의 스페이스에 포함되지 않은 요청이 있습니다.")
2121
}

0 commit comments

Comments
 (0)