From f06554c0bbd3652265de7dd71d1178e755075679 Mon Sep 17 00:00:00 2001 From: Tolmachev Igor Date: Fri, 26 Sep 2025 21:34:20 +0300 Subject: Add get_by_id and get_by_owner --- src/routers/queue/manage.rs | 63 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 10 deletions(-) (limited to 'src/routers') diff --git a/src/routers/queue/manage.rs b/src/routers/queue/manage.rs index 10f38f5..67a3abc 100644 --- a/src/routers/queue/manage.rs +++ b/src/routers/queue/manage.rs @@ -5,12 +5,12 @@ use sea_orm::{ IntoActiveModel, ModelTrait, QueryFilter, }; use serde::Deserialize; -use utoipa::ToSchema; +use utoipa::{IntoParams, ToSchema}; use utoipa_axum::{router::OpenApiRouter, routes}; use crate::{ ApiError, ApiResult, AppState, ClientError, GlobalResponses, SuccessResponse, - extract::{ApiJson, Auth}, + extract::{ApiJson, ApiQuery, Auth}, models::Queue, tags::QUEUE_MANAGEMENT, }; @@ -36,6 +36,18 @@ async fn get_owned_queue( Ok(queue) } +#[derive(Deserialize, IntoParams)] +#[into_params(parameter_in = Query)] +struct GetByIdQueueQuery { + id: i64, +} + +#[derive(Deserialize, IntoParams)] +#[into_params(parameter_in = Query)] +struct GetByOwnerIdQuery { + owner_id: i64, +} + #[derive(Deserialize, ToSchema)] #[schema(description = "Body of the create queue request")] struct CreateQueueRequest { @@ -70,23 +82,53 @@ struct DeleteQueueRequest { #[utoipa::path( get, - path = "/owned", + path = "/get/id", tag = QUEUE_MANAGEMENT, - summary = "Get owned", - description = "Get your queues", + summary = "Get by id", + description = "Get the queue by id", + params(GetByIdQueueQuery), + responses( + ( + status = 200, body = SuccessResponse>, + description = "Success response with the requested queue" + ), + GlobalResponses + ), +)] +async fn get_by_id( + State(state): State, + ApiQuery(req): ApiQuery, +) -> ApiResult> { + Ok(SuccessResponse::ok( + queues::Entity::find_by_id(req.id) + .one(&state.db) + .await? + .map(Into::into), + )) +} + +#[utoipa::path( + get, + path = "/get/owner", + tag = QUEUE_MANAGEMENT, + summary = "Get by owner", + description = "Get queues for a given owner", + params(GetByOwnerIdQuery), responses( ( status = 200, body = SuccessResponse>, - description = "Success response with your queues" + description = "Success response with queues owned by the given user" ), GlobalResponses ), - security(("auth" = [])), )] -async fn owned(State(state): State, Auth(user): Auth) -> ApiResult> { +async fn get_by_owner( + State(state): State, + ApiQuery(req): ApiQuery, +) -> ApiResult> { return Ok(SuccessResponse::ok( queues::Entity::find() - .filter(queues::Column::OwnerId.eq(user.id)) + .filter(queues::Column::OwnerId.eq(req.owner_id)) .all(&state.db) .await? .into_iter() @@ -225,7 +267,8 @@ async fn delete( pub fn router() -> OpenApiRouter { OpenApiRouter::new() - .routes(routes!(owned)) + .routes(routes!(get_by_id)) + .routes(routes!(get_by_owner)) .routes(routes!(create)) .routes(routes!(update_name)) .routes(routes!(update_owner)) -- cgit v1.2.3