Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moved all query string serialization in payment api to 'serde_qs' #908

Merged
merged 4 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ ya-sb-router = { path = "service-bus/router" }
ya-sb-util = { path = "service-bus/util" }

## CLIENT
ya-client = { git = "https://github.com/golemfactory/ya-client.git", rev = "87f106498a7a7b1519d82d0981fc21b260a89cf2"}
ya-client-model = { git = "https://github.com/golemfactory/ya-client.git", rev = "87f106498a7a7b1519d82d0981fc21b260a89cf2"}
ya-client = { git = "https://github.com/golemfactory/ya-client.git", rev = "200d42efa6bd77de071b5674efe55aeb2f6296e1"}
ya-client-model = { git = "https://github.com/golemfactory/ya-client.git", rev = "200d42efa6bd77de071b5674efe55aeb2f6296e1"}

#ya-client = { path = "../ya-client" }
#ya-client-model = { path = "../ya-client/model" }
Expand Down
89 changes: 0 additions & 89 deletions core/payment/src/api.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use actix_web::Scope;
use chrono::{DateTime, Utc};
use serde::{Deserialize, Deserializer};
use ya_client_model::payment::PAYMENT_API_PATH;
use ya_persistence::executor::DbExecutor;
use ya_service_api_web::scope::ExtendableScope;
Expand All @@ -27,90 +25,3 @@ pub fn web_scope(db: &DbExecutor) -> Scope {
// TODO: TEST
// Scope::new(PAYMENT_API_PATH).extend(api_scope).data(db.clone())
}

pub const DEFAULT_ACK_TIMEOUT: f64 = 60.0; // seconds
pub const DEFAULT_EVENT_TIMEOUT: f64 = 0.0; // seconds

#[inline(always)]
pub(crate) fn default_ack_timeout() -> f64 {
DEFAULT_ACK_TIMEOUT
}

#[inline(always)]
pub(crate) fn default_event_timeout() -> f64 {
DEFAULT_EVENT_TIMEOUT
}

#[derive(Deserialize)]
pub struct DebitNoteId {
pub debit_note_id: String,
}

#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct DebitNotePaymentsParams {
pub debit_note_id: String,
#[serde(default)]
pub max_items: Option<u32>,
#[serde(default)]
pub after_timestamp: Option<DateTime<Utc>>,
}

#[derive(Deserialize)]
pub struct InvoiceId {
pub invoice_id: String,
}

#[derive(Deserialize)]
pub struct AllocationId {
pub allocation_id: String,
}

#[derive(Deserialize)]
pub struct PaymentId {
pub payment_id: String,
}

#[derive(Deserialize)]
pub struct Timeout {
#[serde(default = "default_ack_timeout")]
pub timeout: f64,
}

#[derive(Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EventParams {
#[serde(default = "default_event_timeout")]
pub poll_timeout: f64,
#[serde(default)]
pub after_timestamp: Option<DateTime<Utc>>,
#[serde(default)]
pub max_events: Option<u32>,
#[serde(default)]
pub app_session_id: Option<String>,
}

#[derive(Deserialize)]
pub struct FilterParams {
#[serde(rename = "maxItems", default)]
pub max_items: Option<u32>,
#[serde(rename = "afterTimestamp", default)]
pub after_timestamp: Option<DateTime<Utc>>,
}

#[derive(Deserialize)]
pub struct AllocationIds {
#[serde(
rename = "allocationIds",
deserialize_with = "deserialize_comma_separated"
)]
pub allocation_ids: Vec<String>,
}

fn deserialize_comma_separated<'de, D>(deserializer: D) -> Result<Vec<String>, D::Error>
where
D: Deserializer<'de>,
{
let s: &str = Deserialize::deserialize(deserializer)?;
Ok(s.split(",").map(str::to_string).collect())
}
11 changes: 5 additions & 6 deletions core/payment/src/api/allocations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use ya_service_api_web::middleware::Identity;
use ya_service_bus::{typed as bus, RpcEndpoint};

// Local uses
use crate::api::*;
use crate::dao::*;
use crate::error::{DbError, Error};
use crate::utils::response;
Expand Down Expand Up @@ -80,7 +79,7 @@ async fn create_allocation(

async fn get_allocations(
db: Data<DbExecutor>,
query: Query<FilterParams>,
query: Query<params::FilterParams>,
id: Identity,
) -> HttpResponse {
let node_id = id.identity;
Expand All @@ -95,7 +94,7 @@ async fn get_allocations(

async fn get_allocation(
db: Data<DbExecutor>,
path: Path<AllocationId>,
path: Path<params::AllocationId>,
id: Identity,
) -> HttpResponse {
let allocation_id = path.allocation_id.clone();
Expand All @@ -110,15 +109,15 @@ async fn get_allocation(

async fn amend_allocation(
db: Data<DbExecutor>,
path: Path<AllocationId>,
path: Path<params::AllocationId>,
body: Json<Allocation>,
) -> HttpResponse {
response::not_implemented() // TODO
}

async fn release_allocation(
db: Data<DbExecutor>,
path: Path<AllocationId>,
path: Path<params::AllocationId>,
id: Identity,
) -> HttpResponse {
let allocation_id = path.allocation_id.clone();
Expand All @@ -133,7 +132,7 @@ async fn release_allocation(

async fn get_demand_decorations(
db: Data<DbExecutor>,
path: Query<AllocationIds>,
path: Query<params::AllocationIds>,
id: Identity,
) -> HttpResponse {
let allocation_ids = path.allocation_ids.clone();
Expand Down
36 changes: 20 additions & 16 deletions core/payment/src/api/debit_notes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use ya_service_api_web::middleware::Identity;
use ya_service_bus::{typed as bus, RpcEndpoint};

// Local uses
use crate::api::*;
use crate::dao::*;
use crate::error::{DbError, Error};
use crate::utils::provider::get_agreement_for_activity;
Expand Down Expand Up @@ -57,7 +56,7 @@ pub fn register_endpoints(scope: Scope) -> Scope {

async fn get_debit_notes(
db: Data<DbExecutor>,
query: Query<FilterParams>,
query: Query<params::FilterParams>,
id: Identity,
) -> HttpResponse {
let node_id = id.identity;
Expand All @@ -75,7 +74,7 @@ async fn get_debit_notes(

async fn get_debit_note(
db: Data<DbExecutor>,
path: Path<DebitNoteId>,
path: Path<params::DebitNoteId>,
id: Identity,
) -> HttpResponse {
let debit_note_id = path.debit_note_id.clone();
Expand All @@ -88,17 +87,20 @@ async fn get_debit_note(
}
}

async fn get_debit_note_payments(db: Data<DbExecutor>, path: Path<DebitNoteId>) -> HttpResponse {
async fn get_debit_note_payments(
db: Data<DbExecutor>,
path: Path<params::DebitNoteId>,
) -> HttpResponse {
response::not_implemented() // TODO
}

async fn get_debit_note_events(
db: Data<DbExecutor>,
query: Query<EventParams>,
query: Query<params::EventParams>,
id: Identity,
) -> HttpResponse {
let node_id = id.identity;
let timeout_secs = query.poll_timeout;
let timeout_secs = query.poll_timeout.unwrap_or(params::DEFAULT_EVENT_TIMEOUT);
let after_timestamp = query.after_timestamp.map(|d| d.naive_utc());
let max_events = query.max_events;
let app_session_id = &query.app_session_id;
Expand Down Expand Up @@ -173,8 +175,8 @@ async fn issue_debit_note(

async fn send_debit_note(
db: Data<DbExecutor>,
path: Path<DebitNoteId>,
query: Query<Timeout>,
path: Path<params::DebitNoteId>,
query: Query<params::Timeout>,
id: Identity,
) -> HttpResponse {
let debit_note_id = path.debit_note_id.clone();
Expand All @@ -190,7 +192,8 @@ async fn send_debit_note(
return response::ok(Null); // Debit note has been already sent
}

with_timeout(query.timeout, async move {
let timeout = query.timeout.unwrap_or(params::DEFAULT_ACK_TIMEOUT);
with_timeout(timeout, async move {
match async move {
ya_net::from(node_id)
.to(debit_note.recipient_id)
Expand All @@ -215,8 +218,8 @@ async fn send_debit_note(

async fn cancel_debit_note(
db: Data<DbExecutor>,
path: Path<DebitNoteId>,
query: Query<Timeout>,
path: Path<params::DebitNoteId>,
query: Query<params::Timeout>,
) -> HttpResponse {
response::not_implemented() // TODO
}
Expand All @@ -225,8 +228,8 @@ async fn cancel_debit_note(

async fn accept_debit_note(
db: Data<DbExecutor>,
path: Path<DebitNoteId>,
query: Query<Timeout>,
path: Path<params::DebitNoteId>,
query: Query<params::Timeout>,
body: Json<Acceptance>,
id: Identity,
) -> HttpResponse {
Expand Down Expand Up @@ -287,7 +290,8 @@ async fn accept_debit_note(
return response::bad_request(&msg);
}

with_timeout(query.timeout, async move {
let timeout = query.timeout.unwrap_or(params::DEFAULT_ACK_TIMEOUT);
with_timeout(timeout, async move {
let issuer_id = debit_note.issuer_id;
let accept_msg = AcceptDebitNote::new(debit_note_id.clone(), acceptance, issuer_id);
let schedule_msg =
Expand Down Expand Up @@ -320,8 +324,8 @@ async fn accept_debit_note(

async fn reject_debit_note(
db: Data<DbExecutor>,
path: Path<DebitNoteId>,
query: Query<Timeout>,
path: Path<params::DebitNoteId>,
query: Query<params::Timeout>,
body: Json<Rejection>,
) -> HttpResponse {
response::not_implemented() // TODO
Expand Down
Loading