summaryrefslogtreecommitdiffstats
path: root/rust/src
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-05-25 17:05:03 -0700
committerBryan Newbold <bnewbold@robocracy.org>2018-05-25 17:05:03 -0700
commit92d297ffc895f471a5061250bdd49b71e50a95ab (patch)
tree4f232bf398e53cf2db3aef0dac4c4146390c848a /rust/src
parent8e92be6e1e9396f4920c0f947337e1be643e1994 (diff)
downloadfatcat-92d297ffc895f471a5061250bdd49b71e50a95ab.tar.gz
fatcat-92d297ffc895f471a5061250bdd49b71e50a95ab.zip
refs and contribs
Diffstat (limited to 'rust/src')
-rw-r--r--rust/src/api_server.rs114
-rw-r--r--rust/src/database_models.rs46
2 files changed, 140 insertions, 20 deletions
diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs
index a2e133fe..19e33994 100644
--- a/rust/src/api_server.rs
+++ b/rust/src/api_server.rs
@@ -6,7 +6,7 @@ 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,
- work_ident, work_rev};
+ release_contrib, release_ref, work_ident, work_rev};
use diesel::prelude::*;
use diesel::{self, insert_into};
use errors::*;
@@ -295,18 +295,44 @@ impl Server {
Err(e) => return Err(e.into()),
};
+ let refs: Vec<ReleaseRef> = release_ref::table
+ .filter(release_ref::release_rev.eq(rev.id))
+ .get_results(&conn)
+ .expect("fetch release refs")
+ .iter()
+ .map(|r: &ReleaseRefRow| ReleaseRef {
+ index: r.index.clone(),
+ stub: r.stub.clone(),
+ target_release_id: r.target_release_ident_id.map(|v| v.to_string())
+ })
+ .collect();
+
+ let contribs: Vec<ReleaseContrib> = release_contrib::table
+ .filter(release_contrib::release_rev.eq(rev.id))
+ .get_results(&conn)
+ .expect("fetch release refs")
+ .iter()
+ .map(|c: &ReleaseContribRow| ReleaseContrib {
+ // XXX: index: c.index,
+ index: None,
+ contrib_type: c.contrib_type.clone(),
+ creator_stub: c.stub.clone(),
+ creator_id: c.creator_ident_id.map(|v| v.to_string()),
+ })
+ .collect();
+
let entity = ReleaseEntity {
title: rev.title,
release_type: rev.release_type,
- //date: rev.date,
+ // XXX: date: rev.date,
doi: rev.doi,
volume: rev.volume,
pages: rev.pages,
issue: rev.issue,
container_id: rev.container_ident_id.map(|u| u.to_string()),
work_id: rev.work_ident_id.to_string(),
- refs: None,
- contribs: None,
+ refs: Some(refs),
+ contribs: Some(contribs),
state: Some(ident.state().unwrap().shortname()),
ident: Some(ident.id.to_string()),
revision: ident.rev_id,
@@ -333,18 +359,44 @@ impl Server {
Err(e) => return Err(e.into()),
};
+ let refs: Vec<ReleaseRef> = release_ref::table
+ .filter(release_ref::release_rev.eq(rev.id))
+ .get_results(&conn)
+ .expect("fetch release refs")
+ .iter()
+ .map(|r: &ReleaseRefRow| ReleaseRef {
+ index: r.index.clone(),
+ stub: r.stub.clone(),
+ target_release_id: r.target_release_ident_id.map(|v| v.to_string())
+ })
+ .collect();
+
+ let contribs: Vec<ReleaseContrib> = release_contrib::table
+ .filter(release_contrib::release_rev.eq(rev.id))
+ .get_results(&conn)
+ .expect("fetch release refs")
+ .iter()
+ .map(|c: &ReleaseContribRow| ReleaseContrib {
+ // XXX: index: c.index,
+ index: None,
+ contrib_type: c.contrib_type.clone(),
+ creator_stub: c.stub.clone(),
+ creator_id: c.creator_ident_id.map(|v| v.to_string()),
+ })
+ .collect();
+
let entity = ReleaseEntity {
title: rev.title,
release_type: rev.release_type,
- //date: rev.date,
+ // XXX: date: rev.date,
doi: rev.doi,
volume: rev.volume,
pages: rev.pages,
issue: rev.issue,
container_id: rev.container_ident_id.map(|u| u.to_string()),
work_id: rev.work_ident_id.to_string(),
- refs: None,
- contribs: None,
+ refs: Some(refs),
+ contribs: Some(contribs),
state: Some(ident.state().unwrap().shortname()),
ident: Some(ident.id.to_string()),
revision: ident.rev_id,
@@ -649,6 +701,7 @@ impl Api for Server {
None => None,
};
+ println!("{:?}", container_id);
let edit: ReleaseEditRow = diesel::sql_query(
"WITH rev AS ( INSERT INTO release_rev (title, release_type, doi, volume, pages, issue, work_ident_id, container_ident_id)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
@@ -669,10 +722,57 @@ impl Api for Server {
.bind::<diesel::sql_types::Uuid, _>(work_id)
.bind::<diesel::sql_types::Nullable<diesel::sql_types::Uuid>, _>(container_id)
.bind::<diesel::sql_types::BigInt, _>(editgroup_id)
+ //XXX: extra_json
.get_result(&conn)
.unwrap();
let edit = &edit;
+ let _refs: Option<Vec<ReleaseRefRow>> = match body.refs {
+ None => None,
+ Some(ref_list) => {
+ if ref_list.len() == 0 {
+ Some(vec![])
+ } else {
+ let ref_rows: Vec<ReleaseRefNewRow> = ref_list.iter().map(|r| ReleaseRefNewRow {
+ release_rev: edit.rev_id.unwrap(),
+ target_release_ident_id:
+ r.target_release_id.clone().map(|v| uuid::Uuid::parse_str(&v).expect("valid UUID")),
+ // XXX: index: r.index,
+ index: None,
+ stub: r.stub.clone(),
+ }).collect();
+ let ref_rows: Vec<ReleaseRefRow> = insert_into(release_ref::table)
+ .values(ref_rows)
+ .get_results(&conn)
+ .expect("error inserting release_refs");
+ Some(ref_rows)
+ }
+ }
+ };
+
+ let _contribs: Option<Vec<ReleaseContribRow>> = match body.contribs {
+ None => None,
+ Some(contrib_list) => {
+ if contrib_list.len() == 0 {
+ Some(vec![])
+ } else {
+ let contrib_rows: Vec<ReleaseContribNewRow> = contrib_list.iter().map(|c| ReleaseContribNewRow {
+ release_rev: edit.rev_id.unwrap(),
+ creator_ident_id:
+ c.creator_id.clone().map(|v| uuid::Uuid::parse_str(&v).expect("valid UUID")),
+ // XXX: index: r.index,
+ contrib_type: c.contrib_type.clone(),
+ stub: c.creator_stub.clone(),
+ }).collect();
+ let contrib_rows: Vec<ReleaseContribRow> = insert_into(release_contrib::table)
+ .values(contrib_rows)
+ .get_results(&conn)
+ .expect("error inserting release_contribs");
+ Some(contrib_rows)
+ }
+ }
+ };
+
let entity_edit = EntityEdit {
editgroup_id: Some(edit.editgroup_id),
revision: Some(edit.rev_id.unwrap()),
diff --git a/rust/src/database_models.rs b/rust/src/database_models.rs
index 5e4e9710..44b57f85 100644
--- a/rust/src/database_models.rs
+++ b/rust/src/database_models.rs
@@ -150,29 +150,49 @@ entity_structs!("work_edit", WorkEditRow, "work_ident", WorkIdentRow);
#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)]
#[table_name = "release_contrib"]
pub struct ReleaseContribRow {
- id: i64,
- release_rev: i64,
- creator_ident_id: Option<Uuid>,
- stub: Option<String>,
- contrib_type: Option<String>,
+ pub id: i64,
+ pub release_rev: i64,
+ pub creator_ident_id: Option<Uuid>,
+ pub stub: Option<String>,
+ // XXX: pub index: Option<i64>,
+ pub contrib_type: Option<String>,
+}
+
+#[derive(Debug, Insertable)]
+#[table_name = "release_contrib"]
+pub struct ReleaseContribNewRow {
+ pub release_rev: i64,
+ pub creator_ident_id: Option<Uuid>,
+ pub stub: Option<String>,
+ // XXX: pub index: Option<i64>,
+ pub contrib_type: Option<String>,
}
#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)]
#[table_name = "release_ref"]
pub struct ReleaseRefRow {
- id: i64,
- release_rev: i64,
- target_release_ident_id: Option<Uuid>,
- index: Option<i64>,
- stub: Option<String>,
+ pub id: i64,
+ pub release_rev: i64,
+ pub target_release_ident_id: Option<Uuid>,
+ pub index: Option<i64>,
+ pub stub: Option<String>,
+}
+
+#[derive(Debug, Insertable, AsChangeset)]
+#[table_name = "release_ref"]
+pub struct ReleaseRefNewRow {
+ pub release_rev: i64,
+ pub target_release_ident_id: Option<Uuid>,
+ pub index: Option<i64>,
+ pub stub: Option<String>,
}
#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)]
#[table_name = "file_release"]
pub struct FileReleaseRow {
- id: i64,
- file_rev: i64,
- target_release_ident_id: Uuid,
+ pub id: i64,
+ pub file_rev: i64,
+ pub target_release_ident_id: Uuid,
}
#[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)]