Skip to content

Commit

Permalink
feat :: 여러 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
HyunSu1768 committed May 7, 2024
1 parent eb8ff2b commit e25d800
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import xquare.app.xquareinfra.domain.container.adapter.dto.request.SyncContainerRequest
import xquare.app.xquareinfra.domain.container.adapter.dto.response.GetContainerLogResponse
import xquare.app.xquareinfra.domain.container.application.port.`in`.GetContainerLogUseCase
import xquare.app.xquareinfra.domain.container.application.port.`in`.GetEnvironmentVariableUseCase
import xquare.app.xquareinfra.domain.container.application.port.`in`.SyncContainerUseCase
import xquare.app.xquareinfra.domain.container.application.port.`in`.UpdateEnvironmentVariableUseCase
import xquare.app.xquareinfra.domain.container.adapter.dto.response.SimpleContainerResponse
import xquare.app.xquareinfra.domain.container.application.port.`in`.*
import xquare.app.xquareinfra.domain.container.domain.ContainerEnvironment
import java.util.UUID

@RequestMapping("/container")
@RestController
class ContainerWebAdapter(
private val syncContainerUseCase: SyncContainerUseCase,
private val getEnvironmentVariableUseCase: GetEnvironmentVariableUseCase,
private val updateEnvironmentVariableUseCase: UpdateEnvironmentVariableUseCase,
private val getContainerLogUseCase: GetContainerLogUseCase
private val getContainerLogUseCase: GetContainerLogUseCase,
private val getContainerByDeployIdUseCase: GetContainerByDeployIdUseCase
) {
@PostMapping("/sync")
fun syncContainer(
Expand Down Expand Up @@ -64,4 +64,10 @@ class ContainerWebAdapter(
): GetContainerLogResponse {
return getContainerLogUseCase.getContainerLog(deployName, environment)
}

@GetMapping
fun getContainerByDeployId(
@RequestParam("deployId")
deployId: UUID
): List<SimpleContainerResponse> = getContainerByDeployIdUseCase.getContainerByDeploy(deployId)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package xquare.app.xquareinfra.domain.container.adapter.dto.response

import xquare.app.xquareinfra.domain.container.domain.ContainerEnvironment
import xquare.app.xquareinfra.domain.container.domain.ContainerStatus
import java.time.LocalDateTime

data class SimpleContainerResponse(
val containerName: String,
val containerEnvironment: ContainerEnvironment,
val containerStatus: ContainerStatus,
val repository: String,
val domain: String,
val lastDeploy: LocalDateTime
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package xquare.app.xquareinfra.domain.container.application.port.`in`

import xquare.app.xquareinfra.domain.container.adapter.dto.response.SimpleContainerResponse
import java.util.UUID

interface GetContainerByDeployIdUseCase {
fun getContainerByDeploy(deployId: UUID): List<SimpleContainerResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ import xquare.app.xquareinfra.domain.deploy.domain.Deploy

interface FindContainerPort {
fun findByDeployAndEnvironment(deploy: Deploy, containerEnvironment: ContainerEnvironment): Container?
fun findAllByDeploy(deploy: Deploy): List<Container>
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ContainerPersistenceAdapter(
override fun findByDeployAndEnvironment(deploy: Deploy, containerEnvironment: ContainerEnvironment): Container? =
containerRepository.findByContainerEnvironmentAndDeploy(containerEnvironment, deploy)

override fun findAllByDeploy(deploy: Deploy): List<Container> = containerRepository.findAllByDeploy(deploy)

override fun save(container: Container): Container = containerRepository.save(container)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ import java.util.UUID

interface ContainerRepository : JpaRepository<Container, UUID> {
fun findByContainerEnvironmentAndDeploy(containerEnvironment: ContainerEnvironment, deploy: Deploy): Container?

fun findAllByDeploy(deploy: Deploy): List<Container>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package xquare.app.xquareinfra.domain.container.application.service

import org.springframework.stereotype.Service
import xquare.app.xquareinfra.domain.container.adapter.dto.response.SimpleContainerResponse
import xquare.app.xquareinfra.domain.container.application.port.`in`.GetContainerByDeployIdUseCase
import xquare.app.xquareinfra.domain.container.application.port.out.FindContainerPort
import xquare.app.xquareinfra.domain.container.domain.Container
import xquare.app.xquareinfra.domain.container.domain.ContainerEnvironment
import xquare.app.xquareinfra.domain.container.domain.ContainerStatus
import xquare.app.xquareinfra.domain.deploy.application.port.out.FindDeployPort
import xquare.app.xquareinfra.infrastructure.exception.BusinessLogicException
import java.util.*

@Service
class GetContainerByDeployIdService(
private val findDeployPort: FindDeployPort,
private val findContainerPort: FindContainerPort
): GetContainerByDeployIdUseCase {
override fun getContainerByDeploy(deployId: UUID): List<SimpleContainerResponse> {
val deploy = findDeployPort.findById(deployId) ?: throw BusinessLogicException.DEPLOY_NOT_FOUND
val containers = findContainerPort.findAllByDeploy(deploy)

return containers.map {
SimpleContainerResponse(
containerName = deploy.deployName,
containerEnvironment = it.containerEnvironment,
containerStatus = ContainerStatus.RUNNING,
repository = "${deploy.organization}/${deploy.repository}",
domain = generateDomain(it),
lastDeploy = it.lastDeploy
)
}
}

private fun generateDomain(container: Container): String {
if(container.subDomain!!.isEmpty()) {
val baseDomain = when (container.containerEnvironment) {
ContainerEnvironment.prod -> "prod-server.xquare.app"
else -> "stag-server.xquare.app"
}
return "https://$baseDomain/${container.deploy.deployName}"
}
return container.subDomain!!
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package xquare.app.xquareinfra.domain.container.application.service

import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import xquare.app.xquareinfra.domain.container.adapter.dto.response.GetContainerLogResponse
Expand All @@ -17,7 +16,7 @@ import java.time.Instant

@Transactional(readOnly = true)
@Service
class GetContainerService(
class GetContainerLogService(
private val findContainerPort: FindContainerPort,
private val findDeployPort: FindDeployPort,
private val logClient: LogClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ import xquare.app.xquareinfra.domain.deploy.adapter.dto.request.CreateDeployRequ
import java.util.UUID

interface CreateDeployUseCase {
fun createDeploy(teamId: UUID, createDeployRequest: CreateDeployRequest)
fun createDeploy(teamId: UUID, createDeployRequest: CreateDeployRequest): UUID
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CreateDeployService(
private val deployClient: DeployClient,
private val readCurrentUserPort: ReadCurrentUserPort
): CreateDeployUseCase {
override fun createDeploy(teamId: UUID, req: CreateDeployRequest) {
override fun createDeploy(teamId: UUID, req: CreateDeployRequest): UUID {
val team = findTeamPort.findById(teamId) ?: throw BusinessLogicException.TEAM_NOT_FOUND
val user = readCurrentUserPort.readCurrentUser()

Expand All @@ -50,7 +50,7 @@ class CreateDeployService(
throw BusinessLogicException.CREATE_DEPLOY_BAD_REQUEST
}

req.run {
val deploy = req.run {
saveDeployPort.saveDeploy(
Deploy(
id = null,
Expand All @@ -68,5 +68,6 @@ class CreateDeployService(
)
)
}
return deploy.id!!
}
}

0 comments on commit e25d800

Please sign in to comment.