Add API method for finding subscription by participants
This commit is contained in:
parent
05e295744d
commit
6accf8ac2e
3 changed files with 74 additions and 3 deletions
|
@ -683,6 +683,42 @@ paths:
|
||||||
description: User's wallet address is not known or not verified
|
description: User's wallet address is not known or not verified
|
||||||
418:
|
418:
|
||||||
description: Blockchain integration is not enabled
|
description: Blockchain integration is not enabled
|
||||||
|
/api/v1/subscriptions/find:
|
||||||
|
get:
|
||||||
|
summary: Find subscription by sender and recipient
|
||||||
|
parameters:
|
||||||
|
- name: sender_id
|
||||||
|
in: query
|
||||||
|
description: Sender ID.
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
- name: recipient_id
|
||||||
|
in: query
|
||||||
|
description: Recipient ID.
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
format: uuid
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: Successful operation
|
||||||
|
content:
|
||||||
|
application/json:
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
id:
|
||||||
|
description: Subscription ID.
|
||||||
|
type: number
|
||||||
|
example: 1
|
||||||
|
expires_at:
|
||||||
|
description: The date when subscription expires.
|
||||||
|
type: string
|
||||||
|
format: dateTime
|
||||||
|
404:
|
||||||
|
description: Subscription not found
|
||||||
/api/v1/subscriptions/invoices:
|
/api/v1/subscriptions/invoices:
|
||||||
post:
|
post:
|
||||||
summary: Create invoice
|
summary: Create invoice
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use chrono::{DateTime, Utc};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
|
@ -30,7 +31,7 @@ impl From<DbInvoice> for Invoice {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct SubscriptionQueryParams {
|
pub struct SubscriptionAuthorizationQueryParams {
|
||||||
pub price: u64,
|
pub price: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,3 +55,15 @@ impl SubscriptionOption {
|
||||||
Some(settings)
|
Some(settings)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
pub struct SubscriptionQueryParams {
|
||||||
|
pub sender_id: Uuid,
|
||||||
|
pub recipient_id: Uuid,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize)]
|
||||||
|
pub struct SubscriptionDetails {
|
||||||
|
pub id: i32,
|
||||||
|
pub expires_at: DateTime<Utc>,
|
||||||
|
}
|
||||||
|
|
|
@ -23,21 +23,24 @@ use crate::models::profiles::types::{
|
||||||
PaymentType,
|
PaymentType,
|
||||||
ProfileUpdateData,
|
ProfileUpdateData,
|
||||||
};
|
};
|
||||||
|
use crate::models::subscriptions::queries::get_subscription_by_participants;
|
||||||
use crate::models::users::queries::get_user_by_id;
|
use crate::models::users::queries::get_user_by_id;
|
||||||
use crate::monero::wallet::create_monero_address;
|
use crate::monero::wallet::create_monero_address;
|
||||||
use crate::utils::currencies::Currency;
|
use crate::utils::currencies::Currency;
|
||||||
use super::types::{
|
use super::types::{
|
||||||
Invoice,
|
Invoice,
|
||||||
InvoiceData,
|
InvoiceData,
|
||||||
SubscriptionQueryParams,
|
SubscriptionAuthorizationQueryParams,
|
||||||
|
SubscriptionDetails,
|
||||||
SubscriptionOption,
|
SubscriptionOption,
|
||||||
|
SubscriptionQueryParams,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub async fn authorize_subscription(
|
pub async fn authorize_subscription(
|
||||||
auth: BearerAuth,
|
auth: BearerAuth,
|
||||||
config: web::Data<Config>,
|
config: web::Data<Config>,
|
||||||
db_pool: web::Data<Pool>,
|
db_pool: web::Data<Pool>,
|
||||||
query_params: web::Query<SubscriptionQueryParams>,
|
query_params: web::Query<SubscriptionAuthorizationQueryParams>,
|
||||||
) -> Result<HttpResponse, HttpError> {
|
) -> Result<HttpResponse, HttpError> {
|
||||||
let db_client = &**get_database_client(&db_pool).await?;
|
let db_client = &**get_database_client(&db_pool).await?;
|
||||||
let current_user = get_current_user(db_client, auth.token()).await?;
|
let current_user = get_current_user(db_client, auth.token()).await?;
|
||||||
|
@ -145,6 +148,24 @@ pub async fn subscriptions_enabled(
|
||||||
Ok(HttpResponse::Ok().json(account))
|
Ok(HttpResponse::Ok().json(account))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/find")]
|
||||||
|
async fn find_subscription(
|
||||||
|
db_pool: web::Data<Pool>,
|
||||||
|
query_params: web::Query<SubscriptionQueryParams>,
|
||||||
|
) -> Result<HttpResponse, HttpError> {
|
||||||
|
let db_client = &**get_database_client(&db_pool).await?;
|
||||||
|
let subscription = get_subscription_by_participants(
|
||||||
|
db_client,
|
||||||
|
&query_params.sender_id,
|
||||||
|
&query_params.recipient_id,
|
||||||
|
).await?;
|
||||||
|
let details = SubscriptionDetails {
|
||||||
|
id: subscription.id,
|
||||||
|
expires_at: subscription.expires_at,
|
||||||
|
};
|
||||||
|
Ok(HttpResponse::Ok().json(details))
|
||||||
|
}
|
||||||
|
|
||||||
#[post("/invoices")]
|
#[post("/invoices")]
|
||||||
async fn create_invoice_view(
|
async fn create_invoice_view(
|
||||||
config: web::Data<Config>,
|
config: web::Data<Config>,
|
||||||
|
@ -177,5 +198,6 @@ pub fn subscription_api_scope() -> Scope {
|
||||||
.route("/authorize", web::get().to(authorize_subscription))
|
.route("/authorize", web::get().to(authorize_subscription))
|
||||||
.service(get_subscription_options)
|
.service(get_subscription_options)
|
||||||
.route("/enable", web::post().to(subscriptions_enabled))
|
.route("/enable", web::post().to(subscriptions_enabled))
|
||||||
|
.service(find_subscription)
|
||||||
.service(create_invoice_view)
|
.service(create_invoice_view)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue