Skip to content

Commit

Permalink
feat: enable update creation and publication' info when status is 2
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Dec 1, 2023
1 parent 00ebe7f commit d14bee8
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "writing"
version = "1.4.0"
version = "1.4.1"
edition = "2021"
rust-version = "1.64"
description = ""
Expand Down
13 changes: 11 additions & 2 deletions src/api/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ use axum::{
};
use isolang::Language;
use serde::{Deserialize, Serialize};
use std::{collections::HashMap, convert::From, sync::Arc};
use std::{
collections::{HashMap, HashSet},
convert::From,
sync::Arc,
};
use validator::{Validate, ValidationError};

use axum_web::context::ReqContext;
Expand Down Expand Up @@ -169,6 +173,7 @@ pub struct UpdateMessageInput {
#[validate(length(min = 0, max = 4096))]
pub context: Option<String>,
pub language: Option<PackObject<Language>>,
pub languages: Option<Vec<PackObject<Language>>>,
#[validate(custom = "validate_message")]
pub message: Option<PackObject<Vec<u8>>>,
}
Expand All @@ -179,6 +184,10 @@ impl UpdateMessageInput {
if let Some(context) = self.context {
cols.set_as("context", &context);
}
if let Some(languages) = self.languages {
let languages: HashSet<Language> = languages.into_iter().map(|v| v.unwrap()).collect();
cols.set_as("languages", &languages);
}

if cols.is_empty() {
return Err(HTTPError::new(400, "No fields to update".to_string()).into());
Expand Down Expand Up @@ -219,7 +228,7 @@ pub async fn update(
}

let mut ok = false;
if input.context.is_some() {
if input.context.is_some() || input.languages.is_some() {
let cols = input.clone().into()?;
ok = doc.update(&app.scylla, cols, version).await?;
}
Expand Down
2 changes: 1 addition & 1 deletion src/db/model_creation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ impl Creation {
)
.into());
}
if self.status < 0 || self.status > 1 {
if self.status < 0 {
return Err(HTTPError::new(
409,
format!("Creation can not be update, status {}", self.status),
Expand Down
2 changes: 1 addition & 1 deletion src/db/model_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl Message {
cols: ColumnsMap,
version: i16,
) -> anyhow::Result<bool> {
let valid_fields = ["context"];
let valid_fields = ["context", "languages"];
let update_fields = cols.keys();
for field in &update_fields {
if !valid_fields.contains(&field.as_str()) {
Expand Down
2 changes: 1 addition & 1 deletion src/db/model_publication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ impl Publication {
.into());
}

if self.status != 0 {
if self.status < 0 {
return Err(HTTPError::new(
409,
format!("Publication can not be update, status {}", self.status),
Expand Down

0 comments on commit d14bee8

Please sign in to comment.