Skip to content

Commit

Permalink
fix: fix RFP with id
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Nov 19, 2023
1 parent 04a28cb commit a66cc3b
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 62 deletions.
44 changes: 22 additions & 22 deletions 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.3.9"
version = "1.3.10"
edition = "2021"
rust-version = "1.64"
description = ""
Expand Down
72 changes: 42 additions & 30 deletions src/api/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ use scylla_orm::ColumnsMap;

use super::{
get_fields, message, token_from_xid, token_to_xid, AppState, GIDPagination, IDGIDPagination,
QueryGidCid, QueryGidId, QueryGidIdCid, QueryId, SubscriptionInput, SubscriptionOutput,
UpdateStatusInput, RFP,
QueryGidCid, QueryGidId, QueryGidIdCid, QueryId, RFPInfo, SubscriptionInput,
SubscriptionOutput, UpdateStatusInput, RFP,
};

#[derive(Debug, Deserialize, Serialize, Validate)]
pub struct CreateCollectionInput {
pub gid: PackObject<xid::Id>,
pub language: PackObject<Language>,
#[validate(length(min = 0, max = 512))]
#[validate(length(min = 0, max = 1024))]
pub context: String,
pub info: CollectionInfoInput,
#[validate(url)]
Expand Down Expand Up @@ -304,15 +304,21 @@ pub async fn get(
if *output.gid != user_gid {
output.rfp = Some(RFP {
creation: None,
collection: Some(price),
collection: Some(RFPInfo {
id: to.with(id),
price: price,
}),
})
}
}
Some(ref sub) => {
if sub.expire_at * 1000 < ctx.unix_ms as i64 {
output.rfp = Some(RFP {
creation: None,
collection: Some(price),
collection: Some(RFPInfo {
id: to.with(id),
price: price,
}),
})
}
}
Expand Down Expand Up @@ -738,9 +744,7 @@ pub async fn add_children(
child.price = parent.creation_price;
child.update_field(&app.scylla, "price").await?;
}
}

if parent.gid != child.gid || input.kind == 1 {
} else {
// ensure the creation is published
let _ = db::PublicationIndex::get_implicit_published(
&app.scylla,
Expand Down Expand Up @@ -1147,29 +1151,37 @@ pub async fn list_by_child(
};

let mut output = CollectionOutput::from(doc, &to);
match subscription {
Some(s) => {
if s.expire_at * 1000 < ctx.unix_ms as i64 {
output.rfp = Some(RFP {
creation: None,
collection: Some(price),
})
if price > 0 {
match subscription {
Some(s) => {
if s.expire_at * 1000 < ctx.unix_ms as i64 {
output.rfp = Some(RFP {
creation: None,
collection: Some(RFPInfo {
id: to.with(child.id),
price: price,
}),
})
}
output.subscription = Some(SubscriptionOutput {
uid: to.with(s.uid),
cid: to.with(s.cid),
gid: to.with(*output.gid),
txn: to.with(s.txn),
updated_at: s.updated_at,
expire_at: s.expire_at,
});
}
output.subscription = Some(SubscriptionOutput {
uid: to.with(s.uid),
cid: to.with(s.cid),
gid: to.with(*output.gid),
txn: to.with(s.txn),
updated_at: s.updated_at,
expire_at: s.expire_at,
});
}
None => {
if *output.gid != user_gid {
output.rfp = Some(RFP {
creation: None,
collection: Some(price),
})
None => {
if *output.gid != user_gid {
output.rfp = Some(RFP {
creation: None,
collection: Some(RFPInfo {
id: to.with(child.id),
price: price,
}),
})
}
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,20 @@ pub struct SubscriptionOutput {
pub updated_at: i64,
pub expire_at: i64,
}

#[derive(Debug, Default, Deserialize, Serialize)]
pub struct RFPInfo {
pub id: PackObject<xid::Id>,
pub price: i64,
}

// Request for Payment
#[derive(Debug, Default, Deserialize, Serialize)]
pub struct RFP {
#[serde(skip_serializing_if = "Option::is_none")]
pub creation: Option<i64>,
pub creation: Option<RFPInfo>,
#[serde(skip_serializing_if = "Option::is_none")]
pub collection: Option<i64>,
pub collection: Option<RFPInfo>,
}

pub fn get_fields(fields: Option<String>) -> Vec<String> {
Expand Down
35 changes: 28 additions & 7 deletions src/api/publication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use scylla_orm::ColumnsMap;

use crate::api::{
get_fields, segment_content, token_from_xid, token_to_xid, validate_cbor_content, AppState,
GIDPagination, Pagination, QueryGidCid, SubscriptionOutput, RFP,
GIDPagination, Pagination, QueryGidCid, RFPInfo, SubscriptionOutput, RFP,
};
use crate::{db, db::meili};

Expand Down Expand Up @@ -302,8 +302,15 @@ pub async fn get(
}
}

let (rfp, subscription) =
try_get_subscription(&app.scylla, &index, ctx.user, parent, ctx.unix_ms as i64).await;
let (rfp, subscription) = try_get_subscription(
&app.scylla,
&index,
ctx.user,
parent,
ctx.unix_ms as i64,
&to,
)
.await;
output.rfp = rfp;
if output.rfp.is_some() {
output.content = segment_content(output.content, 0.6);
Expand Down Expand Up @@ -398,8 +405,15 @@ pub async fn implicit_get(
}
}

let (rfp, subscription) =
try_get_subscription(&app.scylla, &index, ctx.user, parent, ctx.unix_ms as i64).await;
let (rfp, subscription) = try_get_subscription(
&app.scylla,
&index,
ctx.user,
parent,
ctx.unix_ms as i64,
&to,
)
.await;
output.rfp = rfp;
if output.rfp.is_some() {
output.content = segment_content(output.content, 0.6);
Expand Down Expand Up @@ -428,9 +442,13 @@ async fn try_get_subscription(
uid: xid::Id,
parent: xid::Id,
now_ms: i64,
to: &PackObject<()>,
) -> (Option<RFP>, Option<db::CreationSubscription>) {
let mut rfp = RFP {
creation: Some(creation.price),
creation: Some(RFPInfo {
id: to.with(creation.id),
price: creation.price,
}),
collection: None,
};

Expand Down Expand Up @@ -485,7 +503,10 @@ async fn try_get_subscription(
.await
.is_ok()
{
rfp.collection = Some(doc.price);
rfp.collection = Some(RFPInfo {
id: to.with(doc.id),
price: doc.price,
});
}
}

Expand Down

0 comments on commit a66cc3b

Please sign in to comment.