aboutsummaryrefslogtreecommitdiffstats
path: root/rust/fatcat-api/src
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-07-20 20:00:16 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-07-20 20:00:16 -0700
commit313f6926a6608e9740924e3ff4fe6dfea2016397 (patch)
treed8ca08c6e73afa079673fe04ac54d45851f100a8 /rust/fatcat-api/src
parent1cd3969ce81470a24f5443e3ea1ad4ce73482288 (diff)
downloadfatcat-313f6926a6608e9740924e3ff4fe6dfea2016397.tar.gz
fatcat-313f6926a6608e9740924e3ff4fe6dfea2016397.zip
update fatcat-api lib with schema changes
Diffstat (limited to 'rust/fatcat-api/src')
-rw-r--r--rust/fatcat-api/src/client.rs20
-rw-r--r--rust/fatcat-api/src/lib.rs28
-rw-r--r--rust/fatcat-api/src/models.rs42
-rw-r--r--rust/fatcat-api/src/server.rs24
4 files changed, 55 insertions, 59 deletions
diff --git a/rust/fatcat-api/src/client.rs b/rust/fatcat-api/src/client.rs
index b68c43d2..b785adab 100644
--- a/rust/fatcat-api/src/client.rs
+++ b/rust/fatcat-api/src/client.rs
@@ -163,7 +163,7 @@ impl Client {
}
impl Api for Client {
- fn accept_editgroup(&self, param_id: i64, context: &Context) -> Box<Future<Item = AcceptEditgroupResponse, Error = ApiError> + Send> {
+ fn accept_editgroup(&self, param_id: String, context: &Context) -> Box<Future<Item = AcceptEditgroupResponse, Error = ApiError> + Send> {
let url = format!("{}/v0/editgroup/{id}/accept", self.base_path, id = utf8_percent_encode(&param_id.to_string(), PATH_SEGMENT_ENCODE_SET));
let hyper_client = (self.hyper_client)();
@@ -1349,7 +1349,7 @@ impl Api for Client {
Box::new(futures::done(result))
}
- fn get_editgroup(&self, param_id: i64, context: &Context) -> Box<Future<Item = GetEditgroupResponse, Error = ApiError> + Send> {
+ fn get_editgroup(&self, param_id: String, context: &Context) -> Box<Future<Item = GetEditgroupResponse, Error = ApiError> + Send> {
let url = format!("{}/v0/editgroup/{id}", self.base_path, id = utf8_percent_encode(&param_id.to_string(), PATH_SEGMENT_ENCODE_SET));
let hyper_client = (self.hyper_client)();
@@ -1409,12 +1409,8 @@ impl Api for Client {
Box::new(futures::done(result))
}
- fn get_editor(&self, param_username: String, context: &Context) -> Box<Future<Item = GetEditorResponse, Error = ApiError> + Send> {
- let url = format!(
- "{}/v0/editor/{username}",
- self.base_path,
- username = utf8_percent_encode(&param_username.to_string(), PATH_SEGMENT_ENCODE_SET)
- );
+ fn get_editor(&self, param_id: String, context: &Context) -> Box<Future<Item = GetEditorResponse, Error = ApiError> + Send> {
+ let url = format!("{}/v0/editor/{id}", self.base_path, id = utf8_percent_encode(&param_id.to_string(), PATH_SEGMENT_ENCODE_SET));
let hyper_client = (self.hyper_client)();
let request = hyper_client.request(hyper::method::Method::Get, &url);
@@ -1466,12 +1462,8 @@ impl Api for Client {
Box::new(futures::done(result))
}
- fn get_editor_changelog(&self, param_username: String, context: &Context) -> Box<Future<Item = GetEditorChangelogResponse, Error = ApiError> + Send> {
- let url = format!(
- "{}/v0/editor/{username}/changelog",
- self.base_path,
- username = utf8_percent_encode(&param_username.to_string(), PATH_SEGMENT_ENCODE_SET)
- );
+ fn get_editor_changelog(&self, param_id: String, context: &Context) -> Box<Future<Item = GetEditorChangelogResponse, Error = ApiError> + Send> {
+ let url = format!("{}/v0/editor/{id}/changelog", self.base_path, id = utf8_percent_encode(&param_id.to_string(), PATH_SEGMENT_ENCODE_SET));
let hyper_client = (self.hyper_client)();
let request = hyper_client.request(hyper::method::Method::Get, &url);
diff --git a/rust/fatcat-api/src/lib.rs b/rust/fatcat-api/src/lib.rs
index ce5674cd..47d23d04 100644
--- a/rust/fatcat-api/src/lib.rs
+++ b/rust/fatcat-api/src/lib.rs
@@ -438,7 +438,7 @@ pub enum LookupReleaseResponse {
/// API
pub trait Api {
- fn accept_editgroup(&self, id: i64, context: &Context) -> Box<Future<Item = AcceptEditgroupResponse, Error = ApiError> + Send>;
+ fn accept_editgroup(&self, id: String, context: &Context) -> Box<Future<Item = AcceptEditgroupResponse, Error = ApiError> + Send>;
fn create_container(&self, entity: models::ContainerEntity, context: &Context) -> Box<Future<Item = CreateContainerResponse, Error = ApiError> + Send>;
@@ -476,11 +476,11 @@ pub trait Api {
fn get_creator_releases(&self, id: String, context: &Context) -> Box<Future<Item = GetCreatorReleasesResponse, Error = ApiError> + Send>;
- fn get_editgroup(&self, id: i64, context: &Context) -> Box<Future<Item = GetEditgroupResponse, Error = ApiError> + Send>;
+ fn get_editgroup(&self, id: String, context: &Context) -> Box<Future<Item = GetEditgroupResponse, Error = ApiError> + Send>;
- fn get_editor(&self, username: String, context: &Context) -> Box<Future<Item = GetEditorResponse, Error = ApiError> + Send>;
+ fn get_editor(&self, id: String, context: &Context) -> Box<Future<Item = GetEditorResponse, Error = ApiError> + Send>;
- fn get_editor_changelog(&self, username: String, context: &Context) -> Box<Future<Item = GetEditorChangelogResponse, Error = ApiError> + Send>;
+ fn get_editor_changelog(&self, id: String, context: &Context) -> Box<Future<Item = GetEditorChangelogResponse, Error = ApiError> + Send>;
fn get_file(&self, id: String, context: &Context) -> Box<Future<Item = GetFileResponse, Error = ApiError> + Send>;
@@ -511,7 +511,7 @@ pub trait Api {
/// API without a `Context`
pub trait ApiNoContext {
- fn accept_editgroup(&self, id: i64) -> Box<Future<Item = AcceptEditgroupResponse, Error = ApiError> + Send>;
+ fn accept_editgroup(&self, id: String) -> Box<Future<Item = AcceptEditgroupResponse, Error = ApiError> + Send>;
fn create_container(&self, entity: models::ContainerEntity) -> Box<Future<Item = CreateContainerResponse, Error = ApiError> + Send>;
@@ -549,11 +549,11 @@ pub trait ApiNoContext {
fn get_creator_releases(&self, id: String) -> Box<Future<Item = GetCreatorReleasesResponse, Error = ApiError> + Send>;
- fn get_editgroup(&self, id: i64) -> Box<Future<Item = GetEditgroupResponse, Error = ApiError> + Send>;
+ fn get_editgroup(&self, id: String) -> Box<Future<Item = GetEditgroupResponse, Error = ApiError> + Send>;
- fn get_editor(&self, username: String) -> Box<Future<Item = GetEditorResponse, Error = ApiError> + Send>;
+ fn get_editor(&self, id: String) -> Box<Future<Item = GetEditorResponse, Error = ApiError> + Send>;
- fn get_editor_changelog(&self, username: String) -> Box<Future<Item = GetEditorChangelogResponse, Error = ApiError> + Send>;
+ fn get_editor_changelog(&self, id: String) -> Box<Future<Item = GetEditorChangelogResponse, Error = ApiError> + Send>;
fn get_file(&self, id: String) -> Box<Future<Item = GetFileResponse, Error = ApiError> + Send>;
@@ -598,7 +598,7 @@ impl<'a, T: Api + Sized> ContextWrapperExt<'a> for T {
}
impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> {
- fn accept_editgroup(&self, id: i64) -> Box<Future<Item = AcceptEditgroupResponse, Error = ApiError> + Send> {
+ fn accept_editgroup(&self, id: String) -> Box<Future<Item = AcceptEditgroupResponse, Error = ApiError> + Send> {
self.api().accept_editgroup(id, &self.context())
}
@@ -674,16 +674,16 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> {
self.api().get_creator_releases(id, &self.context())
}
- fn get_editgroup(&self, id: i64) -> Box<Future<Item = GetEditgroupResponse, Error = ApiError> + Send> {
+ fn get_editgroup(&self, id: String) -> Box<Future<Item = GetEditgroupResponse, Error = ApiError> + Send> {
self.api().get_editgroup(id, &self.context())
}
- fn get_editor(&self, username: String) -> Box<Future<Item = GetEditorResponse, Error = ApiError> + Send> {
- self.api().get_editor(username, &self.context())
+ fn get_editor(&self, id: String) -> Box<Future<Item = GetEditorResponse, Error = ApiError> + Send> {
+ self.api().get_editor(id, &self.context())
}
- fn get_editor_changelog(&self, username: String) -> Box<Future<Item = GetEditorChangelogResponse, Error = ApiError> + Send> {
- self.api().get_editor_changelog(username, &self.context())
+ fn get_editor_changelog(&self, id: String) -> Box<Future<Item = GetEditorChangelogResponse, Error = ApiError> + Send> {
+ self.api().get_editor_changelog(id, &self.context())
}
fn get_file(&self, id: String) -> Box<Future<Item = GetFileResponse, Error = ApiError> + Send> {
diff --git a/rust/fatcat-api/src/models.rs b/rust/fatcat-api/src/models.rs
index cd18469c..4ecc180c 100644
--- a/rust/fatcat-api/src/models.rs
+++ b/rust/fatcat-api/src/models.rs
@@ -15,7 +15,7 @@ pub struct ChangelogEntry {
pub index: i64,
#[serde(rename = "editgroup_id")]
- pub editgroup_id: i64,
+ pub editgroup_id: String,
#[serde(rename = "timestamp")]
pub timestamp: chrono::DateTime<chrono::Utc>,
@@ -26,7 +26,7 @@ pub struct ChangelogEntry {
}
impl ChangelogEntry {
- pub fn new(index: i64, editgroup_id: i64, timestamp: chrono::DateTime<chrono::Utc>) -> ChangelogEntry {
+ pub fn new(index: i64, editgroup_id: String, timestamp: chrono::DateTime<chrono::Utc>) -> ChangelogEntry {
ChangelogEntry {
index: index,
editgroup_id: editgroup_id,
@@ -63,7 +63,7 @@ pub struct ContainerEntity {
#[serde(rename = "editgroup_id")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub editgroup_id: Option<i64>,
+ pub editgroup_id: Option<String>,
#[serde(rename = "redirect")]
#[serde(skip_serializing_if = "Option::is_none")]
@@ -71,7 +71,7 @@ pub struct ContainerEntity {
#[serde(rename = "revision")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub revision: Option<i64>,
+ pub revision: Option<String>,
#[serde(rename = "ident")]
#[serde(skip_serializing_if = "Option::is_none")]
@@ -129,7 +129,7 @@ pub struct CreatorEntity {
#[serde(rename = "revision")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub revision: Option<i64>,
+ pub revision: Option<String>,
#[serde(rename = "redirect")]
#[serde(skip_serializing_if = "Option::is_none")]
@@ -137,7 +137,7 @@ pub struct CreatorEntity {
#[serde(rename = "editgroup_id")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub editgroup_id: Option<i64>,
+ pub editgroup_id: Option<String>,
#[serde(rename = "extra")]
#[serde(skip_serializing_if = "Option::is_none")]
@@ -165,10 +165,10 @@ impl CreatorEntity {
pub struct Editgroup {
#[serde(rename = "id")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub id: Option<i64>,
+ pub id: Option<String>,
#[serde(rename = "editor_id")]
- pub editor_id: i64,
+ pub editor_id: String,
#[serde(rename = "description")]
#[serde(skip_serializing_if = "Option::is_none")]
@@ -184,7 +184,7 @@ pub struct Editgroup {
}
impl Editgroup {
- pub fn new(editor_id: i64) -> Editgroup {
+ pub fn new(editor_id: String) -> Editgroup {
Editgroup {
id: None,
editor_id: editor_id,
@@ -232,13 +232,17 @@ impl EditgroupEdits {
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct Editor {
+ #[serde(rename = "id")]
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub id: Option<String>,
+
#[serde(rename = "username")]
pub username: String,
}
impl Editor {
pub fn new(username: String) -> Editor {
- Editor { username: username }
+ Editor { id: None, username: username }
}
}
@@ -252,14 +256,14 @@ pub struct EntityEdit {
#[serde(rename = "revision")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub revision: Option<i64>,
+ pub revision: Option<String>,
#[serde(rename = "redirect_ident")]
#[serde(skip_serializing_if = "Option::is_none")]
pub redirect_ident: Option<String>,
#[serde(rename = "editgroup_id")]
- pub editgroup_id: i64,
+ pub editgroup_id: String,
#[serde(rename = "extra")]
#[serde(skip_serializing_if = "Option::is_none")]
@@ -267,7 +271,7 @@ pub struct EntityEdit {
}
impl EntityEdit {
- pub fn new(edit_id: i64, ident: String, editgroup_id: i64) -> EntityEdit {
+ pub fn new(edit_id: i64, ident: String, editgroup_id: String) -> EntityEdit {
EntityEdit {
edit_id: edit_id,
ident: ident,
@@ -349,7 +353,7 @@ pub struct FileEntity {
#[serde(rename = "editgroup_id")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub editgroup_id: Option<i64>,
+ pub editgroup_id: Option<String>,
#[serde(rename = "redirect")]
#[serde(skip_serializing_if = "Option::is_none")]
@@ -357,7 +361,7 @@ pub struct FileEntity {
#[serde(rename = "revision")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub revision: Option<i64>,
+ pub revision: Option<String>,
#[serde(rename = "ident")]
#[serde(skip_serializing_if = "Option::is_none")]
@@ -492,7 +496,7 @@ pub struct ReleaseEntity {
#[serde(rename = "revision")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub revision: Option<i64>,
+ pub revision: Option<String>,
#[serde(rename = "redirect")]
#[serde(skip_serializing_if = "Option::is_none")]
@@ -500,7 +504,7 @@ pub struct ReleaseEntity {
#[serde(rename = "editgroup_id")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub editgroup_id: Option<i64>,
+ pub editgroup_id: Option<String>,
#[serde(rename = "extra")]
#[serde(skip_serializing_if = "Option::is_none")]
@@ -622,7 +626,7 @@ pub struct WorkEntity {
#[serde(rename = "editgroup_id")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub editgroup_id: Option<i64>,
+ pub editgroup_id: Option<String>,
#[serde(rename = "redirect")]
#[serde(skip_serializing_if = "Option::is_none")]
@@ -630,7 +634,7 @@ pub struct WorkEntity {
#[serde(rename = "revision")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub revision: Option<i64>,
+ pub revision: Option<String>,
#[serde(rename = "ident")]
#[serde(skip_serializing_if = "Option::is_none")]
diff --git a/rust/fatcat-api/src/server.rs b/rust/fatcat-api/src/server.rs
index 35b31691..e4e0bc1d 100644
--- a/rust/fatcat-api/src/server.rs
+++ b/rust/fatcat-api/src/server.rs
@@ -2002,7 +2002,7 @@ where
let api_clone = api.clone();
router.get(
- "/v0/editor/:username",
+ "/v0/editor/:id",
move |req: &mut Request| {
let mut context = Context::default();
@@ -2016,20 +2016,20 @@ where
context.authorization = req.extensions.remove::<Authorization>();
// Path parameters
- let param_username = {
+ let param_id = {
let param = req.extensions
.get::<Router>()
.ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))?
- .find("username")
- .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter username".to_string())))?;
+ .find("id")
+ .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?;
percent_decode(param.as_bytes())
.decode_utf8()
.map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))?
.parse()
- .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter username: {}", e))))?
+ .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))?
};
- match api.get_editor(param_username, context).wait() {
+ match api.get_editor(param_id, context).wait() {
Ok(rsp) => match rsp {
GetEditorResponse::FoundEditor(body) => {
let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
@@ -2080,7 +2080,7 @@ where
let api_clone = api.clone();
router.get(
- "/v0/editor/:username/changelog",
+ "/v0/editor/:id/changelog",
move |req: &mut Request| {
let mut context = Context::default();
@@ -2094,20 +2094,20 @@ where
context.authorization = req.extensions.remove::<Authorization>();
// Path parameters
- let param_username = {
+ let param_id = {
let param = req.extensions
.get::<Router>()
.ok_or_else(|| Response::with((status::InternalServerError, "An internal error occurred".to_string())))?
- .find("username")
- .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter username".to_string())))?;
+ .find("id")
+ .ok_or_else(|| Response::with((status::BadRequest, "Missing path parameter id".to_string())))?;
percent_decode(param.as_bytes())
.decode_utf8()
.map_err(|_| Response::with((status::BadRequest, format!("Couldn't percent-decode path parameter as UTF-8: {}", param))))?
.parse()
- .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter username: {}", e))))?
+ .map_err(|e| Response::with((status::BadRequest, format!("Couldn't parse path parameter id: {}", e))))?
};
- match api.get_editor_changelog(param_username, context).wait() {
+ match api.get_editor_changelog(param_id, context).wait() {
Ok(rsp) => match rsp {
GetEditorChangelogResponse::FoundMergedChanges(body) => {
let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");