Skip to content

Instantly share code, notes, and snippets.

@juancho088
Last active June 10, 2018 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juancho088/028a774dd805b5fd78318d17eaa978fc to your computer and use it in GitHub Desktop.
Save juancho088/028a774dd805b5fd78318d17eaa978fc to your computer and use it in GitHub Desktop.
Models for the Request-Dispatcher
package com.myblockbuster.core
import com.amazonaws.services.lambda.runtime.Context
import java.io.Serializable
/**
* Generic Model that any body in the future should reply to
*/
interface Model: Serializable {
var id: Int?
}
/**
* In case of no model this is the default model reply
*/
class EmptyModel(override var id: Int? = null) : Model
/**
* In case of error this is the Default Error model to return
*/
class ErrorModel(var message: String): Model {
override var id: Int?
get() = null
set(value) {}
constructor(): this("")
}
/**
* Represents a client Request
* @property input JSON object with all the request data described in https://serverless.com/framework/docs/providers/aws/events/apigateway/
* @property context Lambda function Metadata
*/
interface Request {
var input: Map<String, Any>
var context: Context
}
/**
* Request Dispatcher route to a concrete function based on a regex
* @property regex Regex that needs to satisfy to route the request
* @property func Function name to be executed
* @property cls ClassPath
* @constructor Creates an empty object with empty values
*/
data class Route(var regex: String, var func: String, var cls: String) {
constructor(): this("", "", "")
}
/**
* List of routes
* @property List of routes
* @constructor emptyList
*/
data class Routes(var routes: List<Route>) {
constructor(): this(emptyList())
}
/**
* Represents an APIGateway Request (implements {@link Request})
* @property input JSON object with all the request data described in https://serverless.com/framework/docs/providers/aws/events/apigateway/
* @property context Lambda function Metadata
*/
class ApiGatewayRequest(override var input:Map<String, Any>, override var context: Context): Request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment