miner
This commit is contained in:
@@ -327,6 +327,11 @@ final class Router
|
||||
Http::json(['data' => $this->updatePurchasedMiner($projectKey, (int) $matches[1], Http::input())]);
|
||||
}
|
||||
|
||||
if (preg_match('~^purchased-miners/(\d+)$~', $resource, $matches) && $method === 'DELETE') {
|
||||
$this->deletePurchasedMiner($projectKey, (int) $matches[1]);
|
||||
Http::json(['data' => ['deleted' => true]]);
|
||||
}
|
||||
|
||||
if (preg_match('~^miner-offers/([^/]+)/purchase$~', $resource, $matches) && $method === 'POST') {
|
||||
$this->repository()->ensureProject($projectKey);
|
||||
Http::json(['data' => $this->purchaseMiner($projectKey, rawurldecode((string) $matches[1]), Http::input())], 201);
|
||||
@@ -2179,6 +2184,19 @@ final class Router
|
||||
);
|
||||
}
|
||||
|
||||
private function deletePurchasedMiner(string $projectKey, int $minerId): void
|
||||
{
|
||||
if ($minerId <= 0) {
|
||||
throw new ApiException('miner_id ist ungueltig.', 422);
|
||||
}
|
||||
|
||||
if (!is_array($this->repository()->getPurchasedMiner($projectKey, $minerId))) {
|
||||
throw new ApiException('Gemieteter Miner nicht gefunden.', 404);
|
||||
}
|
||||
|
||||
$this->repository()->deletePurchasedMiner($projectKey, $minerId);
|
||||
}
|
||||
|
||||
private function findComputedMinerOffer(string $projectKey, string $offerId): ?array
|
||||
{
|
||||
foreach ($this->minerOffers($projectKey) as $offer) {
|
||||
|
||||
@@ -1144,6 +1144,37 @@ final class MiningRepository
|
||||
return $this->normalizeRow($fetch->fetch() ?: []);
|
||||
}
|
||||
|
||||
public function deletePurchasedMiner(string $projectKey, int $minerId): void
|
||||
{
|
||||
if ($minerId <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
$delete = $this->pdo->prepare(
|
||||
'DELETE FROM ' . $this->table('purchased_miners') . '
|
||||
WHERE id = :id AND project_key = :project_key AND owner_sub = :owner_sub'
|
||||
);
|
||||
$delete->execute([
|
||||
'id' => $minerId,
|
||||
'project_key' => $projectKey,
|
||||
'owner_sub' => $this->ownerSub,
|
||||
]);
|
||||
|
||||
if ($delete->rowCount() > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Older rows without an owner assignment remain deletable like the existing read/update fallback.
|
||||
$legacyDelete = $this->pdo->prepare(
|
||||
'DELETE FROM ' . $this->table('purchased_miners') . '
|
||||
WHERE id = :id AND project_key = :project_key AND owner_sub IS NULL'
|
||||
);
|
||||
$legacyDelete->execute([
|
||||
'id' => $minerId,
|
||||
'project_key' => $projectKey,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getMinerOffer(string $projectKey, int $offerId): ?array
|
||||
{
|
||||
$stmt = $this->pdo->prepare('SELECT * FROM ' . $this->table('miner_offers') . ' WHERE project_key = :project_key AND id = :id LIMIT 1');
|
||||
|
||||
Reference in New Issue
Block a user