ifx merge for update
This commit is contained in:
19
app/Http/Controllers/AutomationController.php
Normal file
19
app/Http/Controllers/AutomationController.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class AutomationController extends Controller
|
||||
{
|
||||
public function home()
|
||||
{
|
||||
$url = "http://192.168.1.32/meteo/meteo/api/?device=all&instant";
|
||||
$client = new \GuzzleHttp\Client();
|
||||
|
||||
$promise = $client->requestAsync('GET', $url);
|
||||
$response = $promise->wait();
|
||||
|
||||
return $response->getBody()->getContents();
|
||||
}
|
||||
}
|
||||
85
app/Http/Controllers/EventCategoryController.php
Normal file
85
app/Http/Controllers/EventCategoryController.php
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\EventCategoryRequest;
|
||||
use App\Http\Resources\EventCategory as EventCategoryResource;
|
||||
use App\Models\EventCategory;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class EventCategoryController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return response()->json([
|
||||
'data' => EventCategoryResource::collection(EventCategory::orderBy('name')->get()),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function store(EventCategoryRequest $request)
|
||||
{
|
||||
$validated = $request->validated();
|
||||
|
||||
$category = EventCategory::create($validated);
|
||||
$category->save();
|
||||
|
||||
return (new EventCategoryResource($category))
|
||||
->response()
|
||||
->setStatusCode(201);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\EventCategory $category
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function show(EventCategory $category)
|
||||
{
|
||||
return (new EventCategoryResource($category))
|
||||
->response()
|
||||
->setStatusCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\EventCategory $category
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function update(EventCategoryRequest $request, EventCategory $category)
|
||||
{
|
||||
$category->update($request->validated());
|
||||
return (new EventCategoryResource($category))
|
||||
->response()
|
||||
->setStatusCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\EventCategory $category
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function destroy(EventCategory $category)
|
||||
{
|
||||
if(auth()->user()->isAdmin()) {
|
||||
$category->delete();
|
||||
return response()->json([], 204);
|
||||
} else {
|
||||
return response()->json([], 403);
|
||||
}
|
||||
}
|
||||
}
|
||||
96
app/Http/Controllers/EventController.php
Normal file
96
app/Http/Controllers/EventController.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\EventRequest;
|
||||
use App\Models\Event;
|
||||
use App\Http\Resources\Event as EventResource;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class EventController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param EventRequest $request
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function store(EventRequest $request)
|
||||
{
|
||||
$validated = $request->validated();
|
||||
|
||||
$event = $request->user()->events()->create($validated);
|
||||
$event->save();
|
||||
|
||||
return (new EventResource($event))
|
||||
->response()
|
||||
->setStatusCode(201);
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\Models\Event $event
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function show(Event $event)
|
||||
{
|
||||
return (new EventResource($event))
|
||||
->response()
|
||||
->setStatusCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Event $event
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Event $event)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\Event $event
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, Event $event)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Event $event
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Event $event)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -6,12 +6,20 @@ use App\Http\Resources\Image as ImageResource;
|
||||
use App\Models\Memo;
|
||||
use App\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Intervention\Image\Facades\Image;
|
||||
|
||||
class ImageController extends Controller
|
||||
{
|
||||
public function users(User $user)
|
||||
{
|
||||
foreach (auth()->user()->images as $image) {
|
||||
if(File::exists(storage_path('app/public/'.$image->path))) {
|
||||
File::delete(storage_path('app/public/'.$image->path));
|
||||
auth()->user()->images()->where('id', $image->id)->delete();
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->storeImage();
|
||||
|
||||
$newImage = auth()->user()->images()->create([
|
||||
@@ -21,11 +29,22 @@ class ImageController extends Controller
|
||||
'location' => $data['location'],
|
||||
]);
|
||||
|
||||
$this->haveThumbnailImage($data, auth()->user());
|
||||
|
||||
auth()->user()->update(['updated_at' => now()]);
|
||||
|
||||
return new ImageResource($newImage);
|
||||
}
|
||||
|
||||
public function memos(Memo $memo)
|
||||
{
|
||||
foreach ($memo->images as $image) {
|
||||
if(File::exists(storage_path('app/public/'.$image->path))) {
|
||||
File::delete(storage_path('app/public/'.$image->path));
|
||||
$memo->images()->where('id', $image->id)->delete();
|
||||
}
|
||||
}
|
||||
|
||||
$data = $this->storeImage();
|
||||
|
||||
$newImage = $memo->images()->create([
|
||||
@@ -35,10 +54,29 @@ class ImageController extends Controller
|
||||
'location' => $data['location'],
|
||||
]);
|
||||
|
||||
$this->haveThumbnailImage($data, $memo);
|
||||
|
||||
$memo->update(['updated_at' => now()]);
|
||||
|
||||
return new ImageResource($newImage);
|
||||
}
|
||||
|
||||
private function storeImage() {
|
||||
private function haveThumbnailImage($data, $object)
|
||||
{
|
||||
Image::make($data['image'])
|
||||
->fit(round($data['width'] / 3, 0), round($data['height'] / 3, 0))
|
||||
->save(storage_path('app/public/thumbnail/images/'.$data['image']->hashName()));
|
||||
|
||||
$object->images()->create([
|
||||
'path' => "thumbnail/".$data['path'],
|
||||
'width' => round($data['width'] / 3, 0),
|
||||
'height' => round($data['height'] / 3, 0),
|
||||
'location' => $data['location']."-small",
|
||||
]);
|
||||
}
|
||||
|
||||
private function storeImage()
|
||||
{
|
||||
$data = request()->validate([
|
||||
'image' => 'required',
|
||||
'width' => 'required',
|
||||
|
||||
31
app/Http/Requests/EventCategoryRequest.php
Normal file
31
app/Http/Requests/EventCategoryRequest.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class EventCategoryRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return auth()->user()->isAdmin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'name' => 'required',
|
||||
'description' => 'nullable|string',
|
||||
];
|
||||
}
|
||||
}
|
||||
63
app/Http/Requests/EventRequest.php
Normal file
63
app/Http/Requests/EventRequest.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class EventRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return !!(auth()->user());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'name' => 'required',
|
||||
'description' => 'nullable|string',
|
||||
'category_id' => 'required|exists:event_categories,id',
|
||||
'start_date' => 'required|date',
|
||||
'end_date' => 'date|after_or_equal:start_date',
|
||||
'location' => 'string|nullable'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get custom attributes for validator errors.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function attributes()
|
||||
{
|
||||
return [
|
||||
'name' => 'nom',
|
||||
'start_date' => 'date de début',
|
||||
'end_date' => 'date de fin',
|
||||
'location' => 'lieu',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the error messages for the defined validation rules.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'name.required' => 'A :attribute is required',
|
||||
'start_date.required' => 'A :attribute is required',
|
||||
];
|
||||
}
|
||||
}
|
||||
41
app/Http/Resources/Event.php
Normal file
41
app/Http/Resources/Event.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class Event extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'data' => [
|
||||
'type' => 'events',
|
||||
'event_id' => $this->id,
|
||||
'attributes' => [
|
||||
'data' => [
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
'start_date' => $this->start_date,
|
||||
'end_date' => $this->end_date,
|
||||
'location' => $this->location,
|
||||
'category' => [
|
||||
'data' => [
|
||||
'category_id' => $this->category_id
|
||||
],
|
||||
],
|
||||
]
|
||||
],
|
||||
],
|
||||
'links' => [
|
||||
'self' => url('/events/'.$this->id),
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
33
app/Http/Resources/EventCategory.php
Normal file
33
app/Http/Resources/EventCategory.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class EventCategory extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'data' => [
|
||||
'type' => 'event categories',
|
||||
'event_category_id' => $this->id,
|
||||
'attributes' => [
|
||||
'data' => [
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
]
|
||||
],
|
||||
],
|
||||
'links' => [
|
||||
'self' => url('/events/categories/'.$this->id),
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ class Memo extends JsonResource
|
||||
'attributes' => [
|
||||
'posted_by' => new UserResource($this->user),
|
||||
'cover_image' => new ImageResource($this->coverImage),
|
||||
'thumbnail_cover_image' => new ImageResource($this->thumbnailImage),
|
||||
]
|
||||
//'tags' => TagResource::collection($this->tags),
|
||||
],
|
||||
|
||||
@@ -24,6 +24,7 @@ class User extends JsonResource
|
||||
'email' => $this->email,
|
||||
'profile_image' => new ImageResource($this->profileImage),
|
||||
'cover_image' => new ImageResource($this->coverImage),
|
||||
'thumbnail_cover_image' => new ImageResource($this->thumbnailImage),
|
||||
'last_login' => optional($this->login_at)->diffForHumans(),
|
||||
'is_admin' => $this->isAdmin(),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user