Skip to content

Commit

Permalink
Merge branch 'main' into #10-regulations-for-escooters
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubKermes authored Apr 8, 2024
2 parents d46f1e3 + 911b999 commit a94e7f0
Show file tree
Hide file tree
Showing 71 changed files with 1,914 additions and 368 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-and-lint-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- uses: actions/checkout@v4

- name: Cache dependencies
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-npm-dependencies-${{ hashFiles('package.lock') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-and-lint-php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
run: composer validate

- name: Cache dependencies
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-composer-dependencies-${{ hashFiles('composer.lock') }}
Expand Down
1 change: 1 addition & 0 deletions api.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ protected function schedule(Schedule $schedule): void
$service = new DataImporterService();
$service->run("server");
})->monthly();
$schedule->command("sanctum:prune-expired --hours=24")->daily();
}

protected function commands(): void
Expand Down
84 changes: 84 additions & 0 deletions app/Http/Controllers/Admin/ProviderController.php
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 app/Http/Controllers/Api/Admin/CityAlternativeNameController.php
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.")]);
}
}
67 changes: 67 additions & 0 deletions app/Http/Controllers/Api/Admin/CityController.php
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.")]);
}
}
49 changes: 49 additions & 0 deletions app/Http/Controllers/Api/Admin/CountryController.php
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.")]);
}
}
32 changes: 32 additions & 0 deletions app/Http/Controllers/Api/Admin/ImportInfoController.php
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,
]);
}
}
94 changes: 94 additions & 0 deletions app/Http/Controllers/Api/Admin/ProviderController.php
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();
}
}
Loading

0 comments on commit a94e7f0

Please sign in to comment.