Skip to content

Commit 47eb08d

Browse files
feat: enhancement for POST /filters (#836)
server sends filter json with filter id as response and list filters by users
1 parent 22a7d87 commit 47eb08d

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

server/src/handlers/http/users/filters.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
*/
1818

1919
use crate::{
20-
handlers::{http::ingest::PostError, STREAM_NAME_HEADER_KEY},
20+
handlers::http::ingest::PostError,
2121
option::CONFIG,
2222
storage::{object_storage::filter_path, ObjectStorageError},
2323
users::filters::{Filter, CURRENT_FILTER_VERSION, FILTERS},
@@ -33,15 +33,7 @@ pub async fn list(req: HttpRequest) -> Result<impl Responder, FiltersError> {
3333
.match_info()
3434
.get("user_id")
3535
.ok_or(FiltersError::Metadata("No User Id Provided"))?;
36-
let stream_name = req
37-
.headers()
38-
.iter()
39-
.find(|&(key, _)| key == STREAM_NAME_HEADER_KEY)
40-
.ok_or_else(|| FiltersError::Metadata("Stream Name Not Provided"))?
41-
.1
42-
.to_str()
43-
.map_err(|_| FiltersError::Metadata("Non ASCII Stream Name Provided"))?;
44-
let filters = FILTERS.list_filters_by_user_and_stream(user_id, stream_name);
36+
let filters = FILTERS.list_filters_by_user(user_id);
4537

4638
Ok((web::Json(filters), StatusCode::OK))
4739
}
@@ -59,7 +51,7 @@ pub async fn get(req: HttpRequest) -> Result<impl Responder, FiltersError> {
5951
Err(FiltersError::Metadata("Filter Not Found"))
6052
}
6153

62-
pub async fn post(body: Bytes) -> Result<HttpResponse, PostError> {
54+
pub async fn post(body: Bytes) -> Result<impl Responder, PostError> {
6355
let filter: Filter = serde_json::from_slice(&body)?;
6456
let filter_id = rand::distributions::Alphanumeric.sample_string(&mut rand::thread_rng(), 10);
6557
let user_id = &filter.user_id;
@@ -75,7 +67,7 @@ pub async fn post(body: Bytes) -> Result<HttpResponse, PostError> {
7567
let filter_bytes = serde_json::to_vec(&cloned_filter)?;
7668
store.put_object(&path, Bytes::from(filter_bytes)).await?;
7769

78-
Ok(HttpResponse::Ok().finish())
70+
Ok((web::Json(cloned_filter), StatusCode::OK))
7971
}
8072

8173
pub async fn update(req: HttpRequest, body: Bytes) -> Result<HttpResponse, PostError> {

server/src/users/filters.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ impl Filters {
106106
.cloned()
107107
}
108108

109-
pub fn list_filters_by_user_and_stream(&self, user_id: &str, stream_name: &str) -> Vec<Filter> {
109+
pub fn list_filters_by_user(&self, user_id: &str) -> Vec<Filter> {
110110
self.0
111111
.read()
112112
.expect(LOCK_EXPECT)
113113
.iter()
114-
.filter(|f| f.user_id == user_id && f.stream_name == stream_name)
114+
.filter(|f| f.user_id == user_id)
115115
.cloned()
116116
.collect()
117117
}

0 commit comments

Comments
 (0)