Skip to content
This repository was archived by the owner on Jul 7, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,24 @@ sealed class SpaceException(
class InvalidSpaceUpdateException(
message: String = "유효하지 않는 스페이스 순서 변경 요청입니다.",
) : SpaceException(
errorCode = 1,
message = message,
)
errorCode = 1,
message = message,
)

class SpaceNotFoundException(
message: String = "해당 스페이스를 찾을 수 없습니다.",
) : SpaceException(
errorCode = 2,
message = message,
)
errorCode = 2,
message = message,
)

class MainSpaceNotFoundException(
message: String = "메인 스페이스를 찾을 수 없습니다.",
) : SpaceException(
errorCode = 3,
message = message,
httpStatus = 500
)

companion object {
const val CODE_PREFIX = "SPACE"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.asap.application.space.port.out

import com.asap.domain.common.DomainId
import com.asap.domain.space.entity.MainSpace
import com.asap.domain.space.entity.Space

interface SpaceManagementPort {
fun getMainSpace(userId: DomainId): MainSpace
fun getMainSpace(userId: DomainId): Space

fun getSpaceNotNull(
userId: DomainId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,11 @@ class SpaceQueryService(
) : GetMainSpaceUsecase,
GetSpaceUsecase {
override fun get(query: GetMainSpaceUsecase.Query): GetMainSpaceUsecase.Response {
val mainSpace =
spaceManagementPort.getMainSpace(
userId = DomainId(query.userId),
)
val space =
spaceManagementPort.getSpaceNotNull(
userId = DomainId(query.userId),
spaceId = mainSpace.id,
)
val space = spaceManagementPort.getMainSpace(
userId = DomainId(query.userId),
)
return GetMainSpaceUsecase.Response(
id = mainSpace.id.value,
id = space.id.value,
username = userManagementPort.getUserNotNull(DomainId(query.userId)).username,
templateType = space.templateType,
spaceName = space.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.asap.application.user.port.out.UserManagementPort
import com.asap.domain.SpaceFixture
import com.asap.domain.UserFixture
import com.asap.domain.common.DomainId
import com.asap.domain.space.entity.MainSpace
import io.kotest.core.spec.style.BehaviorSpec
import io.kotest.matchers.nulls.shouldNotBeNull
import io.kotest.matchers.shouldBe
Expand All @@ -30,10 +29,6 @@ class SpaceQueryServiceTest :
)

given("메인 스페이스 조회 요청이 들어왔을 때") {
val mainSpace =
MainSpace(
id = DomainId.generate(),
)
val user = UserFixture.createUser()
val query =
GetMainSpaceUsecase.Query(
Expand All @@ -42,13 +37,13 @@ class SpaceQueryServiceTest :
val space = SpaceFixture.createSpace(
userId = user.id,
)
every { spaceManagementPort.getMainSpace(any()) } returns mainSpace
every { spaceManagementPort.getMainSpace(any()) } returns space
every { userManagementPort.getUserNotNull(any()) } returns user
every { spaceManagementPort.getSpaceNotNull(any(), any()) } returns space
`when`("유저 아이디가 주어진다면") {
val response = spaceQueryService.get(query)
then("메인 스페이스를 반환한다") {
response.id shouldBe mainSpace.id.value
response.id shouldBe space.id.value
response.username shouldBe user.username
response.templateType shouldBe space.templateType
response.spaceName shouldBe space.name
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
package com.asap.persistence.jpa.space

import com.asap.domain.common.DomainId
import com.asap.domain.space.entity.MainSpace
import com.asap.domain.space.entity.Space
import com.asap.persistence.jpa.space.entity.SpaceEntity

object SpaceMapper {
fun toMainSpace(spaceEntity: SpaceEntity): MainSpace =
MainSpace(
id = DomainId(spaceEntity.id),
)

fun toSpace(spaceEntity: SpaceEntity) =
Space(
id = DomainId(spaceEntity.id),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import com.asap.application.space.exception.SpaceException
import com.asap.application.space.port.out.SpaceManagementPort
import com.asap.common.event.EventPublisher
import com.asap.domain.common.DomainId
import com.asap.domain.space.entity.MainSpace
import com.asap.domain.space.entity.Space
import com.asap.persistence.jpa.space.SpaceMapper
import com.asap.persistence.jpa.space.repository.*
Expand All @@ -15,14 +14,14 @@ class SpaceManagementJpaAdapter(
private val spaceJpaRepository: SpaceJpaRepository,
private val eventPublisher: EventPublisher,
) : SpaceManagementPort {
override fun getMainSpace(userId: DomainId): MainSpace =
override fun getMainSpace(userId: DomainId): Space =
spaceJpaRepository
.findAllActiveSpaceByUserId(userId.value)
.first {
it.isMain
}.let {
SpaceMapper.toMainSpace(it)
.findActiveMainSpace(userId.value)
?.let {
SpaceMapper.toSpace(it)
}
?: throw SpaceException.MainSpaceNotFoundException()


override fun getSpaceNotNull(
userId: DomainId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ interface SpaceJpaRepository : JpaRepository<SpaceEntity, String> {
entityStatus: EntityStatus,
): List<SpaceEntity>

@Query("""
SELECT s
FROM SpaceEntity s
WHERE s.isMain = true
AND s.userId = :userId
AND s.spaceStatus = :entityStatus
""")
fun findMainSpace(
userId: String,
entityStatus: EntityStatus
): SpaceEntity?

@Modifying
@Query(
"""
Expand Down Expand Up @@ -105,4 +117,8 @@ fun SpaceJpaRepository.findActiveSpaceByIdAndUserId(
userId: String,
): SpaceEntity? = findByIdAndUserId(id, userId, EntityStatus.ACTIVE)

fun SpaceJpaRepository.findActiveMainSpace(
userId: String,
): SpaceEntity? = findMainSpace(userId, EntityStatus.ACTIVE)

fun SpaceJpaRepository.countActiveSpaceByUserId(userId: String): Long = countByUserId(userId, EntityStatus.ACTIVE)