dynamic_db (#17)
All checks were successful
Release Tagging / release (push) Successful in 39s
Rust Build / Check (push) Successful in 41s
Rust Build / Test Suite (push) Successful in 48s
Rust Build / Rustfmt (push) Successful in 28s
Rust Build / Clippy (push) Successful in 48s
Rust Build / build (push) Successful in 1m13s
Rust Build / Check (pull_request) Successful in 57s
Rust Build / Test Suite (pull_request) Successful in 48s
Rust Build / Rustfmt (pull_request) Successful in 26s
Rust Build / Clippy (pull_request) Successful in 46s
Rust Build / build (pull_request) Successful in 1m12s
All checks were successful
Release Tagging / release (push) Successful in 39s
Rust Build / Check (push) Successful in 41s
Rust Build / Test Suite (push) Successful in 48s
Rust Build / Rustfmt (push) Successful in 28s
Rust Build / Clippy (push) Successful in 48s
Rust Build / build (push) Successful in 1m13s
Rust Build / Check (pull_request) Successful in 57s
Rust Build / Test Suite (pull_request) Successful in 48s
Rust Build / Rustfmt (pull_request) Successful in 26s
Rust Build / Clippy (pull_request) Successful in 46s
Rust Build / build (pull_request) Successful in 1m12s
Reviewed-on: #17 Co-authored-by: phoenix <kundeng94@gmail.com> Co-committed-by: phoenix <kundeng94@gmail.com>
This commit is contained in:
@@ -1,12 +1,47 @@
|
||||
use axum::{Json, http::StatusCode};
|
||||
|
||||
use crate::models;
|
||||
use crate::repo;
|
||||
|
||||
mod response {
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::models;
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Response {
|
||||
pub message: String,
|
||||
pub data: models::common::User,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn register_user(
|
||||
axum::Extension(pool): axum::Extension<sqlx::PgPool>,
|
||||
Json(payload): Json<models::common::CreateUser>,
|
||||
) -> (StatusCode, Json<models::common::User>) {
|
||||
let user = models::common::User {
|
||||
) -> (StatusCode, Json<response::Response>) {
|
||||
let mut user = models::common::User {
|
||||
id: uuid::Uuid::nil(),
|
||||
username: payload.username.clone(),
|
||||
password: payload.password.clone(),
|
||||
};
|
||||
(StatusCode::CREATED, Json(user))
|
||||
|
||||
match repo::user::insert(&pool, &user).await {
|
||||
Ok(id) => {
|
||||
user.id = id;
|
||||
(
|
||||
StatusCode::CREATED,
|
||||
Json(response::Response {
|
||||
message: String::from("User inserted"),
|
||||
data: user,
|
||||
}),
|
||||
)
|
||||
}
|
||||
Err(err) => (
|
||||
StatusCode::BAD_REQUEST,
|
||||
Json(response::Response {
|
||||
message: err.to_string(),
|
||||
data: user,
|
||||
}),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user