diff options
| author | Bryan Newbold <bnewbold@robocracy.org> | 2018-12-14 22:01:14 +0800 | 
|---|---|---|
| committer | Bryan Newbold <bnewbold@robocracy.org> | 2018-12-14 22:01:16 +0800 | 
| commit | 595a15cfd3b3bd1e06d13f6274867616bea61ef0 (patch) | |
| tree | dfb10d3da8cc16d3868723cb66a1e2dc8d49ea3f /rust/src/api_wrappers.rs | |
| parent | e2deb74b7839aa05c1827a830ffc5e3c68ed58b4 (diff) | |
| download | fatcat-595a15cfd3b3bd1e06d13f6274867616bea61ef0.tar.gz fatcat-595a15cfd3b3bd1e06d13f6274867616bea61ef0.zip | |
many redirect implementations
Probably should have split this commit up, it's huge:
- accept the state of "redirect to a deletion", where redirect_id is
  Some but rev_id is None. call this a "redirect"; previously this was
  an invalid state.
- GET for a deleted entity returns a 200 and a stub entity, not a 404
- to PUT a redirect, or to "revert" an entity to point at a specific
  pre-existing revision, PUT a stub entity. things are getting messy
  here... to detect this state, ensure the 'state' field is blank/none
  (this is for API usage ergonomics, where results from a GET are often
  re-used in a PUT or even POST)
- rustfmt
- maybe even more small tweaks along the way? mystery meat!
Tests are in python, not rust (and a future commit)
Diffstat (limited to 'rust/src/api_wrappers.rs')
| -rw-r--r-- | rust/src/api_wrappers.rs | 49 | 
1 files changed, 25 insertions, 24 deletions
| diff --git a/rust/src/api_wrappers.rs b/rust/src/api_wrappers.rs index a2357fe1..c8f6b390 100644 --- a/rust/src/api_wrappers.rs +++ b/rust/src/api_wrappers.rs @@ -664,30 +664,31 @@ impl Api for Server {              Some(param) => HideFlags::from_str(¶m).unwrap(),          };          // No transaction for GET -        let ret = match self.lookup_file_handler(&md5, &sha1, &sha256, expand_flags, hide_flags, &conn) { -            Ok(entity) => LookupFileResponse::FoundEntity(entity), -            Err(Error(ErrorKind::Diesel(::diesel::result::Error::NotFound), _)) => { -                LookupFileResponse::NotFound(ErrorResponse { -                    message: format!("Not found: {:?} / {:?} / {:?}", md5, sha1, sha256), -                }) -            } -            Err(Error(ErrorKind::MalformedExternalId(e), _)) => { -                LookupFileResponse::BadRequest(ErrorResponse { -                    message: e.to_string(), -                }) -            } -            Err(Error(ErrorKind::MissingOrMultipleExternalId(e), _)) => { -                LookupFileResponse::BadRequest(ErrorResponse { -                    message: e.to_string(), -                }) -            } -            Err(e) => { -                error!("{}", e); -                LookupFileResponse::BadRequest(ErrorResponse { -                    message: e.to_string(), -                }) -            } -        }; +        let ret = +            match self.lookup_file_handler(&md5, &sha1, &sha256, expand_flags, hide_flags, &conn) { +                Ok(entity) => LookupFileResponse::FoundEntity(entity), +                Err(Error(ErrorKind::Diesel(::diesel::result::Error::NotFound), _)) => { +                    LookupFileResponse::NotFound(ErrorResponse { +                        message: format!("Not found: {:?} / {:?} / {:?}", md5, sha1, sha256), +                    }) +                } +                Err(Error(ErrorKind::MalformedExternalId(e), _)) => { +                    LookupFileResponse::BadRequest(ErrorResponse { +                        message: e.to_string(), +                    }) +                } +                Err(Error(ErrorKind::MissingOrMultipleExternalId(e), _)) => { +                    LookupFileResponse::BadRequest(ErrorResponse { +                        message: e.to_string(), +                    }) +                } +                Err(e) => { +                    error!("{}", e); +                    LookupFileResponse::BadRequest(ErrorResponse { +                        message: e.to_string(), +                    }) +                } +            };          Box::new(futures::done(Ok(ret)))      } | 
