From 21aea5d755cdd264d58e75a22806631c20731088 Mon Sep 17 00:00:00 2001 From: Harsh Verma <55652117+Harsh3305@users.noreply.github.com> Date: Fri, 14 Jul 2023 17:40:28 +0530 Subject: [PATCH] Add auth with usr type model (#24) * Add mongo db support * rename Auth model * Create auth with user type model to store role of user * Add user id * Minor update * Fix detekt build fail --- build.gradle.kts | 5 +++-- .../model/{Auth.kt => AppWriteAuth.kt} | 8 ++++---- .../hrv/mart/authlibrary/model/AuthResponse.kt | 2 +- .../mart/authlibrary/model/AuthWithUserType.kt | 17 +++++++++++++++++ .../com/hrv/mart/authlibrary/model/UserType.kt | 2 +- 5 files changed, 26 insertions(+), 8 deletions(-) rename src/main/kotlin/com/hrv/mart/authlibrary/model/{Auth.kt => AppWriteAuth.kt} (74%) create mode 100644 src/main/kotlin/com/hrv/mart/authlibrary/model/AuthWithUserType.kt diff --git a/build.gradle.kts b/build.gradle.kts index 085857b..a4d4fb2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -54,10 +54,11 @@ dependencies { testImplementation("io.projectreactor:reactor-test") // Detekt plugins detektPlugins ("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.0") - // User Model + // HRV-Mart implementation("com.hrv.mart:user-library:0.0.3") - // API-Call implementation("com.hrv.mart:api-call:0.0.3") + // Mongo-DB + implementation("org.springframework.boot:spring-boot-starter-data-mongodb-reactive") } tasks.withType { diff --git a/src/main/kotlin/com/hrv/mart/authlibrary/model/Auth.kt b/src/main/kotlin/com/hrv/mart/authlibrary/model/AppWriteAuth.kt similarity index 74% rename from src/main/kotlin/com/hrv/mart/authlibrary/model/Auth.kt rename to src/main/kotlin/com/hrv/mart/authlibrary/model/AppWriteAuth.kt index f48df62..7ffb309 100644 --- a/src/main/kotlin/com/hrv/mart/authlibrary/model/Auth.kt +++ b/src/main/kotlin/com/hrv/mart/authlibrary/model/AppWriteAuth.kt @@ -2,17 +2,17 @@ package com.hrv.mart.authlibrary.model import com.hrv.mart.userlibrary.model.User -data class Auth ( +data class AppWriteAuth ( + val userId: String, val createdAt: String, val updatedAt: String, val name: String, val email: String, - val emailVerification: Boolean, - val userType: UserType = UserType.USER + val emailVerification: Boolean ) { fun toUser() = User( emailId = email, name = name ) -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/hrv/mart/authlibrary/model/AuthResponse.kt b/src/main/kotlin/com/hrv/mart/authlibrary/model/AuthResponse.kt index 2a4832c..67443f6 100644 --- a/src/main/kotlin/com/hrv/mart/authlibrary/model/AuthResponse.kt +++ b/src/main/kotlin/com/hrv/mart/authlibrary/model/AuthResponse.kt @@ -3,4 +3,4 @@ package com.hrv.mart.authlibrary.model data class AuthResponse ( val userId: String, val userType: UserType -) \ No newline at end of file +) diff --git a/src/main/kotlin/com/hrv/mart/authlibrary/model/AuthWithUserType.kt b/src/main/kotlin/com/hrv/mart/authlibrary/model/AuthWithUserType.kt new file mode 100644 index 0000000..bf0a52d --- /dev/null +++ b/src/main/kotlin/com/hrv/mart/authlibrary/model/AuthWithUserType.kt @@ -0,0 +1,17 @@ +package com.hrv.mart.authlibrary.model + +import org.springframework.data.mongodb.core.mapping.Document + +@Document +data class AuthWithUserType ( + val userId: String, + val userType: UserType +) { + companion object { + fun parseFrom(auth: AppWriteAuth, userType: UserType) = + AuthWithUserType( + userId = auth.userId, + userType = userType + ) + } +} diff --git a/src/main/kotlin/com/hrv/mart/authlibrary/model/UserType.kt b/src/main/kotlin/com/hrv/mart/authlibrary/model/UserType.kt index 22d84d8..9d0baf7 100644 --- a/src/main/kotlin/com/hrv/mart/authlibrary/model/UserType.kt +++ b/src/main/kotlin/com/hrv/mart/authlibrary/model/UserType.kt @@ -2,4 +2,4 @@ package com.hrv.mart.authlibrary.model enum class UserType { USER, ADMIN -} \ No newline at end of file +}