Skip to content

Commit

Permalink
list filters by users
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilsinhaparseable committed Jun 28, 2024
1 parent 277dd1d commit 9289724
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
12 changes: 2 additions & 10 deletions server/src/handlers/http/users/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/

use crate::{
handlers::{http::ingest::PostError, STREAM_NAME_HEADER_KEY},
handlers::http::ingest::PostError,
option::CONFIG,
storage::{object_storage::filter_path, ObjectStorageError},
users::filters::{Filter, CURRENT_FILTER_VERSION, FILTERS},
Expand All @@ -33,15 +33,7 @@ pub async fn list(req: HttpRequest) -> Result<impl Responder, FiltersError> {
.match_info()
.get("user_id")
.ok_or(FiltersError::Metadata("No User Id Provided"))?;
let stream_name = req
.headers()
.iter()
.find(|&(key, _)| key == STREAM_NAME_HEADER_KEY)
.ok_or_else(|| FiltersError::Metadata("Stream Name Not Provided"))?
.1
.to_str()
.map_err(|_| FiltersError::Metadata("Non ASCII Stream Name Provided"))?;
let filters = FILTERS.list_filters_by_user_and_stream(user_id, stream_name);
let filters = FILTERS.list_filters_by_user(user_id);

Ok((web::Json(filters), StatusCode::OK))
}
Expand Down
4 changes: 2 additions & 2 deletions server/src/users/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ impl Filters {
.cloned()
}

pub fn list_filters_by_user_and_stream(&self, user_id: &str, stream_name: &str) -> Vec<Filter> {
pub fn list_filters_by_user(&self, user_id: &str) -> Vec<Filter> {
self.0
.read()
.expect(LOCK_EXPECT)
.iter()
.filter(|f| f.user_id == user_id && f.stream_name == stream_name)
.filter(|f| f.user_id == user_id)
.cloned()
.collect()
}
Expand Down

0 comments on commit 9289724

Please sign in to comment.