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

Commit 709de3f

Browse files
committed
ASAP-409 main 행성 조정 로직 수정
1 parent aeff161 commit 709de3f

1 file changed

Lines changed: 27 additions & 24 deletions

File tree

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

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,20 @@ class SpaceCommandService(
2525

2626
override fun create(command: CreateSpaceUsecase.Command) {
2727
val userId = DomainId(command.userId)
28-
Space
29-
.create(
30-
userId = userId,
31-
name = command.spaceName,
32-
templateType = command.templateType,
33-
).apply {
34-
spaceManagementPort.save(this)
35-
}
28+
Space.create(
29+
userId = userId,
30+
name = command.spaceName,
31+
templateType = command.templateType,
32+
).apply {
33+
spaceManagementPort.save(this)
34+
}
3635

37-
updateMainSpace(userId)
38-
reIndexingSpaceOrder(userId)
39-
}
36+
// TODO 동시성 문제가 발생한다면?
37+
if (spaceManagementPort.countByUserId(userId) == 1L) {
38+
updateMainSpace(userId)
39+
}
4040

41-
override fun update(command: UpdateSpaceNameUsecase.Command) {
42-
val space =
43-
spaceManagementPort.getSpaceNotNull(
44-
userId = DomainId(command.userId),
45-
spaceId = DomainId(command.spaceId),
46-
)
47-
space.updateName(command.name)
48-
spaceManagementPort.update(space)
41+
reIndexingSpaceOrder(userId)
4942
}
5043

5144
override fun deleteOne(command: DeleteSpaceUsecase.DeleteOneCommand) {
@@ -116,6 +109,17 @@ class SpaceCommandService(
116109
spaceManagementPort.saveAll(spaces)
117110
}
118111

112+
override fun update(command: UpdateSpaceNameUsecase.Command) {
113+
val space =
114+
spaceManagementPort.getSpaceNotNull(
115+
userId = DomainId(command.userId),
116+
spaceId = DomainId(command.spaceId),
117+
)
118+
119+
space.updateName(command.name)
120+
spaceManagementPort.update(space)
121+
}
122+
119123
private fun reIndexingSpaceOrder(userId: DomainId) {
120124
val spaces = spaceManagementPort
121125
.getAllSpaceBy(userId)
@@ -134,10 +138,9 @@ class SpaceCommandService(
134138
return
135139
}
136140

137-
if (spaces.size == 1) {
138-
spaces[0].updateToMain()
139-
spaceManagementPort.save(spaces[0])
140-
return
141-
}
141+
spaces.forEach { it.updateToSub() }
142+
spaces.first().updateToMain()
143+
144+
spaceManagementPort.saveAll(spaces)
142145
}
143146
}

0 commit comments

Comments
 (0)