|
| 1 | +use crate::{ |
| 2 | + endpoints::{Endpoint, HandleGetContext}, |
| 3 | + errors::AtomicResult, |
| 4 | + urls, Resource, |
| 5 | +}; |
| 6 | + |
| 7 | +// Note that the actual logic of this endpoint resides in `atomic-server`, as it depends on the Actix runtime. |
| 8 | +pub fn query_endpoint() -> Endpoint { |
| 9 | + Endpoint { |
| 10 | + path: urls::PATH_QUERY.into(), |
| 11 | + params: [ |
| 12 | + urls::COLLECTION_PROPERTY.to_string(), |
| 13 | + urls::COLLECTION_VALUE.to_string(), |
| 14 | + urls::COLLECTION_PAGE_SIZE.to_string(), |
| 15 | + urls::COLLECTION_CURRENT_PAGE.to_string(), |
| 16 | + urls::COLLECTION_INCLUDE_EXTERNAL.to_string(), |
| 17 | + urls::COLLECTION_INCLUDE_NESTED.to_string(), |
| 18 | + urls::COLLECTION_SORT_BY.to_string(), |
| 19 | + urls::COLLECTION_SORT_DESC.to_string(), |
| 20 | + ] |
| 21 | + .into(), |
| 22 | + description: "Query the server for resources matching the query filter.".to_string(), |
| 23 | + shortname: "query".to_string(), |
| 24 | + handle: Some(handle_query_request), |
| 25 | + handle_post: None, |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +fn handle_query_request(context: HandleGetContext) -> AtomicResult<Resource> { |
| 30 | + let HandleGetContext { |
| 31 | + subject, |
| 32 | + store, |
| 33 | + for_agent, |
| 34 | + } = context; |
| 35 | + |
| 36 | + if subject.query_pairs().into_iter().next().is_none() { |
| 37 | + return query_endpoint().to_resource(store); |
| 38 | + } |
| 39 | + let mut resource = Resource::new(subject.to_string()); |
| 40 | + crate::collections::construct_collection_from_params( |
| 41 | + store, |
| 42 | + subject.query_pairs(), |
| 43 | + &mut resource, |
| 44 | + for_agent, |
| 45 | + ) |
| 46 | +} |
0 commit comments