Skip to content

Commit

Permalink
Merge pull request #21 from darkredz/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
darkredz committed Dec 8, 2020
2 parents bf8eb76 + 89a9b3c commit 0fdd43d
Show file tree
Hide file tree
Showing 25 changed files with 551 additions and 353 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Add this to your maven pom.xml
<dependency>
<groupId>io.zeko</groupId>
<artifactId>zeko-restapi</artifactId>
<version>1.1.8</version>
<version>1.2.3</version>
</dependency>
<!-- Jasync Mysql driver if needed -->
<dependency>
Expand All @@ -65,7 +65,7 @@ Add this to your maven pom.xml
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-jdbc-client</artifactId>
<version>3.9.2</version>
<version>3.9.4</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
Expand Down
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>io.zeko</groupId>
<artifactId>zeko-restapi</artifactId>
<version>1.1.8-SNAPSHOT</version>
<version>1.2.3-SNAPSHOT</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand Down Expand Up @@ -76,7 +76,7 @@

<properties>
<kotlin.version>1.3.61</kotlin.version>
<vertx.version>3.9.2</vertx.version>
<vertx.version>3.9.4</vertx.version>
<spek.version>2.0.9</spek.version>
<jupiter.version>5.2.0</jupiter.version>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down Expand Up @@ -126,7 +126,7 @@
<dependency>
<groupId>io.zeko</groupId>
<artifactId>zeko-validator</artifactId>
<version>1.1.0</version>
<version>1.1.2</version>
</dependency>

<dependency>
Expand All @@ -144,7 +144,7 @@
<dependency>
<groupId>io.zeko</groupId>
<artifactId>zeko-sql-builder</artifactId>
<version>1.2.0</version>
<version>1.2.1</version>
</dependency>

<dependency>
Expand Down Expand Up @@ -180,7 +180,7 @@
<dependency>
<groupId>com.cronutils</groupId>
<artifactId>cron-utils</artifactId>
<version>9.0.2</version>
<version>9.1.3</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.zeko.restapi.annotation.codegen

data class CronDefinition (
data class CronDefinition(
val className: String,
val methodName: String,
val schedule: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.zeko.restapi.annotation.codegen

data class RouteDefinition (
data class RouteDefinition(
val className: String,
val methodName: String,
val routePath: String,
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.zeko.restapi.annotation.codegen

class RoutingAnnotation (map: Map<String, Any?>) {
class RoutingAnnotation(map: Map<String, Any?>) {
protected val defaultMap = map.withDefault { null }
val path: String? by defaultMap
val method: String? by defaultMap
Expand Down
22 changes: 11 additions & 11 deletions src/main/kotlin/io/zeko/restapi/annotation/codegen/SwaggerUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ class SwaggerUtils {
companion object {
@JvmStatic
val vertxUriParamPattern: Pattern
get() {
val paths = JsonObject()
val rgxStr = "\\:([a-zA-Z_0-9]+)"
val rgx = Regex(rgxStr)
val uriParamPattern = rgx.toPattern()
return uriParamPattern
}
get() {
val paths = JsonObject()
val rgxStr = "\\:([a-zA-Z_0-9]+)"
val rgx = Regex(rgxStr)
val uriParamPattern = rgx.toPattern()
return uriParamPattern
}

@JvmStatic
fun convertToSwaggerUri(path: String, pattern: Pattern) = path.replace(pattern.toRegex(), "\\{\$1\\}")
Expand Down Expand Up @@ -89,13 +89,13 @@ class SwaggerUtils {
fieldSchema.put("format", "alphaNumDashSpace")
} else if (rule.containsKey("alphaNumUnderscore")) {
fieldSchema.put("format", "alphaNumUnderscore")
} else if (rule.containsKey("alphaNumQuoteDashSpace")) {
} else if (rule.containsKey("alphaNumQuoteDashSpace")) {
fieldSchema.put("format", "alphaNumQuoteDashSpace")
} else if (rule.containsKey("alphaNumQuoteSpace")) {
} else if (rule.containsKey("alphaNumQuoteSpace")) {
fieldSchema.put("format", "alphaNumQuoteSpace")
} else if (rule.containsKey("alphaQuoteDashSpace")) {
} else if (rule.containsKey("alphaQuoteDashSpace")) {
fieldSchema.put("format", "alphaQuoteDashSpace")
} else if (rule.containsKey("alphaQuoteSpace")) {
} else if (rule.containsKey("alphaQuoteSpace")) {
fieldSchema.put("format", "alphaQuoteSpace")
} else if (rule.containsKey("allLowerCase")) {
fieldSchema.put("format", "allLowerCase")
Expand Down
14 changes: 12 additions & 2 deletions src/main/kotlin/io/zeko/restapi/core/CircuitBreakerBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import io.vertx.core.Vertx
class CircuitBreakerBuilder {
companion object {
@JvmStatic
fun make(vertx: Vertx, name: String, options: CircuitBreakerOptions? = null, retryPolicy: ((Int) -> Long)? = null): CircuitBreaker {
fun make(
vertx: Vertx,
name: String,
options: CircuitBreakerOptions? = null,
retryPolicy: ((Int) -> Long)? = null
): CircuitBreaker {
var opt = options
if (options == null) {
opt = CircuitBreakerOptions().apply {
Expand All @@ -27,7 +32,12 @@ class CircuitBreakerBuilder {
}

@JvmStatic
fun makeWithUnlimitedRetries(vertx: Vertx, name: String, delayMs: Long = 5000L, maxFailCount: Int = 10): CircuitBreaker {
fun makeWithUnlimitedRetries(
vertx: Vertx,
name: String,
delayMs: Long = 5000L,
maxFailCount: Int = 10
): CircuitBreaker {
val options = CircuitBreakerOptions().apply {
maxFailures = maxFailCount
maxRetries = 0
Expand Down
9 changes: 5 additions & 4 deletions src/main/kotlin/io/zeko/restapi/core/RouteSchema.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import kotlin.coroutines.CoroutineContext

abstract class RouteSchema(val vertx: Vertx) {
open fun handleRoutes(
router: Router,
logger: Logger,
koto: (route: Route, fn: suspend (rc: RoutingContext, cc: CoroutineContext) -> Unit) -> Unit
) {}
router: Router,
logger: Logger,
koto: (route: Route, fn: suspend (rc: RoutingContext, cc: CoroutineContext) -> Unit) -> Unit
) {
}
}
8 changes: 6 additions & 2 deletions src/main/kotlin/io/zeko/restapi/core/TimeoutHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ package io.zeko.restapi.core
import io.vertx.core.Handler
import io.vertx.ext.web.RoutingContext

class TimeoutHandler(private val timeout: Long, private val errorCode: Int, private val skipPaths: List<String>? = null) : Handler<RoutingContext> {
class TimeoutHandler(
private val timeout: Long,
private val errorCode: Int,
private val skipPaths: List<String>? = null
) : Handler<RoutingContext> {
override fun handle(ctx: RoutingContext) {
var shouldSkip = false

if (skipPaths != null) {
val path = ctx.normalisedPath()
for (uri in skipPaths) {
if (uri.contains("*")) {
if (path.startsWith(uri.removeSuffix("*"))) {
if (path.startsWith(uri.removeSuffix("*"))) {
shouldSkip = true
break
}
Expand Down
18 changes: 13 additions & 5 deletions src/main/kotlin/io/zeko/restapi/core/controllers/ApiController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ open abstract class ApiController(val vertx: Vertx, val logger: Logger, val cont
return validateInput(rules[action]!!, statusCode)
}

protected open fun validateInput(rules: Map<String, Any>?, statusCode: Int = 400, errorCode: Int = 400): ValidateResult {
protected open fun validateInput(
rules: Map<String, Any>?,
statusCode: Int = 400,
errorCode: Int = 400
): ValidateResult {
if (rules.isNullOrEmpty()) {
return outputNoRulesError(statusCode, errorCode)
}
Expand All @@ -65,13 +69,13 @@ open abstract class ApiController(val vertx: Vertx, val logger: Logger, val cont
protected open fun outputNoRulesError(statusCode: Int, errorCode: Int): ValidateResult {
val values = HashMap<String, Any?>()
val errors = mapOf(
"server_error" to listOf("Undefined input rules for this endpoint")
"server_error" to listOf("Undefined input rules for this endpoint")
)
val validateResult = ValidateResult(false, -1, errors, values)
val res = json {
obj(
"error_code" to errorCode,
"errors" to validateResult.errors
"error_code" to errorCode,
"errors" to validateResult.errors
)
}
context.response().setStatusCode(405).putHeader("Content-Type", "application/json").end(res.toString())
Expand Down Expand Up @@ -120,7 +124,11 @@ open abstract class ApiController(val vertx: Vertx, val logger: Logger, val cont

companion object {
@JvmStatic
fun checkInputErrors(params: Map<String, String>?, rules: Map<String, Any>, inputErrorMessages: Map<String, String>): ValidateResult {
fun checkInputErrors(
params: Map<String, String>?,
rules: Map<String, Any>,
inputErrorMessages: Map<String, String>
): ValidateResult {
val note = Notification("__", inputErrorMessages)
val values = HashMap<String, Any?>()
val errors = HashMap<String, List<String>>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import io.zeko.db.sql.utilities.toSnakeCase
import io.zeko.restapi.core.utilities.downloadZip
import io.zeko.restapi.core.utilities.zip.TempFile

open class ProjectInitController(vertx: Vertx, logger: Logger, context: RoutingContext) : ApiController(vertx, logger, context) {
open class ProjectInitController(vertx: Vertx, logger: Logger, context: RoutingContext) :
ApiController(vertx, logger, context) {

/**
* Visit this url to generate and download a new project setup automatically by the framework. JDBC url should be uri encoded
Expand All @@ -21,21 +22,23 @@ open class ProjectInitController(vertx: Vertx, logger: Logger, context: RoutingC
* &db_driver=hikari&jdbc_url=jdbc%3Amysql%3A%2F%2Flocalhost%3A3306%2Fzeko_test%3Fuser%3Droot%26password%3D123456
*/
@Routing("/create", "route", true, "Create New Zeko Project")
@Params([
"artifact_id => required, minLength;3, maxLength;60, alphaNumDash",
"group_id => required, minLength;3, maxLength;60, [a-zA-Z0-9\\\\_\\\\.]",
"version => required, minLength;3, maxLength;10, regex;[0-9\\\\.]+",
"package_name => required, minLength;3, maxLength;60, regex;[a-zA-Z0-9\\\\_\\\\.]+",
"jwt_key => required",
"jwt_refresh_key => required",
"jwt_expiry => required, min;60;",
"jwt_refresh_expiry => required, min;60;",
"jwt_refresh_when_expire => required, isBoolean",
"db_driver => required, inArray;jasync;hikari;vertx",
"jdbc_url => required, minLength;16, maxLength;160",
"controllers => required, separateBy",
"http_port => required, isInteger, min;80, max:20000"
])
@Params(
[
"artifact_id => required, minLength;3, maxLength;60, alphaNumDash",
"group_id => required, minLength;3, maxLength;60, [a-zA-Z0-9\\\\_\\\\.]",
"version => required, minLength;3, maxLength;10, regex;[0-9\\\\.]+",
"package_name => required, minLength;3, maxLength;60, regex;[a-zA-Z0-9\\\\_\\\\.]+",
"jwt_key => required",
"jwt_refresh_key => required",
"jwt_expiry => required, min;60;",
"jwt_refresh_expiry => required, min;60;",
"jwt_refresh_when_expire => required, isBoolean",
"db_driver => required, inArray;jasync;hikari;vertx",
"jdbc_url => required, minLength;16, maxLength;160",
"controllers => required, separateBy",
"http_port => required, isInteger, min;80, max:20000"
]
)
open suspend fun createNew(ctx: RoutingContext) {
val res = validateInput()
if (!res.success) return
Expand Down Expand Up @@ -372,8 +375,8 @@ mvn clean compile vertx:run -Dvertx.verticle="$packageName.BootstrapVerticle" \
<properties>
<vertx.verticle>$packageName.BootstrapVerticle</vertx.verticle>
<kotlin.version>1.3.61</kotlin.version>
<zeko-restapi.version>1.1.8</zeko-restapi.version>
<vertx.version>3.9.2</vertx.version>
<zeko-restapi.version>1.2.3</zeko-restapi.version>
<vertx.version>3.9.4</vertx.version>
<micrometer.version>1.1.0</micrometer.version>
<java.version>1.8</java.version>
<jib.version>2.2.0</jib.version>
Expand Down
24 changes: 12 additions & 12 deletions src/main/kotlin/io/zeko/restapi/core/mail/MailService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@ import io.vertx.circuitbreaker.CircuitBreaker

interface MailService {
suspend fun send(
toEmail: String, name: String,
subject: String, content: String,
text: String? = null, tags: List<String>? = null
toEmail: String, name: String,
subject: String, content: String,
text: String? = null, tags: List<String>? = null
): MailResponse

suspend fun send(
toList: List<String>, subject: String,
content: String, text: String? = null,
tags: List<String>? = null
toList: List<String>, subject: String,
content: String, text: String? = null,
tags: List<String>? = null
): MailResponse

suspend fun send(
toEmail: List<String>, names: List<String>,
subject: String, content: String, text: String? = null,
tags: List<String>? = null
toEmail: List<String>, names: List<String>,
subject: String, content: String, text: String? = null,
tags: List<String>? = null
): MailResponse

suspend fun retry(numRetries: Int, delayTry: Long = 0, operation: suspend (MailService) -> MailResponse)

suspend fun sendInCircuit(
breaker: CircuitBreaker, toEmail: String,
name: String, subject: String, content: String,
text: String? = null, tags: List<String>? = null
breaker: CircuitBreaker, toEmail: String,
name: String, subject: String, content: String,
text: String? = null, tags: List<String>? = null
): MailResponse

}
Loading

0 comments on commit 0fdd43d

Please sign in to comment.