summaryrefslogtreecommitdiffstats
path: root/rust
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-09-07 21:51:31 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-09-07 21:51:31 -0700
commitd2070ba3718978a9615ae2aa3d81825803522a91 (patch)
treef62fe241fdbbd32180e582bd5533582558c6b979 /rust
parent20c5cf5a8b9acf98db7487ab49de8dcbc1ddb2f9 (diff)
parent8cccbcdef11e7ddc761ec494cb894a8d49a0d510 (diff)
downloadfatcat-d2070ba3718978a9615ae2aa3d81825803522a91.tar.gz
fatcat-d2070ba3718978a9615ae2aa3d81825803522a91.zip
Merge branch 'autoaccept' into http-verbs
Started resolving conflicts in: TODO notes/cloud_instances.txt rust/fatcat-api/README.md rust/src/api_server.rs
Diffstat (limited to 'rust')
-rw-r--r--rust/fatcat-api/README.md10
-rw-r--r--rust/fatcat-api/api.yaml54
-rw-r--r--rust/fatcat-api/api/swagger.yaml80
-rw-r--r--rust/fatcat-api/examples/client.rs10
-rw-r--r--rust/fatcat-api/examples/server_lib/server.rs76
-rw-r--r--rust/fatcat-api/src/client.rs95
-rw-r--r--rust/fatcat-api/src/lib.rs100
-rw-r--r--rust/fatcat-api/src/server.rs35
-rw-r--r--rust/src/api_server.rs31
-rw-r--r--rust/src/api_wrappers.rs6
-rw-r--r--rust/tests/test_api_server.rs41
11 files changed, 475 insertions, 63 deletions
diff --git a/rust/fatcat-api/README.md b/rust/fatcat-api/README.md
index 8381b9f7..4be4939f 100644
--- a/rust/fatcat-api/README.md
+++ b/rust/fatcat-api/README.md
@@ -68,11 +68,6 @@ cargo run --example client CreateRelease
cargo run --example client CreateReleaseBatch
cargo run --example client CreateWork
cargo run --example client CreateWorkBatch
-cargo run --example client DeleteContainer
-cargo run --example client DeleteCreator
-cargo run --example client DeleteFile
-cargo run --example client DeleteRelease
-cargo run --example client DeleteWork
cargo run --example client GetChangelog
cargo run --example client GetChangelogEntry
cargo run --example client GetContainer
@@ -96,11 +91,6 @@ cargo run --example client LookupContainer
cargo run --example client LookupCreator
cargo run --example client LookupFile
cargo run --example client LookupRelease
-cargo run --example client UpdateContainer
-cargo run --example client UpdateCreator
-cargo run --example client UpdateFile
-cargo run --example client UpdateRelease
-cargo run --example client UpdateWork
```
### HTTPS
diff --git a/rust/fatcat-api/api.yaml b/rust/fatcat-api/api.yaml
index d9cf8813..a8919216 100644
--- a/rust/fatcat-api/api.yaml
+++ b/rust/fatcat-api/api.yaml
@@ -57,6 +57,10 @@ x-entity-props: &ENTITYPROPS
extra:
type: object
additionalProperties: {}
+# TODO:
+# edit_extra:
+# type: object
+# additionalProperties: {}
definitions:
error_response:
@@ -438,6 +442,16 @@ paths:
post:
operationId: "create_container_batch"
parameters:
+ - name: autoaccept
+ in: query
+ type: boolean
+ required: false
+ description: "If true, and editor is authorized, batch is accepted all at once"
+ - name: editgroup
+ in: query
+ type: string
+ required: false
+ description: "Editgroup to auto-accept and apply to all entities (required if 'autoaccept' is True)"
- name: entity_list
in: body
required: true
@@ -554,6 +568,16 @@ paths:
post:
operationId: "create_creator_batch"
parameters:
+ - name: autoaccept
+ in: query
+ type: boolean
+ required: false
+ description: "If true, and editor is authorized, batch is accepted all at once"
+ - name: editgroup
+ in: query
+ type: string
+ required: false
+ description: "Editgroup to auto-accept and apply to all entities (required if 'autoaccept' is True)"
- name: entity_list
in: body
required: true
@@ -686,6 +710,16 @@ paths:
post:
operationId: "create_file_batch"
parameters:
+ - name: autoaccept
+ in: query
+ type: boolean
+ required: false
+ description: "If true, and editor is authorized, batch is accepted all at once"
+ - name: editgroup
+ in: query
+ type: string
+ required: false
+ description: "Editgroup to auto-accept and apply to all entities (required if 'autoaccept' is True)"
- name: entity_list
in: body
required: true
@@ -802,6 +836,16 @@ paths:
post:
operationId: "create_release_batch"
parameters:
+ - name: autoaccept
+ in: query
+ type: boolean
+ required: false
+ description: "If true, and editor is authorized, batch is accepted all at once"
+ - name: editgroup
+ in: query
+ type: string
+ required: false
+ description: "Editgroup to auto-accept and apply to all entities (required if 'autoaccept' is True)"
- name: entity_list
in: body
required: true
@@ -934,6 +978,16 @@ paths:
post:
operationId: "create_work_batch"
parameters:
+ - name: autoaccept
+ in: query
+ type: boolean
+ required: false
+ description: "If true, and editor is authorized, batch is accepted all at once"
+ - name: editgroup
+ in: query
+ type: string
+ required: false
+ description: "Editgroup to auto-accept and apply to all entities (required if 'autoaccept' is True)"
- name: entity_list
in: body
required: true
diff --git a/rust/fatcat-api/api/swagger.yaml b/rust/fatcat-api/api/swagger.yaml
index e8026c8d..0b1ca88a 100644
--- a/rust/fatcat-api/api/swagger.yaml
+++ b/rust/fatcat-api/api/swagger.yaml
@@ -76,6 +76,22 @@ paths:
post:
operationId: "create_container_batch"
parameters:
+ - name: "autoaccept"
+ in: "query"
+ description: "If true, and editor is authorized, batch is accepted all at\
+ \ once"
+ required: false
+ type: "boolean"
+ formatString: "{:?}"
+ example: "Some(true)"
+ - name: "editgroup"
+ in: "query"
+ description: "Editgroup to auto-accept and apply to all entities (required\
+ \ if 'autoaccept' is True)"
+ required: false
+ type: "string"
+ formatString: "{:?}"
+ example: "Some(\"editgroup_example\".to_string())"
- in: "body"
name: "entity_list"
required: true
@@ -492,6 +508,22 @@ paths:
post:
operationId: "create_creator_batch"
parameters:
+ - name: "autoaccept"
+ in: "query"
+ description: "If true, and editor is authorized, batch is accepted all at\
+ \ once"
+ required: false
+ type: "boolean"
+ formatString: "{:?}"
+ example: "Some(true)"
+ - name: "editgroup"
+ in: "query"
+ description: "Editgroup to auto-accept and apply to all entities (required\
+ \ if 'autoaccept' is True)"
+ required: false
+ type: "string"
+ formatString: "{:?}"
+ example: "Some(\"editgroup_example\".to_string())"
- in: "body"
name: "entity_list"
required: true
@@ -962,6 +994,22 @@ paths:
post:
operationId: "create_file_batch"
parameters:
+ - name: "autoaccept"
+ in: "query"
+ description: "If true, and editor is authorized, batch is accepted all at\
+ \ once"
+ required: false
+ type: "boolean"
+ formatString: "{:?}"
+ example: "Some(true)"
+ - name: "editgroup"
+ in: "query"
+ description: "Editgroup to auto-accept and apply to all entities (required\
+ \ if 'autoaccept' is True)"
+ required: false
+ type: "string"
+ formatString: "{:?}"
+ example: "Some(\"editgroup_example\".to_string())"
- in: "body"
name: "entity_list"
required: true
@@ -1375,6 +1423,22 @@ paths:
post:
operationId: "create_release_batch"
parameters:
+ - name: "autoaccept"
+ in: "query"
+ description: "If true, and editor is authorized, batch is accepted all at\
+ \ once"
+ required: false
+ type: "boolean"
+ formatString: "{:?}"
+ example: "Some(true)"
+ - name: "editgroup"
+ in: "query"
+ description: "Editgroup to auto-accept and apply to all entities (required\
+ \ if 'autoaccept' is True)"
+ required: false
+ type: "string"
+ formatString: "{:?}"
+ example: "Some(\"editgroup_example\".to_string())"
- in: "body"
name: "entity_list"
required: true
@@ -1842,6 +1906,22 @@ paths:
post:
operationId: "create_work_batch"
parameters:
+ - name: "autoaccept"
+ in: "query"
+ description: "If true, and editor is authorized, batch is accepted all at\
+ \ once"
+ required: false
+ type: "boolean"
+ formatString: "{:?}"
+ example: "Some(true)"
+ - name: "editgroup"
+ in: "query"
+ description: "Editgroup to auto-accept and apply to all entities (required\
+ \ if 'autoaccept' is True)"
+ required: false
+ type: "string"
+ formatString: "{:?}"
+ example: "Some(\"editgroup_example\".to_string())"
- in: "body"
name: "entity_list"
required: true
diff --git a/rust/fatcat-api/examples/client.rs b/rust/fatcat-api/examples/client.rs
index 2ee65d7e..cc94af11 100644
--- a/rust/fatcat-api/examples/client.rs
+++ b/rust/fatcat-api/examples/client.rs
@@ -101,7 +101,7 @@ fn main() {
// println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
// },
Some("CreateContainerBatch") => {
- let result = client.create_container_batch(&Vec::new()).wait();
+ let result = client.create_container_batch(&Vec::new(), Some(true), Some("editgroup_example".to_string())).wait();
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
}
@@ -111,7 +111,7 @@ fn main() {
// println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
// },
Some("CreateCreatorBatch") => {
- let result = client.create_creator_batch(&Vec::new()).wait();
+ let result = client.create_creator_batch(&Vec::new(), Some(true), Some("editgroup_example".to_string())).wait();
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
}
@@ -127,7 +127,7 @@ fn main() {
// println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
// },
Some("CreateFileBatch") => {
- let result = client.create_file_batch(&Vec::new()).wait();
+ let result = client.create_file_batch(&Vec::new(), Some(true), Some("editgroup_example".to_string())).wait();
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
}
@@ -137,7 +137,7 @@ fn main() {
// println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
// },
Some("CreateReleaseBatch") => {
- let result = client.create_release_batch(&Vec::new()).wait();
+ let result = client.create_release_batch(&Vec::new(), Some(true), Some("editgroup_example".to_string())).wait();
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
}
@@ -147,7 +147,7 @@ fn main() {
// println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
// },
Some("CreateWorkBatch") => {
- let result = client.create_work_batch(&Vec::new()).wait();
+ let result = client.create_work_batch(&Vec::new(), Some(true), Some("editgroup_example".to_string())).wait();
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
}
diff --git a/rust/fatcat-api/examples/server_lib/server.rs b/rust/fatcat-api/examples/server_lib/server.rs
index af3ece12..ab08f594 100644
--- a/rust/fatcat-api/examples/server_lib/server.rs
+++ b/rust/fatcat-api/examples/server_lib/server.rs
@@ -35,11 +35,19 @@ impl Api for Server {
Box::new(futures::failed("Generic failure".into()))
}
- fn create_container_batch(&self, entity_list: &Vec<models::ContainerEntity>, context: &Context) -> Box<Future<Item = CreateContainerBatchResponse, Error = ApiError> + Send> {
+ fn create_container_batch(
+ &self,
+ entity_list: &Vec<models::ContainerEntity>,
+ autoaccept: Option<bool>,
+ editgroup: Option<String>,
+ context: &Context,
+ ) -> Box<Future<Item = CreateContainerBatchResponse, Error = ApiError> + Send> {
let context = context.clone();
println!(
- "create_container_batch({:?}) - X-Span-ID: {:?}",
+ "create_container_batch({:?}, {:?}, {:?}) - X-Span-ID: {:?}",
entity_list,
+ autoaccept,
+ editgroup,
context.x_span_id.unwrap_or(String::from("<none>")).clone()
);
Box::new(futures::failed("Generic failure".into()))
@@ -51,9 +59,21 @@ impl Api for Server {
Box::new(futures::failed("Generic failure".into()))
}
- fn create_creator_batch(&self, entity_list: &Vec<models::CreatorEntity>, context: &Context) -> Box<Future<Item = CreateCreatorBatchResponse, Error = ApiError> + Send> {
+ fn create_creator_batch(
+ &self,
+ entity_list: &Vec<models::CreatorEntity>,
+ autoaccept: Option<bool>,
+ editgroup: Option<String>,
+ context: &Context,
+ ) -> Box<Future<Item = CreateCreatorBatchResponse, Error = ApiError> + Send> {
let context = context.clone();
- println!("create_creator_batch({:?}) - X-Span-ID: {:?}", entity_list, context.x_span_id.unwrap_or(String::from("<none>")).clone());
+ println!(
+ "create_creator_batch({:?}, {:?}, {:?}) - X-Span-ID: {:?}",
+ entity_list,
+ autoaccept,
+ editgroup,
+ context.x_span_id.unwrap_or(String::from("<none>")).clone()
+ );
Box::new(futures::failed("Generic failure".into()))
}
@@ -69,9 +89,21 @@ impl Api for Server {
Box::new(futures::failed("Generic failure".into()))
}
- fn create_file_batch(&self, entity_list: &Vec<models::FileEntity>, context: &Context) -> Box<Future<Item = CreateFileBatchResponse, Error = ApiError> + Send> {
+ fn create_file_batch(
+ &self,
+ entity_list: &Vec<models::FileEntity>,
+ autoaccept: Option<bool>,
+ editgroup: Option<String>,
+ context: &Context,
+ ) -> Box<Future<Item = CreateFileBatchResponse, Error = ApiError> + Send> {
let context = context.clone();
- println!("create_file_batch({:?}) - X-Span-ID: {:?}", entity_list, context.x_span_id.unwrap_or(String::from("<none>")).clone());
+ println!(
+ "create_file_batch({:?}, {:?}, {:?}) - X-Span-ID: {:?}",
+ entity_list,
+ autoaccept,
+ editgroup,
+ context.x_span_id.unwrap_or(String::from("<none>")).clone()
+ );
Box::new(futures::failed("Generic failure".into()))
}
@@ -81,9 +113,21 @@ impl Api for Server {
Box::new(futures::failed("Generic failure".into()))
}
- fn create_release_batch(&self, entity_list: &Vec<models::ReleaseEntity>, context: &Context) -> Box<Future<Item = CreateReleaseBatchResponse, Error = ApiError> + Send> {
+ fn create_release_batch(
+ &self,
+ entity_list: &Vec<models::ReleaseEntity>,
+ autoaccept: Option<bool>,
+ editgroup: Option<String>,
+ context: &Context,
+ ) -> Box<Future<Item = CreateReleaseBatchResponse, Error = ApiError> + Send> {
let context = context.clone();
- println!("create_release_batch({:?}) - X-Span-ID: {:?}", entity_list, context.x_span_id.unwrap_or(String::from("<none>")).clone());
+ println!(
+ "create_release_batch({:?}, {:?}, {:?}) - X-Span-ID: {:?}",
+ entity_list,
+ autoaccept,
+ editgroup,
+ context.x_span_id.unwrap_or(String::from("<none>")).clone()
+ );
Box::new(futures::failed("Generic failure".into()))
}
@@ -93,9 +137,21 @@ impl Api for Server {
Box::new(futures::failed("Generic failure".into()))
}
- fn create_work_batch(&self, entity_list: &Vec<models::WorkEntity>, context: &Context) -> Box<Future<Item = CreateWorkBatchResponse, Error = ApiError> + Send> {
+ fn create_work_batch(
+ &self,
+ entity_list: &Vec<models::WorkEntity>,
+ autoaccept: Option<bool>,
+ editgroup: Option<String>,
+ context: &Context,
+ ) -> Box<Future<Item = CreateWorkBatchResponse, Error = ApiError> + Send> {
let context = context.clone();
- println!("create_work_batch({:?}) - X-Span-ID: {:?}", entity_list, context.x_span_id.unwrap_or(String::from("<none>")).clone());
+ println!(
+ "create_work_batch({:?}, {:?}, {:?}) - X-Span-ID: {:?}",
+ entity_list,
+ autoaccept,
+ editgroup,
+ context.x_span_id.unwrap_or(String::from("<none>")).clone()
+ );
Box::new(futures::failed("Generic failure".into()))
}
diff --git a/rust/fatcat-api/src/client.rs b/rust/fatcat-api/src/client.rs
index 9b2caa32..6f61f773 100644
--- a/rust/fatcat-api/src/client.rs
+++ b/rust/fatcat-api/src/client.rs
@@ -298,8 +298,23 @@ impl Api for Client {
Box::new(futures::done(result))
}
- fn create_container_batch(&self, param_entity_list: &Vec<models::ContainerEntity>, context: &Context) -> Box<Future<Item = CreateContainerBatchResponse, Error = ApiError> + Send> {
- let url = format!("{}/v0/container/batch", self.base_path);
+ fn create_container_batch(
+ &self,
+ param_entity_list: &Vec<models::ContainerEntity>,
+ param_autoaccept: Option<bool>,
+ param_editgroup: Option<String>,
+ context: &Context,
+ ) -> Box<Future<Item = CreateContainerBatchResponse, Error = ApiError> + Send> {
+ // Query parameters
+ let query_autoaccept = param_autoaccept.map_or_else(String::new, |query| format!("autoaccept={autoaccept}&", autoaccept = query.to_string()));
+ let query_editgroup = param_editgroup.map_or_else(String::new, |query| format!("editgroup={editgroup}&", editgroup = query.to_string()));
+
+ let url = format!(
+ "{}/v0/container/batch?{autoaccept}{editgroup}",
+ self.base_path,
+ autoaccept = utf8_percent_encode(&query_autoaccept, QUERY_ENCODE_SET),
+ editgroup = utf8_percent_encode(&query_editgroup, QUERY_ENCODE_SET)
+ );
let body = serde_json::to_string(&param_entity_list).expect("impossible to fail to serialize");
@@ -428,8 +443,23 @@ impl Api for Client {
Box::new(futures::done(result))
}
- fn create_creator_batch(&self, param_entity_list: &Vec<models::CreatorEntity>, context: &Context) -> Box<Future<Item = CreateCreatorBatchResponse, Error = ApiError> + Send> {
- let url = format!("{}/v0/creator/batch", self.base_path);
+ fn create_creator_batch(
+ &self,
+ param_entity_list: &Vec<models::CreatorEntity>,
+ param_autoaccept: Option<bool>,
+ param_editgroup: Option<String>,
+ context: &Context,
+ ) -> Box<Future<Item = CreateCreatorBatchResponse, Error = ApiError> + Send> {
+ // Query parameters
+ let query_autoaccept = param_autoaccept.map_or_else(String::new, |query| format!("autoaccept={autoaccept}&", autoaccept = query.to_string()));
+ let query_editgroup = param_editgroup.map_or_else(String::new, |query| format!("editgroup={editgroup}&", editgroup = query.to_string()));
+
+ let url = format!(
+ "{}/v0/creator/batch?{autoaccept}{editgroup}",
+ self.base_path,
+ autoaccept = utf8_percent_encode(&query_autoaccept, QUERY_ENCODE_SET),
+ editgroup = utf8_percent_encode(&query_editgroup, QUERY_ENCODE_SET)
+ );
let body = serde_json::to_string(&param_entity_list).expect("impossible to fail to serialize");
@@ -616,8 +646,23 @@ impl Api for Client {
Box::new(futures::done(result))
}
- fn create_file_batch(&self, param_entity_list: &Vec<models::FileEntity>, context: &Context) -> Box<Future<Item = CreateFileBatchResponse, Error = ApiError> + Send> {
- let url = format!("{}/v0/file/batch", self.base_path);
+ fn create_file_batch(
+ &self,
+ param_entity_list: &Vec<models::FileEntity>,
+ param_autoaccept: Option<bool>,
+ param_editgroup: Option<String>,
+ context: &Context,
+ ) -> Box<Future<Item = CreateFileBatchResponse, Error = ApiError> + Send> {
+ // Query parameters
+ let query_autoaccept = param_autoaccept.map_or_else(String::new, |query| format!("autoaccept={autoaccept}&", autoaccept = query.to_string()));
+ let query_editgroup = param_editgroup.map_or_else(String::new, |query| format!("editgroup={editgroup}&", editgroup = query.to_string()));
+
+ let url = format!(
+ "{}/v0/file/batch?{autoaccept}{editgroup}",
+ self.base_path,
+ autoaccept = utf8_percent_encode(&query_autoaccept, QUERY_ENCODE_SET),
+ editgroup = utf8_percent_encode(&query_editgroup, QUERY_ENCODE_SET)
+ );
let body = serde_json::to_string(&param_entity_list).expect("impossible to fail to serialize");
@@ -746,8 +791,23 @@ impl Api for Client {
Box::new(futures::done(result))
}
- fn create_release_batch(&self, param_entity_list: &Vec<models::ReleaseEntity>, context: &Context) -> Box<Future<Item = CreateReleaseBatchResponse, Error = ApiError> + Send> {
- let url = format!("{}/v0/release/batch", self.base_path);
+ fn create_release_batch(
+ &self,
+ param_entity_list: &Vec<models::ReleaseEntity>,
+ param_autoaccept: Option<bool>,
+ param_editgroup: Option<String>,
+ context: &Context,
+ ) -> Box<Future<Item = CreateReleaseBatchResponse, Error = ApiError> + Send> {
+ // Query parameters
+ let query_autoaccept = param_autoaccept.map_or_else(String::new, |query| format!("autoaccept={autoaccept}&", autoaccept = query.to_string()));
+ let query_editgroup = param_editgroup.map_or_else(String::new, |query| format!("editgroup={editgroup}&", editgroup = query.to_string()));
+
+ let url = format!(
+ "{}/v0/release/batch?{autoaccept}{editgroup}",
+ self.base_path,
+ autoaccept = utf8_percent_encode(&query_autoaccept, QUERY_ENCODE_SET),
+ editgroup = utf8_percent_encode(&query_editgroup, QUERY_ENCODE_SET)
+ );
let body = serde_json::to_string(&param_entity_list).expect("impossible to fail to serialize");
@@ -876,8 +936,23 @@ impl Api for Client {
Box::new(futures::done(result))
}
- fn create_work_batch(&self, param_entity_list: &Vec<models::WorkEntity>, context: &Context) -> Box<Future<Item = CreateWorkBatchResponse, Error = ApiError> + Send> {
- let url = format!("{}/v0/work/batch", self.base_path);
+ fn create_work_batch(
+ &self,
+ param_entity_list: &Vec<models::WorkEntity>,
+ param_autoaccept: Option<bool>,
+ param_editgroup: Option<String>,
+ context: &Context,
+ ) -> Box<Future<Item = CreateWorkBatchResponse, Error = ApiError> + Send> {
+ // Query parameters
+ let query_autoaccept = param_autoaccept.map_or_else(String::new, |query| format!("autoaccept={autoaccept}&", autoaccept = query.to_string()));
+ let query_editgroup = param_editgroup.map_or_else(String::new, |query| format!("editgroup={editgroup}&", editgroup = query.to_string()));
+
+ let url = format!(
+ "{}/v0/work/batch?{autoaccept}{editgroup}",
+ self.base_path,
+ autoaccept = utf8_percent_encode(&query_autoaccept, QUERY_ENCODE_SET),
+ editgroup = utf8_percent_encode(&query_editgroup, QUERY_ENCODE_SET)
+ );
let body = serde_json::to_string(&param_entity_list).expect("impossible to fail to serialize");
diff --git a/rust/fatcat-api/src/lib.rs b/rust/fatcat-api/src/lib.rs
index 8ff89b9f..fc1ae2a1 100644
--- a/rust/fatcat-api/src/lib.rs
+++ b/rust/fatcat-api/src/lib.rs
@@ -564,25 +564,55 @@ pub trait Api {
fn create_container(&self, entity: models::ContainerEntity, context: &Context) -> Box<Future<Item = CreateContainerResponse, Error = ApiError> + Send>;
- fn create_container_batch(&self, entity_list: &Vec<models::ContainerEntity>, context: &Context) -> Box<Future<Item = CreateContainerBatchResponse, Error = ApiError> + Send>;
+ fn create_container_batch(
+ &self,
+ entity_list: &Vec<models::ContainerEntity>,
+ autoaccept: Option<bool>,
+ editgroup: Option<String>,
+ context: &Context,
+ ) -> Box<Future<Item = CreateContainerBatchResponse, Error = ApiError> + Send>;
fn create_creator(&self, entity: models::CreatorEntity, context: &Context) -> Box<Future<Item = CreateCreatorResponse, Error = ApiError> + Send>;
- fn create_creator_batch(&self, entity_list: &Vec<models::CreatorEntity>, context: &Context) -> Box<Future<Item = CreateCreatorBatchResponse, Error = ApiError> + Send>;
+ fn create_creator_batch(
+ &self,
+ entity_list: &Vec<models::CreatorEntity>,
+ autoaccept: Option<bool>,
+ editgroup: Option<String>,
+ context: &Context,
+ ) -> Box<Future<Item = CreateCreatorBatchResponse, Error = ApiError> + Send>;
fn create_editgroup(&self, entity: models::Editgroup, context: &Context) -> Box<Future<Item = CreateEditgroupResponse, Error = ApiError> + Send>;
fn create_file(&self, entity: models::FileEntity, context: &Context) -> Box<Future<Item = CreateFileResponse, Error = ApiError> + Send>;
- fn create_file_batch(&self, entity_list: &Vec<models::FileEntity>, context: &Context) -> Box<Future<Item = CreateFileBatchResponse, Error = ApiError> + Send>;
+ fn create_file_batch(
+ &self,
+ entity_list: &Vec<models::FileEntity>,
+ autoaccept: Option<bool>,
+ editgroup: Option<String>,
+ context: &Context,
+ ) -> Box<Future<Item = CreateFileBatchResponse, Error = ApiError> + Send>;
fn create_release(&self, entity: models::ReleaseEntity, context: &Context) -> Box<Future<Item = CreateReleaseResponse, Error = ApiError> + Send>;
- fn create_release_batch(&self, entity_list: &Vec<models::ReleaseEntity>, context: &Context) -> Box<Future<Item = CreateReleaseBatchResponse, Error = ApiError> + Send>;
+ fn create_release_batch(
+ &self,
+ entity_list: &Vec<models::ReleaseEntity>,
+ autoaccept: Option<bool>,
+ editgroup: Option<String>,
+ context: &Context,
+ ) -> Box<Future<Item = CreateReleaseBatchResponse, Error = ApiError> + Send>;
fn create_work(&self, entity: models::WorkEntity, context: &Context) -> Box<Future<Item = CreateWorkResponse, Error = ApiError> + Send>;
- fn create_work_batch(&self, entity_list: &Vec<models::WorkEntity>, context: &Context) -> Box<Future<Item = CreateWorkBatchResponse, Error = ApiError> + Send>;
+ fn create_work_batch(
+ &self,
+ entity_list: &Vec<models::WorkEntity>,
+ autoaccept: Option<bool>,
+ editgroup: Option<String>,
+ context: &Context,
+ ) -> Box<Future<Item = CreateWorkBatchResponse, Error = ApiError> + Send>;
fn delete_container(&self, id: String, editgroup: Option<String>, context: &Context) -> Box<Future<Item = DeleteContainerResponse, Error = ApiError> + Send>;
@@ -657,25 +687,40 @@ pub trait ApiNoContext {
fn create_container(&self, entity: models::ContainerEntity) -> Box<Future<Item = CreateContainerResponse, Error = ApiError> + Send>;
- fn create_container_batch(&self, entity_list: &Vec<models::ContainerEntity>) -> Box<Future<Item = CreateContainerBatchResponse, Error = ApiError> + Send>;
+ fn create_container_batch(
+ &self,
+ entity_list: &Vec<models::ContainerEntity>,
+ autoaccept: Option<bool>,
+ editgroup: Option<String>,
+ ) -> Box<Future<Item = CreateContainerBatchResponse, Error = ApiError> + Send>;
fn create_creator(&self, entity: models::CreatorEntity) -> Box<Future<Item = CreateCreatorResponse, Error = ApiError> + Send>;
- fn create_creator_batch(&self, entity_list: &Vec<models::CreatorEntity>) -> Box<Future<Item = CreateCreatorBatchResponse, Error = ApiError> + Send>;
+ fn create_creator_batch(
+ &self,
+ entity_list: &Vec<models::CreatorEntity>,
+ autoaccept: Option<bool>,
+ editgroup: Option<String>,
+ ) -> Box<Future<Item = CreateCreatorBatchResponse, Error = ApiError> + Send>;
fn create_editgroup(&self, entity: models::Editgroup) -> Box<Future<Item = CreateEditgroupResponse, Error = ApiError> + Send>;
fn create_file(&self, entity: models::FileEntity) -> Box<Future<Item = CreateFileResponse, Error = ApiError> + Send>;
- fn create_file_batch(&self, entity_list: &Vec<models::FileEntity>) -> Box<Future<Item = CreateFileBatchResponse, Error = ApiError> + Send>;
+ fn create_file_batch(&self, entity_list: &Vec<models::FileEntity>, autoaccept: Option<bool>, editgroup: Option<String>) -> Box<Future<Item = CreateFileBatchResponse, Error = ApiError> + Send>;
fn create_release(&self, entity: models::ReleaseEntity) -> Box<Future<Item = CreateReleaseResponse, Error = ApiError> + Send>;
- fn create_release_batch(&self, entity_list: &Vec<models::ReleaseEntity>) -> Box<Future<Item = CreateReleaseBatchResponse, Error = ApiError> + Send>;
+ fn create_release_batch(
+ &self,
+ entity_list: &Vec<models::ReleaseEntity>,
+ autoaccept: Option<bool>,
+ editgroup: Option<String>,
+ ) -> Box<Future<Item = CreateReleaseBatchResponse, Error = ApiError> + Send>;
fn create_work(&self, entity: models::WorkEntity) -> Box<Future<Item = CreateWorkResponse, Error = ApiError> + Send>;
- fn create_work_batch(&self, entity_list: &Vec<models::WorkEntity>) -> Box<Future<Item = CreateWorkBatchResponse, Error = ApiError> + Send>;
+ fn create_work_batch(&self, entity_list: &Vec<models::WorkEntity>, autoaccept: Option<bool>, editgroup: Option<String>) -> Box<Future<Item = CreateWorkBatchResponse, Error = ApiError> + Send>;
fn delete_container(&self, id: String, editgroup: Option<String>) -> Box<Future<Item = DeleteContainerResponse, Error = ApiError> + Send>;
@@ -768,16 +813,26 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> {
self.api().create_container(entity, &self.context())
}
- fn create_container_batch(&self, entity_list: &Vec<models::ContainerEntity>) -> Box<Future<Item = CreateContainerBatchResponse, Error = ApiError> + Send> {
- self.api().create_container_batch(entity_list, &self.context())
+ fn create_container_batch(
+ &self,
+ entity_list: &Vec<models::ContainerEntity>,
+ autoaccept: Option<bool>,
+ editgroup: Option<String>,
+ ) -> Box<Future<Item = CreateContainerBatchResponse, Error = ApiError> + Send> {
+ self.api().create_container_batch(entity_list, autoaccept, editgroup, &self.context())
}
fn create_creator(&self, entity: models::CreatorEntity) -> Box<Future<Item = CreateCreatorResponse, Error = ApiError> + Send> {
self.api().create_creator(entity, &self.context())
}
- fn create_creator_batch(&self, entity_list: &Vec<models::CreatorEntity>) -> Box<Future<Item = CreateCreatorBatchResponse, Error = ApiError> + Send> {
- self.api().create_creator_batch(entity_list, &self.context())
+ fn create_creator_batch(
+ &self,
+ entity_list: &Vec<models::CreatorEntity>,
+ autoaccept: Option<bool>,
+ editgroup: Option<String>,
+ ) -> Box<Future<Item = CreateCreatorBatchResponse, Error = ApiError> + Send> {
+ self.api().create_creator_batch(entity_list, autoaccept, editgroup, &self.context())
}
fn create_editgroup(&self, entity: models::Editgroup) -> Box<Future<Item = CreateEditgroupResponse, Error = ApiError> + Send> {
@@ -788,24 +843,29 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> {
self.api().create_file(entity, &self.context())
}
- fn create_file_batch(&self, entity_list: &Vec<models::FileEntity>) -> Box<Future<Item = CreateFileBatchResponse, Error = ApiError> + Send> {
- self.api().create_file_batch(entity_list, &self.context())
+ fn create_file_batch(&self, entity_list: &Vec<models::FileEntity>, autoaccept: Option<bool>, editgroup: Option<String>) -> Box<Future<Item = CreateFileBatchResponse, Error = ApiError> + Send> {
+ self.api().create_file_batch(entity_list, autoaccept, editgroup, &self.context())
}
fn create_release(&self, entity: models::ReleaseEntity) -> Box<Future<Item = CreateReleaseResponse, Error = ApiError> + Send> {
self.api().create_release(entity, &self.context())
}
- fn create_release_batch(&self, entity_list: &Vec<models::ReleaseEntity>) -> Box<Future<Item = CreateReleaseBatchResponse, Error = ApiError> + Send> {
- self.api().create_release_batch(entity_list, &self.context())
+ fn create_release_batch(
+ &self,
+ entity_list: &Vec<models::ReleaseEntity>,
+ autoaccept: Option<bool>,
+ editgroup: Option<String>,
+ ) -> Box<Future<Item = CreateReleaseBatchResponse, Error = ApiError> + Send> {
+ self.api().create_release_batch(entity_list, autoaccept, editgroup, &self.context())
}
fn create_work(&self, entity: models::WorkEntity) -> Box<Future<Item = CreateWorkResponse, Error = ApiError> + Send> {
self.api().create_work(entity, &self.context())
}
- fn create_work_batch(&self, entity_list: &Vec<models::WorkEntity>) -> Box<Future<Item = CreateWorkBatchResponse, Error = ApiError> + Send> {
- self.api().create_work_batch(entity_list, &self.context())
+ fn create_work_batch(&self, entity_list: &Vec<models::WorkEntity>, autoaccept: Option<bool>, editgroup: Option<String>) -> Box<Future<Item = CreateWorkBatchResponse, Error = ApiError> + Send> {
+ self.api().create_work_batch(entity_list, autoaccept, editgroup, &self.context())
}
fn delete_container(&self, id: String, editgroup: Option<String>) -> Box<Future<Item = DeleteContainerResponse, Error = ApiError> + Send> {
diff --git a/rust/fatcat-api/src/server.rs b/rust/fatcat-api/src/server.rs
index 8db27496..04d10e14 100644
--- a/rust/fatcat-api/src/server.rs
+++ b/rust/fatcat-api/src/server.rs
@@ -309,6 +309,11 @@ where
context.auth_data = req.extensions.remove::<AuthData>();
context.authorization = req.extensions.remove::<Authorization>();
+ // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response)
+ let query_params = req.get::<UrlEncodedQuery>().unwrap_or_default();
+ let param_autoaccept = query_params.get("autoaccept").and_then(|list| list.first()).and_then(|x| x.parse::<bool>().ok());
+ let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::<String>().ok());
+
// Body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields.
@@ -333,7 +338,7 @@ where
};
let param_entity_list = param_entity_list.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity_list".to_string())))?;
- match api.create_container_batch(param_entity_list.as_ref(), context).wait() {
+ match api.create_container_batch(param_entity_list.as_ref(), param_autoaccept, param_editgroup, context).wait() {
Ok(rsp) => match rsp {
CreateContainerBatchResponse::CreatedEntities(body) => {
let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
@@ -521,6 +526,11 @@ where
context.auth_data = req.extensions.remove::<AuthData>();
context.authorization = req.extensions.remove::<Authorization>();
+ // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response)
+ let query_params = req.get::<UrlEncodedQuery>().unwrap_or_default();
+ let param_autoaccept = query_params.get("autoaccept").and_then(|list| list.first()).and_then(|x| x.parse::<bool>().ok());
+ let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::<String>().ok());
+
// Body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields.
@@ -545,7 +555,7 @@ where
};
let param_entity_list = param_entity_list.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity_list".to_string())))?;
- match api.create_creator_batch(param_entity_list.as_ref(), context).wait() {
+ match api.create_creator_batch(param_entity_list.as_ref(), param_autoaccept, param_editgroup, context).wait() {
Ok(rsp) => match rsp {
CreateCreatorBatchResponse::CreatedEntities(body) => {
let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
@@ -826,6 +836,11 @@ where
context.auth_data = req.extensions.remove::<AuthData>();
context.authorization = req.extensions.remove::<Authorization>();
+ // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response)
+ let query_params = req.get::<UrlEncodedQuery>().unwrap_or_default();
+ let param_autoaccept = query_params.get("autoaccept").and_then(|list| list.first()).and_then(|x| x.parse::<bool>().ok());
+ let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::<String>().ok());
+
// Body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields.
@@ -850,7 +865,7 @@ where
};
let param_entity_list = param_entity_list.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity_list".to_string())))?;
- match api.create_file_batch(param_entity_list.as_ref(), context).wait() {
+ match api.create_file_batch(param_entity_list.as_ref(), param_autoaccept, param_editgroup, context).wait() {
Ok(rsp) => match rsp {
CreateFileBatchResponse::CreatedEntities(body) => {
let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
@@ -1038,6 +1053,11 @@ where
context.auth_data = req.extensions.remove::<AuthData>();
context.authorization = req.extensions.remove::<Authorization>();
+ // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response)
+ let query_params = req.get::<UrlEncodedQuery>().unwrap_or_default();
+ let param_autoaccept = query_params.get("autoaccept").and_then(|list| list.first()).and_then(|x| x.parse::<bool>().ok());
+ let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::<String>().ok());
+
// Body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields.
@@ -1062,7 +1082,7 @@ where
};
let param_entity_list = param_entity_list.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity_list".to_string())))?;
- match api.create_release_batch(param_entity_list.as_ref(), context).wait() {
+ match api.create_release_batch(param_entity_list.as_ref(), param_autoaccept, param_editgroup, context).wait() {
Ok(rsp) => match rsp {
CreateReleaseBatchResponse::CreatedEntities(body) => {
let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
@@ -1250,6 +1270,11 @@ where
context.auth_data = req.extensions.remove::<AuthData>();
context.authorization = req.extensions.remove::<Authorization>();
+ // Query parameters (note that non-required or collection query parameters will ignore garbage values, rather than causing a 400 response)
+ let query_params = req.get::<UrlEncodedQuery>().unwrap_or_default();
+ let param_autoaccept = query_params.get("autoaccept").and_then(|list| list.first()).and_then(|x| x.parse::<bool>().ok());
+ let param_editgroup = query_params.get("editgroup").and_then(|list| list.first()).and_then(|x| x.parse::<String>().ok());
+
// Body parameters (note that non-required body parameters will ignore garbage
// values, rather than causing a 400 response). Produce warning header and logs for
// any unused fields.
@@ -1274,7 +1299,7 @@ where
};
let param_entity_list = param_entity_list.ok_or_else(|| Response::with((status::BadRequest, "Missing required body parameter entity_list".to_string())))?;
- match api.create_work_batch(param_entity_list.as_ref(), context).wait() {
+ match api.create_work_batch(param_entity_list.as_ref(), param_autoaccept, param_editgroup, context).wait() {
Ok(rsp) => match rsp {
CreateWorkBatchResponse::CreatedEntities(body) => {
let body_string = serde_json::to_string(&body).expect("impossible to fail to serialize");
diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs
index 57aeebea..602fbfb7 100644
--- a/rust/src/api_server.rs
+++ b/rust/src/api_server.rs
@@ -25,11 +25,40 @@ macro_rules! entity_batch_handler {
pub fn $post_batch_handler(
&self,
entity_list: &[models::$model],
+ autoaccept: bool,
+ editgroup: Option<String>,
conn: &DbConn,
) -> Result<Vec<EntityEdit>> {
- let edit_context = make_edit_context(conn, None)?;
+ // editgroup override logic based on parameters
+ let eg_id: Option<Uuid> = match (editgroup, autoaccept) {
+ (Some(eg_string), _) => Some(fcid2uuid(&eg_string)?),
+ (None, true) => {
+ let eg_row: EditgroupRow = diesel::insert_into(editgroup::table)
+ .values((editgroup::editor_id.eq(editor_id),))
+ .get_result(conn)?;
+ Some(eg_row.id)
+ },
+ (None, false) => None
+ };
+ for entity in entity_list {
+ let mut e = entity.clone();
+ // override individual editgroup IDs (if set earlier)
+ if let Some(inner_id) = eg_id {
+ e.editgroup_id = Some(uuid2fcid(&inner_id));
+ }
+ // actual wrapped function call here
+ ret.push(self.$post_handler(e, autoaccept, conn)?);
+ }
+ let mut edit_context = make_edit_context(conn, eg_id)?;
+ edit_context.autoaccept = autoaccept;
let model_list: Vec<&models::$model> = entity_list.iter().map(|e| e).collect();
let edits = $model::db_create_batch(conn, &edit_context, model_list.as_slice())?;
+ if autoaccept {
+ // if autoaccept, eg_id is always Some
+ let _clr: ChangelogRow = diesel::insert_into(changelog::table)
+ .values((changelog::editgroup_id.eq(eg_id.unwrap()),))
+ .get_result(conn)?;
+ }
edits.into_iter().map(|e| e.into_model()).collect()
}
}
diff --git a/rust/src/api_wrappers.rs b/rust/src/api_wrappers.rs
index de1fc9da..6272814e 100644
--- a/rust/src/api_wrappers.rs
+++ b/rust/src/api_wrappers.rs
@@ -61,7 +61,7 @@ macro_rules! wrap_entity_handlers {
_context: &Context,
) -> Box<Future<Item = $post_resp, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
- let ret = match conn.transaction(|| self.$post_handler(entity, &conn)) {
+ let ret = match conn.transaction(|| self.$post_handler(entity, false, &conn)) {
Ok(edit) =>
$post_resp::CreatedEntity(edit),
Err(Error(ErrorKind::Diesel(e), _)) =>
@@ -84,10 +84,12 @@ macro_rules! wrap_entity_handlers {
fn $post_batch_fn(
&self,
entity_list: &Vec<models::$model>,
+ autoaccept: Option<bool>,
+ editgroup: Option<String>,
_context: &Context,
) -> Box<Future<Item = $post_batch_resp, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
- let ret = match conn.transaction(|| self.$post_batch_handler(entity_list, &conn)) {
+ let ret = match conn.transaction(|| self.$post_batch_handler(entity_list, autoaccept.unwrap_or(false), editgroup, &conn)) {
Ok(edit) =>
$post_batch_resp::CreatedEntities(edit),
Err(Error(ErrorKind::Diesel(e), _)) =>
diff --git a/rust/tests/test_api_server.rs b/rust/tests/test_api_server.rs
index 4b181188..54639228 100644
--- a/rust/tests/test_api_server.rs
+++ b/rust/tests/test_api_server.rs
@@ -983,3 +983,44 @@ fn test_contribs() {
None,
);
}
+
+#[test]
+fn test_post_batch_autoaccept() {
+ let (headers, router, _conn) = setup();
+
+ // "true"
+ check_response(
+ request::post(
+ "http://localhost:9411/v0/container/batch?autoaccept=true",
+ headers.clone(),
+ r#"[{"name": "test journal"}, {"name": "another test journal"}]"#,
+ &router,
+ ),
+ status::Created,
+ None,
+ );
+
+ // "n"
+ check_response(
+ request::post(
+ "http://localhost:9411/v0/container/batch?autoaccept=n",
+ headers.clone(),
+ r#"[{"name": "test journal"}, {"name": "another test journal"}]"#,
+ &router,
+ ),
+ status::Created,
+ None,
+ );
+
+ // editgroup
+ check_response(
+ request::post(
+ "http://localhost:9411/v0/container/batch?autoaccept=yes&editgroup=asdf",
+ headers.clone(),
+ r#"[{"name": "test journal"}, {"name": "another test journal"}]"#,
+ &router,
+ ),
+ status::BadRequest,
+ None,
+ );
+}