-
Notifications
You must be signed in to change notification settings - Fork 150
Expand file tree
/
Copy pathtransactions.rs
More file actions
31 lines (28 loc) · 886 Bytes
/
Copy pathtransactions.rs
File metadata and controls
31 lines (28 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use axum::extract::{Query, State};
use axum::http::HeaderMap;
use axum::response::Response;
use serde::Deserialize;
use crate::auth::extractor::AuthUser;
use crate::error::{bad_request, internal, ApiResult};
use crate::etag;
use crate::services::payments;
use crate::AppState;
#[derive(Deserialize)]
pub struct ListParams {
pub limit: Option<i64>,
}
pub async fn list(
State(state): State<AppState>,
auth: AuthUser,
Query(params): Query<ListParams>,
headers: HeaderMap,
) -> ApiResult<Response> {
let merchant_id = auth
.merchant_id
.ok_or_else(|| bad_request("no merchant associated with this account"))?;
let limit = params.limit.unwrap_or(50).clamp(1, 200);
let payments = payments::payments_by_merchant(&state.db, merchant_id, limit)
.await
.map_err(internal)?;
Ok(etag::conditional_json(&headers, &payments))
}