aboutsummaryrefslogtreecommitdiffstats
path: root/rust
diff options
context:
space:
mode:
Diffstat (limited to 'rust')
-rw-r--r--rust/fatcat-api/README.md2
-rw-r--r--rust/fatcat-api/api.yaml56
-rw-r--r--rust/fatcat-api/api/swagger.yaml38
-rw-r--r--rust/fatcat-api/examples/client.rs4
-rw-r--r--rust/fatcat-api/examples/server_lib/server.rs4
-rw-r--r--rust/fatcat-api/src/client.rs4
-rw-r--r--rust/fatcat-api/src/lib.rs12
-rw-r--r--rust/fatcat-api/src/models.rs50
-rw-r--r--rust/fatcat-openapi2.yml56
-rw-r--r--rust/migrations/2018-05-12-001226_init/up.sql2
-rw-r--r--rust/src/api_helpers.rs25
-rw-r--r--rust/src/api_server.rs92
-rw-r--r--rust/src/bin/fatcatd.rs2
-rw-r--r--rust/src/database_models.rs16
-rw-r--r--rust/src/database_schema.rs1
-rw-r--r--rust/src/lib.rs5
-rw-r--r--rust/tests/test_api_server.rs36
17 files changed, 282 insertions, 123 deletions
diff --git a/rust/fatcat-api/README.md b/rust/fatcat-api/README.md
index 39037531..03472ac3 100644
--- a/rust/fatcat-api/README.md
+++ b/rust/fatcat-api/README.md
@@ -13,7 +13,7 @@ To see how to make this your own, look here:
[README](https://github.com/swagger-api/swagger-codegen/blob/master/README.md)
- API version: 0.1.0
-- Build date: 2018-05-24T01:24:11.840Z
+- Build date: 2018-05-24T08:29:24.065Z
This autogenerated project defines an API crate `fatcat` which contains:
* An `Api` trait defining the API in Rust.
diff --git a/rust/fatcat-api/api.yaml b/rust/fatcat-api/api.yaml
index 0ecb0285..3fd7a213 100644
--- a/rust/fatcat-api/api.yaml
+++ b/rust/fatcat-api/api.yaml
@@ -26,6 +26,7 @@ x-entity-props: &ENTITYPROPS
revision:
type: integer
example: 42
+ format: int64
redirect:
type: string
#format: uuid
@@ -33,19 +34,23 @@ x-entity-props: &ENTITYPROPS
editgroup_id:
type: integer
example: 16
+ format: int64
x-entity-edit-props: &ENTITYEDITPROPS
edit_id:
type: integer
example: 847
+ format: int64
ident:
type: string
example: "f1f046a3-45c9-4b99-adce-000000000001"
revision:
type: integer
example: 42
+ format: int64
editgroup_id:
type: integer
example: 16
+ format: int64
definitions:
@@ -101,6 +106,7 @@ definitions:
size:
type: integer
example: 1048576
+ format: int64
sha1:
type: string
#format: custom
@@ -165,11 +171,55 @@ definitions:
properties:
id:
type: integer
+ format: int64
editor_id:
type: integer
+ format: int64
description:
type: string
- # TODO: work_edits array, etc. ["edits"]["work"] or ["work_edits"]?
+ container_edits:
+ type: array
+ item:
+ type: integer
+ format: int64
+# properties:
+# edit_id:
+# type: integer
+# example: 847
+# format: int64
+# type: array
+# items:
+# type: object
+# proposeties:
+# <<: *ENTITYEDITPROPS
+# creators:
+# type: array
+# items:
+# type: object
+# proposeties:
+# <<: *ENTITYEDITPROPS
+# files:
+# type: array
+# items:
+# type: object
+# proposeties:
+# <<: *ENTITYEDITPROPS
+# releases:
+# type: array
+# items:
+# type: object
+# proposeties:
+# <<: *ENTITYEDITPROPS
+# works:
+# type: array
+# items:
+# type: object
+# proposeties:
+# <<: *ENTITYEDITPROPS
+ extra:
+ type: object
+ additionalProperties:
+ type: string
changelogentries:
type: array
items:
@@ -181,8 +231,10 @@ definitions:
properties:
index:
type: integer
+ format: int64
editgroup_id:
type: integer
+ format: int64
timestamp:
type: string
format: date-time
@@ -455,6 +507,7 @@ paths:
- name: id
in: path
type: integer
+ format: int64
required: true
get:
responses:
@@ -479,6 +532,7 @@ paths:
- name: id
in: path
type: integer
+ format: int64
required: true
post:
responses:
diff --git a/rust/fatcat-api/api/swagger.yaml b/rust/fatcat-api/api/swagger.yaml
index f5391925..a6f7a0fe 100644
--- a/rust/fatcat-api/api/swagger.yaml
+++ b/rust/fatcat-api/api/swagger.yaml
@@ -902,8 +902,9 @@ paths:
in: "path"
required: true
type: "integer"
+ format: "int64"
formatString: "{}"
- example: "56"
+ example: "789"
responses:
200:
description: "Found Entity"
@@ -953,8 +954,9 @@ paths:
in: "path"
required: true
type: "integer"
+ format: "int64"
formatString: "{}"
- example: "56"
+ example: "789"
responses:
200:
description: "Merged Successfully"
@@ -1031,12 +1033,14 @@ definitions:
example: "Grace Hopper"
editgroup_id:
type: "integer"
+ format: "int64"
example: 16
redirect:
type: "string"
example: "f1f046a3-45c9-4b99-adce-000000000002"
revision:
type: "integer"
+ format: "int64"
example: 42
ident:
type: "string"
@@ -1083,12 +1087,14 @@ definitions:
example: "f1f046a3-45c9-4b99-adce-000000000001"
revision:
type: "integer"
+ format: "int64"
example: 42
redirect:
type: "string"
example: "f1f046a3-45c9-4b99-adce-000000000002"
editgroup_id:
type: "integer"
+ format: "int64"
example: 16
example:
redirect: "f1f046a3-45c9-4b99-adce-000000000002"
@@ -1112,15 +1118,18 @@ definitions:
example: "f013d66c7f6817d08b7eb2a93e6d0440c1f3e7f8"
size:
type: "integer"
+ format: "int64"
example: 1048576
editgroup_id:
type: "integer"
+ format: "int64"
example: 16
redirect:
type: "string"
example: "f1f046a3-45c9-4b99-adce-000000000002"
revision:
type: "integer"
+ format: "int64"
example: 42
ident:
type: "string"
@@ -1181,12 +1190,14 @@ definitions:
example: "f1f046a3-45c9-4b99-adce-000000000001"
revision:
type: "integer"
+ format: "int64"
example: 42
redirect:
type: "string"
example: "f1f046a3-45c9-4b99-adce-000000000002"
editgroup_id:
type: "integer"
+ format: "int64"
example: 16
example:
redirect: "f1f046a3-45c9-4b99-adce-000000000002"
@@ -1210,12 +1221,14 @@ definitions:
type: "string"
editgroup_id:
type: "integer"
+ format: "int64"
example: 16
redirect:
type: "string"
example: "f1f046a3-45c9-4b99-adce-000000000002"
revision:
type: "integer"
+ format: "int64"
example: 42
ident:
type: "string"
@@ -1240,15 +1253,18 @@ definitions:
properties:
editgroup_id:
type: "integer"
+ format: "int64"
example: 16
revision:
type: "integer"
+ format: "int64"
example: 42
ident:
type: "string"
example: "f1f046a3-45c9-4b99-adce-000000000001"
edit_id:
type: "integer"
+ format: "int64"
example: 847
example:
ident: "f1f046a3-45c9-4b99-adce-000000000001"
@@ -1274,14 +1290,25 @@ definitions:
properties:
id:
type: "integer"
+ format: "int64"
editor_id:
type: "integer"
+ format: "int64"
description:
type: "string"
+ container_edits:
+ type: "array"
+ extra:
+ type: "object"
+ additionalProperties:
+ type: "string"
example:
+ extra:
+ key: "extra"
description: "description"
editor_id: 6
id: 0
+ container_edits: ""
upperCaseName: "EDITGROUP"
changelogentries:
type: "array"
@@ -1296,8 +1323,10 @@ definitions:
properties:
index:
type: "integer"
+ format: "int64"
editgroup_id:
type: "integer"
+ format: "int64"
timestamp:
type: "string"
format: "date-time"
@@ -1316,25 +1345,30 @@ x-entity-props:
revision:
type: "integer"
example: 42
+ format: "int64"
redirect:
type: "string"
example: "f1f046a3-45c9-4b99-adce-000000000002"
editgroup_id:
type: "integer"
example: 16
+ format: "int64"
x-entity-edit-props:
edit_id:
type: "integer"
example: 847
+ format: "int64"
ident:
type: "string"
example: "f1f046a3-45c9-4b99-adce-000000000001"
revision:
type: "integer"
example: 42
+ format: "int64"
editgroup_id:
type: "integer"
example: 16
+ format: "int64"
x-entity-responses:
400:
description: "Bad Request"
diff --git a/rust/fatcat-api/examples/client.rs b/rust/fatcat-api/examples/client.rs
index a818a5c7..396cf3d1 100644
--- a/rust/fatcat-api/examples/client.rs
+++ b/rust/fatcat-api/examples/client.rs
@@ -95,12 +95,12 @@ fn main() {
// println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
// },
Some("EditgroupIdAcceptPost") => {
- let result = client.editgroup_id_accept_post(56).wait();
+ let result = client.editgroup_id_accept_post(789).wait();
println!("{:?} (X-Span-ID: {:?})", result, client.context().x_span_id.clone().unwrap_or(String::from("<none>")));
}
Some("EditgroupIdGet") => {
- let result = client.editgroup_id_get(56).wait();
+ let result = client.editgroup_id_get(789).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 b81af0f8..68670c07 100644
--- a/rust/fatcat-api/examples/server_lib/server.rs
+++ b/rust/fatcat-api/examples/server_lib/server.rs
@@ -54,13 +54,13 @@ impl Api for Server {
Box::new(futures::failed("Generic failure".into()))
}
- fn editgroup_id_accept_post(&self, id: i32, context: &Context) -> Box<Future<Item = EditgroupIdAcceptPostResponse, Error = ApiError> + Send> {
+ fn editgroup_id_accept_post(&self, id: i64, context: &Context) -> Box<Future<Item = EditgroupIdAcceptPostResponse, Error = ApiError> + Send> {
let context = context.clone();
println!("editgroup_id_accept_post({}) - X-Span-ID: {:?}", id, context.x_span_id.unwrap_or(String::from("<none>")).clone());
Box::new(futures::failed("Generic failure".into()))
}
- fn editgroup_id_get(&self, id: i32, context: &Context) -> Box<Future<Item = EditgroupIdGetResponse, Error = ApiError> + Send> {
+ fn editgroup_id_get(&self, id: i64, context: &Context) -> Box<Future<Item = EditgroupIdGetResponse, Error = ApiError> + Send> {
let context = context.clone();
println!("editgroup_id_get({}) - X-Span-ID: {:?}", id, 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 4fa084f9..517d9705 100644
--- a/rust/fatcat-api/src/client.rs
+++ b/rust/fatcat-api/src/client.rs
@@ -537,7 +537,7 @@ impl Api for Client {
Box::new(futures::done(result))
}
- fn editgroup_id_accept_post(&self, param_id: i32, context: &Context) -> Box<Future<Item = EditgroupIdAcceptPostResponse, Error = ApiError> + Send> {
+ fn editgroup_id_accept_post(&self, param_id: i64, context: &Context) -> Box<Future<Item = EditgroupIdAcceptPostResponse, 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)();
@@ -597,7 +597,7 @@ impl Api for Client {
Box::new(futures::done(result))
}
- fn editgroup_id_get(&self, param_id: i32, context: &Context) -> Box<Future<Item = EditgroupIdGetResponse, Error = ApiError> + Send> {
+ fn editgroup_id_get(&self, param_id: i64, context: &Context) -> Box<Future<Item = EditgroupIdGetResponse, 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)();
diff --git a/rust/fatcat-api/src/lib.rs b/rust/fatcat-api/src/lib.rs
index abd68f04..94633e00 100644
--- a/rust/fatcat-api/src/lib.rs
+++ b/rust/fatcat-api/src/lib.rs
@@ -268,9 +268,9 @@ pub trait Api {
fn creator_post(&self, body: models::CreatorEntity, context: &Context) -> Box<Future<Item = CreatorPostResponse, Error = ApiError> + Send>;
- fn editgroup_id_accept_post(&self, id: i32, context: &Context) -> Box<Future<Item = EditgroupIdAcceptPostResponse, Error = ApiError> + Send>;
+ fn editgroup_id_accept_post(&self, id: i64, context: &Context) -> Box<Future<Item = EditgroupIdAcceptPostResponse, Error = ApiError> + Send>;
- fn editgroup_id_get(&self, id: i32, context: &Context) -> Box<Future<Item = EditgroupIdGetResponse, Error = ApiError> + Send>;
+ fn editgroup_id_get(&self, id: i64, context: &Context) -> Box<Future<Item = EditgroupIdGetResponse, Error = ApiError> + Send>;
fn editgroup_post(&self, body: models::Editgroup, context: &Context) -> Box<Future<Item = EditgroupPostResponse, Error = ApiError> + Send>;
@@ -309,9 +309,9 @@ pub trait ApiNoContext {
fn creator_post(&self, body: models::CreatorEntity) -> Box<Future<Item = CreatorPostResponse, Error = ApiError> + Send>;
- fn editgroup_id_accept_post(&self, id: i32) -> Box<Future<Item = EditgroupIdAcceptPostResponse, Error = ApiError> + Send>;
+ fn editgroup_id_accept_post(&self, id: i64) -> Box<Future<Item = EditgroupIdAcceptPostResponse, Error = ApiError> + Send>;
- fn editgroup_id_get(&self, id: i32) -> Box<Future<Item = EditgroupIdGetResponse, Error = ApiError> + Send>;
+ fn editgroup_id_get(&self, id: i64) -> Box<Future<Item = EditgroupIdGetResponse, Error = ApiError> + Send>;
fn editgroup_post(&self, body: models::Editgroup) -> Box<Future<Item = EditgroupPostResponse, Error = ApiError> + Send>;
@@ -376,11 +376,11 @@ impl<'a, T: Api> ApiNoContext for ContextWrapper<'a, T> {
self.api().creator_post(body, &self.context())
}
- fn editgroup_id_accept_post(&self, id: i32) -> Box<Future<Item = EditgroupIdAcceptPostResponse, Error = ApiError> + Send> {
+ fn editgroup_id_accept_post(&self, id: i64) -> Box<Future<Item = EditgroupIdAcceptPostResponse, Error = ApiError> + Send> {
self.api().editgroup_id_accept_post(id, &self.context())
}
- fn editgroup_id_get(&self, id: i32) -> Box<Future<Item = EditgroupIdGetResponse, Error = ApiError> + Send> {
+ fn editgroup_id_get(&self, id: i64) -> Box<Future<Item = EditgroupIdGetResponse, Error = ApiError> + Send> {
self.api().editgroup_id_get(id, &self.context())
}
diff --git a/rust/fatcat-api/src/models.rs b/rust/fatcat-api/src/models.rs
index 784068e3..9609e5ec 100644
--- a/rust/fatcat-api/src/models.rs
+++ b/rust/fatcat-api/src/models.rs
@@ -72,17 +72,17 @@ impl ::std::ops::DerefMut for Changelogentries {
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct ChangelogentriesInner {
#[serde(rename = "index")]
- pub index: isize,
+ pub index: i64,
#[serde(rename = "editgroup_id")]
- pub editgroup_id: isize,
+ pub editgroup_id: i64,
#[serde(rename = "timestamp")]
pub timestamp: chrono::DateTime<chrono::Utc>,
}
impl ChangelogentriesInner {
- pub fn new(index: isize, editgroup_id: isize, timestamp: chrono::DateTime<chrono::Utc>) -> ChangelogentriesInner {
+ pub fn new(index: i64, editgroup_id: i64, timestamp: chrono::DateTime<chrono::Utc>) -> ChangelogentriesInner {
ChangelogentriesInner {
index: index,
editgroup_id: editgroup_id,
@@ -115,7 +115,7 @@ pub struct ContainerEntity {
#[serde(rename = "revision")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub revision: Option<isize>,
+ pub revision: Option<i64>,
#[serde(rename = "redirect")]
#[serde(skip_serializing_if = "Option::is_none")]
@@ -123,7 +123,7 @@ pub struct ContainerEntity {
#[serde(rename = "editgroup_id")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub editgroup_id: Option<isize>,
+ pub editgroup_id: Option<i64>,
}
impl ContainerEntity {
@@ -152,7 +152,7 @@ pub struct CreatorEntity {
#[serde(rename = "editgroup_id")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub editgroup_id: Option<isize>,
+ pub editgroup_id: Option<i64>,
#[serde(rename = "redirect")]
#[serde(skip_serializing_if = "Option::is_none")]
@@ -160,7 +160,7 @@ pub struct CreatorEntity {
#[serde(rename = "revision")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub revision: Option<isize>,
+ pub revision: Option<i64>,
#[serde(rename = "ident")]
#[serde(skip_serializing_if = "Option::is_none")]
@@ -190,22 +190,32 @@ impl CreatorEntity {
pub struct Editgroup {
#[serde(rename = "id")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub id: Option<isize>,
+ pub id: Option<i64>,
#[serde(rename = "editor_id")]
- pub editor_id: isize,
+ pub editor_id: i64,
#[serde(rename = "description")]
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
+
+ #[serde(rename = "container_edits")]
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub container_edits: Option<Vec>,
+
+ #[serde(rename = "extra")]
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub extra: Option<HashMap<String, String>>,
}
impl Editgroup {
- pub fn new(editor_id: isize) -> Editgroup {
+ pub fn new(editor_id: i64) -> Editgroup {
Editgroup {
id: None,
editor_id: editor_id,
description: None,
+ container_edits: None,
+ extra: None,
}
}
}
@@ -226,11 +236,11 @@ impl Editor {
pub struct EntityEdit {
#[serde(rename = "editgroup_id")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub editgroup_id: Option<isize>,
+ pub editgroup_id: Option<i64>,
#[serde(rename = "revision")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub revision: Option<isize>,
+ pub revision: Option<i64>,
#[serde(rename = "ident")]
#[serde(skip_serializing_if = "Option::is_none")]
@@ -238,7 +248,7 @@ pub struct EntityEdit {
#[serde(rename = "edit_id")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub edit_id: Option<isize>,
+ pub edit_id: Option<i64>,
}
impl EntityEdit {
@@ -276,11 +286,11 @@ pub struct FileEntity {
#[serde(rename = "size")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub size: Option<isize>,
+ pub size: Option<i64>,
#[serde(rename = "editgroup_id")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub editgroup_id: Option<isize>,
+ pub editgroup_id: Option<i64>,
#[serde(rename = "redirect")]
#[serde(skip_serializing_if = "Option::is_none")]
@@ -288,7 +298,7 @@ pub struct FileEntity {
#[serde(rename = "revision")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub revision: Option<isize>,
+ pub revision: Option<i64>,
#[serde(rename = "ident")]
#[serde(skip_serializing_if = "Option::is_none")]
@@ -358,7 +368,7 @@ pub struct ReleaseEntity {
#[serde(rename = "revision")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub revision: Option<isize>,
+ pub revision: Option<i64>,
#[serde(rename = "redirect")]
#[serde(skip_serializing_if = "Option::is_none")]
@@ -366,7 +376,7 @@ pub struct ReleaseEntity {
#[serde(rename = "editgroup_id")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub editgroup_id: Option<isize>,
+ pub editgroup_id: Option<i64>,
}
impl ReleaseEntity {
@@ -409,7 +419,7 @@ pub struct WorkEntity {
#[serde(rename = "editgroup_id")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub editgroup_id: Option<isize>,
+ pub editgroup_id: Option<i64>,
#[serde(rename = "redirect")]
#[serde(skip_serializing_if = "Option::is_none")]
@@ -417,7 +427,7 @@ pub struct WorkEntity {
#[serde(rename = "revision")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub revision: Option<isize>,
+ pub revision: Option<i64>,
#[serde(rename = "ident")]
#[serde(skip_serializing_if = "Option::is_none")]
diff --git a/rust/fatcat-openapi2.yml b/rust/fatcat-openapi2.yml
index 0ecb0285..df828a41 100644
--- a/rust/fatcat-openapi2.yml
+++ b/rust/fatcat-openapi2.yml
@@ -26,6 +26,7 @@ x-entity-props: &ENTITYPROPS
revision:
type: integer
example: 42
+ format: int64
redirect:
type: string
#format: uuid
@@ -33,19 +34,23 @@ x-entity-props: &ENTITYPROPS
editgroup_id:
type: integer
example: 16
+ format: int64
x-entity-edit-props: &ENTITYEDITPROPS
edit_id:
type: integer
example: 847
+ format: int64
ident:
type: string
example: "f1f046a3-45c9-4b99-adce-000000000001"
revision:
type: integer
example: 42
+ format: int64
editgroup_id:
type: integer
example: 16
+ format: int64
definitions:
@@ -101,6 +106,7 @@ definitions:
size:
type: integer
example: 1048576
+ format: int64
sha1:
type: string
#format: custom
@@ -165,11 +171,55 @@ definitions:
properties:
id:
type: integer
+ format: int64
editor_id:
type: integer
+ format: int64
description:
type: string
- # TODO: work_edits array, etc. ["edits"]["work"] or ["work_edits"]?
+# container_edits:
+# type: array
+# item:
+# type: integer
+# format: int64
+# properties:
+# edit_id:
+# type: integer
+# example: 847
+# format: int64
+# type: array
+# items:
+# type: object
+# proposeties:
+# <<: *ENTITYEDITPROPS
+# creators:
+# type: array
+# items:
+# type: object
+# proposeties:
+# <<: *ENTITYEDITPROPS
+# files:
+# type: array
+# items:
+# type: object
+# proposeties:
+# <<: *ENTITYEDITPROPS
+# releases:
+# type: array
+# items:
+# type: object
+# proposeties:
+# <<: *ENTITYEDITPROPS
+# works:
+# type: array
+# items:
+# type: object
+# proposeties:
+# <<: *ENTITYEDITPROPS
+ extra:
+ type: object
+ additionalProperties:
+ type: string
changelogentries:
type: array
items:
@@ -181,8 +231,10 @@ definitions:
properties:
index:
type: integer
+ format: int64
editgroup_id:
type: integer
+ format: int64
timestamp:
type: string
format: date-time
@@ -455,6 +507,7 @@ paths:
- name: id
in: path
type: integer
+ format: int64
required: true
get:
responses:
@@ -479,6 +532,7 @@ paths:
- name: id
in: path
type: integer
+ format: int64
required: true
post:
responses:
diff --git a/rust/migrations/2018-05-12-001226_init/up.sql b/rust/migrations/2018-05-12-001226_init/up.sql
index 05b20fee..09275bdd 100644
--- a/rust/migrations/2018-05-12-001226_init/up.sql
+++ b/rust/migrations/2018-05-12-001226_init/up.sql
@@ -17,7 +17,7 @@ CREATE TABLE editor (
CREATE TABLE editgroup (
id BIGSERIAL PRIMARY KEY,
- -- extra_json JSON,
+ extra_json JSON,
editor_id BIGSERIAL REFERENCES editor(id) NOT NULL,
description TEXT
);
diff --git a/rust/src/api_helpers.rs b/rust/src/api_helpers.rs
index 247eed88..62fc4569 100644
--- a/rust/src/api_helpers.rs
+++ b/rust/src/api_helpers.rs
@@ -1,9 +1,8 @@
-
-use errors::*;
-use diesel;
-use diesel::prelude::*;
use database_models::*;
use database_schema::*;
+use diesel;
+use diesel::prelude::*;
+use errors::*;
pub fn get_or_create_editgroup(editor_id: i64, conn: &PgConnection) -> Result<i64> {
// check for current active
@@ -14,11 +13,8 @@ pub fn get_or_create_editgroup(editor_id: i64, conn: &PgConnection) -> Result<i6
// need to insert and update
conn.build_transaction().run(|| {
-
let eg_row: EditgroupRow = diesel::insert_into(editgroup::table)
- .values((
- editgroup::editor_id.eq(ed_row.id),
- ))
+ .values((editgroup::editor_id.eq(ed_row.id),))
.get_result(conn)?;
diesel::update(editor::table.find(ed_row.id))
.set(editor::active_editgroup_id.eq(eg_row.id))
@@ -29,7 +25,6 @@ pub fn get_or_create_editgroup(editor_id: i64, conn: &PgConnection) -> Result<i6
pub fn accept_editgroup(editgroup_id: i64, conn: &PgConnection) -> Result<ChangelogRow> {
conn.build_transaction().run(|| {
-
// check that we haven't accepted already (in changelog)
// NB: could leave this to a UNIQUE constraint
let count: i64 = changelog::table
@@ -60,8 +55,8 @@ pub fn accept_editgroup(editgroup_id: i64, conn: &PgConnection) -> Result<Change
// Sketchy... but fast? Only a few queries per accept.
for entity in ["container", "creator", "file", "work", "release"].iter() {
- diesel::sql_query(
- format!("
+ diesel::sql_query(format!(
+ "
UPDATE {entity}_ident
SET
is_live = true,
@@ -71,16 +66,14 @@ pub fn accept_editgroup(editgroup_id: i64, conn: &PgConnection) -> Result<Change
WHERE
{entity}_ident.id = {entity}_edit.ident_id
AND {entity}_edit.editgroup_id = $1",
- entity = entity))
- .bind::<diesel::sql_types::BigInt, _>(editgroup_id)
+ entity = entity
+ )).bind::<diesel::sql_types::BigInt, _>(editgroup_id)
.execute(conn)?;
}
// append log/changelog row
let entry: ChangelogRow = diesel::insert_into(changelog::table)
- .values((
- changelog::editgroup_id.eq(editgroup_id),
- ))
+ .values((changelog::editgroup_id.eq(editgroup_id),))
.get_result(conn)?;
// update any editor's active editgroup
diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs
index 3016b92b..c91af9c9 100644
--- a/rust/src/api_server.rs
+++ b/rust/src/api_server.rs
@@ -1,8 +1,8 @@
//! API endpoint handlers
use ConnectionPool;
-use chrono;
use api_helpers::*;
+use chrono;
use database_models::*;
use database_schema::{changelog, container_ident, container_rev, creator_ident, creator_rev,
editgroup, editor, file_ident, file_rev, release_ident, release_rev,
@@ -98,7 +98,7 @@ impl Server {
name: rev.name,
state: Some(ident.state().unwrap().shortname()),
ident: Some(ident.id.to_string()),
- revision: ident.rev_id.map(|v| v as isize),
+ revision: ident.rev_id,
redirect: ident.redirect_id.map(|u| u.to_string()),
editgroup_id: None,
};
@@ -128,7 +128,7 @@ impl Server {
name: rev.name,
state: Some(ident.state().unwrap().shortname()),
ident: Some(ident.id.to_string()),
- revision: ident.rev_id.map(|v| v as isize),
+ revision: ident.rev_id,
redirect: ident.redirect_id.map(|u| u.to_string()),
editgroup_id: None,
};
@@ -155,7 +155,7 @@ impl Server {
orcid: rev.orcid,
state: Some(ident.state().unwrap().shortname()),
ident: Some(ident.id.to_string()),
- revision: ident.rev_id.map(|v| v as isize),
+ revision: ident.rev_id,
redirect: ident.redirect_id.map(|u| u.to_string()),
editgroup_id: None,
};
@@ -183,7 +183,7 @@ impl Server {
orcid: rev.orcid,
state: Some(ident.state().unwrap().shortname()),
ident: Some(ident.id.to_string()),
- revision: ident.rev_id.map(|v| v as isize),
+ revision: ident.rev_id,
redirect: ident.redirect_id.map(|u| u.to_string()),
editgroup_id: None,
};
@@ -207,11 +207,11 @@ impl Server {
let entity = FileEntity {
sha1: rev.sha1,
- size: rev.size.map(|v| v as isize),
+ size: rev.size.map(|v| v as i64),
url: rev.url,
state: Some(ident.state().unwrap().shortname()),
ident: Some(ident.id.to_string()),
- revision: ident.rev_id.map(|v| v as isize),
+ revision: ident.rev_id.map(|v| v),
redirect: ident.redirect_id.map(|u| u.to_string()),
editgroup_id: None,
};
@@ -236,11 +236,11 @@ impl Server {
let entity = FileEntity {
sha1: rev.sha1,
- size: rev.size.map(|v| v as isize),
+ size: rev.size.map(|v| v as i64),
url: rev.url,
state: Some(ident.state().unwrap().shortname()),
ident: Some(ident.id.to_string()),
- revision: ident.rev_id.map(|v| v as isize),
+ revision: ident.rev_id.map(|v| v),
redirect: ident.redirect_id.map(|u| u.to_string()),
editgroup_id: None,
};
@@ -266,7 +266,7 @@ impl Server {
work_type: rev.work_type,
state: Some(ident.state().unwrap().shortname()),
ident: Some(ident.id.to_string()),
- revision: ident.rev_id.map(|v| v as isize),
+ revision: ident.rev_id,
redirect: ident.redirect_id.map(|u| u.to_string()),
editgroup_id: None,
};
@@ -300,7 +300,7 @@ impl Server {
work_id: rev.work_ident_id.to_string(),
state: Some(ident.state().unwrap().shortname()),
ident: Some(ident.id.to_string()),
- revision: ident.rev_id.map(|v| v as isize),
+ revision: ident.rev_id,
redirect: ident.redirect_id.map(|u| u.to_string()),
editgroup_id: None,
};
@@ -335,22 +335,23 @@ impl Server {
work_id: rev.work_ident_id.to_string(),
state: Some(ident.state().unwrap().shortname()),
ident: Some(ident.id.to_string()),
- revision: ident.rev_id.map(|v| v as isize),
+ revision: ident.rev_id,
redirect: ident.redirect_id.map(|u| u.to_string()),
editgroup_id: None,
};
Ok(Some(entity))
}
- fn editgroup_id_get_handler(&self, id: i32) -> Result<Option<Editgroup>> {
+ fn editgroup_id_get_handler(&self, id: i64) -> Result<Option<Editgroup>> {
let conn = self.db_pool.get().expect("db_pool error");
let row: EditgroupRow = editgroup::table.find(id as i64).first(&conn)?;
let eg = Editgroup {
- id: Some(row.id as isize),
- editor_id: row.editor_id as isize,
+ id: Some(row.id),
+ editor_id: row.editor_id,
description: row.description,
+ extra: None,
};
Ok(Some(eg))
}
@@ -383,8 +384,8 @@ impl Server {
let entries = changes
.iter()
.map(|(row, _)| ChangelogentriesInner {
- index: row.id as isize,
- editgroup_id: row.editgroup_id as isize,
+ index: row.id,
+ editgroup_id: row.editgroup_id,
timestamp: chrono::DateTime::from_utc(row.timestamp, chrono::Utc),
})
.collect();
@@ -417,7 +418,7 @@ impl Api for Server {
editgroup_id_get,
editgroup_id_get_handler,
EditgroupIdGetResponse,
- i32
+ i64
);
wrap_lookup_handler!(
@@ -455,7 +456,7 @@ impl Api for Server {
_context: &Context,
) -> Box<Future<Item = ContainerPostResponse, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
- let editor_id = 1; // TODO: auth
+ let editor_id = 1; // TODO: auth
let editgroup_id = match body.editgroup_id {
None => get_or_create_editgroup(editor_id, &conn).expect("current editgroup"),
Some(param) => param as i64,
@@ -480,10 +481,10 @@ impl Api for Server {
let edit = &edit;
let entity_edit = EntityEdit {
- editgroup_id: Some(edit.editgroup_id as isize),
- revision: Some(edit.rev_id.unwrap() as isize),
+ editgroup_id: Some(edit.editgroup_id),
+ revision: Some(edit.rev_id.unwrap()),
ident: Some(edit.ident_id.to_string()),
- edit_id: Some(edit.id as isize),
+ edit_id: Some(edit.id),
};
Box::new(futures::done(Ok(ContainerPostResponse::CreatedEntity(
entity_edit,
@@ -496,7 +497,7 @@ impl Api for Server {
_context: &Context,
) -> Box<Future<Item = CreatorPostResponse, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
- let editor_id = 1; // TODO: auth
+ let editor_id = 1; // TODO: auth
let editgroup_id = match body.editgroup_id {
None => get_or_create_editgroup(editor_id, &conn).expect("current editgroup"),
Some(param) => param as i64,
@@ -520,10 +521,10 @@ impl Api for Server {
let edit = &edit;
let entity_edit = EntityEdit {
- editgroup_id: Some(edit.editgroup_id as isize),
- revision: Some(edit.rev_id.unwrap() as isize),
+ editgroup_id: Some(edit.editgroup_id),
+ revision: Some(edit.rev_id.unwrap()),
ident: Some(edit.ident_id.to_string()),
- edit_id: Some(edit.id as isize),
+ edit_id: Some(edit.id),
};
Box::new(futures::done(Ok(CreatorPostResponse::CreatedEntity(
entity_edit,
@@ -536,7 +537,7 @@ impl Api for Server {
_context: &Context,
) -> Box<Future<Item = FilePostResponse, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
- let editor_id = 1; // TODO: auth
+ let editor_id = 1; // TODO: auth
let editgroup_id = match body.editgroup_id {
None => get_or_create_editgroup(editor_id, &conn).expect("current editgroup"),
Some(param) => param as i64,
@@ -563,10 +564,10 @@ impl Api for Server {
let edit = &edit;
let entity_edit = EntityEdit {
- editgroup_id: Some(edit.editgroup_id as isize),
- revision: Some(edit.rev_id.unwrap() as isize),
+ editgroup_id: Some(edit.editgroup_id),
+ revision: Some(edit.rev_id.unwrap()),
ident: Some(edit.ident_id.to_string()),
- edit_id: Some(edit.id as isize),
+ edit_id: Some(edit.id),
};
Box::new(futures::done(Ok(FilePostResponse::CreatedEntity(
entity_edit,
@@ -579,7 +580,7 @@ impl Api for Server {
_context: &Context,
) -> Box<Future<Item = WorkPostResponse, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
- let editor_id = 1; // TODO: auth
+ let editor_id = 1; // TODO: auth
let editgroup_id = match body.editgroup_id {
None => get_or_create_editgroup(editor_id, &conn).expect("current editgroup"),
Some(param) => param as i64,
@@ -603,10 +604,10 @@ impl Api for Server {
let edit = &edit;
let entity_edit = EntityEdit {
- editgroup_id: Some(edit.editgroup_id as isize),
- revision: Some(edit.rev_id.unwrap() as isize),
+ editgroup_id: Some(edit.editgroup_id),
+ revision: Some(edit.rev_id.unwrap()),
ident: Some(edit.ident_id.to_string()),
- edit_id: Some(edit.id as isize),
+ edit_id: Some(edit.id),
};
Box::new(futures::done(Ok(WorkPostResponse::CreatedEntity(
entity_edit,
@@ -619,7 +620,7 @@ impl Api for Server {
_context: &Context,
) -> Box<Future<Item = ReleasePostResponse, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
- let editor_id = 1; // TODO: auth
+ let editor_id = 1; // TODO: auth
let editgroup_id = match body.editgroup_id {
None => get_or_create_editgroup(editor_id, &conn).expect("current editgroup"),
Some(param) => param as i64,
@@ -656,10 +657,10 @@ impl Api for Server {
let edit = &edit;
let entity_edit = EntityEdit {
- editgroup_id: Some(edit.editgroup_id as isize),
- revision: Some(edit.rev_id.unwrap() as isize),
+ editgroup_id: Some(edit.editgroup_id),
+ revision: Some(edit.rev_id.unwrap()),
ident: Some(edit.ident_id.to_string()),
- edit_id: Some(edit.id as isize),
+ edit_id: Some(edit.id),
};
Box::new(futures::done(Ok(ReleasePostResponse::CreatedEntity(
entity_edit,
@@ -668,16 +669,18 @@ impl Api for Server {
fn editgroup_id_accept_post(
&self,
- id: i32,
+ id: i64,
_context: &Context,
) -> Box<Future<Item = EditgroupIdAcceptPostResponse, Error = ApiError> + Send> {
let conn = self.db_pool.get().expect("db_pool error");
accept_editgroup(id as i64, &conn).expect("failed to accept editgroup");
- Box::new(futures::done(Ok(EditgroupIdAcceptPostResponse::MergedSuccessfully(
- Success { message: "horray!".to_string() }
- ))))
+ Box::new(futures::done(Ok(
+ EditgroupIdAcceptPostResponse::MergedSuccessfully(Success {
+ message: "horray!".to_string(),
+ }),
+ )))
}
fn editgroup_post(
@@ -696,9 +699,10 @@ impl Api for Server {
.expect("error creating edit group");
let new_eg = Editgroup {
- id: Some(row.id as isize),
- editor_id: row.editor_id as isize,
+ id: Some(row.id),
+ editor_id: row.editor_id,
description: row.description,
+ extra: None,
};
Box::new(futures::done(Ok(
EditgroupPostResponse::SuccessfullyCreated(new_eg),
diff --git a/rust/src/bin/fatcatd.rs b/rust/src/bin/fatcatd.rs
index 460246b5..b50da2be 100644
--- a/rust/src/bin/fatcatd.rs
+++ b/rust/src/bin/fatcatd.rs
@@ -4,12 +4,12 @@ extern crate chrono;
extern crate clap;
extern crate diesel;
//extern crate dotenv;
+extern crate error_chain;
extern crate fatcat;
extern crate fatcat_api;
extern crate futures;
extern crate iron;
extern crate iron_slog;
-extern crate error_chain;
#[macro_use]
extern crate slog;
extern crate slog_async;
diff --git a/rust/src/database_models.rs b/rust/src/database_models.rs
index 0e138439..33676c95 100644
--- a/rust/src/database_models.rs
+++ b/rust/src/database_models.rs
@@ -1,8 +1,8 @@
use chrono;
-//use serde_json;
use database_schema::*;
-use uuid::Uuid;
use errors::*;
+use serde_json;
+use uuid::Uuid;
// Ugh. I thought the whole point was to *not* do this, but:
// https://github.com/diesel-rs/diesel/issues/1589
@@ -19,7 +19,7 @@ impl EntityState {
match self {
EntityState::WorkInProgress => "wip",
EntityState::Active(_) => "active",
- EntityState::Redirect(_,_) => "redirect",
+ EntityState::Redirect(_, _) => "redirect",
EntityState::Deleted => "deleted",
}.to_string()
}
@@ -40,7 +40,7 @@ macro_rules! entity_structs {
pub rev_id: Option<i64>,
pub redirect_id: Option<Uuid>,
pub editgroup_id: i64,
- //pub extra_json: Option<String>,
+ //pub extra_json: Option<serde_json::Value>,
}
#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)]
@@ -61,7 +61,7 @@ macro_rules! entity_structs {
(None, None) => Ok(EntityState::Deleted),
(Some(redir), Some(rev)) => Ok(EntityState::Redirect(redir, rev)),
(None, Some(rev)) => Ok(EntityState::Active(rev)),
- _ => bail!("Invalid EntityIdentRow state")
+ _ => bail!("Invalid EntityIdentRow state"),
}
}
}
@@ -89,7 +89,7 @@ entity_structs!(
#[table_name = "creator_rev"]
pub struct CreatorRevRow {
pub id: i64,
- //extra_json: Option<Json>,
+ //extra_json: Option<String>,
pub name: String,
pub orcid: Option<String>,
}
@@ -105,7 +105,7 @@ entity_structs!(
#[table_name = "file_rev"]
pub struct FileRevRow {
pub id: i64,
- //extra_json: Option<Json>,
+ //extra_json: Option<String>,
pub size: Option<i32>,
pub sha1: Option<String>,
pub url: Option<String>,
@@ -181,7 +181,7 @@ pub struct FileReleaseRow {
#[table_name = "editgroup"]
pub struct EditgroupRow {
pub id: i64,
- //extra_json: Option<Json>,
+ pub extra_json: Option<serde_json::Value>,
pub editor_id: i64,
pub description: Option<String>,
}
diff --git a/rust/src/database_schema.rs b/rust/src/database_schema.rs
index f355107a..b25c52e2 100644
--- a/rust/src/database_schema.rs
+++ b/rust/src/database_schema.rs
@@ -64,6 +64,7 @@ table! {
table! {
editgroup (id) {
id -> Int8,
+ extra_json -> Nullable<Json>,
editor_id -> Int8,
description -> Nullable<Text>,
}
diff --git a/rust/src/lib.rs b/rust/src/lib.rs
index c12575a9..0038f9db 100644
--- a/rust/src/lib.rs
+++ b/rust/src/lib.rs
@@ -1,5 +1,5 @@
-extern crate fatcat_api;
extern crate chrono;
+extern crate fatcat_api;
#[macro_use]
extern crate diesel;
extern crate diesel_migrations;
@@ -14,8 +14,8 @@ extern crate error_chain;
extern crate iron;
extern crate serde_json;
-pub mod api_server;
pub mod api_helpers;
+pub mod api_server;
pub mod database_models;
pub mod database_schema;
@@ -68,7 +68,6 @@ pub fn server() -> Result<api_server::Server> {
}
pub fn test_server() -> Result<api_server::Server> {
-
dotenv().ok();
let database_url = env::var("TEST_DATABASE_URL").expect("TEST_DATABASE_URL must be set");
env::set_var("DATABASE_URL", database_url);
diff --git a/rust/tests/test_api_server.rs b/rust/tests/test_api_server.rs
index 6126a0a2..02f88ea4 100644
--- a/rust/tests/test_api_server.rs
+++ b/rust/tests/test_api_server.rs
@@ -1,15 +1,15 @@
+extern crate diesel;
extern crate fatcat;
extern crate fatcat_api;
extern crate iron;
extern crate iron_test;
-extern crate diesel;
-use fatcat::database_schema::*;
-use fatcat::api_helpers::*;
use diesel::prelude::*;
-use iron::{status, Headers};
-use iron::mime::Mime;
+use fatcat::api_helpers::*;
+use fatcat::database_schema::*;
use iron::headers::ContentType;
+use iron::mime::Mime;
+use iron::{status, Headers};
use iron_test::{request, response};
#[test]
@@ -66,7 +66,6 @@ fn test_post_container() {
let mime: Mime = "application/json".parse().unwrap();
headers.set(ContentType(mime));
-
let response = request::post(
"http://localhost:9411/v0/container",
headers,
@@ -93,25 +92,33 @@ fn test_accept_editgroup() {
let c: i64 = container_ident::table
.filter(container_ident::is_live.eq(false))
.count()
- .get_result(&conn).unwrap();
+ .get_result(&conn)
+ .unwrap();
assert_eq!(c, 0);
let c: i64 = changelog::table
.filter(changelog::editgroup_id.eq(editgroup_id))
.count()
- .get_result(&conn).unwrap();
+ .get_result(&conn)
+ .unwrap();
assert_eq!(c, 0);
let response = request::post(
"http://localhost:9411/v0/container",
headers.clone(),
- &format!("{{\"name\": \"test journal 1\", \"editgroup_id\": {}}}", editgroup_id),
+ &format!(
+ "{{\"name\": \"test journal 1\", \"editgroup_id\": {}}}",
+ editgroup_id
+ ),
&router,
).unwrap();
assert_eq!(response.status, Some(status::Created));
let response = request::post(
"http://localhost:9411/v0/container",
headers.clone(),
- &format!("{{\"name\": \"test journal 2\", \"editgroup_id\": {}}}", editgroup_id),
+ &format!(
+ "{{\"name\": \"test journal 2\", \"editgroup_id\": {}}}",
+ editgroup_id
+ ),
&router,
).unwrap();
assert_eq!(response.status, Some(status::Created));
@@ -119,7 +126,8 @@ fn test_accept_editgroup() {
let c: i64 = container_ident::table
.filter(container_ident::is_live.eq(false))
.count()
- .get_result(&conn).unwrap();
+ .get_result(&conn)
+ .unwrap();
assert_eq!(c, 2);
let response = request::post(
@@ -133,11 +141,13 @@ fn test_accept_editgroup() {
let c: i64 = container_ident::table
.filter(container_ident::is_live.eq(false))
.count()
- .get_result(&conn).unwrap();
+ .get_result(&conn)
+ .unwrap();
assert_eq!(c, 0);
let c: i64 = changelog::table
.filter(changelog::editgroup_id.eq(editgroup_id))
.count()
- .get_result(&conn).unwrap();
+ .get_result(&conn)
+ .unwrap();
assert_eq!(c, 1);
}