Skip to content

Instantly share code, notes, and snippets.

View RaheemJnr's full-sized avatar
🎯
Focusing

Raheem Jnr RaheemJnr

🎯
Focusing
View GitHub Profile
@RaheemJnr
RaheemJnr / dependencies.kt
Created October 1, 2022 08:31
amazon amplify dependency
dependencies {
implementation 'com.amplifyframework:aws-api:1.37.3'
implementation 'com.amplifyframework:aws-datastore:1.37.3'
}
//extention method to call in the Application class
fun Application.configureRouting(authController: AuthController) {
routing {
authenticationRoutes(authController)
}
}
//Register route
fun Route.authenticationRoutes(controller: AuthController) {
@Serializable
data class UserDetails(val id: String, val username: String, val email: String, val user_type: String)
@Serializable
data class UserDetailResponse(
override val status: State,
override val message: String,
val user: UserDetails? = null
) : Response {
/**
* Authentication controller
[authDao] was created earlier, an interface that we use to communicate with our database
[jwt controller] a class for user authentication
[encryptor] an helper method for enrypting password string
* */
class AuthController(
private val authDao: AuthDao,
private val jwt: JwtController,
private val encryptor: (String) -> String
class AuthDaoImpl : AuthDao {
//add a new user into database
override fun registerUser(
username: String,
email: String,
usertype: String,
password: String
): User = transaction {
EntityUser.new {
this.username = username
interface AuthDao {
/****
* add a new user to database
* */
fun registerUser(
username: String,
email: String,
password: String,
): User
//extention method to call in the Application class
fun Application.configureRouting(authController: AuthController) {
routing {
authenticationRoutes(authController)
}
}
//Register route
fun Route.authenticationRoutes(controller: AuthController) {
/**
* Authentication controller
[authDao] was created earlier, an interface that we use to communicate with our database
[jwt controller] a class for user authentication
[encryptor] an helper method for enrypting password string
* */
class AuthController(
private val authDao: AuthDao,
private val jwt: JwtController,
private val encryptor: (String) -> String
class AuthDaoImpl : AuthDao {
//add a new user into database
override fun registerUser(
username: String,
email: String,
usertype: String,
password: String
): User = transaction {
EntityUser.new {
this.username = username
interface AuthDao {
/****
* add a new user to database
* */
fun registerUser(
username: String,
email: String,
password: String,
): User