qewqwe
All checks were successful
Deploy / deploy-staging (push) Successful in 52s
Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-07-13 22:48:56 +02:00
parent cb8c494a23
commit e0afaca57b
8 changed files with 406 additions and 28 deletions

View File

@@ -153,6 +153,15 @@ final class Router
$this->respond(['data' => $this->fxHistory()]);
}
if ($resource === 'offer-basis-history' && $method === 'GET') {
$this->respond(['data' => $this->offerBasisHistory($projectKey)]);
}
if ($resource === 'offer-basis-history' && $method === 'POST') {
$this->repository()->ensureProject($projectKey);
$this->respond(['data' => $this->saveOfferBasisHistory($projectKey, Http::input())], 201);
}
if ($resource === 'legacy-fx-migrate' && $method === 'POST') {
$this->respond(['data' => $this->migrateLegacyFxRates($projectKey)], 201);
}
@@ -818,6 +827,11 @@ final class Router
return $rows;
}
private function offerBasisHistory(string $projectKey): array
{
return $this->repository()->listOfferBasisHistory($projectKey, 50);
}
private function migrateLegacyFxRates(string $projectKey): array
{
$fxRepository = $this->sharedFxRatesRepository();
@@ -1694,6 +1708,21 @@ final class Router
}
$measurements = $this->measurements($projectKey, $settings);
$freshFetchId = null;
if ($settings['crypto_base_price_amount'] !== null) {
try {
$fresh = $this->fx()->refreshLatestRates(null, 'USD');
$freshFetchId = is_numeric($fresh['fetch_id'] ?? null) ? (int) $fresh['fetch_id'] : null;
} catch (\Throwable) {
$freshFetchId = null;
}
}
if ($freshFetchId !== null && $freshFetchId > 0 && $measurements !== []) {
$latestIndex = array_key_last($measurements);
if ($latestIndex !== null && is_array($measurements[$latestIndex])) {
$measurements[$latestIndex]['fx_fetch_id'] = $freshFetchId;
}
}
$summary = $this->analytics()->buildSummary($measurements, $settings, [], [
'include_offer_scenarios' => true,
'include_long_term_projection' => true,
@@ -1701,9 +1730,38 @@ final class Router
return [
'miner_offers' => is_array($summary['miner_offers'] ?? null) ? $summary['miner_offers'] : [],
'fx_fetch_id' => $freshFetchId,
];
}
private function saveOfferBasisHistory(string $projectKey, array $input): array
{
$offerType = $this->enumValue($input['offer_type'] ?? null, ['crypto', 'fiat'], 'offer_type');
$basePriceAmount = $this->requiredDecimal($input['base_price_amount'] ?? null, 'base_price_amount');
if ($basePriceAmount <= 0) {
throw new ApiException('base_price_amount muss groesser als 0 sein.', 422, ['field' => 'base_price_amount']);
}
$basePriceCurrency = $offerType === 'crypto'
? $this->requiredCurrency($input['base_price_currency'] ?? 'USD', 'base_price_currency')
: 'EUR';
if ($offerType === 'crypto') {
$cryptoCurrency = $this->requiredCurrency($this->settings($projectKey)['crypto_currency'] ?? 'DOGE', 'crypto_currency');
if (!in_array($basePriceCurrency, ['USD', $cryptoCurrency], true)) {
throw new ApiException('Bei Crypto-Basispreisen sind nur USD oder die Projekt-Kryptowaehrung erlaubt.', 422, [
'field' => 'base_price_currency',
]);
}
}
return $this->repository()->saveOfferBasisEntry($projectKey, [
'offer_type' => $offerType,
'base_price_amount' => $basePriceAmount,
'base_price_currency' => $basePriceCurrency,
]);
}
private function purchasedMiners(string $projectKey): array
{
return $this->repository()->listPurchasedMiners($projectKey);