2026-09-01 19:05:42 +07:00
|
|
|
//! Axum handlers for misc utility endpoints.
|
|
|
|
|
//!
|
|
|
|
|
//! Ported from Shirokami-API `scraper/misc/*.js`.
|
|
|
|
|
|
|
|
|
|
use axum::extract::Query;
|
|
|
|
|
use axum::http::StatusCode;
|
|
|
|
|
use axum::Json;
|
|
|
|
|
use serde::Deserialize;
|
|
|
|
|
use serde_json::Value;
|
2026-09-01 22:39:02 +07:00
|
|
|
use utoipa::IntoParams;
|
2026-09-01 19:05:42 +07:00
|
|
|
|
|
|
|
|
use crate::application::misc as use_cases;
|
|
|
|
|
use crate::presentation::error::AppError;
|
|
|
|
|
|
|
|
|
|
/// Query params for currency converter.
|
2026-09-01 22:39:02 +07:00
|
|
|
#[derive(Deserialize, IntoParams)]
|
2026-09-01 19:05:42 +07:00
|
|
|
pub struct CurrencyParams {
|
|
|
|
|
pub amount: Option<f64>,
|
|
|
|
|
pub from: Option<String>,
|
|
|
|
|
pub to: Option<String>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// GET /misc/currency-converter?amount=100&from=USD&to=IDR
|
2026-09-01 22:39:02 +07:00
|
|
|
#[utoipa::path(
|
|
|
|
|
get,
|
|
|
|
|
path = "/misc/currency-converter",
|
|
|
|
|
tag = "misc",
|
|
|
|
|
operation_id = "currency_converter",
|
|
|
|
|
params(CurrencyParams),
|
|
|
|
|
responses(
|
|
|
|
|
(status = 200, description = "Currency conversion result", body = Value),
|
|
|
|
|
(status = 502, description = "Upstream error"),
|
|
|
|
|
)
|
|
|
|
|
)]
|
2026-09-01 19:05:42 +07:00
|
|
|
pub async fn currency_converter_handler(
|
|
|
|
|
Query(params): Query<CurrencyParams>,
|
|
|
|
|
) -> Result<(StatusCode, Json<Value>), AppError> {
|
|
|
|
|
let amount = params.amount.unwrap_or(1.0);
|
|
|
|
|
let from = params.from.unwrap_or_else(|| "USD".to_string());
|
|
|
|
|
let to = params.to.unwrap_or_else(|| "IDR".to_string());
|
|
|
|
|
|
|
|
|
|
let result = use_cases::currency_converter(amount, &from, &to).await?;
|
|
|
|
|
Ok((StatusCode::OK, Json(result)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// GET /misc/harga-emas
|
2026-09-01 22:39:02 +07:00
|
|
|
#[utoipa::path(
|
|
|
|
|
get,
|
|
|
|
|
path = "/misc/harga-emas",
|
|
|
|
|
tag = "misc",
|
|
|
|
|
operation_id = "harga_emas",
|
|
|
|
|
responses(
|
|
|
|
|
(status = 200, description = "Gold prices (Antam)", body = Value),
|
|
|
|
|
(status = 502, description = "Upstream error"),
|
|
|
|
|
)
|
|
|
|
|
)]
|
2026-09-01 19:05:42 +07:00
|
|
|
pub async fn harga_emas_handler() -> Result<(StatusCode, Json<Value>), AppError> {
|
|
|
|
|
let result = use_cases::harga_emas().await?;
|
|
|
|
|
Ok((StatusCode::OK, Json(result)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// GET /misc/kurs-bca
|
2026-09-01 22:39:02 +07:00
|
|
|
#[utoipa::path(
|
|
|
|
|
get,
|
|
|
|
|
path = "/misc/kurs-bca",
|
|
|
|
|
tag = "misc",
|
|
|
|
|
operation_id = "kurs_bca",
|
|
|
|
|
responses(
|
|
|
|
|
(status = 200, description = "BCA exchange rates", body = Value),
|
|
|
|
|
(status = 502, description = "Upstream error"),
|
|
|
|
|
)
|
|
|
|
|
)]
|
2026-09-01 19:05:42 +07:00
|
|
|
pub async fn kurs_bca_handler() -> Result<(StatusCode, Json<Value>), AppError> {
|
|
|
|
|
let result = use_cases::kurs_bca().await?;
|
|
|
|
|
Ok((StatusCode::OK, Json(result)))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// GET /misc/server-info
|
2026-09-01 22:39:02 +07:00
|
|
|
#[utoipa::path(
|
|
|
|
|
get,
|
|
|
|
|
path = "/misc/server-info",
|
|
|
|
|
tag = "misc",
|
|
|
|
|
operation_id = "server_info",
|
|
|
|
|
responses(
|
|
|
|
|
(status = 200, description = "Server info", body = Value),
|
|
|
|
|
(status = 502, description = "Upstream error"),
|
|
|
|
|
)
|
|
|
|
|
)]
|
2026-09-01 19:05:42 +07:00
|
|
|
pub async fn server_info_handler() -> Result<(StatusCode, Json<Value>), AppError> {
|
|
|
|
|
let result = use_cases::server_info().await?;
|
|
|
|
|
Ok((StatusCode::OK, Json(result)))
|
|
|
|
|
}
|