Skip to content

Commit d713f1f

Browse files
authored
Add auth library (#51)
* Added auth library * Changes done for auth-library * Change endpoint from getMapping to postmapping * Updated unit test
1 parent 8699770 commit d713f1f

File tree

8 files changed

+21
-65
lines changed

8 files changed

+21
-65
lines changed

build.gradle.kts

+2
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ dependencies {
3838
testImplementation("io.projectreactor:reactor-test")
3939
// User Model
4040
implementation("com.hrv.mart:user-library:0.0.2")
41+
// Auth Library
42+
implementation("com.hrv.mart:auth-library:0.0.1")
4143
// Kafka
4244
implementation("org.springframework.kafka:spring-kafka")
4345
testImplementation("org.springframework.kafka:spring-kafka-test")
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,28 @@
11
package com.hrv.mart.backendauth.controller
22

3-
import com.hrv.mart.backendauth.model.Auth
4-
import com.hrv.mart.backendauth.model.UserType
3+
import com.hrv.mart.authlibrary.model.AuthRequest
54
import com.hrv.mart.backendauth.service.AuthService
6-
import org.springframework.http.HttpStatus
75
import org.springframework.http.server.reactive.ServerHttpResponse
8-
import org.springframework.web.bind.annotation.GetMapping
6+
import org.springframework.web.bind.annotation.PostMapping
7+
import org.springframework.web.bind.annotation.RequestBody
98
import org.springframework.web.bind.annotation.RequestMapping
10-
import org.springframework.web.bind.annotation.RequestParam
119
import org.springframework.web.bind.annotation.RestController
12-
import reactor.core.publisher.Mono
13-
import java.util.Optional
14-
import kotlin.jvm.optionals.getOrDefault
15-
import kotlin.jvm.optionals.getOrElse
1610

1711
@RestController
1812
@RequestMapping("/auth")
1913
class AuthController (
2014
private val authService: AuthService
2115
)
2216
{
23-
@OptIn(ExperimentalStdlibApi::class)
24-
@GetMapping
17+
@PostMapping
2518
fun getInfoFromJWT(
26-
@RequestParam jwt: Optional<String>,
27-
@RequestParam userType: Optional<UserType>,
19+
@RequestBody authRequest: AuthRequest,
2820
response: ServerHttpResponse
29-
): Mono<Auth > {
30-
return if (jwt.isEmpty) {
31-
response.statusCode = HttpStatus.INTERNAL_SERVER_ERROR
32-
Mono.empty()
33-
} else {
34-
authService.clientRequest(
35-
jwt = jwt.get(),
36-
userType = userType.getOrDefault(UserType.USER),
37-
response
21+
) =
22+
authService
23+
.clientRequest(
24+
jwt = authRequest.jwt,
25+
userType = authRequest.userType,
26+
response = response
3827
)
39-
}
40-
}
4128
}

src/main/kotlin/com/hrv/mart/backendauth/model/Auth.kt

-19
This file was deleted.

src/main/kotlin/com/hrv/mart/backendauth/model/AuthResponse.kt

-6
This file was deleted.

src/main/kotlin/com/hrv/mart/backendauth/model/UserType.kt

-5
This file was deleted.

src/main/kotlin/com/hrv/mart/backendauth/repository/AuthRepository.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.hrv.mart.backendauth.repository
22

3-
import com.hrv.mart.backendauth.model.Auth
3+
import com.hrv.mart.authlibrary.model.Auth
44
import io.appwrite.Client
55
import io.appwrite.services.Account
66
import kotlinx.coroutines.runBlocking

src/main/kotlin/com/hrv/mart/backendauth/service/AuthService.kt

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
package com.hrv.mart.backendauth.service
22

3-
import com.hrv.mart.backendauth.model.Auth
4-
import com.hrv.mart.backendauth.model.UserType
3+
import com.hrv.mart.authlibrary.model.Auth
4+
import com.hrv.mart.authlibrary.model.UserType
55
import com.hrv.mart.backendauth.repository.AuthRepository
66
import com.hrv.mart.backendauth.repository.KafkaRepository
7-
import io.appwrite.exceptions.AppwriteException
8-
import okhttp3.internal.wait
97
import org.springframework.beans.factory.annotation.Autowired
108
import org.springframework.http.HttpStatus
119
import org.springframework.http.server.reactive.ServerHttpResponse

src/test/kotlin/com/hrv/mart/backendauth/controller/AuthControllerTest.kt

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.hrv.mart.backendauth.controller
22

3-
import com.hrv.mart.backendauth.model.Auth
4-
import com.hrv.mart.backendauth.model.UserType
3+
import com.hrv.mart.authlibrary.model.Auth
4+
import com.hrv.mart.authlibrary.model.AuthRequest
5+
import com.hrv.mart.authlibrary.model.UserType
56
import com.hrv.mart.backendauth.repository.AuthRepository
67
import com.hrv.mart.backendauth.repository.KafkaRepository
78
import com.hrv.mart.backendauth.service.AuthService
@@ -46,8 +47,7 @@ class AuthControllerTest {
4647
StepVerifier
4748
.create(
4849
authController.getInfoFromJWT(
49-
Optional.of(jwt),
50-
Optional.of(userType),
50+
AuthRequest(jwt, userType),
5151
response
5252
)
5353
)
@@ -67,8 +67,7 @@ class AuthControllerTest {
6767
StepVerifier
6868
.create(
6969
authController.getInfoFromJWT(
70-
Optional.of(jwt),
71-
Optional.of(userType),
70+
AuthRequest(jwt, userType),
7271
response
7372
)
7473
)

0 commit comments

Comments
 (0)