Skip to content

Commit 950832d

Browse files
committed
installed scribe
1 parent 1c119d8 commit 950832d

File tree

6 files changed

+432
-22
lines changed

6 files changed

+432
-22
lines changed

frameworks-laravel/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,16 @@ This demo data makes it easy to test the API endpoints without having to create
6262

6363
## API Endpoints
6464

65-
All endpoints are prefixed with `/api/v1`.
65+
All endpoints are prefixed with `/api`.
6666

6767
### Health Check
6868

69-
- `GET /api/v1/health` - Get API health status
69+
- `GET /api/health` - Get API health status
7070

7171
### Drivers
7272

73-
- `GET /api/v1/drivers` - List all drivers
74-
- `POST /api/v1/drivers` - Create a new driver
73+
- `GET /api/drivers` - List all drivers
74+
- `POST /api/drivers` - Create a new driver
7575

7676
**Create Driver Request:**
7777
```json
@@ -83,8 +83,8 @@ All endpoints are prefixed with `/api/v1`.
8383

8484
### Circuits
8585

86-
- `GET /api/v1/circuits` - List all circuits
87-
- `POST /api/v1/circuits` - Create a new circuit
86+
- `GET /api/circuits` - List all circuits
87+
- `POST /api/circuits` - Create a new circuit
8888

8989
**Create Circuit Request:**
9090
```json
@@ -96,15 +96,15 @@ All endpoints are prefixed with `/api/v1`.
9696

9797
### Lap Times
9898

99-
- `GET /api/v1/lap_times` - List all lap times (with optional filters)
99+
- `GET /api/lap_times` - List all lap times (with optional filters)
100100
- Query parameters:
101101
- `driver_id` - Filter by driver ID
102102
- `circuit_id` - Filter by circuit ID
103103
- `lap_min` - Minimum lap number
104104
- `lap_max` - Maximum lap number
105-
- `POST /api/v1/lap_times` - Create a new lap time
106-
- `GET /api/v1/drivers/{driverId}/lap_times` - Get lap times for a specific driver
107-
- `GET /api/v1/circuits/{circuitId}/lap_times` - Get lap times for a specific circuit
105+
- `POST /api/lap_times` - Create a new lap time
106+
- `GET /api/drivers/{driverId}/lap_times` - Get lap times for a specific driver
107+
- `GET /api/circuits/{circuitId}/lap_times` - Get lap times for a specific circuit
108108

109109
**Create Lap Time Request:**
110110
```json

frameworks-laravel/app/Http/Controllers/Api/CircuitController.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,37 @@ public function store(Request $request): CircuitResource
3636
/**
3737
* Display the specified resource.
3838
*/
39-
public function show(string $id)
39+
public function show(string $id): CircuitResource
4040
{
41-
// Not implemented
41+
$circuit = Circuit::findOrFail($id);
42+
return new CircuitResource($circuit);
4243
}
4344

4445
/**
4546
* Update the specified resource in storage.
4647
*/
47-
public function update(Request $request, string $id)
48+
public function update(Request $request, string $id): CircuitResource
4849
{
49-
// Not implemented
50+
$circuit = Circuit::findOrFail($id);
51+
52+
$validated = $request->validate([
53+
'name' => 'sometimes|required|string',
54+
'location' => 'sometimes|required|string',
55+
]);
56+
57+
$circuit->update($validated);
58+
59+
return new CircuitResource($circuit);
5060
}
5161

5262
/**
5363
* Remove the specified resource from storage.
5464
*/
5565
public function destroy(string $id)
5666
{
57-
// Not implemented
67+
$circuit = Circuit::findOrFail($id);
68+
$circuit->delete();
69+
70+
return response()->json(null, 204);
5871
}
5972
}

frameworks-laravel/app/Http/Controllers/Api/DriverController.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,37 @@ public function store(Request $request): DriverResource
3636
/**
3737
* Display the specified resource.
3838
*/
39-
public function show(string $id)
39+
public function show(string $id): DriverResource
4040
{
41-
// Not implemented
41+
$driver = Driver::findOrFail($id);
42+
return new DriverResource($driver);
4243
}
4344

4445
/**
4546
* Update the specified resource in storage.
4647
*/
47-
public function update(Request $request, string $id)
48+
public function update(Request $request, string $id): DriverResource
4849
{
49-
// Not implemented
50+
$driver = Driver::findOrFail($id);
51+
52+
$validated = $request->validate([
53+
'name' => 'sometimes|required|string',
54+
'code' => 'sometimes|required|string',
55+
]);
56+
57+
$driver->update($validated);
58+
59+
return new DriverResource($driver);
5060
}
5161

5262
/**
5363
* Remove the specified resource from storage.
5464
*/
5565
public function destroy(string $id)
5666
{
57-
// Not implemented
67+
$driver = Driver::findOrFail($id);
68+
$driver->delete();
69+
70+
return response()->json(null, 204);
5871
}
5972
}

frameworks-laravel/app/Providers/AppServiceProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Providers;
44

5+
use Illuminate\Http\Resources\Json\JsonResource;
56
use Illuminate\Support\ServiceProvider;
67

78
class AppServiceProvider extends ServiceProvider
@@ -19,6 +20,6 @@ public function register(): void
1920
*/
2021
public function boot(): void
2122
{
22-
//
23+
// Use default Laravel resource wrapping under 'data'
2324
}
2425
}

frameworks-laravel/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
},
1414
"require-dev": {
1515
"fakerphp/faker": "^1.23",
16+
"knuckleswtf/scribe": "^5.5",
1617
"laravel/pail": "^1.2.2",
1718
"laravel/pint": "^1.24",
1819
"laravel/sail": "^1.41",

0 commit comments

Comments
 (0)