feat(axum): add user registry route

This commit is contained in:
xfy
2024-10-21 10:27:06 +08:00
parent 5b681d5cfc
commit 28eb653da1
2 changed files with 36 additions and 0 deletions

View File

@ -11,6 +11,7 @@ use serde::Serialize;
use tower::ServiceBuilder;
use tower_http::timeout::TimeoutLayer;
use tracing::info;
use user::user_routes;
use crate::{
error::{AppResult, ErrorCode},
@ -58,6 +59,7 @@ pub fn routes() -> Router {
.route("/", get(hello).post(hello))
.route("/json", get(json::json).post(json::json))
.route("/text", get(text::text).post(text::text))
.nest("/user", user_routes())
.layer(
ServiceBuilder::new()
.layer(middleware::from_fn(add_version))

View File

@ -1 +1,35 @@
use axum::{routing::post, Json, Router};
use serde::{Deserialize, Serialize};
use super::{RouteResponse, RouteResult};
#[derive(Serialize, Deserialize)]
pub struct UserResigtry {
pub username: String,
pub email: String,
pub password: String,
}
#[derive(Serialize, Deserialize, Default)]
pub struct UserResigtryRes {
pub username: String,
pub email: String,
pub token: String,
}
pub async fn registry(Json(user_param): Json<UserResigtry>) -> RouteResult<UserResigtryRes> {
let data = UserResigtryRes {
username: "xfy".to_string(),
email: "i@rua.plus".to_string(),
token: "abc".to_string(),
};
let res = RouteResponse {
data,
..Default::default()
};
Ok(res)
}
pub fn user_routes() -> Router {
Router::new().route("/regist", post(registry))
}