ldc-mesbr-app/app/Http/Controllers/Api/v1/CustomerController.php

103 lines
2.7 KiB
PHP
Raw Normal View History

2021-04-20 11:16:34 +02:00
<?php
namespace App\Http\Controllers\Api\v1;
2021-04-20 19:51:30 +02:00
use App\Http\Requests\Customers\StoreRequest;
use App\Http\Requests\Customers\UpdateRequest;
use App\Http\Resources\CustomersResource;
2021-04-20 11:16:34 +02:00
use App\Http\Resources\StatusResource;
2021-04-20 19:51:30 +02:00
use App\Models\Customers;
2021-04-20 11:16:34 +02:00
use App\Http\Controllers\Controller;
2021-04-20 19:51:30 +02:00
use Illuminate\Support\Facades\Log;
2021-04-20 11:16:34 +02:00
class CustomerController extends Controller
{
/**
* Display a listing of the resource.
*
* @return StatusResource
*/
public function index()
{
return new StatusResource(['status' => 'KO', 'code' => '501', 'message' => 'Not Implemented']);
}
/**
* Show the form for creating a new resource.
*
* @return StatusResource
*/
public function create()
{
return new StatusResource(['status' => 'KO', 'code' => '501', 'message' => 'Not Implemented']);
}
/**
* Store a newly created resource in storage.
*
2021-04-20 19:51:30 +02:00
* @param StoreRequest $request
* @return CustomersResource | StatusResource
2021-04-20 11:16:34 +02:00
*/
2021-04-20 19:51:30 +02:00
public function store(StoreRequest $request)
2021-04-20 11:16:34 +02:00
{
2021-06-29 16:04:22 +02:00
$datas = $request->validated();
2021-04-20 19:51:30 +02:00
try {
2021-06-29 16:04:22 +02:00
$customer = Customers::where([
['crm_id', $datas['crm_id']],
['email', $datas['email']]
])->firstOrNew();
$customer->fill($datas);
2021-04-20 19:51:30 +02:00
$customer->saveOrFail();
return new CustomersResource($customer);
2021-04-27 17:29:47 +02:00
} catch (\Throwable $e) {
2021-04-20 19:51:30 +02:00
Log::critical($e->getMessage());
return new StatusResource(['status' => 'KO', 'code' => '500', 'message' => 'Server Error.']);
}
2021-04-20 11:16:34 +02:00
}
/**
* Display the specified resource.
*
* @param int $id
* @return StatusResource
*/
public function show($id)
{
return new StatusResource(['status' => 'KO', 'code' => '501', 'message' => 'Not Implemented']);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return StatusResource
*/
public function edit($id)
{
return new StatusResource(['status' => 'KO', 'code' => '501', 'message' => 'Not Implemented']);
}
/**
* Update the specified resource in storage.
*
2021-06-29 16:04:22 +02:00
* @param Request $request
* @return StatusResource
2021-04-20 11:16:34 +02:00
*/
2021-06-29 16:04:22 +02:00
public function update(Request $request)
2021-04-20 11:16:34 +02:00
{
2021-06-29 16:04:22 +02:00
return new StatusResource(['status' => 'KO', 'code' => '501', 'message' => 'Not Implemented']);
2021-04-20 11:16:34 +02:00
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return StatusResource
*/
public function destroy($id)
{
return new StatusResource(['status' => 'KO', 'code' => '501', 'message' => 'Not Implemented']);
}
}