-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
src/main/kotlin/com/example/mergebackend/domain/deploy/entity/Deploy.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.example.mergebackend.domain.deploy.entity | ||
|
||
import com.example.mergebackend.domain.deploy.entity.type.ServiceType | ||
import com.example.mergebackend.domain.deploy.entity.vo.DeployStatus | ||
import com.example.mergebackend.domain.deploy.entity.vo.UseDatabase | ||
import com.example.mergebackend.domain.project.entity.Project | ||
import java.util.UUID | ||
import javax.persistence.* | ||
|
||
@Entity(name = "deploy") | ||
class Deploy( | ||
id: UUID? = null, | ||
project: Project, | ||
accessKey: String, | ||
serviceType: ServiceType, | ||
organization: String, | ||
useDatabase: UseDatabase, | ||
isApproved: Boolean, | ||
deployStatus: DeployStatus, | ||
containerName: String | ||
) { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
@Column(name = "id", columnDefinition = "BINARY(16)") | ||
var id: UUID? = id | ||
protected set | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
var project: Project = project | ||
protected set | ||
|
||
@Column(name = "access_key", nullable = false) | ||
var accessKey: String = accessKey | ||
protected set | ||
|
||
@Enumerated(EnumType.STRING) | ||
var serviceType: ServiceType = serviceType | ||
protected set | ||
|
||
@Column(name = "organization", nullable = false) | ||
var organization: String = organization | ||
protected set | ||
|
||
@ElementCollection | ||
var useDatabase: UseDatabase = useDatabase | ||
protected set | ||
|
||
@Column(name = "is_approved", nullable = false) | ||
var isApproved: Boolean = isApproved | ||
protected set | ||
|
||
@Enumerated(EnumType.STRING) | ||
var deployStatus: DeployStatus = deployStatus | ||
protected set | ||
|
||
@Column(name = "container_name", nullable = false) | ||
var contianerNmae: String = containerName | ||
protected set | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/com/example/mergebackend/domain/deploy/entity/vo/DeployStatus.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.example.mergebackend.domain.deploy.entity.vo | ||
|
||
enum class DeployStatus { | ||
PENDING_APPROVE, | ||
APPROVED, | ||
CONTAINER_PENDING, | ||
CONTAINER_RUNNING, | ||
CONTAINER_CRASHLOOPBACKOFF, | ||
CONTAINER_EVICT | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/kotlin/com/example/mergebackend/domain/deploy/entity/vo/UseDatabase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.example.mergebackend.domain.deploy.entity.vo | ||
|
||
import javax.persistence.Embeddable | ||
|
||
@Embeddable | ||
data class UseDatabase( | ||
var mysql: Boolean, | ||
var redis: Boolean | ||
) |
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/com/example/mergebackend/domain/deploy/presentation/DeployController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.example.mergebackend.domain.deploy.presentation | ||
|
||
import com.example.mergebackend.domain.deploy.presentation.dto.request.CreateDeployRequest | ||
import com.example.mergebackend.domain.deploy.service.DeployService | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestBody | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RequestMapping("/deploy") | ||
@RestController | ||
class DeployController( | ||
private val deployService: DeployService | ||
) { | ||
@PostMapping | ||
fun createDeploy( | ||
@RequestBody | ||
createDeployRequest: CreateDeployRequest | ||
) { | ||
deployService.createDeploy(createDeployRequest) | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
...in/com/example/mergebackend/domain/deploy/presentation/dto/request/CreateDeployRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.example.mergebackend.domain.deploy.presentation.dto.request | ||
|
||
import com.example.mergebackend.domain.deploy.entity.type.ServiceType | ||
import com.example.mergebackend.domain.deploy.entity.vo.UseDatabase | ||
import java.util.UUID | ||
|
||
data class CreateDeployRequest( | ||
val containerName: String, | ||
val projectId: UUID, | ||
val serviceType: ServiceType, | ||
val useDatabase: UseDatabase | ||
) |
5 changes: 5 additions & 0 deletions
5
.../kotlin/com/example/mergebackend/domain/deploy/presentation/dto/request/WebhookRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.example.mergebackend.domain.deploy.presentation.dto.request | ||
|
||
data class WebhookRequest( | ||
val test: String | ||
) |
7 changes: 7 additions & 0 deletions
7
src/main/kotlin/com/example/mergebackend/domain/deploy/repository/DeployRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example.mergebackend.domain.deploy.repository | ||
|
||
import com.example.mergebackend.domain.deploy.entity.Deploy | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
import java.util.UUID | ||
|
||
interface DeployRepository : JpaRepository<Deploy, UUID> |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/com/example/mergebackend/domain/deploy/service/DeployService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.example.mergebackend.domain.deploy.service | ||
|
||
import com.example.mergebackend.domain.deploy.presentation.dto.request.CreateDeployRequest | ||
import com.example.mergebackend.domain.deploy.presentation.dto.request.WebhookRequest | ||
import java.util.UUID | ||
|
||
interface DeployService { | ||
fun createDeploy(createDeployRequest: CreateDeployRequest) | ||
fun regenerateAccessKey(deployId: UUID) | ||
fun getClub(deployId: UUID) | ||
fun verifyAndGetRole(projectName: String, repository: String, accessKey: String, projectType: String) | ||
fun deployApprove(deployId: UUID) | ||
fun containerRestartWebhook(webhookRequest: WebhookRequest) | ||
} |
67 changes: 67 additions & 0 deletions
67
src/main/kotlin/com/example/mergebackend/domain/deploy/service/DeployServiceImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.example.mergebackend.domain.deploy.service | ||
|
||
import com.example.mergebackend.domain.deploy.entity.Deploy | ||
import com.example.mergebackend.domain.deploy.entity.vo.DeployStatus | ||
import com.example.mergebackend.domain.deploy.presentation.dto.request.CreateDeployRequest | ||
import com.example.mergebackend.domain.deploy.presentation.dto.request.WebhookRequest | ||
import com.example.mergebackend.domain.deploy.repository.DeployRepository | ||
import com.example.mergebackend.domain.project.exception.ProjectNotFoundException | ||
import com.example.mergebackend.domain.project.repository.ProjectRepository | ||
import org.springframework.data.repository.findByIdOrNull | ||
import org.springframework.stereotype.Service | ||
import java.util.* | ||
|
||
@Service | ||
private class DeployServiceImpl( | ||
private val deployRepository: DeployRepository, | ||
private val projectRepository: ProjectRepository | ||
): DeployService { | ||
override fun createDeploy(createDeployRequest: CreateDeployRequest) { | ||
val project = projectRepository.findByIdOrNull(createDeployRequest.projectId) ?: throw ProjectNotFoundException | ||
|
||
val organization = extractOrganization(project.githubUrl!!) | ||
deployRepository.save( | ||
createDeployRequest.run { | ||
Deploy( | ||
project = project, | ||
accessKey = "", | ||
serviceType = serviceType, | ||
organization = organization, | ||
useDatabase = useDatabase, | ||
isApproved = false, | ||
deployStatus = DeployStatus.PENDING_APPROVE, | ||
containerName = containerName | ||
) | ||
} | ||
) | ||
} | ||
|
||
override fun regenerateAccessKey(deployId: UUID) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun getClub(deployId: UUID) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun verifyAndGetRole(projectName: String, repository: String, accessKey: String, projectType: String) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun deployApprove(deployId: UUID) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun containerRestartWebhook(webhookRequest: WebhookRequest) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
private fun extractOrganization(githubUrl: String): String { | ||
val parts = githubUrl.split("/") | ||
return if (parts.size >= 4) { | ||
parts[3] | ||
} else { | ||
"" | ||
} | ||
} | ||
} |