-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cat-gateway): Add document put endpoint
- Loading branch information
Showing
6 changed files
with
113 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
catalyst-gateway/bin/src/service/api/documents/put_document.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
//! Implementation of the PUT `/document` endpoint | ||
use bytes::Bytes; | ||
use poem_openapi::{payload::Json, ApiResponse}; | ||
|
||
use crate::service::common::{ | ||
objects::document::bad_put_request::PutDocumentBadRequest, responses::WithErrorResponses, | ||
}; | ||
|
||
/// Maximum size of a Signed Document (1MB) | ||
pub(crate) const MAXIMUM_DOCUMENT_SIZE: usize = 1_048_576; | ||
|
||
/// Endpoint responses. | ||
#[derive(ApiResponse)] | ||
#[allow(dead_code)] | ||
pub(crate) enum Responses { | ||
/// The Document was stored OK for the first time. | ||
#[oai(status = 201)] | ||
Created, | ||
/// The Document was already stored, and has not changed. | ||
#[oai(status = 204)] | ||
NoContent, | ||
/// Error Response | ||
#[oai(status = 400)] | ||
BadRequest(Json<PutDocumentBadRequest>), | ||
/// Payload Too Large | ||
#[oai(status = 413)] | ||
PayloadTooLarge, | ||
} | ||
|
||
/// All responses. | ||
pub(crate) type AllResponses = WithErrorResponses<Responses>; | ||
|
||
/// # PUT `/document` | ||
#[allow(clippy::unused_async, clippy::no_effect_underscore_binding)] | ||
pub(crate) async fn endpoint(document: Bytes) -> AllResponses { | ||
let _doc = document; | ||
|
||
Responses::BadRequest(Json(PutDocumentBadRequest::new("unimplemented"))).into() | ||
} |
28 changes: 28 additions & 0 deletions
28
catalyst-gateway/bin/src/service/common/objects/document/bad_put_request.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
//! Bad Document PUT request. | ||
use poem_openapi::{types::Example, Object}; | ||
|
||
/// Configuration Data Validation Error. | ||
#[derive(Object, Default)] | ||
#[oai(example = true)] | ||
pub(crate) struct PutDocumentBadRequest { | ||
/// Error messages. | ||
#[oai(validator(max_length = "100", pattern = "^[0-9a-zA-Z].*$"))] | ||
error: String, | ||
// TODO: Add optional verbose error fields for documents that fail validation. | ||
} | ||
|
||
impl PutDocumentBadRequest { | ||
/// Create a new instance of `ConfigBadRequest`. | ||
pub(crate) fn new(error: &str) -> Self { | ||
Self { | ||
error: error.to_owned(), | ||
} | ||
} | ||
} | ||
|
||
impl Example for PutDocumentBadRequest { | ||
fn example() -> Self { | ||
PutDocumentBadRequest::new("Missing Document in request body") | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
catalyst-gateway/bin/src/service/common/objects/document/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//! Signed Document Endpoint Objects | ||
pub(crate) mod bad_put_request; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters