Skip to content

Commit

Permalink
♻️ add endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
ksetoue committed Feb 6, 2023
1 parent 2e52bfe commit ee7bc9b
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ksetoue.kotlinspringapi.application
package com.ksetoue.kotlinspringapi.business

import com.ksetoue.kotlinspringapi.domain.HealthContext
import io.opentracing.Span
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.ksetoue.kotlinspringapi.port.client

import org.springframework.boot.web.client.RestTemplateBuilder
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.client.RestTemplate

@Configuration
class HttpClientConfig {
@Bean
fun restClient(restTemplateBuilder: RestTemplateBuilder): RestTemplate =
restTemplateBuilder.build()
}
package com.ksetoue.kotlinspringapi.port.config

import org.springframework.boot.web.client.RestTemplateBuilder
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.web.client.RestTemplate

@Configuration
class HttpClientConfig {
@Bean
fun restClient(restTemplateBuilder: RestTemplateBuilder): RestTemplate =
restTemplateBuilder.build()
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
package com.ksetoue.kotlinspringapi.port.client

import io.swagger.v3.oas.models.Components
import io.swagger.v3.oas.models.OpenAPI
import io.swagger.v3.oas.models.info.Info
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
class SwaggerConfig {
@Bean
fun customOpenAPI(): OpenAPI? {
return OpenAPI()
.components(Components())
.info(
Info().title("Kotlin and Spring Boot API")
.description("API sample")
.version("1.0.0")
)
}
}
package com.ksetoue.kotlinspringapi.port.config

import io.swagger.v3.oas.models.Components
import io.swagger.v3.oas.models.OpenAPI
import io.swagger.v3.oas.models.info.Info
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
class SwaggerConfig {
@Bean
fun customOpenAPI(): OpenAPI? {
return OpenAPI()
.components(Components())
.info(
Info().title("Kotlin and Spring Boot API")
.description("API sample")
.version("1.0.0")
)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.ksetoue.kotlinspringapi.port.controller

import com.ksetoue.kotlinspringapi.application.HealthApplicationService
import com.ksetoue.kotlinspringapi.business.HealthApplicationService
import com.ksetoue.kotlinspringapi.domain.HealthContext
import com.ksetoue.kotlinspringapi.domain.common.ErrorDetails
import io.swagger.v3.oas.annotations.Operation
Expand All @@ -16,13 +16,13 @@ import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/health")
@RequestMapping("/")
class HealthController(
private val healthService: HealthApplicationService
) {
private val logger = LoggerFactory.getLogger(this::class.java)

@GetMapping("status")
@GetMapping("/startup")
@Operation(summary = "Health status of this service", description = "Returns information about the availability of this service")
@ApiResponses(
value = [
Expand All @@ -31,8 +31,18 @@ class HealthController(
ApiResponse(responseCode = "400", description = "Invalid Parameter Request", content = [Content(mediaType = "application/json", schema = Schema(implementation = ErrorDetails::class))])
]
)
fun status(): ResponseEntity<HealthContext> {
fun startup(): ResponseEntity<HealthContext> {
logger.info("attempt to check health")
return ResponseEntity(healthService.getStatus(), HttpStatus.OK)
}

@GetMapping("/liveness")
fun live(): ResponseEntity<String> {
return ResponseEntity("OK", HttpStatus.OK)
}

@GetMapping("/readiness")
fun ready(): ResponseEntity<String> {
return ResponseEntity("OK", HttpStatus.OK)
}
}
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
spring.output.ansi.enabled=always
spring.application.name=kotlin-spring-api
logging.pattern.console=%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}
##### LOGGING #####

opentracing.jaeger.log-spans=true
opentracing.jaeger.http-sender.url=http://localhost:14268/api/traces
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ksetoue.kotlinspringapi.application
package com.ksetoue.kotlinspringapi.business

import com.ksetoue.kotlinspringapi.AbstractBaseTest
import com.ksetoue.kotlinspringapi.template.HealthContextTemplate
Expand Down

0 comments on commit ee7bc9b

Please sign in to comment.