diff --git a/server/src/main/kotlin/kpring/server/adapter/output/mongo/DeleteServerPortMongoImpl.kt b/server/src/main/kotlin/kpring/server/adapter/output/mongo/DeleteServerPortMongoImpl.kt deleted file mode 100644 index 71712de5..00000000 --- a/server/src/main/kotlin/kpring/server/adapter/output/mongo/DeleteServerPortMongoImpl.kt +++ /dev/null @@ -1,38 +0,0 @@ -package kpring.server.adapter.output.mongo - -import kpring.server.adapter.output.mongo.entity.ServerEntity -import kpring.server.adapter.output.mongo.repository.ServerProfileRepository -import kpring.server.adapter.output.mongo.repository.ServerRepository -import kpring.server.application.port.output.DeleteServerPort -import kpring.server.domain.ServerProfile -import org.springframework.data.mongodb.core.MongoTemplate -import org.springframework.data.mongodb.core.query.Criteria.where -import org.springframework.data.mongodb.core.query.Query.query -import org.springframework.data.mongodb.core.query.Update -import org.springframework.stereotype.Component - -@Component -class DeleteServerPortMongoImpl( - val mongoRepository: ServerRepository, - val mongoServerProfileRepository: ServerProfileRepository, - val template: MongoTemplate, -) : DeleteServerPort { - override fun delete(serverId: String) { - mongoRepository.deleteById(serverId) - mongoServerProfileRepository.deleteByServerId(serverId) - } - - override fun deleteMember(profile: ServerProfile) { - template.updateFirst( - query( - where("_id").`is`(profile.server.id) - .and("users").`in`(profile.userId), - ), - Update() - .pull("users", profile.userId), - ServerEntity::class.java, - ) - - mongoServerProfileRepository.deleteByServerIdAndUserId(profile.server.id, profile.userId) - } -} diff --git a/server/src/main/kotlin/kpring/server/adapter/output/mongo/GetServerPortMongoImpl.kt b/server/src/main/kotlin/kpring/server/adapter/output/mongo/GetServerPortMongoImpl.kt deleted file mode 100644 index a4b646b7..00000000 --- a/server/src/main/kotlin/kpring/server/adapter/output/mongo/GetServerPortMongoImpl.kt +++ /dev/null @@ -1,33 +0,0 @@ -package kpring.server.adapter.output.mongo - -import kpring.core.global.exception.CommonErrorCode -import kpring.core.global.exception.ServiceException -import kpring.server.adapter.output.mongo.entity.QServerEntity -import kpring.server.adapter.output.mongo.entity.ServerEntity -import kpring.server.adapter.output.mongo.repository.ServerRepository -import kpring.server.application.port.output.GetServerPort -import kpring.server.domain.Server -import org.springframework.stereotype.Component - -@Component -class GetServerPortMongoImpl( - val serverRepository: ServerRepository, -) : GetServerPort { - override fun get(id: String): Server { - val serverEntity = - serverRepository.findById(id) - .orElseThrow { throw ServiceException(CommonErrorCode.NOT_FOUND) } - - return serverEntity.toDomain() - } - - override fun getServerWith(userId: String): List { - val server = QServerEntity.serverEntity - val servers = - serverRepository.findAll( - server.users.any().eq(userId), - ) - - return servers.map(ServerEntity::toDomain) - } -} diff --git a/server/src/main/kotlin/kpring/server/adapter/output/mongo/SaveServerPortMongoImpl.kt b/server/src/main/kotlin/kpring/server/adapter/output/mongo/SaveServerPortMongoImpl.kt deleted file mode 100644 index 6fac5135..00000000 --- a/server/src/main/kotlin/kpring/server/adapter/output/mongo/SaveServerPortMongoImpl.kt +++ /dev/null @@ -1,44 +0,0 @@ -package kpring.server.adapter.output.mongo - -import kpring.server.adapter.output.mongo.entity.ServerEntity -import kpring.server.adapter.output.mongo.entity.ServerProfileEntity -import kpring.server.adapter.output.mongo.repository.ServerProfileRepository -import kpring.server.adapter.output.mongo.repository.ServerRepository -import kpring.server.application.port.output.SaveServerPort -import kpring.server.domain.Server -import kpring.server.domain.ServerRole -import org.springframework.beans.factory.annotation.Value -import org.springframework.stereotype.Repository -import java.util.* - -@Repository -class SaveServerPortMongoImpl( - val serverRepository: ServerRepository, - val serverProfileRepository: ServerProfileRepository, -) : SaveServerPort { - @Value("\${resource.default.profileImagePath}") - private lateinit var defaultImagePath: String - - override fun create(server: Server): Server { - // create server - val serverEntity = serverRepository.save(ServerEntity(server)) - - // create owner server profile - serverProfileRepository.save( - ServerProfileEntity( - id = null, - userId = server.host.id, - // todo change - name = "USER_${UUID.randomUUID()}", - // todo change - imagePath = defaultImagePath, - serverId = serverEntity.id, - role = ServerRole.OWNER, - bookmarked = false, - ), - ) - - // mapping - return serverEntity.toDomain() - } -} diff --git a/server/src/main/kotlin/kpring/server/adapter/output/mongo/UpdateServerPortMongoImpl.kt b/server/src/main/kotlin/kpring/server/adapter/output/mongo/UpdateServerPortMongoImpl.kt deleted file mode 100644 index cfa6463e..00000000 --- a/server/src/main/kotlin/kpring/server/adapter/output/mongo/UpdateServerPortMongoImpl.kt +++ /dev/null @@ -1,68 +0,0 @@ -package kpring.server.adapter.output.mongo - -import kpring.core.server.dto.request.UpdateHostAtServerRequest -import kpring.server.adapter.output.mongo.entity.ServerEntity -import kpring.server.adapter.output.mongo.entity.ServerProfileEntity -import kpring.server.adapter.output.mongo.repository.ServerProfileRepository -import kpring.server.adapter.output.mongo.repository.ServerRepository -import kpring.server.application.port.output.UpdateServerPort -import kpring.server.domain.ServerProfile -import org.springframework.data.mongodb.core.MongoTemplate -import org.springframework.data.mongodb.core.query.Criteria.where -import org.springframework.data.mongodb.core.query.Query.query -import org.springframework.data.mongodb.core.query.Update -import org.springframework.stereotype.Component -import org.springframework.transaction.annotation.Transactional - -@Component -@Transactional -class UpdateServerPortMongoImpl( - val serverRepository: ServerRepository, - val serverProfileRepository: ServerProfileRepository, - val template: MongoTemplate, -) : UpdateServerPort { - override fun addUser(profile: ServerProfile) { - template.updateFirst( - query( - where("_id").`is`(profile.server.id) - .and("invitedUserIds").`in`(profile.userId), - ), - Update() - .pull("invitedUserIds", profile.userId) - .push("users", profile.userId), - ServerEntity::class.java, - ) - - serverProfileRepository.save(ServerProfileEntity(profile)) - } - - override fun inviteUser( - serverId: String, - userId: String, - ) { - template.updateFirst( - query( - where("_id").`is`(serverId) - .and("invitedUserIds").nin(userId), - ), - Update().push("invitedUserIds").value(userId), - ServerEntity::class.java, - ) - } - - override fun updateServerHost( - serverId: String, - userId: String, - otherUser: UpdateHostAtServerRequest, - ) { - template.updateFirst( - query( - where("_id").`is`(serverId) - .and("hostId").`is`(userId), - ), - Update().set("hostId", otherUser.userId) - .set("hostName", otherUser.userName), - ServerEntity::class.java, - ) - } -} diff --git a/server/src/main/kotlin/kpring/server/adapter/output/mongo/UpdateServerProfilePortMongoImpl.kt b/server/src/main/kotlin/kpring/server/adapter/output/mongo/UpdateServerProfilePortMongoImpl.kt deleted file mode 100644 index 6ee89b05..00000000 --- a/server/src/main/kotlin/kpring/server/adapter/output/mongo/UpdateServerProfilePortMongoImpl.kt +++ /dev/null @@ -1,36 +0,0 @@ -package kpring.server.adapter.output.mongo - -import kpring.server.adapter.output.mongo.entity.ServerProfileEntity -import kpring.server.adapter.output.mongo.repository.ServerProfileRepository -import kpring.server.application.port.output.UpdateServerProfilePort -import kpring.server.domain.ServerProfile -import kpring.server.domain.ServerRole -import org.springframework.data.mongodb.core.MongoTemplate -import org.springframework.data.mongodb.core.query.Criteria -import org.springframework.data.mongodb.core.query.Query -import org.springframework.data.mongodb.core.query.Update -import org.springframework.stereotype.Component -import org.springframework.transaction.annotation.Transactional - -@Component -@Transactional -class UpdateServerProfilePortMongoImpl( - val serverProfileRepository: ServerProfileRepository, - val template: MongoTemplate, -) : UpdateServerProfilePort { - override fun updateServerHost(serverProfile: ServerProfile) { - val newRole = - if (serverProfile.role == ServerRole.OWNER) ServerRole.MEMBER else ServerRole.OWNER - template.updateFirst( - Query.query( - Criteria.where("_id").`is`(serverProfile.server.id) - .and("userId").`is`(serverProfile.userId) - .and("role").`is`(serverProfile.role), - ), - Update().set("role", newRole), - ServerProfileEntity::class.java, - ) - - serverProfileRepository.save(ServerProfileEntity(serverProfile)) - } -} diff --git a/server/src/main/kotlin/kpring/server/application/port/input/AddUserAtServerUseCase.kt b/server/src/main/kotlin/kpring/server/application/port/input/AddUserAtServerUseCase.kt deleted file mode 100644 index e6785360..00000000 --- a/server/src/main/kotlin/kpring/server/application/port/input/AddUserAtServerUseCase.kt +++ /dev/null @@ -1,16 +0,0 @@ -package kpring.server.application.port.input - -import kpring.core.server.dto.request.AddUserAtServerRequest - -interface AddUserAtServerUseCase { - fun inviteUser( - serverId: String, - invitorId: String, - userId: String, - ) - - fun addInvitedUser( - serverId: String, - req: AddUserAtServerRequest, - ) -} diff --git a/server/src/main/kotlin/kpring/server/application/port/input/CreateServerUseCase.kt b/server/src/main/kotlin/kpring/server/application/port/input/CreateServerUseCase.kt deleted file mode 100644 index d3c5a1ac..00000000 --- a/server/src/main/kotlin/kpring/server/application/port/input/CreateServerUseCase.kt +++ /dev/null @@ -1,8 +0,0 @@ -package kpring.server.application.port.input - -import kpring.core.server.dto.request.CreateServerRequest -import kpring.core.server.dto.response.CreateServerResponse - -interface CreateServerUseCase { - fun createServer(req: CreateServerRequest): CreateServerResponse -} diff --git a/server/src/main/kotlin/kpring/server/application/port/input/DeleteServerUseCase.kt b/server/src/main/kotlin/kpring/server/application/port/input/DeleteServerUseCase.kt deleted file mode 100644 index e5bac1c4..00000000 --- a/server/src/main/kotlin/kpring/server/application/port/input/DeleteServerUseCase.kt +++ /dev/null @@ -1,13 +0,0 @@ -package kpring.server.application.port.input - -interface DeleteServerUseCase { - fun deleteServer( - serverId: String, - userId: String, - ) - - fun deleteServerMember( - serverId: String, - userId: String, - ) -} diff --git a/server/src/main/kotlin/kpring/server/application/port/input/GetServerInfoUseCase.kt b/server/src/main/kotlin/kpring/server/application/port/input/GetServerInfoUseCase.kt deleted file mode 100644 index f1ab45b1..00000000 --- a/server/src/main/kotlin/kpring/server/application/port/input/GetServerInfoUseCase.kt +++ /dev/null @@ -1,16 +0,0 @@ -package kpring.server.application.port.input - -import kpring.core.server.dto.ServerInfo -import kpring.core.server.dto.ServerSimpleInfo -import kpring.core.server.dto.request.GetServerCondition - -interface GetServerInfoUseCase { - fun getServerInfo(serverId: String): ServerInfo - - fun getServerList( - condition: GetServerCondition, - userId: String, - ): List - - fun getOwnedServerList(userId: String): List -} diff --git a/server/src/main/kotlin/kpring/server/application/port/input/UpdateHostAtServerUseCase.kt b/server/src/main/kotlin/kpring/server/application/port/input/UpdateHostAtServerUseCase.kt deleted file mode 100644 index cd8f51b8..00000000 --- a/server/src/main/kotlin/kpring/server/application/port/input/UpdateHostAtServerUseCase.kt +++ /dev/null @@ -1,11 +0,0 @@ -package kpring.server.application.port.input - -import kpring.core.server.dto.request.UpdateHostAtServerRequest - -interface UpdateHostAtServerUseCase { - fun updateServerHost( - serverId: String, - userId: String, - otherUser: UpdateHostAtServerRequest, - ) -} diff --git a/server/src/main/kotlin/kpring/server/application/port/output/DeleteServerPort.kt b/server/src/main/kotlin/kpring/server/application/port/output/DeleteServerPort.kt deleted file mode 100644 index 685ca992..00000000 --- a/server/src/main/kotlin/kpring/server/application/port/output/DeleteServerPort.kt +++ /dev/null @@ -1,9 +0,0 @@ -package kpring.server.application.port.output - -import kpring.server.domain.ServerProfile - -interface DeleteServerPort { - fun delete(serverId: String) - - fun deleteMember(serverProfile: ServerProfile) -} diff --git a/server/src/main/kotlin/kpring/server/application/port/output/GetServerPort.kt b/server/src/main/kotlin/kpring/server/application/port/output/GetServerPort.kt deleted file mode 100644 index d0f6aa7c..00000000 --- a/server/src/main/kotlin/kpring/server/application/port/output/GetServerPort.kt +++ /dev/null @@ -1,9 +0,0 @@ -package kpring.server.application.port.output - -import kpring.server.domain.Server - -interface GetServerPort { - fun get(id: String): Server - - fun getServerWith(userId: String): List -} diff --git a/server/src/main/kotlin/kpring/server/application/port/output/SaveServerPort.kt b/server/src/main/kotlin/kpring/server/application/port/output/SaveServerPort.kt deleted file mode 100644 index f0cb75b6..00000000 --- a/server/src/main/kotlin/kpring/server/application/port/output/SaveServerPort.kt +++ /dev/null @@ -1,7 +0,0 @@ -package kpring.server.application.port.output - -import kpring.server.domain.Server - -interface SaveServerPort { - fun create(server: Server): Server -} diff --git a/server/src/main/kotlin/kpring/server/application/port/output/UpdateServerProfilePort.kt b/server/src/main/kotlin/kpring/server/application/port/output/UpdateServerProfilePort.kt deleted file mode 100644 index c7aa6a8c..00000000 --- a/server/src/main/kotlin/kpring/server/application/port/output/UpdateServerProfilePort.kt +++ /dev/null @@ -1,7 +0,0 @@ -package kpring.server.application.port.output - -import kpring.server.domain.ServerProfile - -interface UpdateServerProfilePort { - fun updateServerHost(serverProfile: ServerProfile) -} diff --git a/server/src/main/kotlin/kpring/server/adapter/input/rest/CategoryController.kt b/server/src/main/kotlin/kpring/server/controller/CategoryController.kt similarity index 71% rename from server/src/main/kotlin/kpring/server/adapter/input/rest/CategoryController.kt rename to server/src/main/kotlin/kpring/server/controller/CategoryController.kt index 4aa9232e..8c3e0b00 100644 --- a/server/src/main/kotlin/kpring/server/adapter/input/rest/CategoryController.kt +++ b/server/src/main/kotlin/kpring/server/controller/CategoryController.kt @@ -1,7 +1,7 @@ -package kpring.server.adapter.input.rest +package kpring.server.controller import kpring.core.global.dto.response.ApiResponse -import kpring.server.application.port.input.GetCategoryUseCase +import kpring.server.service.CategoryService import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.RequestMapping @@ -10,11 +10,11 @@ import org.springframework.web.bind.annotation.RestController @RestController @RequestMapping("/api/v1/category") class CategoryController( - val getCategoryUseCase: GetCategoryUseCase, + val categoryService: CategoryService, ) { @GetMapping("") fun getCategories(): ResponseEntity> { - val response = getCategoryUseCase.getCategories() + val response = categoryService.getCategories() return ResponseEntity.ok() .body(ApiResponse(data = response)) } diff --git a/server/src/main/kotlin/kpring/server/adapter/input/rest/RestApiServerController.kt b/server/src/main/kotlin/kpring/server/controller/RestApiServerController.kt similarity index 78% rename from server/src/main/kotlin/kpring/server/adapter/input/rest/RestApiServerController.kt rename to server/src/main/kotlin/kpring/server/controller/RestApiServerController.kt index 7693eb46..226530f1 100644 --- a/server/src/main/kotlin/kpring/server/adapter/input/rest/RestApiServerController.kt +++ b/server/src/main/kotlin/kpring/server/controller/RestApiServerController.kt @@ -1,4 +1,4 @@ -package kpring.server.adapter.input.rest +package kpring.server.controller import kpring.core.auth.client.AuthClient import kpring.core.global.dto.response.ApiResponse @@ -8,18 +8,14 @@ import kpring.core.server.dto.request.AddUserAtServerRequest import kpring.core.server.dto.request.CreateServerRequest import kpring.core.server.dto.request.GetServerCondition import kpring.core.server.dto.request.UpdateHostAtServerRequest -import kpring.server.application.port.input.* +import kpring.server.service.ServerService import org.springframework.http.ResponseEntity import org.springframework.web.bind.annotation.* @RestController @RequestMapping("/api/v1/server") class RestApiServerController( - val createServerUseCase: CreateServerUseCase, - val getServerUseCase: GetServerInfoUseCase, - val addUserAtServerUseCase: AddUserAtServerUseCase, - val deleteServerUseCase: DeleteServerUseCase, - val updateHostAtServerUseCase: UpdateHostAtServerUseCase, + val serverService: ServerService, val authClient: AuthClient, ) { @PostMapping("") @@ -37,7 +33,7 @@ class RestApiServerController( } // logic - val data = createServerUseCase.createServer(request) + val data = serverService.createServer(request) return ResponseEntity.ok() .body(ApiResponse(data = data)) @@ -49,7 +45,7 @@ class RestApiServerController( @ModelAttribute condition: GetServerCondition, ): ResponseEntity>> { val userInfo = authClient.getTokenInfo(token).data!! - val data = getServerUseCase.getServerList(condition, userInfo.userId) + val data = serverService.getServerList(condition, userInfo.userId) return ResponseEntity.ok() .body(ApiResponse(data = data)) } @@ -59,7 +55,7 @@ class RestApiServerController( @RequestHeader("Authorization") token: String, ): ResponseEntity>> { val userInfo = authClient.getTokenInfo(token).data!! - val data = getServerUseCase.getOwnedServerList(userInfo.userId) + val data = serverService.getOwnedServerList(userInfo.userId) return ResponseEntity.ok() .body(ApiResponse(data = data)) } @@ -68,7 +64,7 @@ class RestApiServerController( fun getServerInfo( @PathVariable serverId: String, ): ResponseEntity> { - val data = getServerUseCase.getServerInfo(serverId) + val data = serverService.getServerInfo(serverId) return ResponseEntity.ok() .body(ApiResponse(data = data)) } @@ -80,7 +76,7 @@ class RestApiServerController( @RequestHeader("Authorization") token: String, ): ResponseEntity { val invitor = authClient.getTokenInfo(token).data!! - addUserAtServerUseCase.inviteUser(serverId, invitor.userId, userId) + serverService.inviteUser(serverId, invitor.userId, userId) return ResponseEntity.ok().build() } @@ -90,7 +86,7 @@ class RestApiServerController( @RequestHeader("Authorization") token: String, @RequestBody request: AddUserAtServerRequest, ): ResponseEntity { - addUserAtServerUseCase.addInvitedUser(serverId, request) + serverService.addInvitedUser(serverId, request) return ResponseEntity.ok().build() } @@ -100,7 +96,7 @@ class RestApiServerController( @RequestHeader("Authorization") token: String, ): ResponseEntity { val userInfo = authClient.getTokenInfo(token).data!! - deleteServerUseCase.deleteServer(serverId, userInfo.userId) + serverService.deleteServer(serverId, userInfo.userId) return ResponseEntity.ok().build() } @@ -110,7 +106,7 @@ class RestApiServerController( @RequestHeader("Authorization") token: String, ): ResponseEntity { val userInfo = authClient.getTokenInfo(token).data!! - deleteServerUseCase.deleteServerMember(serverId, userInfo.userId) + serverService.deleteServerMember(serverId, userInfo.userId) return ResponseEntity.ok().build() } @@ -121,7 +117,7 @@ class RestApiServerController( @RequestHeader("Authorization") token: String, ): ResponseEntity { val userInfo = authClient.getTokenInfo(token).data!! - updateHostAtServerUseCase.updateServerHost(serverId, userInfo.userId, otherUser) + serverService.updateServerHost(serverId, userInfo.userId, otherUser) return ResponseEntity.ok().build() } } diff --git a/server/src/main/kotlin/kpring/server/adapter/input/websocket/SignalingController.kt b/server/src/main/kotlin/kpring/server/controller/websocket/SignalingController.kt similarity index 98% rename from server/src/main/kotlin/kpring/server/adapter/input/websocket/SignalingController.kt rename to server/src/main/kotlin/kpring/server/controller/websocket/SignalingController.kt index 47597c92..2ee5c248 100644 --- a/server/src/main/kotlin/kpring/server/adapter/input/websocket/SignalingController.kt +++ b/server/src/main/kotlin/kpring/server/controller/websocket/SignalingController.kt @@ -1,4 +1,4 @@ -package kpring.server.adapter.input.websocket +package kpring.server.controller.websocket import org.slf4j.LoggerFactory import org.springframework.messaging.handler.annotation.DestinationVariable diff --git a/server/src/main/kotlin/kpring/server/adapter/output/mongo/entity/ServerEntity.kt b/server/src/main/kotlin/kpring/server/entity/ServerEntity.kt similarity index 97% rename from server/src/main/kotlin/kpring/server/adapter/output/mongo/entity/ServerEntity.kt rename to server/src/main/kotlin/kpring/server/entity/ServerEntity.kt index 5b90f834..ef86d68b 100644 --- a/server/src/main/kotlin/kpring/server/adapter/output/mongo/entity/ServerEntity.kt +++ b/server/src/main/kotlin/kpring/server/entity/ServerEntity.kt @@ -1,4 +1,4 @@ -package kpring.server.adapter.output.mongo.entity +package kpring.server.entity import kpring.server.domain.Category import kpring.server.domain.Server diff --git a/server/src/main/kotlin/kpring/server/adapter/output/mongo/entity/ServerProfileEntity.kt b/server/src/main/kotlin/kpring/server/entity/ServerProfileEntity.kt similarity index 93% rename from server/src/main/kotlin/kpring/server/adapter/output/mongo/entity/ServerProfileEntity.kt rename to server/src/main/kotlin/kpring/server/entity/ServerProfileEntity.kt index edcf1b02..b419a267 100644 --- a/server/src/main/kotlin/kpring/server/adapter/output/mongo/entity/ServerProfileEntity.kt +++ b/server/src/main/kotlin/kpring/server/entity/ServerProfileEntity.kt @@ -1,4 +1,4 @@ -package kpring.server.adapter.output.mongo.entity +package kpring.server.entity import kpring.server.domain.ServerProfile import kpring.server.domain.ServerRole diff --git a/server/src/main/kotlin/kpring/server/application/port/output/UpdateServerPort.kt b/server/src/main/kotlin/kpring/server/repository/ServerCustomRepository.kt similarity index 58% rename from server/src/main/kotlin/kpring/server/application/port/output/UpdateServerPort.kt rename to server/src/main/kotlin/kpring/server/repository/ServerCustomRepository.kt index b50012fc..9406849c 100644 --- a/server/src/main/kotlin/kpring/server/application/port/output/UpdateServerPort.kt +++ b/server/src/main/kotlin/kpring/server/repository/ServerCustomRepository.kt @@ -1,19 +1,26 @@ -package kpring.server.application.port.output +package kpring.server.repository import kpring.core.server.dto.request.UpdateHostAtServerRequest +import kpring.server.domain.Server import kpring.server.domain.ServerProfile -interface UpdateServerPort { - fun addUser(profile: ServerProfile) - - fun inviteUser( +interface ServerCustomRepository { + fun updateServerHost( serverId: String, userId: String, + otherUser: UpdateHostAtServerRequest, ) - fun updateServerHost( + fun deleteMember(profile: ServerProfile) + + fun addUser(profile: ServerProfile) + + fun inviteUser( serverId: String, userId: String, - otherUser: UpdateHostAtServerRequest, ) + + fun create(server: Server): Server + + fun getServerWith(userId: String): List } diff --git a/server/src/main/kotlin/kpring/server/repository/ServerCustomRepositoryImpl.kt b/server/src/main/kotlin/kpring/server/repository/ServerCustomRepositoryImpl.kt new file mode 100644 index 00000000..7d82aa55 --- /dev/null +++ b/server/src/main/kotlin/kpring/server/repository/ServerCustomRepositoryImpl.kt @@ -0,0 +1,118 @@ +package kpring.server.repository + +import kpring.core.server.dto.request.UpdateHostAtServerRequest +import kpring.server.domain.Server +import kpring.server.domain.ServerProfile +import kpring.server.domain.ServerRole +import kpring.server.entity.QServerEntity +import kpring.server.entity.ServerEntity +import kpring.server.entity.ServerProfileEntity +import org.springframework.beans.factory.annotation.Value +import org.springframework.data.mongodb.core.MongoTemplate +import org.springframework.data.mongodb.core.query.Criteria +import org.springframework.data.mongodb.core.query.Query +import org.springframework.data.mongodb.core.query.Update +import org.springframework.stereotype.Repository +import java.util.* + +@Repository +class ServerCustomRepositoryImpl( + val template: MongoTemplate, + val serverProfileRepository: ServerProfileRepository, + val serverRepository: ServerRepository, +) : ServerCustomRepository { + override fun updateServerHost( + serverId: String, + userId: String, + otherUser: UpdateHostAtServerRequest, + ) { + template.updateFirst( + Query.query( + Criteria.where("_id").`is`(serverId) + .and("hostId").`is`(userId), + ), + Update().set("hostId", otherUser.userId) + .set("hostName", otherUser.userName), + ServerEntity::class.java, + ) + } + + override fun deleteMember(profile: ServerProfile) { + template.updateFirst( + Query.query( + Criteria.where("_id").`is`(profile.server.id) + .and("users").`in`(profile.userId), + ), + Update() + .pull("users", profile.userId), + ServerEntity::class.java, + ) + + serverProfileRepository.deleteByServerIdAndUserId(profile.server.id, profile.userId) + } + + override fun addUser(profile: ServerProfile) { + template.updateFirst( + Query.query( + Criteria.where("_id").`is`(profile.server.id) + .and("invitedUserIds").`in`(profile.userId), + ), + Update() + .pull("invitedUserIds", profile.userId) + .push("users", profile.userId), + ServerEntity::class.java, + ) + + serverProfileRepository.save(ServerProfileEntity(profile)) + } + + override fun inviteUser( + serverId: String, + userId: String, + ) { + template.updateFirst( + Query.query( + Criteria.where("_id").`is`(serverId) + .and("invitedUserIds").nin(userId), + ), + Update().push("invitedUserIds").value(userId), + ServerEntity::class.java, + ) + } + + @Value("\${resource.default.profileImagePath}") + private lateinit var defaultImagePath: String + + override fun create(server: Server): Server { + // create server + val serverEntity = serverRepository.save(ServerEntity(server)) + + // create owner server profile + serverProfileRepository.save( + ServerProfileEntity( + id = null, + userId = server.host.id, + // todo change + name = "USER_${UUID.randomUUID()}", + // todo change + imagePath = defaultImagePath, + serverId = serverEntity.id, + role = ServerRole.OWNER, + bookmarked = false, + ), + ) + + // mapping + return serverEntity.toDomain() + } + + override fun getServerWith(userId: String): List { + val server = QServerEntity.serverEntity + val servers = + serverRepository.findAll( + server.users.any().eq(userId), + ) + + return servers.map(ServerEntity::toDomain) + } +} diff --git a/server/src/main/kotlin/kpring/server/application/port/output/GetServerProfilePort.kt b/server/src/main/kotlin/kpring/server/repository/ServerProfileCustomRepository.kt similarity index 75% rename from server/src/main/kotlin/kpring/server/application/port/output/GetServerProfilePort.kt rename to server/src/main/kotlin/kpring/server/repository/ServerProfileCustomRepository.kt index f1190bb1..76d477ed 100644 --- a/server/src/main/kotlin/kpring/server/application/port/output/GetServerProfilePort.kt +++ b/server/src/main/kotlin/kpring/server/repository/ServerProfileCustomRepository.kt @@ -1,9 +1,11 @@ -package kpring.server.application.port.output +package kpring.server.repository import kpring.core.server.dto.request.GetServerCondition import kpring.server.domain.ServerProfile -interface GetServerProfilePort { +interface ServerProfileCustomRepository { + fun updateServerHost(serverProfile: ServerProfile) + fun get( serverId: String, userId: String, diff --git a/server/src/main/kotlin/kpring/server/adapter/output/mongo/GetServerProfileMongoImpl.kt b/server/src/main/kotlin/kpring/server/repository/ServerProfileCustomRepositoryImpl.kt similarity index 77% rename from server/src/main/kotlin/kpring/server/adapter/output/mongo/GetServerProfileMongoImpl.kt rename to server/src/main/kotlin/kpring/server/repository/ServerProfileCustomRepositoryImpl.kt index 7ac9778e..369a464a 100644 --- a/server/src/main/kotlin/kpring/server/adapter/output/mongo/GetServerProfileMongoImpl.kt +++ b/server/src/main/kotlin/kpring/server/repository/ServerProfileCustomRepositoryImpl.kt @@ -1,29 +1,53 @@ -package kpring.server.adapter.output.mongo +package kpring.server.repository import com.querydsl.core.types.dsl.BooleanExpression import kpring.core.global.exception.CommonErrorCode import kpring.core.global.exception.ServiceException import kpring.core.server.dto.request.GetServerCondition -import kpring.server.adapter.output.mongo.entity.QServerEntity -import kpring.server.adapter.output.mongo.entity.QServerProfileEntity -import kpring.server.adapter.output.mongo.repository.ServerProfileRepository -import kpring.server.adapter.output.mongo.repository.ServerRepository -import kpring.server.application.port.output.GetServerProfilePort import kpring.server.domain.ServerProfile import kpring.server.domain.ServerRole -import org.springframework.stereotype.Component - -@Component -class GetServerProfileMongoImpl( - val serverRepository: ServerRepository, +import kpring.server.entity.QServerEntity +import kpring.server.entity.QServerProfileEntity +import kpring.server.entity.ServerProfileEntity +import org.springframework.data.mongodb.core.MongoTemplate +import org.springframework.data.mongodb.core.query.Criteria +import org.springframework.data.mongodb.core.query.Query +import org.springframework.data.mongodb.core.query.Update +import org.springframework.stereotype.Repository + +@Repository +class ServerProfileCustomRepositoryImpl( + val template: MongoTemplate, val serverProfileRepository: ServerProfileRepository, -) : GetServerProfilePort { + val serverRepository: ServerRepository, +) : ServerProfileCustomRepository { + override fun updateServerHost(serverProfile: ServerProfile) { + val newRole = + if (serverProfile.role == ServerRole.OWNER) ServerRole.MEMBER else ServerRole.OWNER + template.updateFirst( + Query.query( + Criteria.where("_id").`is`(serverProfile.server.id) + .and("userId").`is`(serverProfile.userId) + .and("role").`is`(serverProfile.role), + ), + Update().set("role", newRole), + ServerProfileEntity::class.java, + ) + + serverProfileRepository.save(ServerProfileEntity(serverProfile)) + } + override fun get( serverId: String, userId: String, ): ServerProfile { // get server - val serverEntity = serverRepository.findById(serverId).orElseThrow { throw ServiceException(CommonErrorCode.NOT_FOUND) } + val serverEntity = + serverRepository.findById(serverId).orElseThrow { + throw ServiceException( + CommonErrorCode.NOT_FOUND, + ) + } // get server profile val qProfile = QServerProfileEntity.serverProfileEntity val serverProfileEntity = diff --git a/server/src/main/kotlin/kpring/server/adapter/output/mongo/repository/ServerProfileRepository.kt b/server/src/main/kotlin/kpring/server/repository/ServerProfileRepository.kt similarity index 78% rename from server/src/main/kotlin/kpring/server/adapter/output/mongo/repository/ServerProfileRepository.kt rename to server/src/main/kotlin/kpring/server/repository/ServerProfileRepository.kt index ff65c492..e915f1c5 100644 --- a/server/src/main/kotlin/kpring/server/adapter/output/mongo/repository/ServerProfileRepository.kt +++ b/server/src/main/kotlin/kpring/server/repository/ServerProfileRepository.kt @@ -1,6 +1,6 @@ -package kpring.server.adapter.output.mongo.repository +package kpring.server.repository -import kpring.server.adapter.output.mongo.entity.ServerProfileEntity +import kpring.server.entity.ServerProfileEntity import org.springframework.data.mongodb.repository.MongoRepository import org.springframework.data.querydsl.QuerydslPredicateExecutor import org.springframework.stereotype.Repository diff --git a/server/src/main/kotlin/kpring/server/adapter/output/mongo/repository/ServerRepository.kt b/server/src/main/kotlin/kpring/server/repository/ServerRepository.kt similarity index 72% rename from server/src/main/kotlin/kpring/server/adapter/output/mongo/repository/ServerRepository.kt rename to server/src/main/kotlin/kpring/server/repository/ServerRepository.kt index 414ff1c6..7a0b62ec 100644 --- a/server/src/main/kotlin/kpring/server/adapter/output/mongo/repository/ServerRepository.kt +++ b/server/src/main/kotlin/kpring/server/repository/ServerRepository.kt @@ -1,6 +1,6 @@ -package kpring.server.adapter.output.mongo.repository +package kpring.server.repository -import kpring.server.adapter.output.mongo.entity.ServerEntity +import kpring.server.entity.ServerEntity import org.springframework.data.mongodb.repository.MongoRepository import org.springframework.data.querydsl.QuerydslPredicateExecutor import org.springframework.stereotype.Repository diff --git a/server/src/main/kotlin/kpring/server/application/port/input/GetCategoryUseCase.kt b/server/src/main/kotlin/kpring/server/service/CategoryService.kt similarity index 53% rename from server/src/main/kotlin/kpring/server/application/port/input/GetCategoryUseCase.kt rename to server/src/main/kotlin/kpring/server/service/CategoryService.kt index f2dd3a61..6f5a9c04 100644 --- a/server/src/main/kotlin/kpring/server/application/port/input/GetCategoryUseCase.kt +++ b/server/src/main/kotlin/kpring/server/service/CategoryService.kt @@ -1,7 +1,7 @@ -package kpring.server.application.port.input +package kpring.server.service import kpring.core.server.dto.CategoryInfo -interface GetCategoryUseCase { +interface CategoryService { fun getCategories(): List } diff --git a/server/src/main/kotlin/kpring/server/application/service/CategoryService.kt b/server/src/main/kotlin/kpring/server/service/CategoryServiceImpl.kt similarity index 69% rename from server/src/main/kotlin/kpring/server/application/service/CategoryService.kt rename to server/src/main/kotlin/kpring/server/service/CategoryServiceImpl.kt index 9018fc67..652dcbe1 100644 --- a/server/src/main/kotlin/kpring/server/application/service/CategoryService.kt +++ b/server/src/main/kotlin/kpring/server/service/CategoryServiceImpl.kt @@ -1,12 +1,12 @@ -package kpring.server.application.service +package kpring.server.service import kpring.core.server.dto.CategoryInfo -import kpring.server.application.port.input.GetCategoryUseCase import kpring.server.domain.Category import org.springframework.stereotype.Service @Service -class CategoryService : GetCategoryUseCase { +class CategoryServiceImpl : + CategoryService { override fun getCategories(): List { return Category.entries.map { category -> CategoryInfo( diff --git a/server/src/main/kotlin/kpring/server/service/ServerService.kt b/server/src/main/kotlin/kpring/server/service/ServerService.kt new file mode 100644 index 00000000..945e895f --- /dev/null +++ b/server/src/main/kotlin/kpring/server/service/ServerService.kt @@ -0,0 +1,54 @@ +package kpring.server.service + +import kpring.core.server.dto.ServerInfo +import kpring.core.server.dto.ServerSimpleInfo +import kpring.core.server.dto.request.AddUserAtServerRequest +import kpring.core.server.dto.request.CreateServerRequest +import kpring.core.server.dto.request.GetServerCondition +import kpring.core.server.dto.request.UpdateHostAtServerRequest +import kpring.core.server.dto.response.CreateServerResponse +import kpring.server.domain.Server + +interface ServerService { + fun createServer(req: CreateServerRequest): CreateServerResponse + + fun getServerInfo(serverId: String): ServerInfo + + fun getServerList( + condition: GetServerCondition, + userId: String, + ): List + + fun getOwnedServerList(userId: String): List + + fun inviteUser( + serverId: String, + invitorId: String, + userId: String, + ) + + fun addInvitedUser( + serverId: String, + req: AddUserAtServerRequest, + ) + + fun deleteServer( + serverId: String, + userId: String, + ) + + fun deleteServerMember( + serverId: String, + userId: String, + ) + + fun updateServerHost( + serverId: String, + userId: String, + otherUser: UpdateHostAtServerRequest, + ) + + fun delete(serverId: String) + + fun get(id: String): Server +} diff --git a/server/src/main/kotlin/kpring/server/application/service/ServerService.kt b/server/src/main/kotlin/kpring/server/service/ServerServiceImpl.kt similarity index 68% rename from server/src/main/kotlin/kpring/server/application/service/ServerService.kt rename to server/src/main/kotlin/kpring/server/service/ServerServiceImpl.kt index 70d79947..f3c5dcaa 100644 --- a/server/src/main/kotlin/kpring/server/application/service/ServerService.kt +++ b/server/src/main/kotlin/kpring/server/service/ServerServiceImpl.kt @@ -1,4 +1,4 @@ -package kpring.server.application.service +package kpring.server.service import kpring.core.global.exception.CommonErrorCode import kpring.core.global.exception.ServiceException @@ -10,32 +10,28 @@ import kpring.core.server.dto.request.CreateServerRequest import kpring.core.server.dto.request.GetServerCondition import kpring.core.server.dto.request.UpdateHostAtServerRequest import kpring.core.server.dto.response.CreateServerResponse -import kpring.server.application.port.input.* -import kpring.server.application.port.output.* import kpring.server.domain.Category import kpring.server.domain.Server import kpring.server.domain.ServerAuthority import kpring.server.domain.ServerRole +import kpring.server.repository.ServerCustomRepository +import kpring.server.repository.ServerProfileCustomRepository +import kpring.server.repository.ServerProfileRepository +import kpring.server.repository.ServerRepository import kpring.server.util.toInfo import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional @Service -class ServerService( - val createServerPort: SaveServerPort, - val getServer: GetServerPort, - val getServerProfilePort: GetServerProfilePort, - val updateServerPort: UpdateServerPort, - val updateServerProfilePort: UpdateServerProfilePort, - val deleteServerPort: DeleteServerPort, -) : CreateServerUseCase, - GetServerInfoUseCase, - AddUserAtServerUseCase, - DeleteServerUseCase, - UpdateHostAtServerUseCase { +class ServerServiceImpl( + val serverRepository: ServerRepository, + val serverProfileRepository: ServerProfileRepository, + val serverCustomRepository: ServerCustomRepository, + val serverProfileCustomRepository: ServerProfileCustomRepository, +) : ServerService { override fun createServer(req: CreateServerRequest): CreateServerResponse { val server = - createServerPort.create( + serverCustomRepository.create( Server( name = req.serverName, users = mutableSetOf(req.userId), @@ -55,8 +51,8 @@ class ServerService( } override fun getServerInfo(serverId: String): ServerInfo { - val server = getServer.get(serverId) - val serverProfiles = getServerProfilePort.getAll(server.id!!) + val server = get(serverId) + val serverProfiles = serverProfileCustomRepository.getAll(server.id!!) return ServerInfo( id = server.id, name = server.name, @@ -77,7 +73,7 @@ class ServerService( condition: GetServerCondition, userId: String, ): List { - return getServerProfilePort.getProfiles(condition, userId) + return serverProfileCustomRepository.getProfiles(condition, userId) .map { profile -> ServerSimpleInfo( id = profile.server.id!!, @@ -91,7 +87,7 @@ class ServerService( } override fun getOwnedServerList(userId: String): List { - return getServerProfilePort.getOwnedProfiles(userId) + return serverProfileCustomRepository.getOwnedProfiles(userId) .map { profile -> ServerSimpleInfo( id = profile.server.id!!, @@ -111,14 +107,14 @@ class ServerService( userId: String, ) { // validate invitor authority - val serverProfile = getServerProfilePort.get(serverId, invitorId) + val serverProfile = serverProfileCustomRepository.get(serverId, invitorId) if (serverProfile.dontHasRole(ServerAuthority.INVITE)) { throw ServiceException(CommonErrorCode.FORBIDDEN) } // register invitation val server = serverProfile.server server.registerInvitation(userId) - updateServerPort.inviteUser(server.id!!, userId) + serverCustomRepository.inviteUser(server.id!!, userId) } @Transactional @@ -126,31 +122,31 @@ class ServerService( serverId: String, req: AddUserAtServerRequest, ) { - val server = getServer.get(serverId) + val server = get(serverId) val profile = server.addUser(req.userId, req.userName, req.profileImage) - updateServerPort.addUser(profile) + serverCustomRepository.addUser(profile) } override fun deleteServer( serverId: String, userId: String, ) { - val serverProfile = getServerProfilePort.get(serverId, userId) + val serverProfile = serverProfileCustomRepository.get(serverId, userId) if (serverProfile.dontHasRole(ServerAuthority.DELETE)) { throw ServiceException(CommonErrorCode.FORBIDDEN) } - deleteServerPort.delete(serverId) + delete(serverId) } override fun deleteServerMember( serverId: String, userId: String, ) { - val serverProfile = getServerProfilePort.get(serverId, userId) + val serverProfile = serverProfileCustomRepository.get(serverId, userId) if (serverProfile.role == ServerRole.OWNER) { throw ServiceException(CommonErrorCode.FORBIDDEN) } - deleteServerPort.deleteMember(serverProfile) + serverCustomRepository.deleteMember(serverProfile) } override fun updateServerHost( @@ -158,8 +154,8 @@ class ServerService( userId: String, otherUser: UpdateHostAtServerRequest, ) { - val hostServerProfile = getServerProfilePort.get(serverId, userId) - val newHostServerProfile = getServerProfilePort.get(serverId, otherUser.userId) + val hostServerProfile = serverProfileCustomRepository.get(serverId, userId) + val newHostServerProfile = serverProfileCustomRepository.get(serverId, otherUser.userId) if (hostServerProfile.role != ServerRole.OWNER) { throw ServiceException(CommonErrorCode.FORBIDDEN) @@ -167,11 +163,24 @@ class ServerService( val server = hostServerProfile.server server.updateServerHost(otherUser.userId, otherUser.userName) - updateServerPort.updateServerHost(serverId, userId, otherUser) + serverCustomRepository.updateServerHost(serverId, userId, otherUser) hostServerProfile.updateServerHost(hostServerProfile) newHostServerProfile.updateServerHost(newHostServerProfile) - updateServerProfilePort.updateServerHost(hostServerProfile) - updateServerProfilePort.updateServerHost(newHostServerProfile) + serverProfileCustomRepository.updateServerHost(hostServerProfile) + serverProfileCustomRepository.updateServerHost(newHostServerProfile) + } + + override fun delete(serverId: String) { + serverRepository.deleteById(serverId) + serverProfileRepository.deleteByServerId(serverId) + } + + override fun get(id: String): Server { + val serverEntity = + serverRepository.findById(id) + .orElseThrow { throw ServiceException(CommonErrorCode.NOT_FOUND) } + + return serverEntity.toDomain() } } diff --git a/server/src/test/kotlin/kpring/server/adapter/output/mongo/repository/ServerProfileRepositoryTest.kt b/server/src/test/kotlin/kpring/server/adapter/output/mongo/repository/ServerProfileRepositoryTest.kt deleted file mode 100644 index b8af249b..00000000 --- a/server/src/test/kotlin/kpring/server/adapter/output/mongo/repository/ServerProfileRepositoryTest.kt +++ /dev/null @@ -1,48 +0,0 @@ -package kpring.server.adapter.output.mongo.repository - -import io.kotest.core.spec.style.DescribeSpec -import io.kotest.matchers.collections.shouldHaveSize -import kpring.server.adapter.output.mongo.entity.QServerProfileEntity -import kpring.server.adapter.output.mongo.entity.ServerProfileEntity -import kpring.server.domain.ServerRole -import kpring.test.testcontainer.SpringTestContext -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.test.context.ContextConfiguration - -@SpringBootTest -@ContextConfiguration(initializers = [SpringTestContext.SpringDataMongo::class]) -class ServerProfileRepositoryTest( - serverProfileRepository: ServerProfileRepository, -) : DescribeSpec({ - - it("특정한 서버 아이디를 가지는 프로파일을 삭제한다.") { - // given - val qProfile = QServerProfileEntity.serverProfileEntity - val serverId = "serverId" - - repeat(3) { index -> - val serverProfileEntity = - ServerProfileEntity( - id = null, - userId = "userId $index", - name = "name $index", - imagePath = "imagePath/$index", - serverId = serverId, - role = ServerRole.MEMBER, - bookmarked = false, - ) - serverProfileRepository.save(serverProfileEntity) - } - - // when - serverProfileRepository.deleteByServerId(serverId) - - // then - val result = - serverProfileRepository.findAll( - qProfile.serverId.eq(serverId), - ) - - result shouldHaveSize 0 - } - }) diff --git a/server/src/test/kotlin/kpring/server/application/port/input/AddUserAtServerUseCaseTest.kt b/server/src/test/kotlin/kpring/server/application/port/input/AddUserAtServerUseCaseTest.kt deleted file mode 100644 index 563a2c26..00000000 --- a/server/src/test/kotlin/kpring/server/application/port/input/AddUserAtServerUseCaseTest.kt +++ /dev/null @@ -1,57 +0,0 @@ -package kpring.server.application.port.input - -import io.kotest.assertions.throwables.shouldThrow -import io.kotest.core.spec.style.DescribeSpec -import io.kotest.matchers.shouldBe -import io.mockk.every -import io.mockk.mockk -import kpring.core.global.exception.CommonErrorCode -import kpring.core.global.exception.ServiceException -import kpring.server.application.port.output.* -import kpring.server.application.service.ServerService -import kpring.server.domain.ServerProfile -import kpring.server.domain.ServerRole -import kpring.server.util.testServer - -class AddUserAtServerUseCaseTest( - val getServerPort: GetServerPort = mockk(), - val getServerProfilePort: GetServerProfilePort = mockk(), - val updateServerPort: UpdateServerPort = mockk(), - val updateServerProfilePort: UpdateServerProfilePort = mockk(), - val deleteServerPort: DeleteServerPort = mockk(), - val service: ServerService = - ServerService(mockk(), getServerPort, getServerProfilePort, updateServerPort, updateServerProfilePort, deleteServerPort), -) : DescribeSpec({ - - it("유저 초대시 초대하는 유저가 권한이 없다면 예외를 던진다") { - // given - val invitorId = "invitorId" - val server = testServer() - val userId = server.host.id - val serverId = server.id!! - - server.invitedUserIds.add(invitorId) - - val serverProfile = - ServerProfile( - id = null, - userId = invitorId, - name = "invitor", - imagePath = "imagePath", - role = ServerRole.MEMBER, - server = server, - ) - - every { getServerPort.get(serverId) } returns server - every { getServerProfilePort.get(serverId, invitorId) } returns serverProfile - - // when - val ex = - shouldThrow { - service.inviteUser(serverId, invitorId, userId) - } - - // then - ex.errorCode shouldBe CommonErrorCode.FORBIDDEN - } - }) diff --git a/server/src/test/kotlin/kpring/server/application/port/input/DeleteServerUseCaseTest.kt b/server/src/test/kotlin/kpring/server/application/port/input/DeleteServerUseCaseTest.kt deleted file mode 100644 index 6638f93b..00000000 --- a/server/src/test/kotlin/kpring/server/application/port/input/DeleteServerUseCaseTest.kt +++ /dev/null @@ -1,51 +0,0 @@ -package kpring.server.application.port.input - -import io.kotest.assertions.throwables.shouldThrow -import io.kotest.core.spec.style.DescribeSpec -import io.kotest.matchers.shouldBe -import io.mockk.every -import io.mockk.mockk -import kpring.core.global.exception.CommonErrorCode -import kpring.core.global.exception.ServiceException -import kpring.server.application.port.output.* -import kpring.server.application.service.ServerService -import kpring.server.domain.ServerProfile -import kpring.server.domain.ServerRole -import kpring.server.util.testServer - -class DeleteServerUseCaseTest( - val getServerPort: GetServerPort = mockk(), - val getServerProfilePort: GetServerProfilePort = mockk(), - val updateServerPort: UpdateServerPort = mockk(), - val updateServerProfilePort: UpdateServerProfilePort = mockk(), - val deleteServerPort: DeleteServerPort = mockk(), - val service: ServerService = - ServerService(mockk(), getServerPort, getServerProfilePort, updateServerPort, updateServerProfilePort, deleteServerPort), -) : DescribeSpec({ - it("삭제하는 서버에 대한 삭제 권한이 없는 유저라면 예외가 발생한다.") { - // given - val server = testServer() - val serverId = server.id!! - val userId = server.host.id - val serverProfile = - ServerProfile( - id = null, - userId = userId, - name = "name", - imagePath = "/imagePath", - role = ServerRole.MEMBER, - server = server, - ) - - every { getServerProfilePort.get(serverId, userId) } returns serverProfile - - // when - val ex = - shouldThrow { - service.deleteServer(serverId, userId) - } - - // then - ex.errorCode shouldBe CommonErrorCode.FORBIDDEN - } - }) diff --git a/server/src/test/kotlin/kpring/server/application/port/output/GetServerPortTest.kt b/server/src/test/kotlin/kpring/server/application/port/output/GetServerPortTest.kt deleted file mode 100644 index caa60a5a..00000000 --- a/server/src/test/kotlin/kpring/server/application/port/output/GetServerPortTest.kt +++ /dev/null @@ -1,81 +0,0 @@ -package kpring.server.application.port.output - -import io.kotest.assertions.throwables.shouldThrow -import io.kotest.core.spec.style.DescribeSpec -import io.kotest.matchers.collections.shouldContainAll -import io.kotest.matchers.collections.shouldHaveSize -import io.kotest.matchers.shouldBe -import kpring.core.global.exception.CommonErrorCode -import kpring.core.global.exception.ServiceException -import kpring.server.adapter.output.mongo.entity.ServerEntity -import kpring.server.adapter.output.mongo.repository.ServerRepository -import kpring.server.util.testServer -import kpring.test.testcontainer.SpringTestContext -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.test.context.ContextConfiguration - -@SpringBootTest -@ContextConfiguration(initializers = [SpringTestContext.SpringDataMongo::class]) -class GetServerPortTest( - val getServerPort: GetServerPort, - val serverRepository: ServerRepository, -) : DescribeSpec({ - it("존재하지 서버 id를 조회하는 경우 에러가 발생한다.") { - // given - val notExistServerId = "notExistServerId" - - // when - val ex = - shouldThrow { - getServerPort.get(notExistServerId) - } - - // then - ex.errorCode shouldBe CommonErrorCode.NOT_FOUND - } - - it("저장된 서버의 정보를 조회할 수 있다.") { - // given - val domain = testServer() - val serverEntity = serverRepository.save(ServerEntity(domain)) - - // when - val server = getServerPort.get(serverEntity.id!!) - - // then - server.name shouldBe domain.name - server.users shouldHaveSize domain.users.size - server.users shouldContainAll domain.users - } - - it("존재하지 않은 서버를 조회하면 예외가 발생한다.") { - // when - val exception = - shouldThrow { - getServerPort.get("not-exist") - } - - // then - exception.errorCode shouldBe CommonErrorCode.NOT_FOUND - } - - it("유저가 속한 서버 목록을 조회할 수 있다.") { - // given - val userId = "test-user" - val server = testServer(id = null, hostId = userId) - - repeat(2) { - serverRepository.save(ServerEntity(server)) - } - - // when - val servers = getServerPort.getServerWith(userId) - - // then - servers shouldHaveSize 2 - servers.forEach { - it.users shouldHaveSize server.users.size - it.users shouldContainAll server.users - } - } - }) diff --git a/server/src/test/kotlin/kpring/server/application/port/output/SaveServerPortTest.kt b/server/src/test/kotlin/kpring/server/application/port/output/SaveServerPortTest.kt deleted file mode 100644 index 0788c15b..00000000 --- a/server/src/test/kotlin/kpring/server/application/port/output/SaveServerPortTest.kt +++ /dev/null @@ -1,32 +0,0 @@ -package kpring.server.application.port.output - -import io.kotest.core.spec.style.DescribeSpec -import io.kotest.matchers.shouldBe -import kpring.server.domain.ServerRole -import kpring.server.util.testServer -import kpring.test.testcontainer.SpringTestContext -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.test.context.ContextConfiguration - -@SpringBootTest -@ContextConfiguration(initializers = [SpringTestContext.SpringDataMongo::class]) -class SaveServerPortTest( - val saveServerPort: SaveServerPort, - val getServerProfilePort: GetServerProfilePort, -) : DescribeSpec({ - - it("서버를 저장하면 생성한 유저는 서버의 소유자가 된다.") { - // given - val domain = testServer(id = null) - val userId = domain.host.id - - // when - val server = saveServerPort.create(domain) - val profile = getServerProfilePort.get(server.id!!, userId) - - // then - server.host.id shouldBe domain.host.id - server.host.name shouldBe domain.host.name - profile.role shouldBe ServerRole.OWNER - } - }) diff --git a/server/src/test/kotlin/kpring/server/application/port/output/UpdateServerPortTest.kt b/server/src/test/kotlin/kpring/server/application/port/output/UpdateServerPortTest.kt deleted file mode 100644 index 3a1388b9..00000000 --- a/server/src/test/kotlin/kpring/server/application/port/output/UpdateServerPortTest.kt +++ /dev/null @@ -1,91 +0,0 @@ -package kpring.server.application.port.output - -import io.kotest.core.spec.style.DescribeSpec -import io.kotest.matchers.collections.shouldContain -import io.kotest.matchers.collections.shouldHaveSize -import io.kotest.matchers.equals.shouldBeEqual -import kpring.core.server.dto.request.UpdateHostAtServerRequest -import kpring.server.domain.Theme -import kpring.server.util.testServer -import kpring.test.testcontainer.SpringTestContext -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.test.context.ContextConfiguration - -@ContextConfiguration(initializers = [SpringTestContext.SpringDataMongo::class]) -@SpringBootTest -class UpdateServerPortTest( - val updateServerPort: UpdateServerPort, - val createServerPort: SaveServerPort, - val getServerProfilePort: GetServerProfilePort, - val getServerPort: GetServerPort, -) : DescribeSpec({ - - it("유저를 초대가 작동한다.") { - // given - val server = createServerPort.create(testServer(id = null)) - - // when - repeat(5) { - val userId = "test$it" - server.registerInvitation(userId) - updateServerPort.inviteUser(server.id!!, userId) - } - - // then - val result = getServerPort.get(server.id!!) - result.invitedUserIds shouldHaveSize server.invitedUserIds.size - } - - it("가입 유저를 추가할 수 있다.") { - // given - val server = createServerPort.create(testServer(id = null, users = mutableSetOf())) - val userId = "userId" - - server.registerInvitation(userId) - updateServerPort.inviteUser(server.id!!, userId) - val profile = server.addUser(userId, "name", "/path") - - // when - updateServerPort.addUser(profile) - - // then - val result = getServerPort.get(server.id!!) - - getServerProfilePort.getAll(server.id!!) shouldHaveSize server.users.size - result.users.size shouldBeEqual server.users.size - result.users shouldContain userId - result.invitedUserIds shouldHaveSize server.invitedUserIds.size - } - - it("서버 권한을 다른 사용자에게 상속한다.") { - // given - val userId = "userId" - val username = "username" - val newHostId = "new_host_id" - val newHostName = "new_host_name" - val otherUser = UpdateHostAtServerRequest(newHostId, newHostName) - val server = - createServerPort.create( - testServer( - id = null, - name = "", - users = mutableSetOf(userId, newHostId), - invitedUserIds = mutableSetOf(), - theme = Theme.default(), - categories = setOf(), - hostId = userId, - hostName = username, - ), - ) - - server.updateServerHost(newHostId, newHostName) - - // when - updateServerPort.updateServerHost(server.id!!, userId, otherUser) - - // then - val result = getServerPort.get(server.id!!) - result.host.id shouldBeEqual newHostId - result.host.name shouldBeEqual newHostName - } - }) diff --git a/server/src/test/kotlin/kpring/server/adapter/input/rest/CategoryControllerTest.kt b/server/src/test/kotlin/kpring/server/controller/CategoryControllerTest.kt similarity index 89% rename from server/src/test/kotlin/kpring/server/adapter/input/rest/CategoryControllerTest.kt rename to server/src/test/kotlin/kpring/server/controller/CategoryControllerTest.kt index 9f394f82..b10069f3 100644 --- a/server/src/test/kotlin/kpring/server/adapter/input/rest/CategoryControllerTest.kt +++ b/server/src/test/kotlin/kpring/server/controller/CategoryControllerTest.kt @@ -1,4 +1,4 @@ -package kpring.server.adapter.input.rest +package kpring.server.controller import com.fasterxml.jackson.databind.ObjectMapper import com.ninjasquad.springmockk.MockkBean @@ -7,9 +7,9 @@ import io.mockk.junit5.MockKExtension import kpring.core.auth.client.AuthClient import kpring.core.global.dto.response.ApiResponse import kpring.core.server.dto.CategoryInfo -import kpring.server.application.service.CategoryService -import kpring.server.application.service.ServerService import kpring.server.config.CoreConfiguration +import kpring.server.service.CategoryServiceImpl +import kpring.server.service.ServerServiceImpl import kpring.test.restdoc.dsl.restDoc import kpring.test.web.MvcWebTestClientDescribeSpec import org.junit.jupiter.api.extension.ExtendWith @@ -32,9 +32,9 @@ import org.springframework.web.context.WebApplicationContext class CategoryControllerTest( private val om: ObjectMapper, webContext: WebApplicationContext, - @MockkBean val serverService: ServerService, + @MockkBean val serverService: ServerServiceImpl, @MockkBean val authClient: AuthClient, - @MockkBean val categoryService: CategoryService, + @MockkBean val categoryService: CategoryServiceImpl, ) : MvcWebTestClientDescribeSpec( "Rest api server category controller test", webContext, diff --git a/server/src/test/kotlin/kpring/server/adapter/input/rest/RestApiServerControllerTest.kt b/server/src/test/kotlin/kpring/server/controller/RestApiServerControllerTest.kt similarity index 98% rename from server/src/test/kotlin/kpring/server/adapter/input/rest/RestApiServerControllerTest.kt rename to server/src/test/kotlin/kpring/server/controller/RestApiServerControllerTest.kt index 4d822080..ce21768c 100644 --- a/server/src/test/kotlin/kpring/server/adapter/input/rest/RestApiServerControllerTest.kt +++ b/server/src/test/kotlin/kpring/server/controller/RestApiServerControllerTest.kt @@ -1,4 +1,4 @@ -package kpring.server.adapter.input.rest +package kpring.server.controller import com.fasterxml.jackson.databind.ObjectMapper import com.ninjasquad.springmockk.MockkBean @@ -20,11 +20,11 @@ import kpring.core.server.dto.request.CreateServerRequest import kpring.core.server.dto.request.GetServerCondition import kpring.core.server.dto.request.UpdateHostAtServerRequest import kpring.core.server.dto.response.CreateServerResponse -import kpring.server.application.service.CategoryService -import kpring.server.application.service.ServerService import kpring.server.config.CoreConfiguration import kpring.server.domain.Category import kpring.server.domain.Theme +import kpring.server.service.CategoryServiceImpl +import kpring.server.service.ServerServiceImpl import kpring.server.util.toInfo import kpring.test.restdoc.dsl.restDoc import kpring.test.restdoc.json.JsonDataType.* @@ -50,9 +50,9 @@ import org.springframework.web.context.WebApplicationContext class RestApiServerControllerTest( private val om: ObjectMapper, webContext: WebApplicationContext, - @MockkBean val serverService: ServerService, + @MockkBean val serverService: ServerServiceImpl, @MockkBean val authClient: AuthClient, - @MockkBean val categoryService: CategoryService, + @MockkBean val categoryService: CategoryServiceImpl, ) : MvcWebTestClientDescribeSpec( testMethodName = "RestApiServerControllerTest", webContext = webContext, diff --git a/server/src/test/kotlin/kpring/server/application/port/output/GetServerProfilePortTest.kt b/server/src/test/kotlin/kpring/server/repository/ServerProfileRepositoryTest.kt similarity index 52% rename from server/src/test/kotlin/kpring/server/application/port/output/GetServerProfilePortTest.kt rename to server/src/test/kotlin/kpring/server/repository/ServerProfileRepositoryTest.kt index e228df4d..59fdc23c 100644 --- a/server/src/test/kotlin/kpring/server/application/port/output/GetServerProfilePortTest.kt +++ b/server/src/test/kotlin/kpring/server/repository/ServerProfileRepositoryTest.kt @@ -1,13 +1,13 @@ -package kpring.server.application.port.output +package kpring.server.repository import io.kotest.core.spec.style.DescribeSpec import io.kotest.matchers.collections.shouldHaveSize import kpring.core.server.dto.request.GetServerCondition -import kpring.server.adapter.output.mongo.entity.ServerEntity -import kpring.server.adapter.output.mongo.entity.ServerProfileEntity -import kpring.server.adapter.output.mongo.repository.ServerProfileRepository -import kpring.server.adapter.output.mongo.repository.ServerRepository -import kpring.server.domain.* +import kpring.server.domain.ServerProfile +import kpring.server.domain.ServerRole +import kpring.server.entity.QServerProfileEntity +import kpring.server.entity.ServerEntity +import kpring.server.entity.ServerProfileEntity import kpring.server.util.testServer import kpring.test.testcontainer.SpringTestContext import org.springframework.boot.test.context.SpringBootTest @@ -15,12 +15,43 @@ import org.springframework.test.context.ContextConfiguration @SpringBootTest @ContextConfiguration(initializers = [SpringTestContext.SpringDataMongo::class]) -class GetServerProfilePortTest( - val getServerProfilePort: GetServerProfilePort, - val serverRepository: ServerRepository, - val serverProfileRepository: ServerProfileRepository, +class ServerProfileRepositoryTest( + serverProfileRepository: ServerProfileRepository, + serverRepository: ServerRepository, + serverProfileCustomRepository: ServerProfileCustomRepository, ) : DescribeSpec({ + it("특정한 서버 아이디를 가지는 프로파일을 삭제한다.") { + // given + val qProfile = QServerProfileEntity.serverProfileEntity + val serverId = "serverId" + + repeat(3) { index -> + val serverProfileEntity = + ServerProfileEntity( + id = null, + userId = "userId $index", + name = "name $index", + imagePath = "imagePath/$index", + serverId = serverId, + role = ServerRole.MEMBER, + bookmarked = false, + ) + serverProfileRepository.save(serverProfileEntity) + } + + // when + serverProfileRepository.deleteByServerId(serverId) + + // then + val result = + serverProfileRepository.findAll( + qProfile.serverId.eq(serverId), + ) + + result shouldHaveSize 0 + } + describe("서버 프로필 조회") { it("제한된 서버 프로필을 조회하는 조건을 사용한다면 모든 프로필을 조회하지 않고 조건에 해당하는 서버 프로필만을 조회한다.") { @@ -46,7 +77,7 @@ class GetServerProfilePortTest( val condition = GetServerCondition(serverIds = listOf(serverEntity1.id!!)) // when - val serverProfiles = getServerProfilePort.getProfiles(condition, "testUserId") + val serverProfiles = serverProfileCustomRepository.getProfiles(condition, "testUserId") // then serverProfiles shouldHaveSize 1 diff --git a/server/src/test/kotlin/kpring/server/repository/ServerRepositoryTest.kt b/server/src/test/kotlin/kpring/server/repository/ServerRepositoryTest.kt new file mode 100644 index 00000000..5c205c48 --- /dev/null +++ b/server/src/test/kotlin/kpring/server/repository/ServerRepositoryTest.kt @@ -0,0 +1,172 @@ +package kpring.server.repository + +import io.kotest.assertions.throwables.shouldThrow +import io.kotest.core.spec.style.DescribeSpec +import io.kotest.matchers.collections.shouldContain +import io.kotest.matchers.collections.shouldContainAll +import io.kotest.matchers.collections.shouldHaveSize +import io.kotest.matchers.equals.shouldBeEqual +import io.kotest.matchers.shouldBe +import kpring.core.global.exception.CommonErrorCode +import kpring.core.global.exception.ServiceException +import kpring.core.server.dto.request.UpdateHostAtServerRequest +import kpring.server.domain.ServerRole +import kpring.server.domain.Theme +import kpring.server.entity.ServerEntity +import kpring.server.service.ServerService +import kpring.server.util.testServer +import kpring.test.testcontainer.SpringTestContext +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.test.context.ContextConfiguration + +@SpringBootTest +@ContextConfiguration(initializers = [SpringTestContext.SpringDataMongo::class]) +class ServerRepositoryTest( + serverRepository: ServerRepository, + serverCustomRepository: ServerCustomRepository, + serverProfileCustomRepository: ServerProfileCustomRepository, + service: ServerService, +) : DescribeSpec({ + it("유저를 초대가 작동한다.") { + // given + val server = serverCustomRepository.create(testServer(id = null)) + + // when + repeat(5) { + val userId = "test$it" + server.registerInvitation(userId) + serverCustomRepository.inviteUser(server.id!!, userId) + } + + // then + val result = service.get(server.id!!) + result.invitedUserIds shouldHaveSize server.invitedUserIds.size + } + + it("가입 유저를 추가할 수 있다.") { + // given + val server = serverCustomRepository.create(testServer(id = null, users = mutableSetOf())) + val userId = "userId" + + server.registerInvitation(userId) + serverCustomRepository.inviteUser(server.id!!, userId) + val profile = server.addUser(userId, "name", "/path") + + // when + serverCustomRepository.addUser(profile) + + // then + val result = service.get(server.id!!) + + serverProfileCustomRepository.getAll(server.id!!) shouldHaveSize server.users.size + result.users.size shouldBeEqual server.users.size + result.users shouldContain userId + result.invitedUserIds shouldHaveSize server.invitedUserIds.size + } + + it("서버 권한을 다른 사용자에게 상속한다.") { + // given + val userId = "userId" + val username = "username" + val newHostId = "new_host_id" + val newHostName = "new_host_name" + val otherUser = UpdateHostAtServerRequest(newHostId, newHostName) + val server = + serverCustomRepository.create( + testServer( + id = null, + name = "", + users = mutableSetOf(userId, newHostId), + invitedUserIds = mutableSetOf(), + theme = Theme.default(), + categories = setOf(), + hostId = userId, + hostName = username, + ), + ) + + server.updateServerHost(newHostId, newHostName) + + // when + serverCustomRepository.updateServerHost(server.id!!, userId, otherUser) + + // then + val result = service.get(server.id!!) + result.host.id shouldBeEqual newHostId + result.host.name shouldBeEqual newHostName + } + + it("존재하지 서버 id를 조회하는 경우 에러가 발생한다.") { + // given + val notExistServerId = "notExistServerId" + + // when + val ex = + shouldThrow { + service.get(notExistServerId) + } + + // then + ex.errorCode shouldBe CommonErrorCode.NOT_FOUND + } + + it("저장된 서버의 정보를 조회할 수 있다.") { + // given + val domain = testServer() + val serverEntity = serverRepository.save(ServerEntity(domain)) + + // when + val server = service.get(serverEntity.id!!) + + // then + server.name shouldBe domain.name + server.users shouldHaveSize domain.users.size + server.users shouldContainAll domain.users + } + + it("존재하지 않은 서버를 조회하면 예외가 발생한다.") { + // when + val exception = + shouldThrow { + service.get("not-exist") + } + + // then + exception.errorCode shouldBe CommonErrorCode.NOT_FOUND + } + + it("유저가 속한 서버 목록을 조회할 수 있다.") { + // given + val userId = "test-user" + val server = testServer(id = null, hostId = userId) + + repeat(2) { + serverRepository.save(ServerEntity(server)) + } + + // when + val servers = serverCustomRepository.getServerWith(userId) + + // then + servers shouldHaveSize 2 + servers.forEach { + it.users shouldHaveSize server.users.size + it.users shouldContainAll server.users + } + } + + it("서버를 저장하면 생성한 유저는 서버의 소유자가 된다.") { + // given + val domain = testServer(id = null) + val userId = domain.host.id + + // when + val server = serverCustomRepository.create(domain) + val profile = serverProfileCustomRepository.get(server.id!!, userId) + + // then + server.host.id shouldBe domain.host.id + server.host.name shouldBe domain.host.name + profile.role shouldBe ServerRole.OWNER + } + }) diff --git a/server/src/test/kotlin/kpring/server/application/service/CategoryServiceTest.kt b/server/src/test/kotlin/kpring/server/service/CategoryServiceTest.kt similarity index 57% rename from server/src/test/kotlin/kpring/server/application/service/CategoryServiceTest.kt rename to server/src/test/kotlin/kpring/server/service/CategoryServiceTest.kt index fcf1981d..ead3445c 100644 --- a/server/src/test/kotlin/kpring/server/application/service/CategoryServiceTest.kt +++ b/server/src/test/kotlin/kpring/server/service/CategoryServiceTest.kt @@ -1,4 +1,4 @@ -package kpring.server.application.service +package kpring.server.service import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.shouldBe @@ -9,7 +9,7 @@ class CategoryServiceTest : FunSpec({ test("카테고리 목록 조회시 하드 코딩된 카테고리 정보를 조회한다.") { // given - val categoryService = CategoryService() + val categoryService = CategoryServiceImpl() // when val categories = categoryService.getCategories() @@ -17,8 +17,14 @@ class CategoryServiceTest : FunSpec({ // then categories shouldBe listOf( - CategoryInfo(id = Category.SERVER_CATEGORY1.name, name = Category.SERVER_CATEGORY1.toString()), - CategoryInfo(id = Category.SERVER_CATEGORY2.name, name = Category.SERVER_CATEGORY2.toString()), + CategoryInfo( + id = Category.SERVER_CATEGORY1.name, + name = Category.SERVER_CATEGORY1.toString(), + ), + CategoryInfo( + id = Category.SERVER_CATEGORY2.name, + name = Category.SERVER_CATEGORY2.toString(), + ), ) println(categories) } diff --git a/server/src/test/kotlin/kpring/server/service/ServerServiceTest.kt b/server/src/test/kotlin/kpring/server/service/ServerServiceTest.kt new file mode 100644 index 00000000..54ed2ed2 --- /dev/null +++ b/server/src/test/kotlin/kpring/server/service/ServerServiceTest.kt @@ -0,0 +1,89 @@ +package kpring.server.service + +import io.kotest.assertions.throwables.shouldThrow +import io.kotest.core.spec.style.DescribeSpec +import io.kotest.matchers.shouldBe +import io.mockk.every +import io.mockk.mockk +import kpring.core.global.exception.CommonErrorCode +import kpring.core.global.exception.ServiceException +import kpring.server.domain.ServerProfile +import kpring.server.domain.ServerRole +import kpring.server.repository.ServerCustomRepository +import kpring.server.repository.ServerProfileCustomRepository +import kpring.server.repository.ServerProfileRepository +import kpring.server.repository.ServerRepository +import kpring.server.util.testServer + +class ServerServiceTest( + val serverRepository: ServerRepository = mockk(), + val serverProfileRepository: ServerProfileRepository = mockk(), + val serverCustomRepository: ServerCustomRepository = mockk(), + val serverProfileCustomRepository: ServerProfileCustomRepository = mockk(), + val service: ServerServiceImpl = + ServerServiceImpl( + serverRepository, + serverProfileRepository, + serverCustomRepository, + serverProfileCustomRepository, + ), +) : DescribeSpec({ + it("유저 초대시 초대하는 유저가 권한이 없다면 예외를 던진다") { + // given + val invitorId = "invitorId" + val server = testServer() + val userId = server.host.id + val serverId = server.id!! + + server.invitedUserIds.add(invitorId) + + val serverProfile = + ServerProfile( + id = null, + userId = invitorId, + name = "invitor", + imagePath = "imagePath", + role = ServerRole.MEMBER, + server = server, + ) + + every { service.get(serverId) } returns server + every { serverProfileCustomRepository.get(serverId, invitorId) } returns serverProfile + + // when + val ex = + shouldThrow { + service.inviteUser(serverId, invitorId, userId) + } + + // then + ex.errorCode shouldBe CommonErrorCode.FORBIDDEN + } + + it("삭제하는 서버에 대한 삭제 권한이 없는 유저라면 예외가 발생한다.") { + // given + val server = testServer() + val serverId = server.id!! + val userId = server.host.id + val serverProfile = + ServerProfile( + id = null, + userId = userId, + name = "name", + imagePath = "/imagePath", + role = ServerRole.MEMBER, + server = server, + ) + + every { serverProfileCustomRepository.get(serverId, userId) } returns serverProfile + + // when + val ex = + shouldThrow { + service.deleteServer(serverId, userId) + } + + // then + ex.errorCode shouldBe CommonErrorCode.FORBIDDEN + } + })