Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add put bso and post collection validator/extractors #75

Merged
merged 1 commit into from
Oct 30, 2018
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
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion src/db/params.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Parameter types for database methods.
use web::extractors::HawkIdentifier;
use web::extractors::{BatchBsoBody, HawkIdentifier};

macro_rules! data {
($name:ident {$($property:ident: $type:ty,)*}) => {
Expand Down Expand Up @@ -82,3 +82,14 @@ pub struct PostCollectionBso {
pub payload: Option<String>,
pub ttl: Option<u32>,
}

impl From<BatchBsoBody> for PostCollectionBso {
fn from(b: BatchBsoBody) -> PostCollectionBso {
PostCollectionBso {
id: b.id,
sortindex: b.sortindex,
payload: b.payload,
ttl: b.ttl,
}
}
}
1 change: 1 addition & 0 deletions src/server/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ fn put_bso() {
let now = ms_since_epoch() as u64;
test_endpoint_with_body! {
PUT "/42/storage/bookmarks/wibble", BsoBody {
id: Some("wibble".to_string()),
sortindex: Some(0),
payload: Some("wibble".to_string()),
ttl: Some(31536000),
Expand Down
8 changes: 8 additions & 0 deletions src/web/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::fmt;

use actix_web::http::header::ToStrError;
use actix_web::Error as ActixError;
use base64::DecodeError;
use failure::{Backtrace, Context, Fail, SyncFailure};
use hawk::Error as ParseError;
Expand Down Expand Up @@ -120,6 +121,13 @@ impl From<ValidationErrorKind> for ApiError {
}
}

impl From<ValidationErrorKind> for ActixError {
fn from(kind: ValidationErrorKind) -> Self {
let api_error: ApiError = kind.into();
api_error.into()
}
}

impl Serialize for ValidationError {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
Expand Down
Loading