-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into #10-regulations-for-escooters
- Loading branch information
Showing
71 changed files
with
1,914 additions
and
368 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers\Admin; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\ProviderRequest; | ||
use App\Http\Resources\ProviderResource; | ||
use App\Models\Provider; | ||
use Illuminate\Http\Response as InertiaResponse; | ||
use Illuminate\Support\Facades\File; | ||
use Illuminate\Support\Facades\Storage; | ||
use Inertia\Inertia; | ||
use Inertia\Response; | ||
|
||
class ProviderController extends Controller | ||
{ | ||
public const ITEMS_PER_PAGE = 15; | ||
|
||
public function index(): Response | ||
{ | ||
$providers = Provider::query() | ||
->search("name") | ||
->orderByName() | ||
->orderByTimeRange() | ||
->paginate(self::ITEMS_PER_PAGE) | ||
->withQueryString(); | ||
|
||
return Inertia::render("Providers/Index", [ | ||
"providers" => ProviderResource::collection($providers), | ||
]); | ||
} | ||
|
||
public function store(ProviderRequest $request): void | ||
{ | ||
Provider::query()->create($request->validated()); | ||
|
||
$fileName = $this->getFilename($request); | ||
$fileContents = $request->file("file")->get(); | ||
|
||
Storage::disk("public")->put("providers/" . $fileName, $fileContents); | ||
} | ||
|
||
public function update(ProviderRequest $request, Provider $provider): void | ||
{ | ||
$provider->update($request->validated()); | ||
|
||
$imageName = $this->getFilename($request); | ||
$storageImagePath = storage_path("app/public/providers/" . $imageName); | ||
$resourceImagePath = resource_path("providers/" . $imageName); | ||
$imageContents = $request->file("file")->get(); | ||
|
||
if (file_exists($resourceImagePath)) { | ||
file_put_contents($resourceImagePath, $imageContents); | ||
Storage::put($storageImagePath, file_get_contents($imageContents)); | ||
} else { | ||
Storage::put($storageImagePath, file_get_contents($imageContents)); | ||
} | ||
} | ||
|
||
public function destroy(Provider $provider): void | ||
{ | ||
$provider->delete(); | ||
$imagePath = storage_path("app/public/providers/" . strtolower($provider["name"]) . ".png"); | ||
File::delete($imagePath); | ||
} | ||
|
||
public function showLogo(string $filename): InertiaResponse | ||
{ | ||
$imagePath = storage_path("app/public/providers/" . $filename); | ||
|
||
if (!file_exists($imagePath)) { | ||
$imagePath = storage_path("app/public/providers/unknown.png"); | ||
} | ||
|
||
return response(file_get_contents($imagePath), 200, ["Content-Type" => "image/png"]); | ||
} | ||
|
||
public function getFilename(ProviderRequest $request): string | ||
{ | ||
return strtolower($request["name"]) . "." . $request->file("file")->getClientOriginalExtension(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
app/Http/Controllers/Api/Admin/CityAlternativeNameController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers\Api\Admin; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\CityAlternativeNameRequest; | ||
use App\Models\CityAlternativeName; | ||
use Illuminate\Http\JsonResponse; | ||
|
||
class CityAlternativeNameController extends Controller | ||
{ | ||
public function store(CityAlternativeNameRequest $request): JsonResponse | ||
{ | ||
CityAlternativeName::query()->create($request->validated()); | ||
|
||
return response()->json(["message" => __("City alternative name created successfully.")], 201); | ||
} | ||
|
||
public function destroy(CityAlternativeName $cityAlternativeName): JsonResponse | ||
{ | ||
$cityAlternativeName->delete(); | ||
|
||
return response()->json(["message" => __("City alternative name deleted successfully.")]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers\Api\Admin; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\CityRequest; | ||
use App\Http\Resources\CityResource; | ||
use App\Http\Resources\CityWithoutAssignedCountryResource; | ||
use App\Http\Resources\CountryResource; | ||
use App\Http\Resources\ProviderResource; | ||
use App\Models\City; | ||
use App\Models\CityWithoutAssignedCountry; | ||
use App\Models\Country; | ||
use App\Models\Provider; | ||
use Illuminate\Http\JsonResponse; | ||
|
||
class CityController extends Controller | ||
{ | ||
public function index(): JsonResponse | ||
{ | ||
$cities = City::query() | ||
->with("cityAlternativeNames", "cityProviders", "country") | ||
->orderByProvidersCount() | ||
->searchCityNames() | ||
->orderByName() | ||
->orderByCountry() | ||
->orderByTimeRange() | ||
->orderByEmptyCoordinates() | ||
->paginate(15) | ||
->withQueryString(); | ||
|
||
$providers = Provider::all(); | ||
$countries = Country::all(); | ||
|
||
$citiesWithoutAssignedCountry = CityWithoutAssignedCountry::all(); | ||
|
||
return response()->json([ | ||
"cities" => CityResource::collection($cities), | ||
"providers" => ProviderResource::collection($providers), | ||
"countries" => CountryResource::collection($countries), | ||
"citiesWithoutAssignedCountry" => CityWithoutAssignedCountryResource::collection($citiesWithoutAssignedCountry), | ||
]); | ||
} | ||
|
||
public function store(CityRequest $request): JsonResponse | ||
{ | ||
City::query()->create($request->validated()); | ||
|
||
return response()->json(["message" => __("City created successfully.")], 201); | ||
} | ||
|
||
public function update(CityRequest $request, City $city): JsonResponse | ||
{ | ||
$city->update($request->validated()); | ||
|
||
return response()->json(["message" => __("City updated successfully.")]); | ||
} | ||
|
||
public function destroy(City $city): JsonResponse | ||
{ | ||
$city->delete(); | ||
|
||
return response()->json(["message" => __("City deleted successfully.")]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers\Api\Admin; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\CountryRequest; | ||
use App\Http\Resources\CountryResource; | ||
use App\Models\Country; | ||
use Illuminate\Http\JsonResponse; | ||
|
||
class CountryController extends Controller | ||
{ | ||
public function index(): JsonResponse | ||
{ | ||
$countries = Country::query() | ||
->search("name") | ||
->orderByName() | ||
->orderByTimeRange() | ||
->paginate(15) | ||
->withQueryString(); | ||
|
||
return response()->json([ | ||
"countries" => CountryResource::collection($countries), | ||
]); | ||
} | ||
|
||
public function store(CountryRequest $request): JsonResponse | ||
{ | ||
Country::query()->create($request->validated()); | ||
|
||
return response()->json(["message" => __("Country created successfully.")], 201); | ||
} | ||
|
||
public function update(CountryRequest $request, Country $country): JsonResponse | ||
{ | ||
$country->update($request->validated()); | ||
|
||
return response()->json(["message" => __("Country updated successfully.")]); | ||
} | ||
|
||
public function destroy(Country $country): JsonResponse | ||
{ | ||
$country->delete(); | ||
|
||
return response()->json(["message" => __("Country deleted successfully.")]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers\Api\Admin; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Resources\ImportInfoResource; | ||
use App\Models\Code; | ||
use App\Models\ImportInfo; | ||
use App\Models\Provider; | ||
use Illuminate\Http\JsonResponse; | ||
|
||
class ImportInfoController extends Controller | ||
{ | ||
public function index(): JsonResponse | ||
{ | ||
$importInfo = ImportInfo::query() | ||
->with("importInfoDetails") | ||
->orderByDesc("created_at") | ||
->paginate(15) | ||
->withQueryString(); | ||
$codes = Code::all(); | ||
$providers = Provider::all(); | ||
|
||
return response()->json([ | ||
"importInfo" => ImportInfoResource::collection($importInfo), | ||
"codes" => $codes, | ||
"providers" => $providers, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers\Api\Admin; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\ProviderRequest; | ||
use App\Http\Resources\ProviderResource; | ||
use App\Models\Provider; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Support\Facades\File; | ||
use Illuminate\Support\Facades\Storage; | ||
use Symfony\Component\HttpFoundation\File\UploadedFile; | ||
|
||
class ProviderController extends Controller | ||
{ | ||
public const ITEMS_PER_PAGE = 15; | ||
|
||
public function index(): JsonResponse | ||
{ | ||
$providers = Provider::query() | ||
->search("name") | ||
->orderByName() | ||
->orderByTimeRange() | ||
->paginate(self::ITEMS_PER_PAGE) | ||
->withQueryString(); | ||
|
||
return response()->json([ | ||
"providers" => ProviderResource::collection($providers), | ||
]); | ||
} | ||
|
||
public function store(ProviderRequest $request): JsonResponse | ||
{ | ||
Provider::query()->create($request->validated()); | ||
|
||
$fileName = $this->getFilename($request->name, $request->file("file")); | ||
$fileContents = $request->file("file")->get(); | ||
|
||
Storage::disk("public")->put("providers/" . $fileName, $fileContents); | ||
|
||
return response()->json(["message" => __("Provider created successfully.")], 201); | ||
} | ||
|
||
public function update(ProviderRequest $request, Provider $provider): JsonResponse | ||
{ | ||
$provider->update($request->validated()); | ||
|
||
$imageName = $this->getFilename($request->name, $request->file("file")); | ||
$storageImagePath = storage_path("app/public/providers/" . $imageName); | ||
$resourceImagePath = resource_path("providers/" . $imageName); | ||
$imageContents = $request->file("file")->get(); | ||
|
||
if (file_exists($resourceImagePath)) { | ||
file_put_contents($resourceImagePath, $imageContents); | ||
Storage::put($storageImagePath, file_get_contents($imageContents)); | ||
} else { | ||
Storage::put($storageImagePath, file_get_contents($imageContents)); | ||
} | ||
|
||
return response()->json(["message" => __("Provider updated successfully.")]); | ||
} | ||
|
||
public function destroy(Provider $provider): JsonResponse | ||
{ | ||
$provider->delete(); | ||
$imagePath = storage_path("app/public/providers/" . strtolower($provider["name"]) . ".png"); | ||
File::delete($imagePath); | ||
|
||
return response()->json(["message" => __("Provider deleted successfully.")]); | ||
} | ||
|
||
public function showLogo(string $filename): JsonResponse | ||
{ | ||
$imagePath = storage_path("app/public/providers/" . $filename); | ||
|
||
if (!file_exists($imagePath)) { | ||
$imagePath = storage_path("app/public/providers/unknown.png"); | ||
} | ||
|
||
$imageData = base64_encode(file_get_contents($imagePath)); | ||
|
||
return response()->json([ | ||
"image" => $imageData, | ||
"mime_type" => "image/png", | ||
]); | ||
} | ||
|
||
private function getFilename(string $name, UploadedFile $file): string | ||
{ | ||
return strtolower($name) . "." . $file->getClientOriginalExtension(); | ||
} | ||
} |
Oops, something went wrong.