数据校验,添加ResErr转换

This commit is contained in:
liyunjia 2024-05-26 14:03:41 +08:00
parent d00d07d46e
commit 022f0ba4bd
5 changed files with 13 additions and 7 deletions

1
Cargo.lock generated
View File

@ -1080,6 +1080,7 @@ dependencies = [
"tracing-appender",
"tracing-subscriber",
"ulid",
"validator",
]
[[package]]

View File

@ -1,15 +1,13 @@
use axum::Json;
use axum_extra::extract::WithRejection;
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;
pub async fn authenticate_google(
WithRejection(Json(req), _): IRejection<Json<AuthenticateGooleAccountReq>>
) -> ResResult<ResOK<()>> {
if let Err(err) = req.validate() {
return Err(ResErr::ErrParams(Some(err.to_string())));
}
req.validate()?;
service::account::authticate_google(req).await?;

View File

@ -25,4 +25,5 @@ moka = { workspace = true, features = ["future"] }
tokio = { workspace = true, features = ["rt-multi-thread", "macros" ] }
futures-util = { workspace = true }
jsonwebtoken = { workspace = true }
reqwest = { workspace = true, features = ["blocking", "json"] }
reqwest = { workspace = true, features = ["blocking", "json"] }
validator = { workspace = true }

View File

@ -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 {
fn default() -> Self {
ErrSystem(None)

View File

@ -1,7 +1,7 @@
use std::{collections::HashMap, fmt::Error};
use std::collections::HashMap;
use chrono::Utc;
use jsonwebtoken::{decode, errors::ErrorKind, Algorithm, DecodingKey, TokenData, Validation};
use jsonwebtoken::{decode, Algorithm, DecodingKey, Validation};
use reqwest::Client;
use serde_json::Value;