cat_gateway/service/api/documents/
get_document.rs1use poem_openapi::ApiResponse;
4
5use super::common;
6use crate::{
7 db::event::error::NotFoundError,
8 service::common::{responses::WithErrorResponses, types::payload::cbor::Cbor},
9};
10
11#[derive(ApiResponse)]
13pub(crate) enum Responses {
14 #[oai(status = 200)]
18 Ok(Cbor<Vec<u8>>),
19 #[oai(status = 404)]
23 NotFound,
24}
25
26pub(crate) type AllResponses = WithErrorResponses<Responses>;
28
29pub(crate) async fn endpoint(
31 document_id: uuid::Uuid,
32 version: Option<uuid::Uuid>,
33) -> AllResponses {
34 match common::get_document_cbor_bytes(&document_id, version.as_ref()).await {
35 Ok(doc_cbor_bytes) => Responses::Ok(Cbor(doc_cbor_bytes)).into(),
36 Err(err) if err.is::<NotFoundError>() => Responses::NotFound.into(),
37 Err(err) => AllResponses::handle_error(&err),
38 }
39}