Implementar upload de imagem para o cliente.
This commit is contained in:
parent
c53d0e0ed3
commit
3fa0440b31
@ -5,24 +5,14 @@ namespace App\Helpers;
|
||||
|
||||
class Helpers
|
||||
{
|
||||
public static function object_to_array($object)
|
||||
public static function uploadFiles($params, $field): ?string
|
||||
{
|
||||
if (!is_object($object) && !is_array($object)) {
|
||||
return $object;
|
||||
$result = null;
|
||||
if ($params->hasFile($field))
|
||||
{
|
||||
$result = url('storage') . '/' . $params->file($field)->store('users');
|
||||
}
|
||||
return array_map([__CLASS__, 'object_to_array'], (array) $object);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function array_enkeyize($array, $iten): array
|
||||
{
|
||||
$keized = [];
|
||||
foreach ($array as $key => $value) {
|
||||
foreach ($value as $v_key => $v_value) {
|
||||
if ($v_key === $iten) {
|
||||
$keized[$v_value] = $array[$key];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $keized;
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,6 +19,18 @@ class PldController extends Controller
|
||||
protected PldContractInterface $pldContract
|
||||
){}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
$response = $this->pldContract->searchPLd($request->all());
|
||||
return (new PldResource($response))
|
||||
->response()
|
||||
->setStatusCode(Response::HTTP_OK);
|
||||
}catch (\Exception $ex){
|
||||
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
public function overviewByRegion()
|
||||
{
|
||||
try {
|
||||
|
||||
@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Helpers\Helpers;
|
||||
use App\Http\Requests\StoreUserRequest;
|
||||
use App\Http\Resources\UserResource;
|
||||
use App\Repositories\Users\UserContractInterface;
|
||||
@ -47,7 +48,15 @@ class UserController extends Controller
|
||||
public function store(StoreUserRequest $request): JsonResponse
|
||||
{
|
||||
try {
|
||||
$response = $this->user->create($request->all());
|
||||
$user = $request->all();
|
||||
$user['password'] = bcrypt($request->password);
|
||||
|
||||
if ($request->hasFile('profile_picture'))
|
||||
{
|
||||
$user['profile_picture'] = url('storage') . '/' . $request->file('profile_picture')->store('users');
|
||||
}
|
||||
|
||||
$response = $this->user->create($user);
|
||||
return (new UserResource($response))
|
||||
->response()
|
||||
->setStatusCode(Response::HTTP_CREATED);
|
||||
|
||||
@ -24,10 +24,15 @@ class StoreUserRequest extends FormRequest
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'name' => 'required|string',
|
||||
'email' => 'required|string|email|max:255|unique:users',
|
||||
'name' => 'required|string|max:255|min:3',
|
||||
'email' => [
|
||||
'required',
|
||||
'email',
|
||||
"unique:users,email"
|
||||
],
|
||||
'password'=> 'required|string|min:6|confirmed',
|
||||
'client_id' => 'required'
|
||||
'client_id' => 'nullable',
|
||||
'profile_picture' =>'nullable|image|max:1024'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,6 +24,7 @@ class User extends Authenticatable implements Auditing
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
'profile_picture',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
|
||||
@ -10,5 +10,5 @@ interface ContractInterface
|
||||
public function update(array $params, $id);
|
||||
public function destroy($id);
|
||||
public function withRelationsByAll($relations);
|
||||
public function selectGlobal($params);
|
||||
public function search($params);
|
||||
}
|
||||
|
||||
@ -38,14 +38,12 @@ trait MethodsTrait
|
||||
return $this->model->with($relations)->get();
|
||||
}
|
||||
|
||||
public function selectGlobal($params)
|
||||
public function search($params)
|
||||
{
|
||||
$filter = static::getFilterBuilder($params);
|
||||
|
||||
$query = $this->model->select($filter->getFields());
|
||||
|
||||
$result = $filter->applyFilter($query)->get();
|
||||
|
||||
dd($result);
|
||||
return $filter->applyFilter($query)->get();
|
||||
}
|
||||
}
|
||||
@ -10,4 +10,5 @@ interface PldContractInterface extends ContractInterface
|
||||
public function getConsumptionByDaily($params);
|
||||
public function getListConsumption($params);
|
||||
public function getConsumptionBySchedule($params);
|
||||
public function searchPLd($params);
|
||||
}
|
||||
@ -31,6 +31,16 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function searchPLd($params)
|
||||
{
|
||||
$fields = [
|
||||
'pld.mes_ref as year_month',
|
||||
DB::raw("TO_CHAR(TO_DATE(pld.mes_ref, 'YYMM'), 'MM/YYYY') as year_month_formatted"),
|
||||
];
|
||||
|
||||
return $this->execute($fields, $params)->distinct()->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BindingResolutionException
|
||||
*/
|
||||
|
||||
@ -20,6 +20,7 @@ return new class extends Migration
|
||||
$table->string('email')->unique();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password');
|
||||
$table->string('profile_picture')->nullable();
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
|
||||
@ -40,6 +40,7 @@ Route::middleware(['auth:sanctum', 'ability:Admin'])->group(function () {
|
||||
});
|
||||
|
||||
Route::middleware(['auth:sanctum', 'ability:Client'])->group(function () {
|
||||
Route::post('pld', [\App\Http\Controllers\PldController::class, 'index']);
|
||||
Route::post('pld/overview', [\App\Http\Controllers\PldController::class, 'overviewByRegion']);
|
||||
Route::post('pld/list', [\App\Http\Controllers\PldController::class, 'listConsumption']);
|
||||
Route::post('pld/daily', [\App\Http\Controllers\PldController::class, 'consumptionByDaily']);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user