summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--rust/src/editing.rs11
-rw-r--r--rust/src/editing_crud.rs174
-rw-r--r--rust/src/endpoints.rs12
3 files changed, 90 insertions, 107 deletions
diff --git a/rust/src/editing.rs b/rust/src/editing.rs
index 33caf6a9..e181e8a7 100644
--- a/rust/src/editing.rs
+++ b/rust/src/editing.rs
@@ -29,7 +29,9 @@ impl EditContext {
.count()
.get_result(conn)?;
if count > 0 {
- return Err(FatcatError::EditgroupAlreadyAccepted(self.editgroup_id.to_string()).into());
+ Err(FatcatError::EditgroupAlreadyAccepted(
+ self.editgroup_id.to_string(),
+ ))?;
}
Ok(())
}
@@ -60,10 +62,9 @@ pub fn make_edit_context(
let row = eg.db_create(conn, autoaccept)?;
FatcatId::from_uuid(&row.id)
}
- _ => {
- // TODO: better error response
- bail!("unsupported editgroup context");
- }
+ _ => Err(FatcatError::BadRequest(
+ "unsupported batch editgroup/accept combination".to_string(),
+ ))?,
};
Ok(EditContext {
editor_id,
diff --git a/rust/src/editing_crud.rs b/rust/src/editing_crud.rs
index 65403eee..9d6477a5 100644
--- a/rust/src/editing_crud.rs
+++ b/rust/src/editing_crud.rs
@@ -140,32 +140,26 @@ impl EditgroupCrud for Editgroup {
before: Option<chrono::DateTime<chrono::Utc>>,
) -> Result<Vec<(EditgroupRow, Option<ChangelogRow>)>> {
let rows: Vec<(EditgroupRow, Option<ChangelogRow>)> = match (since, before) {
- (Some(since), None) => {
- editgroup::table
- .left_outer_join(changelog::table)
- .filter(editgroup::editor_id.eq(editor_id.to_uuid()))
- .filter(editgroup::created.gt(since))
- .order_by(editgroup::created.asc())
- .limit(limit as i64)
- .get_results(conn)?
- },
- (_, Some(before)) => {
- editgroup::table
- .left_outer_join(changelog::table)
- .filter(editgroup::editor_id.eq(editor_id.to_uuid()))
- .filter(editgroup::created.lt(before))
- .order_by(editgroup::created.desc())
- .limit(limit as i64)
- .get_results(conn)?
- },
- (None, None) => {
- editgroup::table
- .left_outer_join(changelog::table)
- .filter(editgroup::editor_id.eq(editor_id.to_uuid()))
- .order_by(editgroup::created.desc())
- .limit(limit as i64)
- .get_results(conn)?
- },
+ (Some(since), None) => editgroup::table
+ .left_outer_join(changelog::table)
+ .filter(editgroup::editor_id.eq(editor_id.to_uuid()))
+ .filter(editgroup::created.gt(since))
+ .order_by(editgroup::created.asc())
+ .limit(limit as i64)
+ .get_results(conn)?,
+ (_, Some(before)) => editgroup::table
+ .left_outer_join(changelog::table)
+ .filter(editgroup::editor_id.eq(editor_id.to_uuid()))
+ .filter(editgroup::created.lt(before))
+ .order_by(editgroup::created.desc())
+ .limit(limit as i64)
+ .get_results(conn)?,
+ (None, None) => editgroup::table
+ .left_outer_join(changelog::table)
+ .filter(editgroup::editor_id.eq(editor_id.to_uuid()))
+ .order_by(editgroup::created.desc())
+ .limit(limit as i64)
+ .get_results(conn)?,
};
Ok(rows)
}
@@ -177,32 +171,26 @@ impl EditgroupCrud for Editgroup {
before: Option<chrono::DateTime<chrono::Utc>>,
) -> Result<Vec<EditgroupRow>> {
let rows: Vec<EditgroupRow> = match (since, before) {
- (Some(since), None) => {
- editgroup::table
- .filter(editgroup::is_accepted.eq(false))
- .filter(editgroup::submitted.is_not_null())
- .filter(editgroup::submitted.gt(since))
- .order_by(editgroup::submitted.asc())
- .limit(limit as i64)
- .get_results(conn)?
- },
- (_, Some(before)) => {
- editgroup::table
- .filter(editgroup::is_accepted.eq(false))
- .filter(editgroup::submitted.is_not_null())
- .filter(editgroup::submitted.lt(before))
- .order_by(editgroup::submitted.desc())
- .limit(limit as i64)
- .get_results(conn)?
- },
- (None, None) => {
- editgroup::table
- .filter(editgroup::is_accepted.eq(false))
- .filter(editgroup::submitted.is_not_null())
- .order_by(editgroup::created.desc())
- .limit(limit as i64)
- .get_results(conn)?
- },
+ (Some(since), None) => editgroup::table
+ .filter(editgroup::is_accepted.eq(false))
+ .filter(editgroup::submitted.is_not_null())
+ .filter(editgroup::submitted.gt(since))
+ .order_by(editgroup::submitted.asc())
+ .limit(limit as i64)
+ .get_results(conn)?,
+ (_, Some(before)) => editgroup::table
+ .filter(editgroup::is_accepted.eq(false))
+ .filter(editgroup::submitted.is_not_null())
+ .filter(editgroup::submitted.lt(before))
+ .order_by(editgroup::submitted.desc())
+ .limit(limit as i64)
+ .get_results(conn)?,
+ (None, None) => editgroup::table
+ .filter(editgroup::is_accepted.eq(false))
+ .filter(editgroup::submitted.is_not_null())
+ .order_by(editgroup::created.desc())
+ .limit(limit as i64)
+ .get_results(conn)?,
};
Ok(rows)
}
@@ -315,29 +303,23 @@ impl EditgroupAnnotationCrud for EditgroupAnnotation {
before: Option<chrono::DateTime<chrono::Utc>>,
) -> Result<Vec<EditgroupAnnotationRow>> {
let rows: Vec<EditgroupAnnotationRow> = match (since, before) {
- (Some(since), None) => {
- editgroup_annotation::table
- .filter(editgroup_annotation::editor_id.eq(editor_id.to_uuid()))
- .filter(editgroup_annotation::created.gt(since))
- .order_by(editgroup_annotation::created.asc())
- .limit(limit as i64)
- .get_results(conn)?
- },
- (_, Some(before)) => {
- editgroup_annotation::table
- .filter(editgroup_annotation::editor_id.eq(editor_id.to_uuid()))
- .filter(editgroup_annotation::created.lt(before))
- .order_by(editgroup_annotation::created.desc())
- .limit(limit as i64)
- .get_results(conn)?
- },
- (None, None) => {
- editgroup_annotation::table
- .filter(editgroup_annotation::editor_id.eq(editor_id.to_uuid()))
- .order_by(editgroup_annotation::created.desc())
- .limit(limit as i64)
- .get_results(conn)?
- },
+ (Some(since), None) => editgroup_annotation::table
+ .filter(editgroup_annotation::editor_id.eq(editor_id.to_uuid()))
+ .filter(editgroup_annotation::created.gt(since))
+ .order_by(editgroup_annotation::created.asc())
+ .limit(limit as i64)
+ .get_results(conn)?,
+ (_, Some(before)) => editgroup_annotation::table
+ .filter(editgroup_annotation::editor_id.eq(editor_id.to_uuid()))
+ .filter(editgroup_annotation::created.lt(before))
+ .order_by(editgroup_annotation::created.desc())
+ .limit(limit as i64)
+ .get_results(conn)?,
+ (None, None) => editgroup_annotation::table
+ .filter(editgroup_annotation::editor_id.eq(editor_id.to_uuid()))
+ .order_by(editgroup_annotation::created.desc())
+ .limit(limit as i64)
+ .get_results(conn)?,
};
Ok(rows)
}
@@ -350,29 +332,23 @@ impl EditgroupAnnotationCrud for EditgroupAnnotation {
before: Option<chrono::DateTime<chrono::Utc>>,
) -> Result<Vec<EditgroupAnnotationRow>> {
let rows: Vec<EditgroupAnnotationRow> = match (since, before) {
- (Some(since), None) => {
- editgroup_annotation::table
- .filter(editgroup_annotation::editgroup_id.eq(editgroup_id.to_uuid()))
- .filter(editgroup_annotation::created.gt(since))
- .order_by(editgroup_annotation::created.asc())
- .limit(limit as i64)
- .get_results(conn)?
- },
- (_, Some(before)) => {
- editgroup_annotation::table
- .filter(editgroup_annotation::editgroup_id.eq(editgroup_id.to_uuid()))
- .filter(editgroup_annotation::created.lt(before))
- .order_by(editgroup_annotation::created.desc())
- .limit(limit as i64)
- .get_results(conn)?
- },
- (None, None) => {
- editgroup_annotation::table
- .filter(editgroup_annotation::editgroup_id.eq(editgroup_id.to_uuid()))
- .order_by(editgroup_annotation::created.desc())
- .limit(limit as i64)
- .get_results(conn)?
- },
+ (Some(since), None) => editgroup_annotation::table
+ .filter(editgroup_annotation::editgroup_id.eq(editgroup_id.to_uuid()))
+ .filter(editgroup_annotation::created.gt(since))
+ .order_by(editgroup_annotation::created.asc())
+ .limit(limit as i64)
+ .get_results(conn)?,
+ (_, Some(before)) => editgroup_annotation::table
+ .filter(editgroup_annotation::editgroup_id.eq(editgroup_id.to_uuid()))
+ .filter(editgroup_annotation::created.lt(before))
+ .order_by(editgroup_annotation::created.desc())
+ .limit(limit as i64)
+ .get_results(conn)?,
+ (None, None) => editgroup_annotation::table
+ .filter(editgroup_annotation::editgroup_id.eq(editgroup_id.to_uuid()))
+ .order_by(editgroup_annotation::created.desc())
+ .limit(limit as i64)
+ .get_results(conn)?,
};
Ok(rows)
}
@@ -392,6 +368,8 @@ impl EditgroupAnnotationCrud for EditgroupAnnotation {
.values((
editgroup_annotation::editor_id.eq(editor_id.to_uuid()),
editgroup_annotation::editgroup_id.eq(editgroup_id.to_uuid()),
+ editgroup_annotation::comment_markdown.eq(&self.comment_markdown),
+ editgroup_annotation::extra_json.eq(&self.extra),
))
.get_result(conn)?;
Ok(ed)
diff --git a/rust/src/endpoints.rs b/rust/src/endpoints.rs
index 33c4bc3e..f7e93448 100644
--- a/rust/src/endpoints.rs
+++ b/rust/src/endpoints.rs
@@ -754,7 +754,10 @@ impl Api for Server {
let limit = cmp::min(100, limit.unwrap_or(20)) as u64;
let rows =
Editgroup::db_get_range_for_editor(&conn, editor_id, limit, since, before)?;
- Ok(rows.into_iter().map(|(eg, cl)| eg.into_model_partial(cl.map(|v| v.id))).collect())
+ Ok(rows
+ .into_iter()
+ .map(|(eg, cl)| eg.into_model_partial(cl.map(|v| v.id)))
+ .collect())
})
.map_err(|e: Error| FatcatError::from(e))
{
@@ -892,8 +895,10 @@ impl Api for Server {
.transaction(|| {
let limit = cmp::min(100, limit.unwrap_or(20)) as u64;
let row = Editgroup::db_get_range_reviewable(&conn, limit, since, before)?;
- let mut editgroups: Vec<Editgroup> =
- row.into_iter().map(|eg| eg.into_model_partial(None)).collect();
+ let mut editgroups: Vec<Editgroup> = row
+ .into_iter()
+ .map(|eg| eg.into_model_partial(None))
+ .collect();
if let Some(expand) = expand {
let expand = ExpandFlags::from_str(&expand)?;
for eg in editgroups.iter_mut() {
@@ -1031,7 +1036,6 @@ impl Api for Server {
annotation.editor_id = Some(auth_context.editor_id.to_string());
}
};
- // TODO: verify editgroup_id
annotation.db_create(&conn).map(|a| a.into_model())
})
.map_err(|e: Error| FatcatError::from(e))