Task: Add dockerfile and kube
This commit is contained in:
@@ -32,6 +32,8 @@ springBoot {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("org.springframework.boot:spring-boot-starter-data-mongodb")
|
||||
|
||||
// Migrating from SpringFox
|
||||
implementation("org.springdoc:springdoc-openapi-ui:1.5.13")
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.cubetiqs.web.config
|
||||
|
||||
import com.cubetiqs.web.property.AppProperties
|
||||
import io.swagger.v3.oas.annotations.OpenAPIDefinition
|
||||
import io.swagger.v3.oas.annotations.enums.SecuritySchemeType
|
||||
import io.swagger.v3.oas.annotations.security.SecurityScheme
|
||||
import io.swagger.v3.oas.annotations.servers.Server
|
||||
import io.swagger.v3.oas.models.OpenAPI
|
||||
import io.swagger.v3.oas.models.info.Info
|
||||
import io.swagger.v3.oas.models.info.License
|
||||
@@ -18,11 +20,15 @@ import org.springframework.context.annotation.Configuration
|
||||
scheme = "bearer",
|
||||
bearerFormat = "JWT",
|
||||
)
|
||||
@OpenAPIDefinition(
|
||||
servers = [
|
||||
Server(url = "/")
|
||||
],
|
||||
)
|
||||
class OpenApiDocConfig @Autowired constructor(
|
||||
val appProperties: AppProperties,
|
||||
) {
|
||||
companion object {
|
||||
private val ADMIN_API_PATH get() = "/admin/**"
|
||||
private val DEFAULT_API_PATH get() = "/**"
|
||||
}
|
||||
|
||||
@@ -31,19 +37,10 @@ class OpenApiDocConfig @Autowired constructor(
|
||||
return GroupedOpenApi.builder()
|
||||
.group("default")
|
||||
.pathsToMatch(DEFAULT_API_PATH)
|
||||
.pathsToExclude("/error", ADMIN_API_PATH)
|
||||
.packagesToScan("com.cubetiqs.web")
|
||||
.build()
|
||||
}
|
||||
|
||||
@Bean
|
||||
fun adminApi(): GroupedOpenApi {
|
||||
return GroupedOpenApi.builder()
|
||||
.group("admin")
|
||||
.pathsToMatch(ADMIN_API_PATH)
|
||||
.build()
|
||||
}
|
||||
|
||||
@Bean
|
||||
fun cubetiqOpenAPI(): OpenAPI {
|
||||
return OpenAPI()
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.cubetiqs.web.controller
|
||||
|
||||
import com.cubetiqs.web.infrastructure.data.Customer
|
||||
import com.cubetiqs.web.infrastructure.repository.CustomerRepository
|
||||
import io.swagger.v3.oas.annotations.tags.Tag
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.web.bind.annotation.*
|
||||
|
||||
@Tag(name = "Customer")
|
||||
@RestController
|
||||
@RequestMapping("/customers")
|
||||
class CustomerController @Autowired constructor(
|
||||
private val customerRepository: CustomerRepository,
|
||||
) {
|
||||
@GetMapping
|
||||
fun getAll(): List<Customer> = customerRepository.findAll()
|
||||
|
||||
@GetMapping("/{id}")
|
||||
fun getById(@PathVariable id: String): Customer = customerRepository.findById(id).orElse(null)
|
||||
|
||||
@PostMapping
|
||||
fun create(@RequestBody customer: Customer) = customerRepository.save(customer)
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
fun delete(@PathVariable id: String) = customerRepository.deleteById(id)
|
||||
|
||||
@PutMapping("/{id}")
|
||||
fun update(@PathVariable id: String, @RequestBody customer: Customer) = customerRepository.save(customer)
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import org.springframework.http.ResponseEntity
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
import java.net.InetAddress
|
||||
|
||||
@Tag(name = "Miscellaneous")
|
||||
@RestController
|
||||
@@ -26,14 +27,16 @@ class IndexController @Autowired constructor(
|
||||
ApiInfoAuthorResponse(name = "Sambo Chea", email = "sombochea@cubetiqs.com"),
|
||||
ApiInfoAuthorResponse(name = "CUBETIQ OSS", email = "oss@cubetiqs.com"),
|
||||
)
|
||||
val hostname = InetAddress.getLocalHost().hostName
|
||||
val response = ApiInfoResponse(
|
||||
info = "API Operation is running normally on ${environment.activeProfiles.joinToString(separator = ",")}",
|
||||
name = buildProperties.name,
|
||||
name = environment.getProperty("spring.application.name") ?: buildProperties.name,
|
||||
service = buildProperties.artifact,
|
||||
version = buildProperties.version,
|
||||
date = buildProperties.time.toString(),
|
||||
commit = buildProperties["commitId"],
|
||||
authors = authors,
|
||||
hostname = hostname,
|
||||
)
|
||||
return response(response)
|
||||
}
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
package com.cubetiqs.web.controller.admin
|
||||
|
||||
import com.cubetiqs.web.annotation.ApiBearerAuth
|
||||
import com.cubetiqs.web.controller.BaseController
|
||||
import com.cubetiqs.web.util.RouteConstants
|
||||
import io.swagger.v3.oas.annotations.tags.Tag
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.RequestMapping
|
||||
import org.springframework.web.bind.annotation.RestController
|
||||
|
||||
@Tag(name = "Admin")
|
||||
@RestController
|
||||
@RequestMapping(RouteConstants.ADMIN)
|
||||
class AdminController : BaseController {
|
||||
@ApiBearerAuth
|
||||
@GetMapping
|
||||
fun getAdmin(): String {
|
||||
return "Admin"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.cubetiqs.web.infrastructure.data
|
||||
|
||||
import org.springframework.data.annotation.Id
|
||||
import org.springframework.data.mongodb.core.mapping.Document
|
||||
|
||||
@Document(collection = "customer")
|
||||
data class Customer(
|
||||
@Id
|
||||
var id: String? = null,
|
||||
var name: String? = null,
|
||||
var email: String? = null,
|
||||
var phone: String? = null,
|
||||
var address: String? = null,
|
||||
)
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.cubetiqs.web.infrastructure.repository
|
||||
|
||||
import com.cubetiqs.web.infrastructure.data.Customer
|
||||
import org.springframework.data.mongodb.repository.MongoRepository
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
@Repository
|
||||
interface CustomerRepository : MongoRepository<Customer, String>
|
||||
@@ -1,7 +1,9 @@
|
||||
package com.cubetiqs.web.model.response
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude
|
||||
import io.swagger.v3.oas.annotations.media.Schema
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@Schema(name = "ApiInfoResponse", description = "ApiInfoResponse")
|
||||
data class ApiInfoResponse(
|
||||
val name: String,
|
||||
@@ -10,6 +12,7 @@ data class ApiInfoResponse(
|
||||
val version: String,
|
||||
val date: String,
|
||||
val commit: String,
|
||||
val hostname: String? = null,
|
||||
val authors: Collection<ApiInfoAuthorResponse> = listOf(),
|
||||
) : BaseRequestModel
|
||||
|
||||
|
||||
@@ -2,8 +2,10 @@ spring:
|
||||
profiles:
|
||||
active: ${APP_PROFILE:dev}
|
||||
application:
|
||||
name: cubetiq-api-service
|
||||
|
||||
name: ${APP_NAME:cubetiq-api-service}
|
||||
data:
|
||||
mongodb:
|
||||
uri: ${MONGODB_URI:mongodb://192.168.0.202:27017/spring-web-api-db}
|
||||
cubetiq:
|
||||
app:
|
||||
data-dir: ${APP_DATA_DIR:${user.home}/${spring.application.name}}
|
||||
|
||||
Reference in New Issue
Block a user