Added doc gen for endpoint and made some improvements

This commit is contained in:
2026-06-11 14:31:46 -04:00
parent d693db71b1
commit 93a51578c2
+35
View File
@@ -198,6 +198,21 @@ async fn is_registration_enabled() -> Result<bool, std::io::Error> {
} }
/// Endpoint to register a service user /// Endpoint to register a service user
#[utoipa::path(
post,
path = super::endpoints::REGISTER_SERVICE_USER,
request_body(
content = request::RegisterServiceUserRequest,
description = "Data required to register service user",
content_type = "application/json"
),
responses(
(status = 201, description = "Service user created", body = response::RegisterServiceUserResponse),
(status = 400, description = "Issue creating service user", body = response::RegisterServiceUserResponse),
(status = 406, description = "Cannot create service user", body = response::RegisterServiceUserResponse),
(status = 500, description = "Issue creating service user", body = response::RegisterServiceUserResponse),
)
)]
pub async fn register_service_user( pub async fn register_service_user(
axum::Extension(pool): axum::Extension<sqlx::PgPool>, axum::Extension(pool): axum::Extension<sqlx::PgPool>,
Json(payload): Json<request::RegisterServiceUserRequest>, Json(payload): Json<request::RegisterServiceUserRequest>,
@@ -209,11 +224,24 @@ pub async fn register_service_user(
..Default::default() ..Default::default()
}; };
let registration_enabled = match is_registration_enabled().await {
Ok(value) => value,
Err(err) => {
eprintln!("Error: {err:?}");
resp.message = String::from("Registration check failed");
return (
axum::http::StatusCode::INTERNAL_SERVER_ERROR,
Json(resp)
);
}
};
let (res, msg) = payload.is_empty(); let (res, msg) = payload.is_empty();
if res { if res {
resp.message = msg.unwrap(); resp.message = msg.unwrap();
(axum::http::StatusCode::BAD_REQUEST, axum::Json(resp)) (axum::http::StatusCode::BAD_REQUEST, axum::Json(resp))
} else { } else {
if registration_enabled {
match repo::service::exists(&pool, &payload.username).await { match repo::service::exists(&pool, &payload.username).await {
Ok(exists) => { Ok(exists) => {
if exists { if exists {
@@ -260,5 +288,12 @@ pub async fn register_service_user(
) )
} }
} }
} else {
resp.message = String::from("Registration is not enabled");
(
axum::http::StatusCode::NOT_ACCEPTABLE,
Json(resp),
)
}
} }
} }