81 lines
4.0 KiB
Java
81 lines
4.0 KiB
Java
package com.billpaymentservice.bbps.controller;
|
|
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
|
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.RestController;
|
|
|
|
import com.billpaymentservice.bbps.dto.ResponseModel;
|
|
import com.billpaymentservice.bbps.dto.auth.LoginRequest;
|
|
import com.billpaymentservice.bbps.dto.auth.RegisterRequest;
|
|
import com.billpaymentservice.bbps.dto.auth.VerifyOtpRequest;
|
|
import com.billpaymentservice.bbps.service.AuthService;
|
|
import com.billpaymentservice.bbps.util.ApiDocCommonResponses;
|
|
import com.billpaymentservice.bbps.util.BBPSConstant;
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.media.Content;
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
import io.swagger.v3.oas.annotations.responses.ApiResponse;
|
|
import io.swagger.v3.oas.annotations.responses.ApiResponses;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
@RestController
|
|
@RequestMapping("/auth")
|
|
@CrossOrigin(origins = "*")
|
|
@Slf4j
|
|
public class AuthController {
|
|
|
|
private final AuthService authService;
|
|
|
|
public AuthController(AuthService authService) {
|
|
this.authService = authService;
|
|
}
|
|
|
|
@PostMapping(value = "/sendOtp")
|
|
@Operation(summary = "Send OTP to user", description = "This API sends an OTP to the user's registered mobile number for authentication.")
|
|
@ApiResponses(value = {
|
|
@ApiResponse(responseCode = BBPSConstant.OK_STR, description = "OTP sent successfully", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ResponseModel.class))) })
|
|
@ApiDocCommonResponses
|
|
public ResponseEntity<ResponseModel> sendOtp(@Validated @RequestBody LoginRequest request) {
|
|
log.info("Received sendOtp request for mobile: {}", request.getMobile());
|
|
return ResponseEntity.ok(authService.sendOtp(request));
|
|
}
|
|
|
|
@PostMapping(value = "/verifyOtp")
|
|
@Operation(summary = "Verify OTP", description = "This API verifies the OTP entered by the user and validates the authentication flow.")
|
|
@ApiResponses(value = {
|
|
@ApiResponse(responseCode = BBPSConstant.OK_STR, description = "OTP verified successfully", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ResponseModel.class))) })
|
|
@ApiDocCommonResponses
|
|
|
|
public ResponseEntity<ResponseModel> verifyOtp(@Validated @RequestBody VerifyOtpRequest request) {
|
|
|
|
return ResponseEntity.ok(authService.verifyOtp(request));
|
|
}
|
|
|
|
@PostMapping(value = "/register")
|
|
@Operation(summary = "Register a new user", description = "This API registers a new user into the system by validating the provided registration details.")
|
|
@ApiResponses(value = {
|
|
@ApiResponse(responseCode = BBPSConstant.OK_STR, description = "User registered successfully", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ResponseModel.class))) })
|
|
@ApiDocCommonResponses
|
|
public ResponseEntity<ResponseModel> register(@Validated @RequestBody RegisterRequest request) {
|
|
|
|
return ResponseEntity.ok(authService.registerUser(request));
|
|
}
|
|
|
|
@PostMapping("/loginWithoutDecryption")
|
|
@Operation(summary = "Login without decryption (Testing Only)", description = "This API is used only for testing purposes. It authenticates the user without decrypting the credentials, typically used when token generation fails or decryption flow is not enabled.")
|
|
@ApiResponses(value = {
|
|
@ApiResponse(responseCode = BBPSConstant.OK_STR, description = "User authenticated successfully (Testing Only)", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ResponseModel.class))) })
|
|
@ApiDocCommonResponses
|
|
public ResponseEntity<ResponseModel> login(@RequestBody LoginRequest loginRequest) {
|
|
|
|
return ResponseEntity.ok(authService.authenticateUser(loginRequest));
|
|
|
|
}
|
|
|
|
} |