Two month of work
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\PipelineItem;
|
||||
use App\Support\ApiDataTransformer;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class PipelineItemController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$pipelineItems = PipelineItem::withCount(['notes' => function ($query) {
|
||||
$query->where('notable_type', 'App\Models\PipelineItem');
|
||||
}])->orderBy('position')->get();
|
||||
|
||||
return ApiDataTransformer::snakeToCamel($pipelineItems->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function single(int $id)
|
||||
{
|
||||
$pipelineItem = PipelineItem::withCount(['notes' => function ($query) {
|
||||
$query->where('notable_type', 'App\Models\PipelineItem');
|
||||
}])->orderBy('position')->findOrFail($id);
|
||||
|
||||
return ApiDataTransformer::snakeToCamel($pipelineItem->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validatedData = $request->validate([
|
||||
'pipeline_lane_id' => 'required|integer|exists:pipeline_lanes,id',
|
||||
'title' => 'required|string',
|
||||
'position' => 'required|integer|min:0',
|
||||
'expected_revenue' => 'nullable|numeric',
|
||||
'due_date' => 'nullable|date',
|
||||
'description' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$pipelineItem = PipelineItem::create($validatedData);
|
||||
|
||||
return ApiDataTransformer::snakeToCamel($pipelineItem->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, PipelineItem $pipelineItem)
|
||||
{
|
||||
$validatedData = $request->validate([
|
||||
'pipeline_lane_id' => 'sometimes|integer|exists:pipeline_lanes,id',
|
||||
'title' => 'sometimes|string',
|
||||
'position' => 'sometimes|integer|min:0',
|
||||
'expected_revenue' => 'nullable|numeric',
|
||||
'due_date' => 'nullable|date',
|
||||
'description' => 'nullable|string',
|
||||
]);
|
||||
|
||||
$pipelineItem->update($validatedData);
|
||||
|
||||
return ApiDataTransformer::snakeToCamel($pipelineItem->toArray());
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function delete(int $id)
|
||||
{
|
||||
PipelineItem::findOrFail($id)->delete();
|
||||
return response()->noContent();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user