1
0
Files
nir/src/web/routes/user/register.rs
2024-05-20 12:34:46 +03:00

29 lines
656 B
Rust

use axum::{extract::State, response::IntoResponse, Json};
use serde::Deserialize;
use serde_json::json;
use crate::{state::AppState, web};
pub async fn register(
State(state): State<AppState>,
Json(payload): Json<RegisterPayload>,
) -> web::Result<impl IntoResponse> {
let user = state
.database
.create_user(&payload.username, &payload.password)
.await?;
Ok(Json(json!({
"id": user.id,
"username": user.username,
"created_at": user.created_at
})))
}
#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct RegisterPayload {
username: String,
password: String,
}