Fixing service registration that has no id
This commit is contained in:
@@ -261,9 +261,10 @@ pub async fn register_service_user(
|
|||||||
println!("Creating user");
|
println!("Creating user");
|
||||||
|
|
||||||
match repo::service::insert(&pool, &service_user).await {
|
match repo::service::insert(&pool, &service_user).await {
|
||||||
Ok(created) => {
|
Ok((service_user_id, created)) => {
|
||||||
resp.message = String::from(super::messages::SUCCESSFUL_MESSAGE);
|
resp.message = String::from(super::messages::SUCCESSFUL_MESSAGE);
|
||||||
service_user.created = Some(created);
|
service_user.created = Some(created);
|
||||||
|
service_user.id = service_user_id;
|
||||||
resp.data.push(service_user);
|
resp.data.push(service_user);
|
||||||
(axum::http::StatusCode::CREATED, axum::Json(resp))
|
(axum::http::StatusCode::CREATED, axum::Json(resp))
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-3
@@ -111,11 +111,11 @@ pub async fn update_last_login(
|
|||||||
pub async fn insert(
|
pub async fn insert(
|
||||||
pool: &sqlx::PgPool,
|
pool: &sqlx::PgPool,
|
||||||
service_user: &textsender_models::user::ServiceUser,
|
service_user: &textsender_models::user::ServiceUser,
|
||||||
) -> Result<time::OffsetDateTime, sqlx::Error> {
|
) -> Result<(uuid::Uuid, time::OffsetDateTime), sqlx::Error> {
|
||||||
match sqlx::query(
|
match sqlx::query(
|
||||||
r#"INSERT INTO "service_user" (username, passphrase, salt_id)
|
r#"INSERT INTO "service_user" (username, passphrase, salt_id)
|
||||||
VALUES ($1, $2, $3)
|
VALUES ($1, $2, $3)
|
||||||
RETURNING created
|
RETURNING id, created
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
.bind(&service_user.username)
|
.bind(&service_user.username)
|
||||||
@@ -125,8 +125,9 @@ pub async fn insert(
|
|||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(row) => {
|
Ok(row) => {
|
||||||
|
let id: uuid::Uuid = row.try_get("id")?;
|
||||||
let created: time::OffsetDateTime = row.try_get("created")?;
|
let created: time::OffsetDateTime = row.try_get("created")?;
|
||||||
Ok(created)
|
Ok((id, created))
|
||||||
}
|
}
|
||||||
Err(err) => Err(err),
|
Err(err) => Err(err),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user