Skip to content

Commit eadadd2

Browse files
Pollepsjoepio
authored andcommitted
Create Query endpoint
1 parent 3011a93 commit eadadd2

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ See [STATUS.md](server/STATUS.md) to learn more about which features will remain
1515
- Don't require building index for populate commands
1616
- Refactor `for_agent` arguments to use the new `ForAgent` enum #623
1717
- Add support for Bearer token authentication, find in `/app/token` #632
18+
- Add a `query` endpoint that allows peroforming collection queries via an enpoint instead of repurposing the collections collection.
1819

1920
## [v0.34.2] - 2023-03-04
2021

lib/src/endpoints.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,5 +84,6 @@ pub fn default_endpoints() -> Vec<Endpoint> {
8484
#[cfg(feature = "html")]
8585
plugins::bookmark::bookmark_endpoint(),
8686
plugins::importer::import_endpoint(),
87+
plugins::query::query_endpoint(),
8788
]
8889
}

lib/src/plugins/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,6 @@ pub mod invite;
4343
pub mod bookmark;
4444
pub mod files;
4545
pub mod path;
46+
pub mod query;
4647
pub mod search;
4748
pub mod versioning;

lib/src/plugins/query.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
}

lib/src/urls.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,4 @@ pub fn construct_path_import(base: &str) -> String {
145145

146146
pub const PATH_IMPORT: &str = "/import";
147147
pub const PATH_FETCH_BOOKMARK: &str = "/fetch-bookmark";
148+
pub const PATH_QUERY: &str = "/query";

0 commit comments

Comments
 (0)