Add user registration endpoint
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
// src/handlers/user/mod.rs
|
||||
|
||||
pub mod register;
|
||||
pub mod user;
|
||||
|
||||
40
src/handlers/user/register.rs
Normal file
40
src/handlers/user/register.rs
Normal file
@@ -0,0 +1,40 @@
|
||||
// src/handlers/register/register.rs
|
||||
|
||||
use axum::Json;
|
||||
use axum::http::StatusCode;
|
||||
use axum::response::IntoResponse;
|
||||
use serde::Deserialize;
|
||||
use serde_json::json;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct RegisterPayload {
|
||||
pub email: String,
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
impl RegisterPayload {
|
||||
pub fn new(email: String, password: String) -> Self {
|
||||
RegisterPayload { email, password }
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn register(Json(_payload): Json<RegisterPayload>) -> impl IntoResponse {
|
||||
// TODO: Implement register logic
|
||||
|
||||
(
|
||||
StatusCode::OK,
|
||||
Json(json!(
|
||||
{
|
||||
"message": "new user registered",
|
||||
"data": {
|
||||
"user": {
|
||||
"email" : _payload.email,
|
||||
"password": _payload.password,
|
||||
}
|
||||
},
|
||||
"success": true,
|
||||
"error": false,
|
||||
}
|
||||
)),
|
||||
)
|
||||
}
|
||||
@@ -1,9 +1,15 @@
|
||||
// src/routes/user/user.rs
|
||||
|
||||
use axum::{Router, routing::get};
|
||||
use axum::{
|
||||
Router,
|
||||
routing::{get, post},
|
||||
};
|
||||
|
||||
use crate::handlers::user::register::register;
|
||||
use crate::handlers::user::user::user;
|
||||
|
||||
pub fn user_routes() -> Router {
|
||||
Router::new().route("/", get(user))
|
||||
Router::new()
|
||||
.route("/", get(user))
|
||||
.route("/register", post(register))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user