44
55namespace App \Http \Controllers ;
66
7+ use App \DTO \CityByCodeDTO ;
8+ use App \DTO \DeliveryCalculationDTO ;
9+ use App \DTO \KitTerminalsRequestDTO ;
10+ use App \DTO \SearchCitiesDTO ;
711use App \Services \KitDeliveryService ;
812use Illuminate \Http \JsonResponse ;
913use Illuminate \Http \Request ;
10- use Psr \Http \Client \ClientExceptionInterface ;
1114use Symfony \Component \HttpFoundation \Response ;
1215
1316readonly class DeliveryController
1417{
1518 public function __construct (
1619 private KitDeliveryService $ kitService
17- ) {}
20+ ) {
21+ }
1822
1923 /**
2024 * @return JsonResponse
21- * @throws ClientExceptionInterface
2225 */
2326 public function getAllTerminals (): JsonResponse
2427 {
2528 try {
26- $ terminals = $ this ->kitService ->getTerminals ();
29+ $ dto = new KitTerminalsRequestDTO ();
30+ $ terminals = $ this ->kitService ->getTerminals ($ dto );
2731 return response ()->json ($ terminals , Response::HTTP_OK );
2832 } catch (\Exception $ e ) {
2933 return response ()->json ([
@@ -35,12 +39,12 @@ public function getAllTerminals(): JsonResponse
3539 /**
3640 * @param string $cityId
3741 * @return JsonResponse
38- * @throws ClientExceptionInterface
3942 */
4043 public function getCityTerminals (string $ cityId ): JsonResponse
4144 {
4245 try {
43- $ terminals = $ this ->kitService ->getTerminals ($ cityId );
46+ $ dto = new KitTerminalsRequestDTO ($ cityId );
47+ $ terminals = $ this ->kitService ->getTerminals ($ dto );
4448 return response ()->json ($ terminals , Response::HTTP_OK );
4549 } catch (\Exception $ e ) {
4650 return response ()->json ([
@@ -52,12 +56,12 @@ public function getCityTerminals(string $cityId): JsonResponse
5256 /**
5357 * @param Request $request
5458 * @return JsonResponse
55- * @throws ClientExceptionInterface
5659 */
5760 public function calculateDelivery (Request $ request ): JsonResponse
5861 {
5962 try {
60- $ result = $ this ->kitService ->calculateDelivery ($ request ->all ());
63+ $ dto = DeliveryCalculationDTO::fromArray ($ request ->all ());
64+ $ result = $ this ->kitService ->calculateDelivery ($ dto );
6165 return response ()->json ([
6266 'data ' => $ result
6367 ], Response::HTTP_OK );
@@ -71,7 +75,6 @@ public function calculateDelivery(Request $request): JsonResponse
7175 /**
7276 * @param Request $request
7377 * @return JsonResponse
74- * @throws ClientExceptionInterface
7578 */
7679 public function searchCities (Request $ request ): JsonResponse
7780 {
@@ -82,12 +85,30 @@ public function searchCities(Request $request): JsonResponse
8285 }
8386
8487 try {
85- $ cities = $ this ->kitService ->searchCitiesByName ($ request ->get ('query ' ));
88+ $ dto = new SearchCitiesDTO ($ request ->get ('query ' ));
89+ $ cities = $ this ->kitService ->searchCitiesByName ($ dto );
8690 return response ()->json ($ cities , Response::HTTP_OK );
8791 } catch (\Exception $ e ) {
8892 return response ()->json ([
8993 'message ' => $ e ->getMessage ()
9094 ], Response::HTTP_INTERNAL_SERVER_ERROR );
9195 }
9296 }
93- }
97+
98+ /**
99+ * @param string $code
100+ * @return JsonResponse
101+ */
102+ public function getCityByCode (string $ code ): JsonResponse
103+ {
104+ try {
105+ $ dto = new CityByCodeDTO ($ code );
106+ $ city = $ this ->kitService ->getCityByCode ($ dto );
107+ return response ()->json ($ city , Response::HTTP_OK );
108+ } catch (\Exception $ e ) {
109+ return response ()->json ([
110+ 'message ' => $ e ->getMessage ()
111+ ], Response::HTTP_INTERNAL_SERVER_ERROR );
112+ }
113+ }
114+ }
0 commit comments