Skip to content

Commit

Permalink
Add auth library (#51)
Browse files Browse the repository at this point in the history
* Added auth library

* Changes done for auth-library

* Change endpoint from getMapping to postmapping

* Updated unit test
  • Loading branch information
Harsh3305 authored Jun 18, 2023
1 parent 8699770 commit d713f1f
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 65 deletions.
2 changes: 2 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ dependencies {
testImplementation("io.projectreactor:reactor-test")
// User Model
implementation("com.hrv.mart:user-library:0.0.2")
// Auth Library
implementation("com.hrv.mart:auth-library:0.0.1")
// Kafka
implementation("org.springframework.kafka:spring-kafka")
testImplementation("org.springframework.kafka:spring-kafka-test")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,28 @@
package com.hrv.mart.backendauth.controller

import com.hrv.mart.backendauth.model.Auth
import com.hrv.mart.backendauth.model.UserType
import com.hrv.mart.authlibrary.model.AuthRequest
import com.hrv.mart.backendauth.service.AuthService
import org.springframework.http.HttpStatus
import org.springframework.http.server.reactive.ServerHttpResponse
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import reactor.core.publisher.Mono
import java.util.Optional
import kotlin.jvm.optionals.getOrDefault
import kotlin.jvm.optionals.getOrElse

@RestController
@RequestMapping("/auth")
class AuthController (
private val authService: AuthService
)
{
@OptIn(ExperimentalStdlibApi::class)
@GetMapping
@PostMapping
fun getInfoFromJWT(
@RequestParam jwt: Optional<String>,
@RequestParam userType: Optional<UserType>,
@RequestBody authRequest: AuthRequest,
response: ServerHttpResponse
): Mono<Auth > {
return if (jwt.isEmpty) {
response.statusCode = HttpStatus.INTERNAL_SERVER_ERROR
Mono.empty()
} else {
authService.clientRequest(
jwt = jwt.get(),
userType = userType.getOrDefault(UserType.USER),
response
) =
authService
.clientRequest(
jwt = authRequest.jwt,
userType = authRequest.userType,
response = response
)
}
}
}
19 changes: 0 additions & 19 deletions src/main/kotlin/com/hrv/mart/backendauth/model/Auth.kt

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions src/main/kotlin/com/hrv/mart/backendauth/model/UserType.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.hrv.mart.backendauth.repository

import com.hrv.mart.backendauth.model.Auth
import com.hrv.mart.authlibrary.model.Auth
import io.appwrite.Client
import io.appwrite.services.Account
import kotlinx.coroutines.runBlocking
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package com.hrv.mart.backendauth.service

import com.hrv.mart.backendauth.model.Auth
import com.hrv.mart.backendauth.model.UserType
import com.hrv.mart.authlibrary.model.Auth
import com.hrv.mart.authlibrary.model.UserType
import com.hrv.mart.backendauth.repository.AuthRepository
import com.hrv.mart.backendauth.repository.KafkaRepository
import io.appwrite.exceptions.AppwriteException
import okhttp3.internal.wait
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpStatus
import org.springframework.http.server.reactive.ServerHttpResponse
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.hrv.mart.backendauth.controller

import com.hrv.mart.backendauth.model.Auth
import com.hrv.mart.backendauth.model.UserType
import com.hrv.mart.authlibrary.model.Auth
import com.hrv.mart.authlibrary.model.AuthRequest
import com.hrv.mart.authlibrary.model.UserType
import com.hrv.mart.backendauth.repository.AuthRepository
import com.hrv.mart.backendauth.repository.KafkaRepository
import com.hrv.mart.backendauth.service.AuthService
Expand Down Expand Up @@ -46,8 +47,7 @@ class AuthControllerTest {
StepVerifier
.create(
authController.getInfoFromJWT(
Optional.of(jwt),
Optional.of(userType),
AuthRequest(jwt, userType),
response
)
)
Expand All @@ -67,8 +67,7 @@ class AuthControllerTest {
StepVerifier
.create(
authController.getInfoFromJWT(
Optional.of(jwt),
Optional.of(userType),
AuthRequest(jwt, userType),
response
)
)
Expand Down

0 comments on commit d713f1f

Please sign in to comment.