Add information about payment options to Account object
This commit is contained in:
parent
f218936caa
commit
05e295744d
2 changed files with 59 additions and 5 deletions
|
@ -848,16 +848,37 @@ components:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: '#/components/schemas/Field'
|
$ref: '#/components/schemas/Field'
|
||||||
|
payment_options:
|
||||||
|
description: Payment options.
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
type:
|
||||||
|
description: Payment type.
|
||||||
|
type: string
|
||||||
|
enum:
|
||||||
|
- link
|
||||||
|
- ethereum-subscription
|
||||||
|
- monero-subscription
|
||||||
|
name:
|
||||||
|
description: Link name (only for link type).
|
||||||
|
type: string
|
||||||
|
nullable: true
|
||||||
|
href:
|
||||||
|
description: Link URL (only for link type).
|
||||||
|
type: string
|
||||||
|
nullable: true
|
||||||
|
price:
|
||||||
|
description: Subscription price (only for ethereum-subscription and monero-subscription types).
|
||||||
|
type: number
|
||||||
|
nullable: true
|
||||||
|
example: null
|
||||||
fields:
|
fields:
|
||||||
description: Additional metadata attached to a profile as name-value pairs.
|
description: Additional metadata attached to a profile as name-value pairs.
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: '#/components/schemas/Field'
|
$ref: '#/components/schemas/Field'
|
||||||
subscription_page_url:
|
|
||||||
description: Subscription page URL
|
|
||||||
type: string
|
|
||||||
nullable: true
|
|
||||||
example: 'https://example.com/profile/1/subscription'
|
|
||||||
Attachment:
|
Attachment:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
|
|
@ -30,6 +30,14 @@ pub struct AccountField {
|
||||||
verified_at: Option<DateTime<Utc>>,
|
verified_at: Option<DateTime<Utc>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Contains only public information
|
||||||
|
#[derive(Serialize)]
|
||||||
|
#[serde(tag = "type", rename_all = "kebab-case")]
|
||||||
|
pub enum AccountPaymentOption {
|
||||||
|
Link { name: String, href: String },
|
||||||
|
EthereumSubscription,
|
||||||
|
MoneroSubscription { price: u64 },
|
||||||
|
}
|
||||||
/// https://docs.joinmastodon.org/entities/source/
|
/// https://docs.joinmastodon.org/entities/source/
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct Source {
|
pub struct Source {
|
||||||
|
@ -50,6 +58,7 @@ pub struct Account {
|
||||||
pub avatar: Option<String>,
|
pub avatar: Option<String>,
|
||||||
pub header: Option<String>,
|
pub header: Option<String>,
|
||||||
pub identity_proofs: Vec<AccountField>,
|
pub identity_proofs: Vec<AccountField>,
|
||||||
|
pub payment_options: Vec<AccountPaymentOption>,
|
||||||
pub fields: Vec<AccountField>,
|
pub fields: Vec<AccountField>,
|
||||||
pub followers_count: i32,
|
pub followers_count: i32,
|
||||||
pub following_count: i32,
|
pub following_count: i32,
|
||||||
|
@ -93,6 +102,7 @@ impl Account {
|
||||||
extra_fields.push(field);
|
extra_fields.push(field);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: remove
|
||||||
let subscription_page_url = profile.payment_options.clone()
|
let subscription_page_url = profile.payment_options.clone()
|
||||||
.into_inner().into_iter()
|
.into_inner().into_iter()
|
||||||
.map(|option| {
|
.map(|option| {
|
||||||
|
@ -107,6 +117,28 @@ impl Account {
|
||||||
})
|
})
|
||||||
.next();
|
.next();
|
||||||
|
|
||||||
|
let payment_options = profile.payment_options.clone()
|
||||||
|
.into_inner().into_iter()
|
||||||
|
.map(|option| {
|
||||||
|
match option {
|
||||||
|
PaymentOption::Link(link) => {
|
||||||
|
AccountPaymentOption::Link {
|
||||||
|
name: link.name,
|
||||||
|
href: link.href,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
PaymentOption::EthereumSubscription(_) => {
|
||||||
|
AccountPaymentOption::EthereumSubscription
|
||||||
|
},
|
||||||
|
PaymentOption::MoneroSubscription(payment_info) => {
|
||||||
|
AccountPaymentOption::MoneroSubscription {
|
||||||
|
price: payment_info.price,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
id: profile.id,
|
id: profile.id,
|
||||||
username: profile.username,
|
username: profile.username,
|
||||||
|
@ -118,6 +150,7 @@ impl Account {
|
||||||
avatar: avatar_url,
|
avatar: avatar_url,
|
||||||
header: header_url,
|
header: header_url,
|
||||||
identity_proofs,
|
identity_proofs,
|
||||||
|
payment_options,
|
||||||
fields: extra_fields,
|
fields: extra_fields,
|
||||||
followers_count: profile.follower_count,
|
followers_count: profile.follower_count,
|
||||||
following_count: profile.following_count,
|
following_count: profile.following_count,
|
||||||
|
|
Loading…
Reference in a new issue