Skip to content

Commit

Permalink
wip: Restrict further op
Browse files Browse the repository at this point in the history
  • Loading branch information
lu-zero committed Apr 13, 2023
1 parent ff08da1 commit 92e3c48
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
19 changes: 12 additions & 7 deletions src/servient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,18 @@ mod test {
let servient = Servient::builder("test")
.finish_extend()
.property("hello", |b| {
b.finish_extend_data_schema().null().form(|f| {
f.href("/hello")
.http_get(|| async { "Reading Hello, World!" })
.http_put(|| async { "Writing Hello, World!" })
.op(FormOperation::ReadProperty)
.op(FormOperation::WriteProperty)
})
b.finish_extend_data_schema()
.null()
.form(|f| {
f.href("/hello")
.http_get(|| async { "Reading Hello, World!" })
.op(FormOperation::ReadProperty)
})
.form(|f| {
f.href("/hello")
.http_put(|| async { "Writing Hello, World!" })
.op(FormOperation::WriteProperty)
})
})
.build_servient()
.unwrap();
Expand Down
17 changes: 8 additions & 9 deletions src/servient/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use datta::{Operator, UriTemplate};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
use wot_td::{
builder::{FormBuilderInner, ThingBuilder, CAN_ADD_ANY_OPS},
builder::{FormBuilder, ThingBuilder, CAN_ADD_ANY_OPS, CAN_ADD_ONE_OP},
extend::ExtendableThing,
protocol::http,
};
Expand Down Expand Up @@ -267,13 +267,12 @@ pub trait HttpRouter {
T: 'static;
}

impl<Other, Href, OtherForm> HttpRouter
for FormBuilderInner<Other, Href, OtherForm, CAN_ADD_ANY_OPS>
impl<Other, Href, OtherForm> HttpRouter for FormBuilder<Other, Href, OtherForm, CAN_ADD_ANY_OPS>
where
Other: ExtendableThing + Holder<ServientExtension>,
OtherForm: Holder<Form>,
{
type Target = FormBuilderInner<Other, Href, OtherForm, CAN_ADD_ANY_OPS>;
type Target = FormBuilder<Other, Href, OtherForm, CAN_ADD_ONE_OP>;

/// Route GET requests to the given handler.
fn http_get<H, T>(mut self, handler: H) -> Self::Target
Expand All @@ -285,7 +284,7 @@ where
let f = self.other.field_mut();
f.method_router = method_router.get(handler);
f.htv.method_name = Some(http::Method::Get);
self
self.into()
}
/// Route PUT requests to the given handler.
fn http_put<H, T>(mut self, handler: H) -> Self::Target
Expand All @@ -297,7 +296,7 @@ where
let f = self.other.field_mut();
f.method_router = method_router.put(handler);
f.htv.method_name = Some(http::Method::Put);
self
self.into()
}
/// Route POST requests to the given handler.
fn http_post<H, T>(mut self, handler: H) -> Self::Target
Expand All @@ -309,7 +308,7 @@ where
let f = self.other.field_mut();
f.method_router = method_router.post(handler);
f.htv.method_name = Some(http::Method::Post);
self
self.into()
}
/// Route PATCH requests to the given handler.
fn http_patch<H, T>(mut self, handler: H) -> Self::Target
Expand All @@ -321,7 +320,7 @@ where
let f: &mut Form = self.other.field_mut();
f.method_router = method_router.patch(handler);
f.htv.method_name = Some(http::Method::Patch);
self
self.into()
}
/// Route DELETE requests to the given handler.
fn http_delete<H, T>(mut self, handler: H) -> Self::Target
Expand All @@ -333,7 +332,7 @@ where
let f: &mut Form = self.other.field_mut();
f.method_router = method_router.delete(handler);
f.htv.method_name = Some(http::Method::Delete);
self
self.into()
}
}

Expand Down

0 comments on commit 92e3c48

Please sign in to comment.