Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
daVitekPL committed Jul 19, 2024
1 parent e0656c2 commit d4e936d
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 30 deletions.
1 change: 1 addition & 0 deletions src/Exceptions/StationaryEventNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace EscolaLms\StationaryEvents\Exceptions;

use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
use Throwable;

class StationaryEventNotFoundException extends UnprocessableEntityHttpException
{
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Resources/StationaryEventAdminResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class StationaryEventAdminResource extends StationaryEventResource
public function toArray($request): array
{
return array_merge(parent::toArray($request), [
'users' => $this->users ? UserResource::collection($this->users) : [],
'users' => $this->resource->users ? UserResource::collection($this->resource->users) : [],
]);
}
}
40 changes: 20 additions & 20 deletions src/Http/Resources/StationaryEventResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@ class StationaryEventResource extends JsonResource
public function toArray($request): array
{
$fields = [
'id' => $this->id,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'name' => $this->name,
'description' => $this->description,
'short_desc' => $this->short_desc,
'started_at' => $this->started_at,
'finished_at' => $this->finished_at,
'max_participants' => $this->max_participants,
'place' => $this->place,
'program' => $this->program,
'categories' => $this->categories,
'status' => $this->status,
'authors' => $this->authors ? UserResource::collection($this->authors) : [],
'image_path' => $this->image_path,
'image_url' => $this->image_path ? Storage::url($this->image_path) : null,
'in_coming' => $this->in_coming,
'is_ended' => $this->is_ended,
'is_started' => $this->is_started,
'agenda' => $this->agenda,
'id' => $this->resource->id,
'created_at' => $this->resource->created_at,
'updated_at' => $this->resource->updated_at,
'name' => $this->resource->name,
'description' => $this->resource->description,
'short_desc' => $this->resource->short_desc,
'started_at' => $this->resource->started_at,
'finished_at' => $this->resource->finished_at,
'max_participants' => $this->resource->max_participants,
'place' => $this->resource->place,
'program' => $this->resource->program,
'categories' => $this->resource->categories,
'status' => $this->resource->status,
'authors' => $this->resource->authors ? UserResource::collection($this->resource->authors) : [],
'image_path' => $this->resource->image_path,
'image_url' => $this->resource->image_path ? Storage::url($this->resource->image_path) : null,
'in_coming' => $this->resource->in_coming,
'is_ended' => $this->resource->is_ended,
'is_started' => $this->resource->is_started,
'agenda' => $this->resource->agenda,
];

return self::apply($fields, $this);
Expand Down
8 changes: 4 additions & 4 deletions src/Http/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class UserResource extends JsonResource
public function toArray($request): array
{
return [
'id' => $this->id,
'first_name' => $this->first_name,
'last_name' => $this->last_name,
'path_avatar' => $this->path_avatar,
'id' => $this->resource->id,
'first_name' => $this->resource->first_name,
'last_name' => $this->resource->last_name,
'path_avatar' => $this->resource->path_avatar,
];
}
}
14 changes: 14 additions & 0 deletions src/Models/StationaryEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@
* ),
* )
*
* @property int $id
* @property string $name
* @property string $description
* @property string $short_description
* @property Carbon|null $started_at
* @property Carbon|null $finished_at
* @property int $max_participants
* @property string $place
* @property string $program
* @property string $image_path
* @property Carbon $created_at
* @property Carbon $updated_at
* @property object $agenda
* @property string $status
*/
class StationaryEvent extends Model
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace EscolaLms\StationaryEvents\Repositories\Contracts;

use EscolaLms\Core\Repositories\Contracts\BaseRepositoryContract;
use Illuminate\Database\Eloquent\Builder;

interface StationaryEventRepositoryContract
interface StationaryEventRepositoryContract extends BaseRepositoryContract
{
public function forCurrentUser(array $criteria = []): Builder;
public function allQueryBuilder(array $criteria = []): Builder;
}
14 changes: 14 additions & 0 deletions src/Repositories/Criteria/Primitives/OrderCriterion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace EscolaLms\StationaryEvents\Repositories\Criteria\Primitives;

use EscolaLms\Core\Repositories\Criteria\Criterion;
use Illuminate\Database\Eloquent\Builder;

class OrderCriterion extends Criterion
{
public function apply(Builder $query): Builder
{
return $query->orderBy($this->key, $this->value);
}
}
5 changes: 4 additions & 1 deletion src/Services/StationaryEventService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use EscolaLms\Core\Repositories\Criteria\Primitives\InCriterion;
use EscolaLms\Core\Repositories\Criteria\Primitives\LikeCriterion;
use EscolaLms\Core\Repositories\Criteria\Primitives\WhereCriterion;
use EscolaLms\Courses\Repositories\Criteria\Primitives\OrderCriterion;
use EscolaLms\Files\Helpers\FileHelper;
use EscolaLms\StationaryEvents\Enum\ConstantEnum;
use EscolaLms\StationaryEvents\Enum\StationaryEventStatusEnum;
Expand All @@ -20,6 +19,7 @@
use EscolaLms\StationaryEvents\Events\StationaryEventUnassigned;
use EscolaLms\StationaryEvents\Models\StationaryEvent;
use EscolaLms\StationaryEvents\Repositories\Contracts\StationaryEventRepositoryContract;
use EscolaLms\StationaryEvents\Repositories\Criteria\Primitives\OrderCriterion;
use EscolaLms\StationaryEvents\Services\Contracts\StationaryEventServiceContract;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\UploadedFile;
Expand Down Expand Up @@ -59,6 +59,7 @@ public function getStationaryEventListForCurrentUser(OrderDto $orderDto, array $

public function create(array $data): StationaryEvent
{
/** @var StationaryEvent $stationaryEvent */
$stationaryEvent = $this->stationaryEventRepository->create($data);
$this->syncAuthors($stationaryEvent, $data['authors'] ?? []);

Expand All @@ -80,6 +81,7 @@ public function update(StationaryEvent $stationaryEvent, array $data): Stationar
$data['image_path'] = FileHelper::getFilePath($data['image'], ConstantEnum::DIRECTORY . '/' . $stationaryEvent->getKey() . '/images');
}

/** @var StationaryEvent $stationaryEvent */
$stationaryEvent = $this->stationaryEventRepository->update($data, $stationaryEvent->getKey());
$this->syncAuthors($stationaryEvent, $data['authors'] ?? []);

Expand Down Expand Up @@ -122,6 +124,7 @@ private function dispatchEventForUsersAttachedToStationaryEvent(StationaryEvent
}
}

// @phpstan-ignore-next-line
private function dispatchEventForUsersDetachedToStationaryEvent(StationaryEvent $stationaryEvent, array $users = []): void
{
foreach ($users as $detached) {
Expand Down
6 changes: 3 additions & 3 deletions src/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

// admin endpoints
Route::group(['middleware' => ['auth:api'], 'prefix' => 'api/admin/stationary-events'], function () {
Route::get(null, [StationaryEventAdminApiController::class, 'index']);
Route::post(null, [StationaryEventAdminApiController::class, 'store']);
Route::get('', [StationaryEventAdminApiController::class, 'index']);
Route::post('', [StationaryEventAdminApiController::class, 'store']);
Route::put('{id}', [StationaryEventAdminApiController::class, 'update']);
Route::get('{id}', [StationaryEventAdminApiController::class, 'show']);
Route::delete('{id}', [StationaryEventAdminApiController::class, 'delete']);
Expand All @@ -20,6 +20,6 @@

// public routes
Route::group(['prefix' => 'api/stationary-events'], function () {
Route::get(null, [StationaryEventApiController::class, 'index']);
Route::get('', [StationaryEventApiController::class, 'index']);
Route::get('{id}', [StationaryEventApiController::class, 'show']);
});

0 comments on commit d4e936d

Please sign in to comment.