-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added auth library * Changes done for auth-library * Change endpoint from getMapping to postmapping * Updated unit test
- Loading branch information
Showing
8 changed files
with
21 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 11 additions & 24 deletions
35
src/main/kotlin/com/hrv/mart/backendauth/controller/AuthController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
src/main/kotlin/com/hrv/mart/backendauth/model/AuthResponse.kt
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/com/hrv/mart/backendauth/repository/AuthRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 2 additions & 4 deletions
6
src/main/kotlin/com/hrv/mart/backendauth/service/AuthService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters