数据校验,添加ResErr转换
This commit is contained in:
parent
d00d07d46e
commit
022f0ba4bd
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -1080,6 +1080,7 @@ dependencies = [
|
|||||||
"tracing-appender",
|
"tracing-appender",
|
||||||
"tracing-subscriber",
|
"tracing-subscriber",
|
||||||
"ulid",
|
"ulid",
|
||||||
|
"validator",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
use axum::Json;
|
use axum::Json;
|
||||||
use axum_extra::extract::WithRejection;
|
use axum_extra::extract::WithRejection;
|
||||||
use domain::dto::account::AuthenticateGooleAccountReq;
|
use domain::dto::account::AuthenticateGooleAccountReq;
|
||||||
use library::resp::{rejection::IRejection, response::{ResErr, ResOK, ResResult}};
|
use library::resp::{rejection::IRejection, response::{ ResOK, ResResult}};
|
||||||
use validator::Validate;
|
use validator::Validate;
|
||||||
|
|
||||||
pub async fn authenticate_google(
|
pub async fn authenticate_google(
|
||||||
WithRejection(Json(req), _): IRejection<Json<AuthenticateGooleAccountReq>>
|
WithRejection(Json(req), _): IRejection<Json<AuthenticateGooleAccountReq>>
|
||||||
) -> ResResult<ResOK<()>> {
|
) -> ResResult<ResOK<()>> {
|
||||||
if let Err(err) = req.validate() {
|
req.validate()?;
|
||||||
return Err(ResErr::ErrParams(Some(err.to_string())));
|
|
||||||
}
|
|
||||||
|
|
||||||
service::account::authticate_google(req).await?;
|
service::account::authticate_google(req).await?;
|
||||||
|
|
||||||
|
@ -25,4 +25,5 @@ moka = { workspace = true, features = ["future"] }
|
|||||||
tokio = { workspace = true, features = ["rt-multi-thread", "macros" ] }
|
tokio = { workspace = true, features = ["rt-multi-thread", "macros" ] }
|
||||||
futures-util = { workspace = true }
|
futures-util = { workspace = true }
|
||||||
jsonwebtoken = { workspace = true }
|
jsonwebtoken = { workspace = true }
|
||||||
reqwest = { workspace = true, features = ["blocking", "json"] }
|
reqwest = { workspace = true, features = ["blocking", "json"] }
|
||||||
|
validator = { workspace = true }
|
@ -171,6 +171,12 @@ impl From<sqlx::Error> for ResErr {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<validator::ValidationErrors> for ResErr {
|
||||||
|
fn from(value: validator::ValidationErrors) -> Self {
|
||||||
|
ErrParams(Some(value.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Default for ResErr {
|
impl Default for ResErr {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
ErrSystem(None)
|
ErrSystem(None)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::{collections::HashMap, fmt::Error};
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use jsonwebtoken::{decode, errors::ErrorKind, Algorithm, DecodingKey, TokenData, Validation};
|
use jsonwebtoken::{decode, Algorithm, DecodingKey, Validation};
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user