From 311d603168f366ed25d0beecb8fa18e2483de445 Mon Sep 17 00:00:00 2001 From: aecsocket <43144841+aecsocket@users.noreply.github.com> Date: Wed, 19 Aug 2026 16:58:31 +0900 Subject: [PATCH] serialize values as floats --- apps/labrinth/src/queue/payout_run/mod.rs | 6 +++ .../src/routes/internal/payout_runs.rs | 42 +++++++++++++++---- 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/apps/labrinth/src/queue/payout_run/mod.rs b/apps/labrinth/src/queue/payout_run/mod.rs index 1c15da375c..ad304ad3e2 100644 --- a/apps/labrinth/src/queue/payout_run/mod.rs +++ b/apps/labrinth/src/queue/payout_run/mod.rs @@ -80,19 +80,25 @@ const PLATFORM_REVENUE_SPLIT: Decimal = dec!(0.25); #[derive(Debug, Clone, Serialize, Deserialize)] pub struct DayDistribution { /// Amount of revenue input into the algorithm. + #[serde(with = "rust_decimal::serde::float")] pub raw_revenue_usd: Decimal, /// Operational fees to subtract. + #[serde(with = "rust_decimal::serde::float")] pub fees_usd: Decimal, /// Estimation variance to subtract. /// /// For non-estimates (actual revenue values), this is zero. + #[serde(with = "rust_decimal::serde::float")] pub variance_usd: Decimal, /// Total net revenue that we earned; /// `raw_revenue - fees - variance`. + #[serde(with = "rust_decimal::serde::float")] pub net_revenue_usd: Decimal, /// How much of the net revenue goes to the platform. + #[serde(with = "rust_decimal::serde::float")] pub platform_net_revenue_usd: Decimal, /// How much of the net revenue goes to creators. + #[serde(with = "rust_decimal::serde::float")] pub creator_net_revenue_usd: Decimal, } diff --git a/apps/labrinth/src/routes/internal/payout_runs.rs b/apps/labrinth/src/routes/internal/payout_runs.rs index 1cbf8e9883..132fa9cc0e 100644 --- a/apps/labrinth/src/routes/internal/payout_runs.rs +++ b/apps/labrinth/src/routes/internal/payout_runs.rs @@ -1,12 +1,13 @@ use std::collections::HashMap; -use actix_web::{get, web}; +use actix_web::{HttpRequest, get, web}; use chrono::{Months, NaiveDate, Utc}; use rust_decimal::Decimal; use serde::{Deserialize, Serialize}; use xredis::RedisPool; use crate::{ + auth::get_user_from_headers, database::{ PgPool, models::{ @@ -14,9 +15,13 @@ use crate::{ payout_variance_item::DBPayoutVariance, }, }, - queue::payout_run::{ - DayDistribution, PayoutVariance, PayoutVariances, - compute_actual_distribution_flow, distribution_for_day, estimate, + models::pats::Scopes, + queue::{ + payout_run::{ + DayDistribution, PayoutVariance, PayoutVariances, + compute_actual_distribution_flow, distribution_for_day, estimate, + }, + session::AuthQueue, }, routes::ApiError, util::{ @@ -69,19 +74,32 @@ pub struct PayoutRunDay { #[derive(Debug, Serialize, Deserialize)] pub struct PayoutRunAdjustment { /// Total value of the adjustment. + #[serde(with = "rust_decimal::serde::float")] pub amount_usd: Decimal, /// Why this adjustment was applied. /// /// Only visible to admins. + #[serde(skip_serializing_if = "Option::is_none")] pub description: Option, } #[get("")] pub async fn get_runs( + req: HttpRequest, pool: web::Data, redis: web::Data, aditude: web::Data, + session_queue: web::Data, ) -> Result, ApiError> { + let show_adjustment_descriptions = get_user_from_headers( + &req, + &**pool, + &redis, + &session_queue, + Scopes::SESSION_ACCESS, + ) + .await + .is_ok_and(|(_, user)| user.role.is_admin()); let now = Utc::now(); let latest_payout_value = sqlx::query_scalar!( r#" @@ -93,7 +111,7 @@ pub async fn get_runs( .await .wrap_internal_err("fetching latest payout value")? .unwrap_or(now) - .max(now); + .min(now); let current_period = YearMonth::from_day1(now.date_naive()); let mut period = YearMonth::from_day1(latest_payout_value.date_naive()); @@ -146,10 +164,16 @@ pub async fn get_runs( .into_iter() .map(|estimate| -> Result<_, ApiError> { if let Some(period) = stored_periods.get(&estimate.period.date()) { - let adjustments = serde_json::from_value::< - Vec, - >(period.adjustments.clone()) - .wrap_internal_err("deserializing payout adjustments")?; + let mut adjustments = + serde_json::from_value::>( + period.adjustments.clone(), + ) + .wrap_internal_err("deserializing payout adjustments")?; + if !show_adjustment_descriptions { + for adjustment in &mut adjustments { + adjustment.description = None; + } + } let total_estimated_revenue_usd = period .days .iter()