Skip to content
This repository was archived by the owner on Dec 3, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 151 commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
68e8220
Implement login and register, localization feature
PrabuckiDominik Jun 13, 2025
cb3a938
Remove suffix
PrabuckiDominik Jun 13, 2025
478614b
Fix workflow test
PrabuckiDominik Jun 13, 2025
c4cc684
Add .env.ci
PrabuckiDominik Jun 13, 2025
476f850
Try to fix workflow
PrabuckiDominik Jun 13, 2025
75ed108
Try to fix workflow
PrabuckiDominik Jun 13, 2025
b187077
Try to fix workflow
PrabuckiDominik Jun 13, 2025
627985f
Implement reset password, add Spatie's activity log
PrabuckiDominik Jun 16, 2025
e9075b5
Fix TestCase
PrabuckiDominik Jun 16, 2025
6c06208
Fix workflow test's warnings
PrabuckiDominik Jun 16, 2025
0b8d97b
Fix workflow test's warnings
PrabuckiDominik Jun 16, 2025
4080f09
Add organization
PrabuckiDominik Jun 16, 2025
cd29821
Implement facebook login with tests
Jun 16, 2025
33fea8f
Unification of declaring Response as Status
PrabuckiDominik Jun 16, 2025
ebc9be1
Unification of declaring Response as Status
PrabuckiDominik Jun 16, 2025
0c0da65
Implement facebook login with tests
Jun 16, 2025
7ce97e7
Change property type for user id
PrabuckiDominik Jun 16, 2025
f407303
Fix
Jun 16, 2025
099b6e7
Factory update
Jun 16, 2025
56509a3
Fix fail a login message
PrabuckiDominik Jun 16, 2025
c272a66
Fix fail a login message
PrabuckiDominik Jun 16, 2025
c22bfde
Merge branch '8-add-authentication' of https://github.com/blumilksoft…
PrabuckiDominik Jun 16, 2025
ccc30af
Fix rules, change name for first name and last name in a user model
PrabuckiDominik Jun 17, 2025
6c0931e
Fix response for existing or non-existing mail while sending reset pa…
PrabuckiDominik Jun 17, 2025
2e98425
Merge branch '8-add-authentication' of https://github.com/blumilksoft…
PrabuckiDominik Jun 17, 2025
b08535e
Add event model
PrabuckiDominik Jun 17, 2025
e8a9a44
Add seeder
PrabuckiDominik Jun 17, 2025
034dcb9
fix and remove avatar
Jun 18, 2025
2a7fbd3
Add Email Verification Controller
PrabuckiDominik Jun 18, 2025
709835f
Fix adaptation to Code Review
PrabuckiDominik Jun 18, 2025
5171231
Fix typo
PrabuckiDominik Jun 18, 2025
a5c5c96
Fix typo
PrabuckiDominik Jun 18, 2025
c2251ba
Fix adjusted to code review
PrabuckiDominik Jun 18, 2025
9c3f7e2
Remove useless permission function
PrabuckiDominik Jun 18, 2025
dd81354
merge with 08
Jun 18, 2025
5f0ca90
Move Notification::fake to setUp() in TestCase
PrabuckiDominik Jun 18, 2025
a764c1f
Merge branch '8-add-authentication' of https://github.com/blumilksoft…
Jun 18, 2025
5e87c1a
merge fixes
Jun 18, 2025
debf707
verify email fix
Jun 18, 2025
1cb1344
add profile and password management with tests
Jun 23, 2025
6fbac51
Merge branch '12-user-profile---backend' into 16-crud-for-users---bac…
Jun 23, 2025
db99f04
Fix adaptation to Code Review
PrabuckiDominik Jun 24, 2025
41bfdfb
Fix permission import
PrabuckiDominik Jun 24, 2025
b89bebd
Fix permission import
PrabuckiDominik Jun 24, 2025
f52f1bd
Merge branch 'main' of https://github.com/blumilksoftware/interns2025…
PrabuckiDominik Jun 24, 2025
9cd1a98
Merge branch '8-add-authentication' of https://github.com/blumilksoft…
PrabuckiDominik Jun 24, 2025
7368847
Merge branch '15-organization-model' of https://github.com/blumilksof…
PrabuckiDominik Jun 24, 2025
6f05d10
Remove .cache and fix code style
PrabuckiDominik Jun 24, 2025
a14de99
Merge 3 migrations into 1, fix tests
PrabuckiDominik Jun 24, 2025
96c6a4f
Fix role seeder
PrabuckiDominik Jun 24, 2025
7979a6a
Update database/migrations/2025_06_16_070140_create_activity_log_tabl…
PrabuckiDominik Jun 24, 2025
a666a63
Implement User Management CRUD, refine validation, and update depende…
Jun 24, 2025
6f7ea17
Add Admin Management CRUD with validation and resources
Jun 24, 2025
c419df0
Add return type, unification style in request
PrabuckiDominik Jun 25, 2025
4b1255c
Merge branch '8-add-authentication' of https://github.com/blumilksoft…
PrabuckiDominik Jun 25, 2025
077e28c
Merge branch '8-add-authentication' of https://github.com/blumilksoft…
PrabuckiDominik Jun 25, 2025
7f1241e
Remove unnecessary authorize function
PrabuckiDominik Jun 25, 2025
c79ec87
Merge branch '8-add-authentication' of https://github.com/blumilksoft…
PrabuckiDominik Jun 25, 2025
1b87b4b
Remove unnecessary variable, fix function in factory
PrabuckiDominik Jun 25, 2025
afc8b39
Fix function name in user factory
PrabuckiDominik Jun 25, 2025
3348dab
Add details for certain event
PrabuckiDominik Jun 25, 2025
17e17a4
Refactor Admin and User Management for streamlined role handling, upd…
Jun 25, 2025
0bae801
Merge branch 'main' of https://github.com/blumilksoftware/interns2025…
PrabuckiDominik Jun 25, 2025
f14c69f
Fix field in OrganizationFactory
PrabuckiDominik Jun 25, 2025
51c0243
Merge branch 'main' of https://github.com/blumilksoftware/interns2025…
Jun 25, 2025
eec729d
Apply suggestions from code review
PrabuckiDominik Jun 25, 2025
c7edb1c
Apply suggestions from code review
PrabuckiDominik Jun 25, 2025
6f40241
Merge branch 'main' of https://github.com/blumilksoftware/interns2025…
PrabuckiDominik Jun 25, 2025
e0d6a0b
Merge branch '15-organization-model' of https://github.com/blumilksof…
PrabuckiDominik Jun 25, 2025
b8446ba
Refactor Event model queries in EventController.
PrabuckiDominik Jun 26, 2025
78c0553
Refactor migrations to use `foreignIdFor` syntax replacing `foreignId`
PrabuckiDominik Jun 27, 2025
0e98908
Refactor `OrganizationController` to use `OrganizationResource` and s…
PrabuckiDominik Jun 27, 2025
79ebabf
Merge branch '15-organization-model' of https://github.com/blumilksof…
PrabuckiDominik Jun 27, 2025
956a82b
Refactor `EventController` to use `EventResource` for consistent and …
PrabuckiDominik Jun 27, 2025
d8a2f85
Refactor `EventFactory` to ensure proper method usage for faker attri…
PrabuckiDominik Jun 27, 2025
70ed748
Merge branch 'main' of https://github.com/blumilksoftware/interns2025…
PrabuckiDominik Jun 30, 2025
201f60a
Specify return type for user mapping in `OrganizationResource`.
PrabuckiDominik Jun 30, 2025
0f816ac
Merge branch '15-organization-model' of https://github.com/blumilksof…
PrabuckiDominik Jul 1, 2025
d2175b8
Merge branch '16-crud-for-users---backend' into 29-crud-for-events---…
Jul 1, 2025
a33603c
Merge branch 'main' of https://github.com/blumilksoftware/interns2025…
PrabuckiDominik Jul 1, 2025
035fc7d
Add Event Management with CRUD operations, validation, policies, and …
Jul 2, 2025
a8676fc
Refactor `Event` model, migrations, and related resources to utilize …
PrabuckiDominik Jul 2, 2025
5b1724f
Apply suggestions from code review
PrabuckiDominik Jul 2, 2025
c09ff5d
Add `laravel/socialite` dependency to composer.json
PrabuckiDominik Jul 2, 2025
2421d22
Update composer.lock with dependency
PrabuckiDominik Jul 2, 2025
37998b8
Merge branch 'main' of https://github.com/blumilksoftware/interns2025…
Jul 2, 2025
6e4118b
Merge branch '22-event-model' of https://github.com/blumilksoftware/i…
Jul 2, 2025
ff56387
Merge branch 'main' of https://github.com/blumilksoftware/interns2025…
Jul 2, 2025
cf3a732
Enhance UserManagementControllerTest with stricter JSON assertions fo…
Jul 2, 2025
103c798
merge fixes
Jul 2, 2025
65db078
Add Organization-specific Event Management with CRUD operations, role…
Jul 2, 2025
8913631
Merge remote-tracking branch 'origin/29-crud-for-events---backend' in…
Jul 3, 2025
f0b0b5f
Remove AdminEventController, update EventPolicy with admin role check…
Jul 3, 2025
22bd981
Update EventRequest validation, add `authorize` method, and enhance E…
Jul 3, 2025
049116f
Replace hardcoded messages with translatable strings for UserManageme…
Jul 3, 2025
3ef0756
Merge branch 'main' of https://github.com/blumilksoftware/interns2025…
Jul 3, 2025
e1376b0
Refactor Admin and User management tests for consistency by reusing s…
Jul 3, 2025
d65c578
Refactor User query in UserManagementController for consistency and r…
Jul 3, 2025
ec39b1d
Enhance User and Admin tests with additional edge case validations an…
Jul 3, 2025
d87c7ac
Merge branch 'main' of https://github.com/blumilksoftware/interns2025…
Jul 4, 2025
ba6cf67
Add tests for multi-organization user creation and not found response…
Jul 4, 2025
4059b46
Update profile validation rules, adjust admin routes, and remove unus…
Jul 4, 2025
d10a8f4
Update profile validation rules, adjust admin routes, and remove unus…
Jul 4, 2025
0eb0c54
Refactor Admin and UserManagementController to utilize RegisterUserAc…
Jul 7, 2025
c67ad34
Fix adjusted to code review
Jul 7, 2025
611abdf
Resource fix
Jul 7, 2025
5e6664f
Merge branch 'main' of https://github.com/blumilksoftware/interns2025…
Jul 7, 2025
4ffbcb1
Merge branch '16-crud-for-users---backend' of https://github.com/blum…
Jul 7, 2025
3e9022d
Add OrganizationEventController tests and implement comprehensive CRU…
Jul 7, 2025
85e36a0
Merge branch 'main' of https://github.com/blumilksoftware/interns2025…
Jul 16, 2025
e364580
Add and schedule UpdateEventStatuses command with tests and EventReso…
Jul 16, 2025
598acb4
Add pagination to EventController index endpoint and update related t…
Jul 17, 2025
937eb51
Merge
Jul 18, 2025
5d2c362
Localize event-related responses and enhance OrganizationEventControl…
Jul 18, 2025
97ba1b2
Refactor OrganizationEventController to use authorization policies; u…
Jul 18, 2025
bb82d7f
Remove unused AuthServiceProvider and related policy registration.
Jul 18, 2025
030a3e9
Refactor OrganizationEventControllerTest to streamline setup and reus…
Jul 18, 2025
bb9404b
Update routes/api.php
AKasprzy Jul 18, 2025
4597d19
Merge branch 'main' of https://github.com/blumilksoftware/interns2025…
Jul 18, 2025
0267a7c
Merge remote-tracking branch 'origin/29-crud-for-events---backend' in…
Jul 18, 2025
ce2a94c
Merge remote-tracking branch 'origin/29-crud-for-events---backend' in…
Jul 18, 2025
931b097
Merge remote-tracking branch 'origin/29-crud-for-events---backend' in…
Jul 18, 2025
7b470a3
Refactor `OrganizationEventController` to streamline request handling…
Jul 18, 2025
c7f27c5
Refactor routes and tests: remove duplicate user route, update test p…
Jul 18, 2025
974fdd5
Add latitude and longitude generation to EventSeeder for randomly ass…
Jul 18, 2025
5b8576d
Add return types to latitude and longitude closures in EventSeeder fo…
Jul 18, 2025
975a2fb
Apply suggestions from code review
AKasprzy Jul 21, 2025
14aa9f6
Refactor event request validation and route definitions; improve type…
Jul 21, 2025
385b926
Refactor event-organization relationship: add pivot table and streaml…
Jul 21, 2025
e1b727a
Merge branch 'main' of https://github.com/blumilksoftware/interns2025…
Jul 22, 2025
bf1dfd0
Introduce request throttling for account deletion, password updates, …
Jul 22, 2025
f19cfd0
Add validation restricting users to one active event; update tests an…
Jul 22, 2025
10b24b3
Update deletion confirmation route to GET; adjust test and translatio…
Jul 22, 2025
4489c45
Refactor event test setup to reuse a shared `$event` instance. Optimi…
Jul 23, 2025
5aa8863
Update tests/Feature/OrganizationInvitationTest.php
AKasprzy Jul 23, 2025
ab4223e
Refactor tests to use `createPublishedEventForUser` helper; introduce…
Jul 23, 2025
c15e4dd
Merge remote-tracking branch 'origin/40-permissions' into 40-permissions
Jul 23, 2025
389eaa7
Refactor tests to use `createPublishedEventForUser` helper; introduce…
Jul 24, 2025
3397181
Refactor throttling logic into `ThrottleAction`; simplify controllers…
AKasprzy Jul 24, 2025
4f871eb
Refactor throttling logic into `ThrottleAction`; simplify controllers…
Jul 21, 2025
c777627
Refactor throttling logic into `ThrottleAction`; simplify controllers…
AKasprzy Jul 25, 2025
36e9923
Add reporting feature with daily throttling and polymorphic relations…
AKasprzy Jul 25, 2025
1c8936c
Merge branch 'main' of https://github.com/blumilksoftware/interns2025…
AKasprzy Jul 27, 2025
435533e
Merge branch 'main' of https://github.com/blumilksoftware/interns2025…
AKasprzy Jul 29, 2025
b77a1de
Add reporting system with polymorphic support, APIs, and admin report…
AKasprzy Jul 30, 2025
a9239d1
Apply suggestions from code review
AKasprzy Jul 30, 2025
7238778
Apply suggestions from code review
AKasprzy Jul 30, 2025
9620294
Refactor routes and remove unnecessary whitespace in `StoreReportRequ…
AKasprzy Jul 30, 2025
85909b5
Extract report messages to language files and update `ReportControlle…
AKasprzy Jul 30, 2025
7b23849
Refactor `ReportController`, simplify `Report` model logic, and updat…
AKasprzy Jul 30, 2025
2ab970f
Remove unused `Carbon` import and adjust whitespace formatting in `Re…
AKasprzy Jul 30, 2025
c349a59
Merge branch 'main' of https://github.com/blumilksoftware/interns2025…
AKasprzy Jul 30, 2025
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
78 changes: 78 additions & 0 deletions app/Http/Controllers/ReportController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

declare(strict_types=1);

namespace Interns2025b\Http\Controllers;

use Illuminate\Http\JsonResponse;
use Interns2025b\Http\Requests\StoreReportRequest;
use Interns2025b\Http\Resources\ReportResource;
use Interns2025b\Models\Event;
use Interns2025b\Models\Organization;
use Interns2025b\Models\Report;
use Interns2025b\Models\User;
use Symfony\Component\HttpFoundation\Response as Status;

class ReportController
{
public function store(StoreReportRequest $request): JsonResponse
{
$user = $request->user();

$type = match ($request->input("type")) {
"user" => User::class,
"organization" => Organization::class,
"event" => Event::class,
};
Comment on lines +18 to +26
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

The type mapping logic is duplicated in three methods (store, userReports, organizationReports, eventReports). Consider extracting this into a private method or constant to reduce duplication.

Suggested change
public function store(StoreReportRequest $request): JsonResponse
{
$user = $request->user();
$type = match ($request->input("type")) {
"user" => User::class,
"organization" => Organization::class,
"event" => Event::class,
};
private const TYPE_USER = User::class;
private const TYPE_ORGANIZATION = Organization::class;
private const TYPE_EVENT = Event::class;
private function _getTypeMapping(string $type): string
{
return match ($type) {
"user" => self::TYPE_USER,
"organization" => self::TYPE_ORGANIZATION,
"event" => self::TYPE_EVENT,
default => throw new \InvalidArgumentException("Invalid type: $type"),
};
}
public function store(StoreReportRequest $request): JsonResponse
{
$user = $request->user();
$type = $this->_getTypeMapping($request->input("type"));

Copilot uses AI. Check for mistakes.

$alreadyReported = Report::alreadyReportedToday(
$user->id,
$type,
(int)$request->input("id"),
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

The controller doesn't validate that the reported entity exists before creating the report. This could lead to reports for non-existent entities.

Copilot uses AI. Check for mistakes.
);

if ($alreadyReported) {
return response()->json([
"message" => __("report.already_reported"),
], Status::HTTP_TOO_MANY_REQUESTS);
}

Report::create([
"reporter_id" => $user->id,
"reportable_type" => $type,
"reportable_id" => $request->input("id"),
"reason" => $request->input("reason"),
]);

return response()->json([
"message" => __("report.success"),
], Status::HTTP_OK);
}

public function userReports(): JsonResponse
{
return response()->json([
"data" => ReportResource::collection(
Report::query()->where("reportable_type", User::class)->latest()->get(),
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

Using get() without pagination could cause performance issues when there are many reports. Consider implementing pagination for these admin endpoints.

Suggested change
Report::query()->where("reportable_type", User::class)->latest()->get(),
Report::query()->where("reportable_type", User::class)->latest()->paginate($request->query('per_page', 15)),

Copilot uses AI. Check for mistakes.
),
], Status::HTTP_OK);
}

public function organizationReports(): JsonResponse
{
return response()->json([
"data" => ReportResource::collection(
Report::query()->where("reportable_type", Organization::class)->latest()->get(),
),
], Status::HTTP_OK);
}

public function eventReports(): JsonResponse
{
return response()->json([
"data" => ReportResource::collection(
Report::query()->where("reportable_type", Event::class)->latest()->get(),
Comment on lines +54 to +74
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

Using get() without pagination could cause performance issues when there are many reports. Consider implementing pagination for these admin endpoints.

Suggested change
return response()->json([
"data" => ReportResource::collection(
Report::query()->where("reportable_type", User::class)->latest()->get(),
),
], Status::HTTP_OK);
}
public function organizationReports(): JsonResponse
{
return response()->json([
"data" => ReportResource::collection(
Report::query()->where("reportable_type", Organization::class)->latest()->get(),
),
], Status::HTTP_OK);
}
public function eventReports(): JsonResponse
{
return response()->json([
"data" => ReportResource::collection(
Report::query()->where("reportable_type", Event::class)->latest()->get(),
$perPage = request()->query('per_page', 15);
return response()->json([
"data" => ReportResource::collection(
Report::query()->where("reportable_type", User::class)->latest()->paginate($perPage),
),
], Status::HTTP_OK);
}
public function organizationReports(): JsonResponse
{
$perPage = request()->query('per_page', 15);
return response()->json([
"data" => ReportResource::collection(
Report::query()->where("reportable_type", Organization::class)->latest()->paginate($perPage),
),
], Status::HTTP_OK);
}
public function eventReports(): JsonResponse
{
$perPage = request()->query('per_page', 15);
return response()->json([
"data" => ReportResource::collection(
Report::query()->where("reportable_type", Event::class)->latest()->paginate($perPage),

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

Using get() without pagination could cause performance issues when there are many reports. Consider implementing pagination for these admin endpoints.

Suggested change
Report::query()->where("reportable_type", Event::class)->latest()->get(),
Report::query()->where("reportable_type", Event::class)->latest()->paginate(15),

Copilot uses AI. Check for mistakes.
),
], Status::HTTP_OK);
}
}
19 changes: 19 additions & 0 deletions app/Http/Requests/StoreReportRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace Interns2025b\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class StoreReportRequest extends FormRequest
{
public function rules(): array
{
return [
"type" => "required|in:user,organization,event",
"id" => "required|integer",
"reason" => "nullable|string|max:1000",
];
}
}
22 changes: 22 additions & 0 deletions app/Http/Resources/ReportResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Interns2025b\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class ReportResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
"id" => $this->id,
"reporter_id" => $this->reporter_id,
"reportable_type" => class_basename($this->reportable_type),
"reportable_id" => $this->reportable_id,
"reason" => $this->reason,
];
}
}
44 changes: 44 additions & 0 deletions app/Models/Report.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace Interns2025b\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;

/**
* @property int $reporter_id
* @property string $reportable_type
* @property int $reportable_id
* @property string $reason
* @property Model|MorphTo $reportable
*/
class Report extends Model
{
use HasFactory;

protected $fillable = [
"reporter_id",
"reportable_type",
"reportable_id",
"reason",
];

public function reportable(): MorphTo
{
return $this->morphTo();
}

public static function alreadyReportedToday(int $reporterId, string $reportableType, int $reportableId): bool
{
return static::query()
->where("reporter_id", $reporterId)
->where("reportable_type", $reportableType)
->where("reportable_id", $reportableId)
->whereDate("created_at", Carbon::today())
->exists();
}
}
5 changes: 5 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ public function followers(): MorphToMany
);
}

public function reports(): HasMany
{
return $this->hasMany(Report::class, "reporter_id");
}

protected function casts(): array
{
return [
Expand Down
37 changes: 37 additions & 0 deletions database/factories/ReportFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use Interns2025b\Models\Event;
use Interns2025b\Models\Organization;
use Interns2025b\Models\Report;
use Interns2025b\Models\User;

class ReportFactory extends Factory
{
protected $model = Report::class;

public function definition(): array
{
$reportables = [
User::class,
Organization::class,
Event::class,
];

$reportableType = $this->faker->randomElement($reportables);
$reportableId = $reportableType::factory()->create()->id;

return [
"reporter_id" => User::factory()->create()->id,
"reportable_type" => $reportableType,
"reportable_id" => $reportableId,
"reason" => $this->faker->sentence(),
"created_at" => now(),
"updated_at" => now(),
];
}
}
32 changes: 32 additions & 0 deletions database/migrations/2025_07_25_082312_create_reports_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration {
public function up(): void
{
Schema::create("reports", function (Blueprint $table): void {
$table->id();
$table->foreignId("reporter_id")->constrained("users")->cascadeOnDelete();
$table->morphs("reportable");
$table->text("reason")->nullable();
$table->timestamps();

$table->unique([
"reporter_id",
"reportable_type",
"reportable_id",
"created_at",
Comment on lines +18 to +23
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

The unique constraint includes 'created_at' which is a timestamp. This will not effectively prevent duplicate reports on the same day since 'created_at' includes time components. The constraint should use a date-based approach or the logic should rely on application-level checking only.

Suggested change
$table->unique([
"reporter_id",
"reportable_type",
"reportable_id",
"created_at",
$table->date("created_date")->virtualAs("DATE(created_at)");
$table->unique([
"reporter_id",
"reportable_type",
"reportable_id",
"created_date",

Copilot uses AI. Check for mistakes.
], "daily_unique_report");
});
}

public function down(): void
{
Schema::dropIfExists("reports");
}
};
8 changes: 8 additions & 0 deletions lang/en/report.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

declare(strict_types=1);

return [
"already_reported" => "You have already reported this today.",
"success" => "Reported successfully.",
];
8 changes: 8 additions & 0 deletions lang/pl/report.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

declare(strict_types=1);

return [
"already_reported" => "Już zgłosiłeś to dzisiaj.",
"success" => "Zgłoszono pomyślnie.",
];
6 changes: 5 additions & 1 deletion routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Interns2025b\Http\Controllers\OrganizationEventController;
use Interns2025b\Http\Controllers\OrganizationInvitationController;
use Interns2025b\Http\Controllers\RegisterController;
use Interns2025b\Http\Controllers\ReportController;
use Interns2025b\Http\Controllers\ResetPasswordController;
use Interns2025b\Http\Controllers\UpdatePasswordController;
use Interns2025b\Http\Controllers\UserDeletionController;
Expand All @@ -40,6 +41,7 @@
Route::post("/events", [EventController::class, "store"]);
Route::put("/events/{event}", [EventController::class, "update"]);
Route::delete("/events/{event}", [EventController::class, "destroy"]);
Route::post("/reports", [ReportController::class, "store"]);

Route::scopeBindings()->group(function (): void {
Route::get("/organizations/{organization}/events", [OrganizationEventController::class, "index"]);
Expand All @@ -48,7 +50,6 @@
Route::delete("/organizations/{organization}/events/{event}", [OrganizationEventController::class, "destroy"]);
});
});

Route::get("/confirm-delete/{user}", [UserDeletionController::class, "confirmDelete"])
->middleware("signed")
->name("api.confirmDelete");
Expand Down Expand Up @@ -81,6 +82,9 @@
Route::put("/users/{user}", [UserManagementController::class, "update"])->name("users.update");
Route::delete("/users/{user}", [UserManagementController::class, "destroy"])->name("users.destroy");
Route::resource("organizations", OrganizationController::class);
Route::get("/reports/users", [ReportController::class, "userReports"]);
Route::get("/reports/organizations", [ReportController::class, "organizationReports"]);
Route::get("/reports/events", [ReportController::class, "eventReports"]);
});

Route::group(["middleware" => ["auth:sanctum", "role:superAdministrator"]], function (): void {
Expand Down
Loading