mirror of
https://github.com/DefectingCat/phthonus
synced 2025-07-15 08:31:33 +00:00
feat(axum): add user registry route
This commit is contained in:
@ -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))
|
||||
|
@ -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))
|
||||
}
|
||||
|
Reference in New Issue
Block a user