1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
use std::collections::BTreeMap; use api::raw::Relationship; use Serializer; use Value; pub mod mock; pub trait Router { type Response: Response; fn attach_delete<F>(&mut self, resource: &'static str, f: F) where F: Fn(String) -> Self::Response; fn attach_get<F>(&mut self, resource: &'static str, f: F) where F: Fn(GetRequest) -> Self::Response; fn attach_index<F>(&mut self, resource: &'static str, f: F) where F: Fn(IndexRequest) -> Self::Response; fn attach_patch<F>(&mut self, resource: &'static str, f: F) where F: Fn(PatchRequest) -> Self::Response; fn attach_post<F>(&mut self, resource: &'static str, f: F) where F: Fn(PostRequest) -> Self::Response; fn attach_fetch_one<F>(&mut self, resource: &'static str, relationship: &'static str, f: F) where F: Fn(GetRequest) -> Self::Response; fn attach_fetch_many<F>(&mut self, resource: &'static str, relationship: &'static str, f: F) where F: Fn(GetRequest) -> Self::Response; fn attach_fetch_rel<F>(&mut self, resource: &'static str, relationship: &'static str, f: F) where F: Fn(String) -> Self::Response; fn attach_delete_one<F>(&mut self, resource: &'static str, relationship: &'static str, f: F) where F: Fn(String) -> Self::Response; fn attach_delete_one_rel<F>(&mut self, resource: &'static str, relationship: &'static str, f: F) where F: Fn(String) -> Self::Response; fn attach_remove_many<F>(&mut self, resource: &'static str, relationship: &'static str, f: F) where F: Fn(String, Vec<String>) -> Self::Response; fn attach_remove_many_rel<F>(&mut self, resource: &'static str, relationship: &'static str, f: F) where F: Fn(String, Vec<String>) -> Self::Response; fn attach_clear_many<F>(&mut self, resource: &'static str, relationship: &'static str, f: F) where F: Fn(String) -> Self::Response; fn attach_clear_many_rel<F>(&mut self, resource: &'static str, relationship: &'static str, f: F) where F: Fn(String) -> Self::Response; fn attach_patch_one<F>(&mut self, resource: &'static str, relationship: &'static str, f: F) where F: Fn(PatchRequest) -> Self::Response; fn attach_post_one<F>(&mut self, resource: &'static str, relationship: &'static str, f: F) where F: Fn(String, PostRequest) -> Self::Response; fn attach_append_many<F>(&mut self, resource: &'static str, relationship: &'static str, f: F) where F: Fn(String, PostRequest) -> Self::Response; fn attach_link_one<F>(&mut self, resource: &'static str, relationship: &'static str, _: F) where F: Fn(String, Relationship) -> Self::Response; fn attach_append_link_many<F>(&mut self, resource: &'static str, relationship: &'static str, f: F) where F: Fn(String, Relationship) -> Self::Response; fn attach_replace_link_many<F>(&mut self, resource: &'static str, relationship: &'static str, f: F) where F: Fn(String, Relationship) -> Self::Response; } pub enum Status { Ok = 200, NoContent = 203, BadRequest = 400, Forbidden = 403, NotFound = 404, Conflict = 409, InternalError = 500, } pub trait Response: Default { type Serializer: Serializer; fn set_status(&mut self, status: Status); fn serializer(&mut self) -> &mut Self::Serializer; } pub struct GetRequest { pub id: String, pub includes: Vec<String>, } pub struct IndexRequest { pub includes: Vec<String>, } pub struct PatchRequest { pub attributes: Value, pub relationships: BTreeMap<String, Relationship>, pub id: String, } pub struct PostRequest { pub attributes: Value, pub relationships: BTreeMap<String, Relationship>, }