Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 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 All @@ -59,7 +51,7 @@ pub async fn get(req: HttpRequest) -> Result<impl Responder, FiltersError> {
Err(FiltersError::Metadata("Filter Not Found"))
}

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

Ok(HttpResponse::Ok().finish())
Ok((web::Json(cloned_filter), StatusCode::OK))
}

pub async fn update(req: HttpRequest, body: Bytes) -> Result<HttpResponse, PostError> {
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