-
Notifications
You must be signed in to change notification settings - Fork 0
#5 - Report Listing #44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,22 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Otoszroto\Actions\Auction; | ||
|
|
||
| use Otoszroto\Models\Auction; | ||
| use Otoszroto\Models\Report; | ||
| use Otoszroto\Models\User; | ||
|
|
||
| class CreateReportAction | ||
| { | ||
| public function execute(User $user, Auction $auction, array $reportData): Report | ||
| { | ||
| $report = new Report($reportData); | ||
| $report->reporter->associate($user); | ||
| $report->auction->associate($auction); | ||
| $report->save(); | ||
|
|
||
| return $report; | ||
| } | ||
| } |
This file contains hidden or 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,18 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Otoszroto\Actions\Auction; | ||
|
|
||
| use Otoszroto\Models\Report; | ||
|
|
||
| class ResolveReportAction | ||
| { | ||
| public function execute(Report $report): Report | ||
| { | ||
| $report->resolved_at = now(); | ||
| $report->save(); | ||
|
|
||
| return $report; | ||
| } | ||
| } |
This file contains hidden or 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,65 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Otoszroto\Http\Controllers\Auction; | ||
|
|
||
| use Illuminate\Http\RedirectResponse; | ||
| use Inertia\Inertia; | ||
| use Inertia\Response; | ||
| use Otoszroto\Actions\Auction\CreateReportAction; | ||
| use Otoszroto\Actions\Auction\ResolveReportAction; | ||
| use Otoszroto\Helpers\SortHelper; | ||
| use Otoszroto\Http\Controllers\Controller; | ||
| use Otoszroto\Http\Requests\Auction\CreateReportRequest; | ||
| use Otoszroto\Http\Resources\ReportResource; | ||
| use Otoszroto\Models\Auction; | ||
| use Otoszroto\Models\Report; | ||
|
|
||
| class ReportController extends Controller | ||
| { | ||
| public function create(Auction $auction): Response | ||
| { | ||
| return Inertia::render("Auction/ReportAuction", ["auction" => $auction]); | ||
| } | ||
|
|
||
| public function store(CreateReportRequest $request, CreateReportAction $createReportAction, Auction $auction): RedirectResponse | ||
| { | ||
| $user = $request->user(); | ||
| $this->authorize("report", $auction); | ||
| $validated = $request->validated(); | ||
| $createReportAction->execute($user, $auction, $validated); | ||
|
|
||
| return redirect()->route("auctions.show", ["auction" => $auction])->with(["message" => "Aukcja została zgłoszona."]); | ||
| } | ||
|
|
||
| public function index(SortHelper $sorter): Response | ||
| { | ||
| $reports = Report::query()->with(["reporter", "auction"])->where("resolved_at", "=", null); | ||
|
|
||
| $perPage = (int)request()->query("per_page", 10); | ||
|
|
||
| $query = $sorter->sort($reports, ["id", "created_at"], []); | ||
| $query = $sorter->search($query, "id"); | ||
|
|
||
| return Inertia::render("Auction/Reports", [ | ||
| "reports" => ReportResource::collection($query->paginate($perPage)), | ||
| ]); | ||
| } | ||
|
|
||
| public function show(Report $report): Response | ||
| { | ||
| $report->load(["reporter", "auction"]); | ||
|
|
||
| return Inertia::render("Auction/ShowReport", [ | ||
| "report" => new ReportResource($report), | ||
| ]); | ||
| } | ||
|
|
||
| public function resolve(ResolveReportAction $resolveReportAction, Report $report): RedirectResponse | ||
| { | ||
| $report = $resolveReportAction->execute($report); | ||
|
|
||
| return redirect()->route("reports.show", ["report" => $report])->with(["message" => "Zgłoszenie zostało rozwiązane."]); | ||
| } | ||
| } | ||
This file contains hidden or 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,33 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Otoszroto\Http\Requests\Auction; | ||
|
|
||
| use Illuminate\Contracts\Validation\ValidationRule; | ||
| use Illuminate\Foundation\Http\FormRequest; | ||
|
|
||
| class CreateReportRequest extends FormRequest | ||
| { | ||
| public function authorize(): bool | ||
| { | ||
| $user = $this->user(); | ||
| $auction = $this->route("auction"); | ||
|
|
||
| if ($user === null || $auction === null) { | ||
| return false; | ||
| } | ||
|
|
||
| return $user->can("report", $auction); | ||
| } | ||
|
|
||
| /** | ||
| * @return array<string, ValidationRule|array<mixed>|string> | ||
| */ | ||
| public function rules(): array | ||
| { | ||
| return [ | ||
| "reason" => ["sometimes", "string", "max:255"], | ||
DawBaz15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ]; | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 Otoszroto\Http\Resources; | ||
|
|
||
| use Illuminate\Http\Request; | ||
| use Illuminate\Http\Resources\Json\JsonResource; | ||
|
|
||
| class ReportResource extends JsonResource | ||
| { | ||
| /** | ||
| * @return array<string, mixed> | ||
| */ | ||
| public function toArray(Request $request): array | ||
| { | ||
| return [ | ||
| "id" => $this->id, | ||
| "reporter" => UserResource::make($this->whenLoaded("reporter")), | ||
| "auction" => AuctionResource::make($this->whenLoaded("auction")), | ||
| "reason" => $this->reason, | ||
| "resolvedAt" => optional($this->resolved_at)?->toDateTimeString(), | ||
| "createdAt" => optional($this->created_at)?->toDateTimeString(), | ||
| "updatedAt" => optional($this->updated_at)?->toDateTimeString(), | ||
| ]; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,53 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Otoszroto\Models; | ||
|
|
||
| use Carbon\Carbon; | ||
| use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
| use Illuminate\Database\Eloquent\Model; | ||
| use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
|
|
||
| /** | ||
| * @property int $id | ||
| * @property int $reporter_id | ||
| * @property int $auction_id | ||
| * @property string|null $reason | ||
| * @property Carbon|null $resolved_at | ||
| * @property Carbon $created_at | ||
| * @property Carbon $updated_at | ||
| * @property User $reporter | ||
| * @property Auction $auction | ||
| */ | ||
| class Report extends Model | ||
| { | ||
| use HasFactory; | ||
|
|
||
| public $timestamps = true; | ||
| protected $fillable = [ | ||
| "reporter_id", | ||
| "auction_id", | ||
| "reason", | ||
| "resolved_at", | ||
| ]; | ||
| protected $casts = [ | ||
| "resolved_at" => "datetime", | ||
| ]; | ||
|
|
||
DawBaz15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** | ||
| * @return BelongsTo<User, $this> | ||
| */ | ||
| public function reporter(): BelongsTo | ||
| { | ||
| return $this->belongsTo(User::class, "reporter_id"); | ||
| } | ||
|
|
||
| /** | ||
| * @return BelongsTo<Auction, $this> | ||
| */ | ||
| public function auction(): BelongsTo | ||
| { | ||
| return $this->belongsTo(Auction::class, "auction_id"); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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,26 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Database\Factories; | ||
|
|
||
| use Illuminate\Database\Eloquent\Factories\Factory; | ||
| use Otoszroto\Models\Auction; | ||
| use Otoszroto\Models\Report; | ||
| use Otoszroto\Models\User; | ||
DawBaz15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * @extends Factory<Report> | ||
| */ | ||
| class ReportFactory extends Factory | ||
| { | ||
| public function definition(): array | ||
| { | ||
| return [ | ||
| "reporter_id" => User::factory(), | ||
| "auction_id" => Auction::factory(), | ||
| "reason" => fake()->text(200), | ||
| "resolved_at" => null, | ||
| ]; | ||
| } | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
database/migrations/2026_01_06_155512_create_reports_table.php
This file contains hidden or 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,29 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| use Illuminate\Database\Migrations\Migration; | ||
| use Illuminate\Database\Schema\Blueprint; | ||
| use Illuminate\Support\Facades\Schema; | ||
| use Otoszroto\Models\Auction; | ||
| use Otoszroto\Models\User; | ||
|
|
||
| return new class() extends Migration { | ||
DawBaz15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| public function up(): void | ||
| { | ||
| Schema::create("reports", function (Blueprint $table): void { | ||
| $table->id(); | ||
| $table->foreignIdFor(User::class, "reporter_id")->constrained("users")->cascadeOnDelete(); | ||
| $table->foreignIdFor(Auction::class, "auction_id")->constrained("auctions")->cascadeOnDelete(); | ||
| $table->text("reason")->nullable(); | ||
| $table->timestamp("resolved_at")->nullable(); | ||
| $table->timestamps(); | ||
DawBaz15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $table->unique(["reporter_id", "auction_id"]); | ||
| }); | ||
| } | ||
|
|
||
| public function down(): void | ||
| { | ||
| Schema::dropIfExists("reports"); | ||
| } | ||
| }; | ||
This file contains hidden or 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 hidden or 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,16 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace Database\Seeders; | ||
|
|
||
| use Illuminate\Database\Seeder; | ||
| use Otoszroto\Models\Report; | ||
|
|
||
| class ReportSeeder extends Seeder | ||
| { | ||
| public function run(): void | ||
| { | ||
| Report::factory()->count(30)->create(); | ||
| } | ||
| } |
This file contains hidden or 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,25 @@ | ||
| import React from 'react'; | ||
| import {Form} from "@inertiajs/react"; | ||
| import { Auction } from "@/Types/auction"; | ||
|
|
||
| type Props = { | ||
| errors: any; | ||
| auction: Auction; | ||
| } | ||
|
|
||
| export function ReportAuction({errors, auction}: Props) { | ||
| return ( | ||
| <> | ||
| <h1 className={"text-lg font-semibold"}>Report auction</h1> | ||
| <Form | ||
| action={`/auctions/${auction.id}/report`} | ||
| method="POST" | ||
| > | ||
| <input type="text" placeholder="Reason" name="reason"/> | ||
KacperWalenga marked this conversation as resolved.
Show resolved
Hide resolved
KacperWalenga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| {errors?.reason && <p>{errors.reason}</p>} | ||
|
|
||
| <input type="submit" value="Zgłoś" /> | ||
| </Form> | ||
| </> | ||
| ); | ||
| } | ||
This file contains hidden or 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,22 @@ | ||
| import { Title } from "@/Components/Title"; | ||
| import { Report } from "@/Types/report"; | ||
|
|
||
| type Props = { | ||
| report: Report, | ||
| } | ||
|
|
||
| export function ShowReport({report}: Props) { | ||
| return ( | ||
| <div className='w-full p-4 mt-5 mx-auto md:px-10'> | ||
| <Title type='h2'>Szczegóły zgłoszenia</Title> | ||
|
|
||
| <div><strong>ID:</strong> {report.id}</div> | ||
| <div><strong>Reporter:</strong> {report.reporter?.email || "N/A"}</div> | ||
| <div><strong>Auction:</strong> {report.auction?.name || "N/A"}</div> | ||
| <div><strong>Reason:</strong> {report.reason || "Brak"}</div> | ||
| <div><strong>Resolved At:</strong> {report.resolvedAt || "Nie rozwiązano"}</div> | ||
| <div><strong>Created At:</strong> {report.createdAt}</div> | ||
| <div><strong>Updated At:</strong> {report.updatedAt}</div> | ||
KacperWalenga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| </div> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.