aboutsummaryrefslogtreecommitdiffstats
path: root/rust/src/api_wrappers.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-11-26 23:43:56 -0800
committerBryan Newbold <bnewbold@robocracy.org>2018-11-26 23:45:02 -0800
commitda113570daf4b2d17cd828e3b512774485870ff0 (patch)
tree075b02998eb3eb4d4d0878317dbd0a71ef8b64a9 /rust/src/api_wrappers.rs
parent32cd25bf48d54f5ede4e327d073d2782e4a81524 (diff)
downloadfatcat-da113570daf4b2d17cd828e3b512774485870ff0.tar.gz
fatcat-da113570daf4b2d17cd828e3b512774485870ff0.zip
implement hide flag
Diffstat (limited to 'rust/src/api_wrappers.rs')
-rw-r--r--rust/src/api_wrappers.rs58
1 files changed, 52 insertions, 6 deletions
diff --git a/rust/src/api_wrappers.rs b/rust/src/api_wrappers.rs
index 098ea0b9..e5176ac6 100644
--- a/rust/src/api_wrappers.rs
+++ b/rust/src/api_wrappers.rs
@@ -30,17 +30,22 @@ macro_rules! wrap_entity_handlers {
&self,
id: String,
expand: Option<String>,
+ hide: Option<String>,
_context: &Context,
) -> Box<Future<Item = $get_resp, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
// No transaction for GET
let ret = match conn.transaction(|| {
let entity_id = FatCatId::from_str(&id)?;
+ let hide_flags = match hide {
+ None => HideFlags::none(),
+ Some(param) => HideFlags::from_str(&param)?,
+ };
match expand {
- None => $model::db_get(&conn, entity_id),
+ None => $model::db_get(&conn, entity_id, hide_flags),
Some(param) => {
let expand_flags = ExpandFlags::from_str(&param)?;
- let mut entity = $model::db_get(&conn, entity_id)?;
+ let mut entity = $model::db_get(&conn, entity_id, hide_flags)?;
entity.db_expand(&conn, expand_flags)?;
Ok(entity)
},
@@ -247,11 +252,16 @@ macro_rules! wrap_lookup_handler {
fn $get_fn(
&self,
$idname: $idtype,
+ hide: Option<String>,
_context: &Context,
) -> Box<Future<Item = $get_resp, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
+ let hide_flags = match hide {
+ None => HideFlags::none(),
+ Some(param) => HideFlags::from_str(&param).unwrap(),
+ };
// No transaction for GET
- let ret = match self.$get_handler(&$idname, &conn) {
+ let ret = match self.$get_handler(&$idname, hide_flags, &conn) {
Ok(entity) =>
$get_resp::FoundEntity(entity),
Err(Error(ErrorKind::Diesel(::diesel::result::Error::NotFound), _)) =>
@@ -299,6 +309,42 @@ macro_rules! wrap_fcid_handler {
}
}
+macro_rules! wrap_fcid_hide_handler {
+ ($get_fn:ident, $get_handler:ident, $get_resp:ident) => {
+ fn $get_fn(
+ &self,
+ id: String,
+ hide: Option<String>,
+ _context: &Context,
+ ) -> Box<Future<Item = $get_resp, Error = ApiError> + Send> {
+ let conn = self.db_pool.get().expect("db_pool error");
+ // No transaction for GET
+ let ret = match (|| {
+ let fcid = FatCatId::from_str(&id)?;
+ let hide_flags = match hide {
+ None => HideFlags::none(),
+ Some(param) => HideFlags::from_str(&param)?,
+ };
+ self.$get_handler(fcid, hide_flags, &conn)
+ })() {
+ Ok(entity) =>
+ $get_resp::Found(entity),
+ Err(Error(ErrorKind::Diesel(::diesel::result::Error::NotFound), _)) =>
+ $get_resp::NotFound(ErrorResponse { message: format!("Not found: {}", id) }),
+ Err(Error(ErrorKind::MalformedExternalId(e), _)) =>
+ $get_resp::BadRequest(ErrorResponse { message: e.to_string() }),
+ Err(Error(ErrorKind::NotInControlledVocabulary(e), _)) =>
+ $get_resp::BadRequest(ErrorResponse { message: e.to_string() }),
+ Err(e) => {
+ error!("{}", e);
+ $get_resp::BadRequest(ErrorResponse { message: e.to_string() })
+ },
+ };
+ Box::new(futures::done(Ok(ret)))
+ }
+ }
+}
+
impl Api for Server {
wrap_entity_handlers!(
get_container,
@@ -411,17 +457,17 @@ impl Api for Server {
String
);
- wrap_fcid_handler!(
+ wrap_fcid_hide_handler!(
get_release_files,
get_release_files_handler,
GetReleaseFilesResponse
);
- wrap_fcid_handler!(
+ wrap_fcid_hide_handler!(
get_work_releases,
get_work_releases_handler,
GetWorkReleasesResponse
);
- wrap_fcid_handler!(
+ wrap_fcid_hide_handler!(
get_creator_releases,
get_creator_releases_handler,
GetCreatorReleasesResponse