Skip to content

Commit

Permalink
feat :: 배포 마이그레이션 API 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
HyunSu1768 committed Apr 17, 2024
1 parent 3f7bf61 commit ad01456
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import xquare.app.xquareinfra.domain.deploy.adapter.dto.request.ApproveDeployReq
import xquare.app.xquareinfra.domain.deploy.adapter.dto.request.CreateDeployRequest
import xquare.app.xquareinfra.domain.deploy.adapter.dto.response.DeployDetailsResponse
import xquare.app.xquareinfra.domain.deploy.adapter.dto.response.SimpleDeployListResponse
import xquare.app.xquareinfra.domain.deploy.application.port.`in`.ApproveDeployUseCase
import xquare.app.xquareinfra.domain.deploy.application.port.`in`.CreateDeployUseCase
import xquare.app.xquareinfra.domain.deploy.application.port.`in`.GetAllDeployInTeamUseCase
import xquare.app.xquareinfra.domain.deploy.application.port.`in`.GetDeployDetailsUseCase
import xquare.app.xquareinfra.domain.deploy.application.port.`in`.*
import java.util.*

@RequestMapping("/deploy")
Expand All @@ -17,7 +14,8 @@ class DeployWebAdapter(
private val createDeployUseCase: CreateDeployUseCase,
private val approveDeployUseCase: ApproveDeployUseCase,
private val getAllDeployInTeamUseCase: GetAllDeployInTeamUseCase,
private val getDeployDetailsUseCase: GetDeployDetailsUseCase
private val getDeployDetailsUseCase: GetDeployDetailsUseCase,
private val migrationDeployUseCase: MigrationDeployUseCase
) {
@PostMapping
fun createDeploy(
Expand Down Expand Up @@ -50,4 +48,7 @@ class DeployWebAdapter(
@PathVariable("deployId", required = true)
deployId: UUID
): DeployDetailsResponse = getDeployDetailsUseCase.getDeployDetails(deployId)

@PostMapping("/migration")
fun migrationDeploy() = migrationDeployUseCase.migrationDeploy()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package xquare.app.xquareinfra.domain.deploy.application.port.`in`

interface MigrationDeployUseCase {
fun migrationDeploy()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package xquare.app.xquareinfra.domain.deploy.application.port.out

import xquare.app.xquareinfra.domain.deploy.domain.Deploy

interface saveDeployPort {
fun saveDeploy(deploy: Deploy): Deploy
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package xquare.app.xquareinfra.domain.deploy.application.service

import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
import xquare.app.xquareinfra.domain.auth.application.port.out.ReadCurrentUserPort
import xquare.app.xquareinfra.domain.deploy.application.port.`in`.MigrationDeployUseCase
import xquare.app.xquareinfra.domain.deploy.application.port.out.saveDeployPort
import xquare.app.xquareinfra.domain.deploy.domain.Deploy
import xquare.app.xquareinfra.domain.deploy.domain.DeployStatus
import xquare.app.xquareinfra.domain.deploy.domain.DeployType
import xquare.app.xquareinfra.domain.team.application.port.out.ExistsUserTeamPort
import xquare.app.xquareinfra.domain.team.application.port.out.FindTeamPort
import xquare.app.xquareinfra.infrastructure.exception.BusinessLogicException
import xquare.app.xquareinfra.infrastructure.exception.XquareException
import xquare.app.xquareinfra.infrastructure.feign.client.deploy.DeployClient

@Transactional
@Service
class MigrationDeployService(
private val readCurrentUserPort: ReadCurrentUserPort,
private val findTeamPort: FindTeamPort,
private val saveDeployPort: saveDeployPort,
private val deployClient: DeployClient,
private val existsUserTeamPort: ExistsUserTeamPort
): MigrationDeployUseCase {
override fun migrationDeploy() {
val user = readCurrentUserPort.readCurrentUser()

val deployList = deployClient.getAllDeploy(user.email)
deployList.map {
println(it.team)
val team = findTeamPort.findByName(it.team) ?: throw BusinessLogicException.TEAM_NOT_FOUND

if(!existsUserTeamPort.existsByTeamAndUser(team, user)) {
throw XquareException.FORBIDDEN
}

saveDeployPort.saveDeploy(
Deploy(
id = null,
deployName = it.nameEn,
organization = it.organization,
repository = it.repository.split("/")[1],
projectRootDir = "/",
oneLineDescription = "한줄설명을 적어주세요.",
team = team,
secretKey = null,
deployStatus = if (it.isApproved) DeployStatus.AVAILABLE else DeployStatus.WAIT_FOR_APPROVE,
deployType = if (it.type == "be") DeployType.be else DeployType.fe,
useMysql = it.useMysql,
useRedis = it.useRedis
)
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package xquare.app.xquareinfra.infrastructure.feign.client.deploy.dto.request

import com.fasterxml.jackson.databind.PropertyNamingStrategies
import com.fasterxml.jackson.databind.annotation.JsonNaming

@JsonNaming(PropertyNamingStrategies.LowerCamelCaseStrategy::class)
data class FeignCreateDeployRequest(
val email: String,
val nameKo: String,
val nameEn: String,
val team: String,
val repository: String,
val organization: String,
val type: String,
val useRedis: Boolean,
val useMySQL: Boolean
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package xquare.app.xquareinfra.infrastructure.feign.client.deploy.dto.response

import com.fasterxml.jackson.annotation.JsonProperty
import com.fasterxml.jackson.databind.annotation.JsonNaming

data class DeployResponse(
@JsonProperty("nameKo")
val nameKo: String,
@JsonProperty("nameEn")
val nameEn: String,
@JsonProperty("repository")
val repository: String,
@JsonProperty("type")
val type: String,
@JsonProperty("team")
val team: String,
@JsonProperty("email")
val email: String,
@JsonProperty("organization")
val organization: String,
@JsonProperty("useRedis")
val useRedis: Boolean,
@JsonProperty("useMysql")
val useMysql: Boolean,
@JsonProperty("isApproved")
val isApproved: Boolean
)

0 comments on commit ad01456

Please sign in to comment.