Skip to content

Commit

Permalink
Fix the soft delete in DefaultController
Browse files Browse the repository at this point in the history
  • Loading branch information
photino committed Jan 7, 2024
1 parent 0ba2adf commit 42d036e
Show file tree
Hide file tree
Showing 26 changed files with 288 additions and 63 deletions.
2 changes: 1 addition & 1 deletion examples/actix-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ actix-web = "4.4.0"
tracing = "0.1.40"

[dependencies.serde]
version = "1.0.194"
version = "1.0.195"
features = ["derive"]

[dependencies.zino]
Expand Down
2 changes: 1 addition & 1 deletion examples/axum-app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ axum = "0.6.20"
tracing = "0.1.40"

[dependencies.serde]
version = "1.0.194"
version = "1.0.195"
features = ["derive"]

[dependencies.zino]
Expand Down
2 changes: 1 addition & 1 deletion examples/dioxus-desktop/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ features = [
]

[dependencies.serde]
version = "1.0.194"
version = "1.0.195"
features = ["derive"]

[dependencies.zino]
Expand Down
2 changes: 1 addition & 1 deletion examples/dioxus-desktop/src/service/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::App;
use zino::prelude::*;

pub async fn list_dependencies() -> Result<Vec<Map>, Error> {
let resource = "https://libraries.io/api/github/photino/zino/dependencies";
let resource = "https://libraries.io/api/github/zino-rs/zino/dependencies";
let mut data = App::fetch_json::<Map>(resource, None)
.await?
.remove("dependencies")
Expand Down
29 changes: 7 additions & 22 deletions examples/dioxus-desktop/src/view/layout.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use crate::router::Route;
use dioxus::prelude::*;
use dioxus_free_icons::{
icons::{bs_icons::*, fa_brands_icons::FaRust, fa_solid_icons::FaCubes},
Icon as SvgIcon,
};
use dioxus_free_icons::icons::{bs_icons::*, fa_brands_icons::FaRust, fa_solid_icons::FaCubes};
use dioxus_router::prelude::*;
use zino_dioxus::prelude::*;

Expand All @@ -14,27 +11,21 @@ pub fn Wrapper(cx: Scope) -> Element {
NavbarLink {
to: Route::Overview {},
IconText {
Icon {
SvgIcon { icon: BsSpeedometer2 }
}
SvgIcon { shape: BsSpeedometer2 }
span { "Overview" }
}
}
NavbarLink {
to: Route::StargazerList {},
IconText {
Icon {
SvgIcon { icon: BsStars }
}
SvgIcon { shape: BsStars }
span { "Stargazers" }
}
}
NavbarLink {
to: Route::DependencyList {},
IconText {
Icon {
SvgIcon { icon: BsBricks }
}
SvgIcon { shape: BsBricks }
span { "Dependencies" }
}
}
Expand All @@ -43,27 +34,21 @@ pub fn Wrapper(cx: Scope) -> Element {
NavbarLink {
to: "https://github.com/zino-rs/zino",
IconText {
Icon {
SvgIcon { icon: BsGithub }
}
SvgIcon { shape: BsGithub }
span { "github" }
}
}
NavbarLink {
to: "https://crates.io/crates/zino",
IconText {
Icon {
SvgIcon { icon: FaRust }
}
SvgIcon { shape: FaRust }
span { "crates.io" }
}
}
NavbarLink {
to: "https://docs.rs/zino",
IconText {
Icon {
SvgIcon { icon: FaCubes }
}
SvgIcon { shape: FaCubes }
span { "docs.rs" }
}
}
Expand Down
6 changes: 3 additions & 3 deletions zino-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ ryu = "1.0.16"
serde_qs = "0.12.0"
serde_yaml = "0.9.30"
sha2 = "0.10.8"
sysinfo = "0.30.4"
sysinfo = "0.30.5"
task-local-extensions = "0.1.4"
toml = "0.8.8"
tracing = "0.1.40"
Expand Down Expand Up @@ -261,7 +261,7 @@ version = "4.4.2"
optional = true

[dependencies.opendal]
version = "0.44.0"
version = "0.44.1"
optional = true
default-features = false
features = ["layers-all"]
Expand Down Expand Up @@ -290,7 +290,7 @@ features = [
]

[dependencies.serde]
version = "1.0.194"
version = "1.0.195"
features = ["derive"]

[dependencies.serde_json]
Expand Down
8 changes: 7 additions & 1 deletion zino-core/src/datetime/date.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{error::Error, AvroValue, JsonValue};
use chrono::{format::ParseError, Datelike, Days, Local, Months, NaiveDate};
use chrono::{format::ParseError, Datelike, Days, Local, Months, NaiveDate, Weekday};
use serde::{Deserialize, Serialize, Serializer};
use std::{
fmt,
Expand Down Expand Up @@ -150,6 +150,12 @@ impl Date {
self.0.leap_year()
}

/// Returns `true` if the current day is weekend.
#[inline]
pub fn is_weekend(&self) -> bool {
matches!(self.0.weekday(), Weekday::Sat | Weekday::Sun)
}

/// Returns the number of days in the current year.
#[inline]
pub fn days_in_current_year(&self) -> u32 {
Expand Down
8 changes: 7 additions & 1 deletion zino-core/src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::{AvroValue, JsonValue};
use chrono::{
format::ParseError, Datelike, Days, Local, Months, NaiveDate, NaiveDateTime, NaiveTime,
SecondsFormat, TimeZone, Timelike, Utc,
SecondsFormat, TimeZone, Timelike, Utc, Weekday,
};
use serde::{Deserialize, Serialize, Serializer};
use std::{
Expand Down Expand Up @@ -327,6 +327,12 @@ impl DateTime {
self.0.date_naive().leap_year()
}

/// Returns `true` if the current day is weekend.
#[inline]
pub fn is_weekend(&self) -> bool {
matches!(self.0.weekday(), Weekday::Sat | Weekday::Sun)
}

/// Returns the number of days in the current year.
#[inline]
pub fn days_in_current_year(&self) -> u32 {
Expand Down
16 changes: 8 additions & 8 deletions zino-core/src/extension/json_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ pub trait JsonObjectExt {
/// If the `Uuid` is `nil`, it also returns `None`.
fn parse_uuid(&self, key: &str) -> Option<Result<Uuid, uuid::Error>>;

/// Extracts the string corresponding to the key and parses it as `Decimal`.
fn parse_decimal(&self, key: &str) -> Option<Result<Decimal, rust_decimal::Error>>;

/// Extracts the string corresponding to the key and parses it as `Date`.
fn parse_date(&self, key: &str) -> Option<Result<Date, chrono::format::ParseError>>;

Expand All @@ -188,9 +191,6 @@ pub trait JsonObjectExt {
/// Extracts the string corresponding to the key and parses it as `Duration`.
fn parse_duration(&self, key: &str) -> Option<Result<Duration, datetime::ParseDurationError>>;

/// Extracts the string corresponding to the key and parses it as `Decimal`.
fn parse_decimal(&self, key: &str) -> Option<Result<Decimal, rust_decimal::Error>>;

/// Extracts the string corresponding to the key and parses it as `Url`.
fn parse_url(&self, key: &str) -> Option<Result<Url, url::ParseError>>;

Expand Down Expand Up @@ -596,6 +596,11 @@ impl JsonObjectExt for Map {
.map(|s| s.parse())
}

#[inline]
fn parse_decimal(&self, key: &str) -> Option<Result<Decimal, rust_decimal::Error>> {
self.get_str(key).map(|s| s.parse())
}

#[inline]
fn parse_date(&self, key: &str) -> Option<Result<Date, chrono::format::ParseError>> {
self.get_str(key).map(|s| s.parse())
Expand All @@ -616,11 +621,6 @@ impl JsonObjectExt for Map {
self.get_str(key).map(datetime::parse_duration)
}

#[inline]
fn parse_decimal(&self, key: &str) -> Option<Result<Decimal, rust_decimal::Error>> {
self.get_str(key).map(|s| s.parse())
}

#[inline]
fn parse_url(&self, key: &str) -> Option<Result<Url, url::ParseError>> {
self.get_str(key).map(|s| s.parse())
Expand Down
10 changes: 9 additions & 1 deletion zino-core/src/extension/json_value.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
datetime::{self, Date, DateTime, Time},
extension::JsonObjectExt,
helper, JsonValue, Map, Uuid,
helper, Decimal, JsonValue, Map, Uuid,
};
use csv::{ByteRecord, Writer};
use std::{
Expand Down Expand Up @@ -136,6 +136,9 @@ pub trait JsonValueExt {
/// If the `Uuid` is `nil`, it also returns `None`.
fn parse_uuid(&self) -> Option<Result<Uuid, uuid::Error>>;

/// Parses the JSON value as `Decimal`.
fn parse_decimal(&self) -> Option<Result<Decimal, rust_decimal::Error>>;

/// Parses the JSON value as `Date`.
fn parse_date(&self) -> Option<Result<Date, chrono::format::ParseError>>;

Expand Down Expand Up @@ -395,6 +398,11 @@ impl JsonValueExt for JsonValue {
.map(|s| s.parse())
}

#[inline]
fn parse_decimal(&self) -> Option<Result<Decimal, rust_decimal::Error>> {
self.as_str().map(|s| s.parse())
}

#[inline]
fn parse_date(&self) -> Option<Result<Date, chrono::format::ParseError>> {
self.as_str().map(|s| s.parse())
Expand Down
23 changes: 23 additions & 0 deletions zino-core/src/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ impl NamedFile {
self.field_name = Some(field_name.into());
}

/// Sets the file name.
#[inline]
pub fn set_file_name(&mut self, file_name: impl Into<String>) {
self.file_name = Some(file_name.into());
}

/// Sets the content type.
#[inline]
pub fn set_content_type(&mut self, content_type: Mime) {
Expand Down Expand Up @@ -192,6 +198,23 @@ impl NamedFile {
Ok(())
}

/// Renames the stem portion of the file name.
#[inline]
pub fn rename_file_stem(&mut self, file_stem: &str) -> Result<(), Error> {
let file_name = if let Some(ext) = self
.file_name
.as_ref()
.and_then(|s| Path::new(s).extension())
{
let ext = ext.to_string_lossy();
format!("{file_stem}.{ext}")
} else {
file_stem.to_owned()
};
self.file_name = Some(file_name);
Ok(())
}

/// Attempts to create an instance from reading a local file.
pub fn try_from_local(path: impl AsRef<Path>) -> Result<Self, io::Error> {
let path = path.as_ref();
Expand Down
4 changes: 4 additions & 0 deletions zino-derive/src/decode_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ pub(super) fn parse_token_stream(input: DeriveInput) -> TokenStream {
decode_model_fields.push(quote! {
model.#ident = orm::decode_uuid(row, #name)?;
});
} else if type_name == "Option<Uuid>" {
decode_model_fields.push(quote! {
model.#ident = orm::decode_uuid(row, #name).ok();
});
} else if type_name == "Decimal" {
decode_model_fields.push(quote! {
model.#ident = orm::decode_decimal(row, #name)?;
Expand Down
17 changes: 9 additions & 8 deletions zino-derive/src/model_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ pub(super) fn parse_token_stream(input: DeriveInput) -> TokenStream {
if let Some(field_mappings) = field_embeddings.get(&correlatation_field) {
let model_ident = format_ident!("{}", model);
for (field, referenced_field) in field_mappings {
embedding_queries.push(quote! {
if data.contains_key(#correlatation_field) {
let id = &self.#correlatation_field;
let value = <#model_ident>::find_scalar_by_id(&id, #referenced_field).await?;
self.#field = value;
data.upsert(#field, value.to_string());
}
});
let query = quote! {
if data.contains_key(#correlatation_field) {
let id = &self.#correlatation_field;
let value = <#model_ident>::find_scalar_by_id(&id, #referenced_field).await?;
self.#field = value;
data.upsert(#field, value.to_string());
}
};
embedding_queries.push(query);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions zino-dioxus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dioxus = "0.4.3"
dioxus-core = "0.4.3"
dioxus-router = "0.4.3"
dioxus-free-icons = "0.7.0"
rust_decimal = "1.33.1"
smallvec = "1.11.1"

[dependencies.chrono]
Expand Down
5 changes: 5 additions & 0 deletions zino-dioxus/src/dialog/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//! Modal and non-modal dialog boxes.
mod modal;

pub use modal::{ModalCard, ModalCardProps};
Loading

0 comments on commit 42d036e

Please sign in to comment.