Skip to content
This repository was archived by the owner on May 13, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions app/DTO/CityByCodeDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,37 @@

class CityByCodeDTO
{
private string $code;
private ?int $id;
private ?int $tdd_city_code;

public function __construct(string $code)
public function __construct(?int $tdd_city_code = null, ?int $id = null)
{
$this->code = $code;
$this->tdd_city_code = $tdd_city_code;
$this->id = $id;
}

public static function fromId(int $id): self
{
return new self(null, $id);
}

public static function fromCode(int $code): self
{
return new self($code);
}

public function toGetListCityRequest(): GetListCityRequest
{
return new GetListCityRequest($this->code);
$params = [];

if ($this->id !== null) {
$params['id'] = $this->id;
}

if ($this->tdd_city_code !== null) {
$params['tdd_city_code'] = (string)$this->tdd_city_code;
}

return new GetListCityRequest(...$params);
}
}
}
6 changes: 3 additions & 3 deletions app/Http/Controllers/DeliveryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ public function searchCities(Request $request): JsonResponse
}

/**
* @param string $code
* @param int $tdd_city_code
* @return JsonResponse
*/
public function getCityByCode(string $code): JsonResponse
public function getCityByCode(int $tdd_city_code): JsonResponse
{
try {
$dto = new CityByCodeDTO($code);
$dto = new CityByCodeDTO($tdd_city_code);
$city = $this->kitService->getCityByCode($dto);
return response()->json($city, Response::HTTP_OK);
} catch (\Exception $e) {
Expand Down
2 changes: 1 addition & 1 deletion app/Models/Terminal.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ class Terminal extends Model
'email',
'value',
];
}
}
4 changes: 2 additions & 2 deletions app/Repositories/TerminalRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function search(?string $query = null): array

$allTerminals = $this->getAllTerminals();

return array_filter($allTerminals, function($terminal) use ($query) {
return array_filter($allTerminals, function ($terminal) use ($query) {
$query = strtolower($query);
return stripos(strtolower($terminal['city_name'] ?? ''), $query) !== false ||
stripos(strtolower($terminal['address_code'] ?? ''), $query) !== false;
Expand Down Expand Up @@ -98,4 +98,4 @@ public function clearCache(): void

Log::info('Кеш терминалов полностью очищен, удалено ' . count($keys) . ' ключей');
}
}
}
2 changes: 1 addition & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
Route::get('/cities/code/{code}', [DeliveryController::class, 'getCityByCode']);
Route::get('/terminals/search', [TerminalController::class, 'search']);
Route::get('/terminals', [DeliveryController::class, 'getAllTerminals']);
});
});
Loading