diff --git a/app/Filament/Exports/ParticipantExporter.php b/app/Filament/Exports/ParticipantExporter.php index 7e7daaa..4679caf 100644 --- a/app/Filament/Exports/ParticipantExporter.php +++ b/app/Filament/Exports/ParticipantExporter.php @@ -15,7 +15,7 @@ class ParticipantExporter extends Exporter public static function getColumns(): array { return [ - ExportColumn::make('participant_id'), + ExportColumn::make('lan_id'), ExportColumn::make('first_name'), ExportColumn::make('surname'), ExportColumn::make('grade'), diff --git a/app/Http/Controllers/ParticipantController.php b/app/Http/Controllers/ParticipantController.php index 5f41b88..f9160d8 100644 --- a/app/Http/Controllers/ParticipantController.php +++ b/app/Http/Controllers/ParticipantController.php @@ -14,49 +14,59 @@ class ParticipantController extends Controller */ public function index(Request $request) { - $ability = $request->ability; + $permission = $request->permission; - if ($ability === "key_1") { + if ($permission === "key_1") { $participants = Participant::all()->makeHidden(['comment', 'emailed', 'paid', 'member', 'gdpr']); - $volunteers = Volunteer::all()->makeHidden(['gdpr']); + $volunteers = Volunteer::all()->makeHidden(['gdpr', 'emailed']); $dataArr = [ - 'participant' => $participants, - 'volunteer' => $volunteers + 'code' => 200, + 'participants' => $participants, + 'volunteers' => $volunteers ]; return $dataArr; } - if ($ability === "key_2") { + if ($permission === "key_2") { $participants = Participant::all()->select('participant_id', 'first_name', 'surname'); $volunteers = Volunteer::all()->select('first_name', 'surname'); $dataArr = [ - 'participant' => $participants, - 'volunteer' => $volunteers + 'code' => 200, + 'participants' => $participants, + 'volunteers' => $volunteers ]; return $dataArr; } - if ($ability === "key_3") { + if ($permission === "key_3") { $participants = Participant::all()->makeHidden(['comment', 'emailed', 'paid', 'member', 'gdpr']); - return $participants; + return $dataArr = [ + 'code' => 200, + 'participants' => $participants, + ]; } - if ($ability === "key_4") { + if ($permission === "key_4") { $participants = Participant::all()->select('participant_id', 'first_name', 'surname'); - return $participants; + return $dataArr = [ + 'code' => 200, + 'participants' => $participants, + ]; } - return false; + return response()->json([ + 'code' => 401, 'message' => 'Unauthorized' + ]); } /** @@ -72,13 +82,12 @@ class ParticipantController extends Controller */ public function store(Request $request) { - $ability = $request->ability; + $permission = $request->permission; - if ($ability === "key_1") { + if ($permission === "key_1") { $request->validate([ - 'member' => 'required', 'first_name' => 'required', 'surname' => 'required', 'grade' => 'required', @@ -87,20 +96,20 @@ class ParticipantController extends Controller 'guardian_name' => 'required', 'guardian_phone' => 'required', 'guardian_email' => 'required', - 'visiting' => 'required', + 'is_visiting' => 'required', 'gdpr' => 'required', 'friends' => 'nullable', 'special_diet' => 'nullable', ]); - $count = Participant::where('visiting', 0)->count(); + $count = Participant::where('is_visiting', 0)->count(); $status = ""; - if ($count < 2 && $request->visiting === 0) { + if ($count < 2 && $request->is_visiting === 0) { $status = "lan"; } - else if ($request->visiting === 1) { + else if ($request->is_visiting === 1) { $status = "besök"; } @@ -109,7 +118,7 @@ class ParticipantController extends Controller } Participant::create([ - 'member' => $request->member, + 'member' => 1, 'first_name' => $request->first_name, 'surname' => $request->surname, 'grade' => $request->grade, @@ -118,7 +127,7 @@ class ParticipantController extends Controller 'guardian_name' => $request->guardian_name, 'guardian_phone' => $request->guardian_phone, 'guardian_email' => $request->guardian_email, - 'visiting' => $request->visiting, + 'is_visiting' => $request->is_visiting, 'gdpr' => $request->gdpr, 'friends' => $request->friends, 'special_diet' => $request->special_diet, @@ -127,13 +136,13 @@ class ParticipantController extends Controller return response()->json([ - 'success' => true, 'message' => 'Participant was created successfully' + 'code' => 200, 'message' => 'Participant was created successfully' ]); } return response()->json([ - 'success' => false, 'message' => 'Unauthorized' + 'code' => 200, 'message' => 'Unauthorized' ]); } diff --git a/app/Http/Controllers/VersionController.php b/app/Http/Controllers/VersionController.php index e61517b..2f38570 100644 --- a/app/Http/Controllers/VersionController.php +++ b/app/Http/Controllers/VersionController.php @@ -12,55 +12,55 @@ class VersionController extends Controller */ public function index(Request $request) { - $ability = $request->ability; + $permission = $request->permission; - if ($ability === "key_1") { + if ($permission === "key_1") { $latest_version_participants = Version::where('table', 'participants')->latest()->first(); $latest_version_volunteers = Version::where('table', 'volunteers')->latest()->first(); return response()->json([ - 'success' => true, 'participants' => $latest_version_participants ? $latest_version_participants->version : null , 'volunteers' => $latest_version_volunteers ? $latest_version_volunteers->version : null + 'code' => 200, 'participants' => $latest_version_participants ? $latest_version_participants->version : null , 'volunteers' => $latest_version_volunteers ? $latest_version_volunteers->version : null ]); } - if ($ability === "key_2") { + if ($permission === "key_2") { $latest_version_participants = Version::where('table', 'participants')->latest()->first(); $latest_version_volunteers = Version::where('table', 'volunteers')->latest()->first(); return response()->json([ - 'success' => true, 'participants' => $latest_version_participants ? $latest_version_participants->version : null , 'volunteers' => $latest_version_volunteers ? $latest_version_volunteers->version : null + 'code' => 200, 'participants' => $latest_version_participants ? $latest_version_participants->version : null , 'volunteers' => $latest_version_volunteers ? $latest_version_volunteers->version : null ]); } - if ($ability === "key_3") { + if ($permission === "key_3") { $latest_version_participants = Version::where('table', 'participants')->latest()->first(); return response()->json([ - 'success' => true, 'participants' => $latest_version_participants ? $latest_version_participants->version : null + 'code' => 200, 'participants' => $latest_version_participants ? $latest_version_participants->version : null ]); } - if ($ability === "key_4") { + if ($permission === "key_4") { $latest_version_participants = Version::where('table', 'participants')->latest()->first(); return response()->json([ - 'success' => true, 'participants' => $latest_version_participants ? $latest_version_participants->version : null + 'code' => 200, 'participants' => $latest_version_participants ? $latest_version_participants->version : null ]); } return response()->json([ - 'success' => false, 'message' => 'Unauthorized' + 'code' => 401, 'message' => 'Unauthorized' ]); } diff --git a/app/Http/Controllers/VolunteerController.php b/app/Http/Controllers/VolunteerController.php index 4ca88a1..5894433 100644 --- a/app/Http/Controllers/VolunteerController.php +++ b/app/Http/Controllers/VolunteerController.php @@ -12,9 +12,9 @@ class VolunteerController extends Controller */ public function store(Request $request) { - $ability = $request->ability; + $permission = $request->permission; - if ($ability === "key_1") { + if ($permission === "key_1") { $request->validate([ @@ -38,13 +38,13 @@ class VolunteerController extends Controller return response()->json([ - 'success' => true, 'message' => 'Volunteer was created successfully' + 'code' => 200, 'message' => 'Volunteer was created successfully' ]); } return response()->json([ - 'success' => false, 'message' => 'Unauthorized' + 'code' => 401, 'message' => 'Unauthorized' ]); } diff --git a/app/Http/Middleware/ApiToken.php b/app/Http/Middleware/ApiToken.php index f2e4d9f..810f55a 100644 --- a/app/Http/Middleware/ApiToken.php +++ b/app/Http/Middleware/ApiToken.php @@ -15,24 +15,24 @@ class ApiToken */ public function handle(Request $request, Closure $next): Response { - if ($request->api_token === env('API_KEY_1')) { + if ($request->api_token === config('apikeys.key_1')) { - $request->merge(["ability" => "key_1"]); + $request->merge(["permission" => "key_1"]); - } elseif ($request->api_token === env('API_KEY_2')) { + } elseif ($request->api_token === config('apikeys.key_2')) { - $request->merge(["ability" => "key_2"]); + $request->merge(["permission" => "key_2"]); - } elseif ($request->api_token === env('API_KEY_3')) { + } elseif ($request->api_token === config('apikeys.key_3')) { - $request->merge(["ability" => "key_3"]); + $request->merge(["permission" => "key_3"]); - } elseif ($request->api_token === env('API_KEY_4')) { + } elseif ($request->api_token === config('apikeys.key_4')) { - $request->merge(["ability" => "key_4"]); + $request->merge(["permission" => "key_4"]); } else { - return response()->json('Unauthorized', 401); + return response()->json(['code' => 401, 'message' => 'Unauthorized']); } return $next($request); } diff --git a/config/apikeys.php b/config/apikeys.php new file mode 100644 index 0000000..b006013 --- /dev/null +++ b/config/apikeys.php @@ -0,0 +1,18 @@ + env('API_KEY_1'), + 'key_2' => env('API_KEY_2'), + 'key_3' => env('API_KEY_3'), + 'key_4' => env('API_KEY_4'), + +]; \ No newline at end of file