Skip to content

Commit

Permalink
Add admin endpoints for monitors (#33)
Browse files Browse the repository at this point in the history
* Add GET endpoints for monitors

* Add custom codecov config

* Fine-tune custom codecov config

* Add POST, DELETE and PATCH endpoints for monitors

* Add missing test cases to UptimeCheckerTest

* Refactor AuthenticationTest to use @MicronautTest annotation

* Add missing test cases for monitor admin endpoints

* Refact jOOQ related extension functions

* Decrease Codecov patch coverage target
  • Loading branch information
adamkobor authored Aug 9, 2020
1 parent 7cb6c9b commit 29d526a
Show file tree
Hide file tree
Showing 47 changed files with 1,147 additions and 154 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,19 @@ dependencies {
implementation("io.micronaut.kotlin:micronaut-kotlin-extension-functions")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation "nu.studer:gradle-jooq-plugin:$jooqPluginVersion"
implementation("org.postgresql:postgresql:${postgresVersion}")
detektPlugins "io.gitlab.arturbosch.detekt:detekt-formatting:$detektVersion"
runtimeOnly("ch.qos.logback:logback-classic")
runtimeOnly("ch.qos.logback.contrib:logback-json-classic:${logbackJsonVersion}")
runtimeOnly("ch.qos.logback.contrib:logback-jackson:${logbackJsonVersion}")
runtimeOnly("net.logstash.logback:logstash-logback-encoder:${logstashEncoderVersion}")
runtimeOnly("org.codehaus.janino:janino:${janinoVersion}")
runtimeOnly("org.postgresql:postgresql:${postgresVersion}")
kaptTest(platform("io.micronaut:micronaut-bom:$micronautVersion"))
kaptTest("io.micronaut:micronaut-inject-java")
testImplementation(platform("io.micronaut:micronaut-bom:$micronautVersion"))
testImplementation("io.micronaut.test:micronaut-test-kotest")
testImplementation("io.kotest:kotest-runner-junit5-jvm")
testImplementation("io.kotest:kotest-assertions-core:${kotestVersion}")
testImplementation("io.mockk:mockk:${mockkVersion}")
testImplementation("org.testcontainers:postgresql:${testContainersVersion}")
jooqRuntime("org.postgresql:postgresql:${postgresVersion}")
Expand Down
10 changes: 10 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
coverage:
status:
project:
default:
target: 90%
threshold: 0%
patch:
default:
target: 80%
threshold: 0%
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ micronautVersion=2.0.1
kotlinVersion=1.3.72
detektVersion=1.10.0
jooqPluginVersion=4.2
jibVersion=2.4.0
jibVersion=2.5.0
shadowVersion=6.0.0
arrowDataVersion=0.10.5
kotlinCoroutinesVersion=1.3.8
Expand All @@ -13,3 +13,4 @@ palantirGitVersion=0.12.3
logbackJsonVersion=0.1.5
logstashEncoderVersion=6.4
janinoVersion=3.1.2
kotestVersion=4.0.3
2 changes: 1 addition & 1 deletion src/jooq/java/com/kuvaszuptime/kuvasz/DefaultCatalog.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/jooq/java/com/kuvaszuptime/kuvasz/DefaultSchema.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/jooq/java/com/kuvaszuptime/kuvasz/Keys.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/jooq/java/com/kuvaszuptime/kuvasz/Sequences.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/jooq/java/com/kuvaszuptime/kuvasz/Tables.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/jooq/java/com/kuvaszuptime/kuvasz/tables/Monitor.java

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 0 additions & 11 deletions src/main/kotlin/com/kuvaszuptime/kuvasz/Controller.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.kuvaszuptime.kuvasz.controllers

import com.fasterxml.jackson.core.JsonParseException
import com.kuvaszuptime.kuvasz.models.DuplicationError
import com.kuvaszuptime.kuvasz.models.MonitorNotFoundError
import com.kuvaszuptime.kuvasz.models.PersistenceError
import com.kuvaszuptime.kuvasz.models.SchedulingError
import com.kuvaszuptime.kuvasz.models.ServiceError
import io.micronaut.core.convert.exceptions.ConversionErrorException
import io.micronaut.http.HttpRequest
import io.micronaut.http.HttpResponse
import io.micronaut.http.HttpStatus
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Error
import javax.validation.ValidationException

@Controller
class GlobalErrorHandler {

@Suppress("UNUSED_PARAMETER")
@Error(global = true)
fun jsonError(request: HttpRequest<*>, monitorNotFoundError: MonitorNotFoundError): HttpResponse<ServiceError> {
val error = ServiceError(monitorNotFoundError.message)
return HttpResponse.notFound(error)
}

@Suppress("UNUSED_PARAMETER")
@Error(global = true)
fun jsonError(request: HttpRequest<*>, duplicationError: DuplicationError): HttpResponse<ServiceError> {
val error = ServiceError(duplicationError.message)
return HttpResponse.status<ServiceError>(HttpStatus.CONFLICT).body(error)
}

@Suppress("UNUSED_PARAMETER")
@Error(global = true)
fun error(request: HttpRequest<*>, throwable: ValidationException): HttpResponse<ServiceError> =
HttpResponse.badRequest(ServiceError(throwable.message))

@Suppress("UNUSED_PARAMETER")
@Error(global = true)
fun error(request: HttpRequest<*>, throwable: ConversionErrorException): HttpResponse<ServiceError> {
val message = "Failed to convert argument: ${throwable.argument}"
return HttpResponse.badRequest(ServiceError(message))
}

@Suppress("UNUSED_PARAMETER")
@Error(global = true)
fun error(request: HttpRequest<*>, throwable: JsonParseException): HttpResponse<ServiceError> {
val message = "Can't parse the JSON in the payload"
return HttpResponse.badRequest(ServiceError(message))
}

@Suppress("UNUSED_PARAMETER")
@Error(global = true)
fun jsonError(request: HttpRequest<*>, persistencyError: PersistenceError): HttpResponse<ServiceError> {
val error = ServiceError(persistencyError.message)
return HttpResponse.status<ServiceError>(HttpStatus.INTERNAL_SERVER_ERROR).body(error)
}

@Suppress("UNUSED_PARAMETER")
@Error(global = true)
fun jsonError(request: HttpRequest<*>, schedulingError: SchedulingError): HttpResponse<ServiceError> {
val error = ServiceError(schedulingError.message)
return HttpResponse.status<ServiceError>(HttpStatus.INTERNAL_SERVER_ERROR).body(error)
}
}
Loading

0 comments on commit 29d526a

Please sign in to comment.