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
|
||||
items:
|
||||
$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:
|
||||
description: Additional metadata attached to a profile as name-value pairs.
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Field'
|
||||
subscription_page_url:
|
||||
description: Subscription page URL
|
||||
type: string
|
||||
nullable: true
|
||||
example: 'https://example.com/profile/1/subscription'
|
||||
Attachment:
|
||||
type: object
|
||||
properties:
|
||||
|
|
|
@ -30,6 +30,14 @@ pub struct AccountField {
|
|||
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/
|
||||
#[derive(Serialize)]
|
||||
pub struct Source {
|
||||
|
@ -50,6 +58,7 @@ pub struct Account {
|
|||
pub avatar: Option<String>,
|
||||
pub header: Option<String>,
|
||||
pub identity_proofs: Vec<AccountField>,
|
||||
pub payment_options: Vec<AccountPaymentOption>,
|
||||
pub fields: Vec<AccountField>,
|
||||
pub followers_count: i32,
|
||||
pub following_count: i32,
|
||||
|
@ -93,6 +102,7 @@ impl Account {
|
|||
extra_fields.push(field);
|
||||
};
|
||||
|
||||
// TODO: remove
|
||||
let subscription_page_url = profile.payment_options.clone()
|
||||
.into_inner().into_iter()
|
||||
.map(|option| {
|
||||
|
@ -107,6 +117,28 @@ impl Account {
|
|||
})
|
||||
.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 {
|
||||
id: profile.id,
|
||||
username: profile.username,
|
||||
|
@ -118,6 +150,7 @@ impl Account {
|
|||
avatar: avatar_url,
|
||||
header: header_url,
|
||||
identity_proofs,
|
||||
payment_options,
|
||||
fields: extra_fields,
|
||||
followers_count: profile.follower_count,
|
||||
following_count: profile.following_count,
|
||||
|
|
Loading…
Reference in a new issue