1234567891011121314151617181920212223242526272829303132333435363738394041 |
- use crate::{Context, Handler};
- use axum::{extract::State, http::StatusCode, Json};
- use serde::Deserialize;
- use verax::{AccountId, AnyAmount, Status, Tag};
- #[derive(Deserialize)]
- pub struct Deposit {
- pub account: AccountId,
- #[serde(flatten)]
- pub amount: AnyAmount,
- pub memo: String,
- pub tags: Vec<Tag>,
- pub status: Status,
- }
- #[async_trait::async_trait]
- impl Handler for Deposit {
- type Ok = verax::Transaction;
- type Err = verax::Error;
- async fn handle(self, ctx: &Context) -> Result<Self::Ok, Self::Err> {
- ctx.ledger
- .deposit(
- &self.account,
- self.amount.try_into()?,
- self.status,
- self.tags,
- self.memo,
- )
- .await
- }
- }
- pub async fn handler(
- State(ledger): State<Context>,
- Json(item): Json<Deposit>,
- ) -> Result<Json<verax::Transaction>, (StatusCode, String)> {
- Ok(Json(item.handle(&ledger).await.map_err(|err| {
- (StatusCode::BAD_REQUEST, err.to_string())
- })?))
- }
|