feat: add Swagger annotations for user authentication endpoints and update validation in LoginRequest
This commit is contained in:
@@ -6,9 +6,11 @@ import com.onixbyte.deltaforceguide.client.TokenClient;
|
|||||||
import com.onixbyte.deltaforceguide.service.AuthService;
|
import com.onixbyte.deltaforceguide.service.AuthService;
|
||||||
import com.onixbyte.deltaforceguide.service.CookieService;
|
import com.onixbyte.deltaforceguide.service.CookieService;
|
||||||
import com.onixbyte.deltaforceguide.shared.CookieName;
|
import com.onixbyte.deltaforceguide.shared.CookieName;
|
||||||
import jakarta.validation.Valid;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
@@ -16,6 +18,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
|
||||||
|
@Tag(name = "用户鉴权", description = "处理用户登录与退出功能")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/auth")
|
@RequestMapping("/auth")
|
||||||
public class AuthController {
|
public class AuthController {
|
||||||
@@ -30,8 +33,9 @@ public class AuthController {
|
|||||||
this.cookieService = cookieService;
|
this.cookieService = cookieService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(description = "用户登录")
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
public ResponseEntity<UserResponse> login(@Valid @RequestBody LoginRequest request) {
|
public ResponseEntity<UserResponse> login(@Validated @RequestBody LoginRequest request) {
|
||||||
var user = authService.login(request);
|
var user = authService.login(request);
|
||||||
var accessToken = tokenClient.generateToken(user);
|
var accessToken = tokenClient.generateToken(user);
|
||||||
var accessTokenCookie = cookieService.buildCookie(CookieName.ACCESS_TOKEN, accessToken);
|
var accessTokenCookie = cookieService.buildCookie(CookieName.ACCESS_TOKEN, accessToken);
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
package com.onixbyte.deltaforceguide.domain.dto;
|
package com.onixbyte.deltaforceguide.domain.dto;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
|
||||||
|
@Schema(description = "登录请求")
|
||||||
public record LoginRequest(
|
public record LoginRequest(
|
||||||
@NotBlank(message = "登录名称不能为空") String principle,
|
@NotBlank(message = "登录名称不能为空")
|
||||||
@NotBlank(message = "登录口令不能为空") String credential
|
@Schema(description = "用户名或电子邮箱")
|
||||||
|
String principle,
|
||||||
|
@NotBlank(message = "登录口令不能为空")
|
||||||
|
@Schema(description = "密码")
|
||||||
|
String credential
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user