All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.rocketbase.commons.controller.ValidationController Maven / Gradle / Ivy

package io.rocketbase.commons.controller;


import io.rocketbase.commons.converter.ValidationConverter;
import io.rocketbase.commons.dto.validation.*;
import io.rocketbase.commons.exception.ValidationErrorCode;
import io.rocketbase.commons.service.validation.ValidationService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Set;

@Slf4j
@RestController
@RequestMapping("${auth.prefix:}")
@RequiredArgsConstructor
public class ValidationController implements BaseController {

    @Resource
    private ValidationService validationService;


    @RequestMapping(value = "/auth/validate/password", method = RequestMethod.POST)
    public ResponseEntity> validatePassword(@RequestBody String password) {
        Set> passwordErrorCodes = validationService.getPasswordValidationDetails(password);
        return ResponseEntity.ok(ValidationConverter.convert(passwordErrorCodes));
    }

    @RequestMapping(value = "/auth/validate/username", method = RequestMethod.POST)
    public ResponseEntity> validateUsername(@RequestBody String username) {
        Set> usernameErrorCodes = validationService.getUsernameValidationDetails(username);
        return ResponseEntity.ok(ValidationConverter.convert(usernameErrorCodes));
    }

    @RequestMapping(value = "/auth/validate/email", method = RequestMethod.POST)
    public ResponseEntity> validateEmail(@RequestBody String email) {
        Set> emailErrorCodes = validationService.getEmailValidationDetails(email);
        return ResponseEntity.ok(ValidationConverter.convert(emailErrorCodes));
    }

    @RequestMapping(value = "/auth/validate/token", method = RequestMethod.POST)
    public ResponseEntity> validateToken(@RequestBody String token) {
        Set> tokenErrorCodes = validationService.getTokenValidationDetails(token);
        return ResponseEntity.ok(ValidationConverter.convert(tokenErrorCodes));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy