Skip to content
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
18 changes: 18 additions & 0 deletions app/Actions/Auction/AddImageToAuctionAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace Otoszroto\Actions\Auction;

use Illuminate\Http\UploadedFile;
use Otoszroto\Models\Auction;

class AddImageToAuctionAction
{
public function execute(Auction $auction, UploadedFile $uploadedFile): bool
{
$stored = $uploadedFile->storeAs("", $auction->id . ".png", "auctionImage");

return $stored !== false;
}
}
21 changes: 21 additions & 0 deletions app/Actions/Auction/GetAuctionImageAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Otoszroto\Actions\Auction;

use Illuminate\Support\Facades\Storage;

class GetAuctionImageAction
{
public function execute(int $auctionId): ?string
{
$filename = $auctionId . ".png";

if (Storage::disk("auctionImage")->exists($filename)) {
return Storage::disk("auctionImage")->get($filename);
}

return null;
}
}
21 changes: 21 additions & 0 deletions app/Actions/Auction/GetDefaultAuctionImageAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

namespace Otoszroto\Actions\Auction;

use Illuminate\Support\Facades\Storage;

class GetDefaultAuctionImageAction
{
public function execute(): ?string
{
$filename = "default.png";

if (Storage::disk("auctionImage")->exists($filename)) {
return Storage::disk("auctionImage")->get($filename);
}

return null;
}
}
39 changes: 39 additions & 0 deletions app/Helpers/IdenticonHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace Otoszroto\Helpers;

use Identicon\Identicon;
use Illuminate\Support\Facades\Storage;

class IdenticonHelper
{
private Identicon $identicon;

public function __construct()
{
$this->identicon = new Identicon();
}

public static function url(string|int $name): string
{
return url("/auctions/{$name}/image");
}

public function create(string|int $filename, string $data): string
{
$image = $this->identicon->getImageData($data, 300);

return $this->save($filename, $image);
}

private function save(string|int $name, string $imageData): string
{
$path = $name . ".png";

Storage::disk("avatars")->put($path, $imageData);

return Storage::disk("avatars")->url($path);
Comment on lines +35 to +37
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The disk configuration references a disk named "auctionImage" in the filesystem config, but the IdenticonHelper class incorrectly uses the disk name "avatars". This will cause a runtime error when trying to save identicon images.

Suggested change
Storage::disk("avatars")->put($path, $imageData);
return Storage::disk("avatars")->url($path);
Storage::disk("auctionImage")->put($path, $imageData);
return Storage::disk("auctionImage")->url($path);

Copilot uses AI. Check for mistakes.
}
}
23 changes: 21 additions & 2 deletions app/Http/Controllers/Auction/AuctionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;
use Otoszroto\Actions\Auction\AddImageToAuctionAction;
use Otoszroto\Actions\Auction\CancelAuctionAction;
use Otoszroto\Actions\Auction\CreateAuctionAction;
use Otoszroto\Actions\Auction\FinishAuctionAction;
use Otoszroto\Actions\Auction\GetAuctionImageAction;
use Otoszroto\Actions\Auction\GetDefaultAuctionImageAction;
use Otoszroto\Actions\Auction\UpdateAuctionAction;
use Otoszroto\Enums\AuctionState;
use Otoszroto\Helpers\SortHelper;
Expand Down Expand Up @@ -41,11 +44,17 @@ public function edit(Auction $auction): Response
return Inertia::render("Auction/EditAuction", ["auction" => $auction]);
}

public function store(CreateAuctionRequest $request, CreateAuctionAction $createAuctionAction): RedirectResponse
public function store(CreateAuctionRequest $request, CreateAuctionAction $createAuctionAction, AddImageToAuctionAction $addImageToAuctionAction): RedirectResponse
{
$user = $request->user();
$validated = $request->validated();
$createAuctionAction->execute($user, $validated);
$auction = $createAuctionAction->execute($user, $validated);
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CreateAuctionAction should return the created Auction instance to support the new image upload flow, but this change is not visible in the diff. Verify that CreateAuctionAction has been updated to return an Auction instance.

Copilot uses AI. Check for mistakes.

$photo = $validated["photo"];

if ($photo) {
$addImageToAuctionAction->execute($auction, $photo);
}

return redirect()->route("auctions.create")->with(["message" => "Aukcja została utworzona."]);
}
Expand Down Expand Up @@ -110,6 +119,16 @@ public function index(SortHelper $sorter, Request $request): Response
]);
}

public function getImage(int $id, GetAuctionImageAction $getAuctionImageAction, GetDefaultAuctionImageAction $getDefaultAuctionImageAction): \Illuminate\Http\Response
{
$image = $getAuctionImageAction->execute($id);
$default = $getDefaultAuctionImageAction->execute();

return response($image ?? $default)
->header("Content-Type", "image/png")
->header("Cache-Control", "max-age=31536000, public");
}

private function filterCategory(Builder $query, Request $request): Builder
{
$category_id = $request->query("category", null);
Expand Down
1 change: 1 addition & 0 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function store(RegisterRequest $request): RedirectResponse
$user->password = Hash::make($validated["password"]);
$user->save();

$user->assignRole(Role::User);
$user->syncPermissions(Role::User->permissions());

return redirect()->route("home")->with(["message" => "Your account has been created."]);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Requests/Auction/CreateAuctionRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public function rules(): array
return [
"name" => ["required", "string", "max:255"],
"description" => ["required", "string", "max:255"],
"photo_url" => ["required", "string", "max:255"],
"city" => ["required", "string", "max:255"],
"price" => ["required", "numeric"],
"model_id" => ["required", "integer", "exists:car_models,id"],
"category_id" => ["required", "integer", "exists:categories,id"],
"condition" => ["required", Rule::enum(Condition::class)],
"photo" => ["image", "mimes:png", "max:2048"],
];
}
}
2 changes: 1 addition & 1 deletion app/Http/Resources/AuctionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function toArray(Request $request): array
"id" => $this->id,
"name" => $this->name,
"description" => $this->description,
"photo" => $this->photo_url,
"photo" => $this->photo,
"price" => $this->price,
"city" => $this->city,
"owner" => UserResource::make($this->owner)->resolve(),
Expand Down
11 changes: 9 additions & 2 deletions app/Models/Auction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
namespace Otoszroto\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Otoszroto\Enums\AuctionState;
use Otoszroto\Enums\Condition;
use Otoszroto\Helpers\IdenticonHelper;

/**
* @property int $id
Expand All @@ -33,7 +35,7 @@ class Auction extends Model
{
use HasFactory;

public $timestamps = true;
public $timestamps = true;
protected $fillable = [
"name",
"description",
Expand All @@ -45,7 +47,7 @@ class Auction extends Model
"category_id",
"condition",
"auction_state",
];
];
protected $casts = [
"condition" => Condition::class,
"auction_state" => AuctionState::class,
Expand Down Expand Up @@ -82,4 +84,9 @@ public function reports()
{
return $this->hasMany(Report::class);
}

protected function photo(): Attribute
{
return Attribute::get(fn(): string => IdenticonHelper::url($this->id));
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"laravel/framework": "^12.20.0",
"laravel/sanctum": "^4.1.2",
"laravel/tinker": "^2.10.1",
"spatie/laravel-permission": "^6.24"
"spatie/laravel-permission": "^6.24",
"yzalis/identicon": "^2.0"
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package "yzalis/identicon" is marked as abandoned in Packagist. Consider using a maintained alternative like "bitverse/identicon" or implementing a custom solution to avoid security and compatibility issues in the future.

Suggested change
"yzalis/identicon": "^2.0"
"bitverse/identicon": "^2.0"

Copilot uses AI. Check for mistakes.
},
"require-dev": {
"blumilksoftware/codestyle": "^v5.0.0",
Expand Down
Loading