diff --git a/app/Classes/Modules/Announcements/ControllersLogic/AssignAnnouncementToSegmentLogic.php b/app/Classes/Modules/Announcements/ControllersLogic/AssignAnnouncementToSegmentLogic.php new file mode 100644 index 00000000..18552989 --- /dev/null +++ b/app/Classes/Modules/Announcements/ControllersLogic/AssignAnnouncementToSegmentLogic.php @@ -0,0 +1,61 @@ + 'Assign Announcement To Segment', + 'message' => 'You have successfully assigned Announcement to segment' + ]; + } + + /** @var FetchesAnnouncement */ + private $fetchesAnnouncement; + + /** @var AssignAnnouncementToSegmentProcessor */ + private $assignAnnouncementToSegmentProcessor; + + /** + * AssignAnnouncementToSegmentLogic constructor. + * @param FetchesAnnouncement $fetchesAnnouncement + * @param AssignAnnouncementToSegmentProcessor $assignAnnouncementToSegmentProcessor + */ + public function __construct(FetchesAnnouncement $fetchesAnnouncement, AssignAnnouncementToSegmentProcessor $assignAnnouncementToSegmentProcessor) + { + $this->fetchesAnnouncement = $fetchesAnnouncement; + $this->assignAnnouncementToSegmentProcessor = $assignAnnouncementToSegmentProcessor; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request): JsonResponse + { + $announcement = $this->fetchesAnnouncement->execute(['id' => $request->route('id')]); + + $this->assignAnnouncementToSegmentProcessor->execute($announcement, $request->input('segment_id')); + + return $this->resourceResponse(new AnnouncementResource($announcement)); + } +} diff --git a/app/Classes/Modules/Announcements/ControllersLogic/CreateAnnouncementLogic.php b/app/Classes/Modules/Announcements/ControllersLogic/CreateAnnouncementLogic.php new file mode 100644 index 00000000..9c740601 --- /dev/null +++ b/app/Classes/Modules/Announcements/ControllersLogic/CreateAnnouncementLogic.php @@ -0,0 +1,82 @@ + 'Created Annoucement', + 'message' => 'You have successfully created a new Annoucements' + ]; + } + + /** @var CanCreateAnnouncement */ + private $canCreateAnnouncement; + + /** @var CreatesAnnoucement */ + private $createsAnnoucement; + + /** @var AssignAnnouncementToSegmentProcessor */ + private $assignAnnouncementToSegmentProcessor; + + + /** + * CreateAnnouncementLogic constructor. + * @param CanCreateAnnoucement $canCreateAnnoucement + * @param CreatesAnnoucement $createsAnnoucement + * @param AssignAnnouncementToSegmentProcessor $assignAnnouncementToSegmentProcessor + */ + public function __construct( + CanCreateAnnouncement $canCreateAnnouncement, + CreatesAnnouncement $createsAnnoucement, + AssignAnnouncementToSegmentProcessor $assignAnnouncementToSegmentProcessor + ) { + $this->canCreateAnnouncement = $canCreateAnnouncement; + $this->createsAnnoucement = $createsAnnoucement; + $this->assignAnnouncementToSegmentProcessor = $assignAnnouncementToSegmentProcessor; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request): JsonResponse + { + $annoucement_object = new AnnouncementObject( + $request->input('title'), + $request->input('description'), + $request->input('starting_on'), + $request->input('ending_on') + ); + + $this->canCreateAnnouncement->passes($annoucement_object); + + $announcement = $this->createsAnnoucement->execute($annoucement_object); + + $this->assignAnnouncementToSegmentProcessor->execute($announcement); + + return $this->resourceResponse(new AnnouncementResource($announcement)); + } +} diff --git a/app/Classes/Modules/Announcements/ControllersLogic/DeleteAnnouncementLogic.php b/app/Classes/Modules/Announcements/ControllersLogic/DeleteAnnouncementLogic.php new file mode 100644 index 00000000..55dc710c --- /dev/null +++ b/app/Classes/Modules/Announcements/ControllersLogic/DeleteAnnouncementLogic.php @@ -0,0 +1,71 @@ + 'Delete Announcement', + 'message' => 'You have successfully deleted the Announcement' + ]; + } + + /** @var CanDeleteAnnouncement */ + private $canDeleteAnnouncement; + + /** @var FetchesAnnouncement */ + private $fetchesAnnouncement; + + /** @var DeletesAnnouncement */ + private $deletesAnnouncement; + + /** + * DeleteAnnouncementLogic constructor. + * @param CanDeleteAnnouncement $canDeleteAnnouncement + * @param FetchesAnnouncement $fetchesAnnouncement + * @param DeletesAnnouncement $deletesAnnouncement + */ + public function __construct( + CanDeleteAnnouncement $canDeleteAnnoucement, + FetchesAnnouncement $fetchesAnnoucement, + DeletesAnnouncement $deletesAnnoucement + ) { + $this->canDeleteAnnoucement = $canDeleteAnnoucement; + $this->fetchesAnnoucement = $fetchesAnnoucement; + $this->deletesAnnoucement = $deletesAnnoucement; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request): JsonResponse + { + + $this->canDeleteAnnoucement->passes(); + + $annoucement = $this->fetchesAnnoucement->execute(['id' => $request->route('id')]); + + $this->deletesAnnoucement->execute($annoucement); + + return $this->response([]); + } +} diff --git a/app/Classes/Modules/Announcements/ControllersLogic/ListAnnouncementsLogic.php b/app/Classes/Modules/Announcements/ControllersLogic/ListAnnouncementsLogic.php new file mode 100644 index 00000000..0055ebeb --- /dev/null +++ b/app/Classes/Modules/Announcements/ControllersLogic/ListAnnouncementsLogic.php @@ -0,0 +1,60 @@ + 'Retrieve Announcements', + 'message' => 'You have successfully retrieved a list of Announcements' + ]; + } + + /** @var CanListAnnouncements */ + private $canListAnnouncements; + + /** @var ListsAnnouncements */ + private $listsAnnouncements; + + /** + * ListAnnouncementsLogic constructor. + * @param CanListAnnouncements $canListAnnouncements + * @param ListsAnnouncements $listsAnnouncements + */ + public function __construct(CanListAnnouncements $canListAnnouncements, ListsAnnouncements $listsAnnouncements) + { + $this->canListAnnouncements = $canListAnnouncements; + $this->listsAnnouncements = $listsAnnouncements; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request): JsonResponse + { + + $this->canListAnnouncements->passes(); + + $annoucements = $this->listsAnnouncements->execute($this->listsAnnouncements->deserializeFilters($request->input('filters'))); + + return $this->collectionResponse(AnnouncementResource::collection($annoucements)); + } +} diff --git a/app/Classes/Modules/Announcements/ControllersLogic/RemoveSegmentFromAnnouncementLogic.php b/app/Classes/Modules/Announcements/ControllersLogic/RemoveSegmentFromAnnouncementLogic.php new file mode 100644 index 00000000..284d20b9 --- /dev/null +++ b/app/Classes/Modules/Announcements/ControllersLogic/RemoveSegmentFromAnnouncementLogic.php @@ -0,0 +1,68 @@ + 'Detach Announcement From Segment', + 'message' => 'You have successfully detached Announcement from segment' + ]; + } + + /** @var FetchesAnnouncement */ + private $fetchesAnnnouncement; + + /** @var FetchesSegment */ + private $fetchesSegment; + + /** @var RemovesAnnouncementFromSegment */ + private $removesAnnouncementFromSegment; + + /** + * RemoveSegmentFromAnnouncementLogic constructor. + * @param FetchesAnnouncement $fetchesAnnnouncement + * @param FetchesSegment $fetchesSegment + * @param RemovesAnnouncementFromSegment $removesAnnouncementFromSegment + */ + public function __construct(FetchesAnnouncement $fetchesAnnnouncement, FetchesSegment $fetchesSegment, RemovesAnnouncementFromSegment $removesAnnouncementFromSegment) + { + $this->fetchesAnnnouncement = $fetchesAnnnouncement; + $this->fetchesSegment = $fetchesSegment; + $this->removesAnnouncementFromSegment = $removesAnnouncementFromSegment; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request): JsonResponse + { + + $announcement = $this->fetchesAnnnouncement->execute(['id' => $request->route('id')]); + + $segment = $this->fetchesSegment->execute(['id' => $request->route('segment_id')]); + + $this->removesAnnouncementFromSegment->execute($announcement, $segment); + + return $this->resourceResponse(new AnnouncementResource($announcement)); + } +} diff --git a/app/Classes/Modules/Announcements/ControllersLogic/UpdateAnnouncementLogic.php b/app/Classes/Modules/Announcements/ControllersLogic/UpdateAnnouncementLogic.php new file mode 100644 index 00000000..4fac4144 --- /dev/null +++ b/app/Classes/Modules/Announcements/ControllersLogic/UpdateAnnouncementLogic.php @@ -0,0 +1,83 @@ + 'Update Announcement', + 'message' => 'You have successfully updated the Announcement' + ]; + } + + /** @var CanUpdateAnnouncement */ + private $canUpdateAnnouncement; + + /** @var FetchesAnnouncement */ + private $fetchesAnnouncement; + + /** @var UpdatesAnnouncement */ + private $updatesAnnouncement; + + /** + * UpdateAnnouncementLogic constructor. + * @param CanUpdateAnnouncement $canUpdateAnnouncement + * @param FetchesAnnouncement $fetchesAnnouncement + * @param UpdatesAnnouncement $updatesAnnouncement + */ + public function __construct( + CanUpdateAnnouncement $canUpdateAnnouncement, + FetchesAnnouncement $fetchesAnnouncement, + UpdatesAnnouncement $updatesAnnouncement + ) { + $this->canUpdateAnnouncement = $canUpdateAnnouncement; + $this->fetchesAnnouncement = $fetchesAnnouncement; + $this->updatesAnnouncement = $updatesAnnouncement; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request): JsonResponse + { + $annoucement_object = new AnnouncementObject( + $request->input('title'), + $request->input('description'), + $request->input('starting_on'), + $request->input('ending_on') + ); + + $this->canUpdateAnnouncement->passes($annoucement_object); + + $annoucement = $this->fetchesAnnouncement->execute(['id' => $request->route('id')]); + + $announcement_query = $this->updatesAnnouncement->execute($annoucement, $annoucement_object); + + //$announcement_query->segments()->sync($request->input('segment_id')); + + return $this->resourceResponse(new AnnouncementResource($announcement_query)); + } +} diff --git a/app/Classes/Modules/Announcements/DataTransferObjects/AnnouncementObject.php b/app/Classes/Modules/Announcements/DataTransferObjects/AnnouncementObject.php new file mode 100644 index 00000000..98d75e8b --- /dev/null +++ b/app/Classes/Modules/Announcements/DataTransferObjects/AnnouncementObject.php @@ -0,0 +1,70 @@ +title = $title; + $this->description = $description; + $this->starting_on = $starting_on; + $this->ending_on = $ending_on; + } + + /** + * @return string + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * @return string + */ + public function getDescription(): string + { + return $this->description; + } + + /** + * @return string + */ + public function getStartingOn(): string + { + return $this->starting_on; + } + + /** + * @return string + */ + public function getEndingOn(): string + { + return $this->ending_on; + } +} diff --git a/app/Classes/Modules/Announcements/Processors/AssignAnnouncementToSegmentProcessor.php b/app/Classes/Modules/Announcements/Processors/AssignAnnouncementToSegmentProcessor.php new file mode 100644 index 00000000..f5468a80 --- /dev/null +++ b/app/Classes/Modules/Announcements/Processors/AssignAnnouncementToSegmentProcessor.php @@ -0,0 +1,56 @@ +canAssignSegment = $canAssignSegment; + $this->assignsAnnouncementToSegment = $assignsAnnouncementToSegment; + $this->fetchesSegment = $fetchesSegment; + } + + + /** + * @param Announcement $announcement + * @param int|null $segmentId + * @return Model + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function execute(Announcement $announcement, ?int $segmentId = SegmentConstants::STANDARD_SEGMENT): Model + { + $this->canAssignSegment->passes(); + + $segment = $this->fetchesSegment->execute(['id' => $segmentId]); + + return $this->assignsAnnouncementToSegment->execute($announcement, $segment); + } +} diff --git a/app/Classes/Modules/Announcements/Services/AssignsAnnouncementToSegment.php b/app/Classes/Modules/Announcements/Services/AssignsAnnouncementToSegment.php new file mode 100644 index 00000000..5cc459b1 --- /dev/null +++ b/app/Classes/Modules/Announcements/Services/AssignsAnnouncementToSegment.php @@ -0,0 +1,33 @@ +segments()->attach($segment); + + return $announcement; + + } catch (QueryException $exception){ + throw new MalformedRequestException($exception); + } + + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Announcements/Services/CreatesAnnouncement.php b/app/Classes/Modules/Announcements/Services/CreatesAnnouncement.php new file mode 100644 index 00000000..4a43bac8 --- /dev/null +++ b/app/Classes/Modules/Announcements/Services/CreatesAnnouncement.php @@ -0,0 +1,26 @@ +title = $object->getTitle(); + $model->description = $object->getDescription(); + $model->starting_on = $object->getStartingOn(); + $model->ending_on = $object->getEndingOn(); + + return $this->handler($model); + } +} diff --git a/app/Classes/Modules/Announcements/Services/DeletesAnnouncement.php b/app/Classes/Modules/Announcements/Services/DeletesAnnouncement.php new file mode 100644 index 00000000..82e312cc --- /dev/null +++ b/app/Classes/Modules/Announcements/Services/DeletesAnnouncement.php @@ -0,0 +1,19 @@ +handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Announcements/Services/FetchesAnnouncement.php b/app/Classes/Modules/Announcements/Services/FetchesAnnouncement.php new file mode 100644 index 00000000..f43b9e46 --- /dev/null +++ b/app/Classes/Modules/Announcements/Services/FetchesAnnouncement.php @@ -0,0 +1,34 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Announcements/Services/ListsAnnouncements.php b/app/Classes/Modules/Announcements/Services/ListsAnnouncements.php new file mode 100644 index 00000000..b821819a --- /dev/null +++ b/app/Classes/Modules/Announcements/Services/ListsAnnouncements.php @@ -0,0 +1,32 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} diff --git a/app/Classes/Modules/Announcements/Services/RemovesAnnouncementFromSegment.php b/app/Classes/Modules/Announcements/Services/RemovesAnnouncementFromSegment.php new file mode 100644 index 00000000..bd34d52f --- /dev/null +++ b/app/Classes/Modules/Announcements/Services/RemovesAnnouncementFromSegment.php @@ -0,0 +1,33 @@ +segments()->detach($segment); + + return $announcement; + + } catch (QueryException $exception){ + throw new MalformedRequestException($exception); + } + + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Announcements/Services/UpdatesAnnouncement.php b/app/Classes/Modules/Announcements/Services/UpdatesAnnouncement.php new file mode 100644 index 00000000..98d5da7a --- /dev/null +++ b/app/Classes/Modules/Announcements/Services/UpdatesAnnouncement.php @@ -0,0 +1,27 @@ +title = $object->getTitle(); + $model->description = $object->getDescription(); + $model->starting_on = $object->getStartingOn(); + $model->ending_on = $object->getEndingOn(); + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Announcements/Standards/Rules/CanAssignSegment.php b/app/Classes/Modules/Announcements/Standards/Rules/CanAssignSegment.php new file mode 100644 index 00000000..625a07a1 --- /dev/null +++ b/app/Classes/Modules/Announcements/Standards/Rules/CanAssignSegment.php @@ -0,0 +1,40 @@ +AnnouncementValidation = $AnnouncementValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + return true; + } + + /** + * @param AnnouncementObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->AnnouncementValidation->validate($object); + } + + /** + * @param AnnouncementObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Announcements/Standards/Rules/CanDeleteAnnouncement.php b/app/Classes/Modules/Announcements/Standards/Rules/CanDeleteAnnouncement.php new file mode 100644 index 00000000..8a41deab --- /dev/null +++ b/app/Classes/Modules/Announcements/Standards/Rules/CanDeleteAnnouncement.php @@ -0,0 +1,40 @@ +AnnouncementValidation = $AnnouncementValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param AnnouncementObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->AnnouncementValidation->validate($object); + } + + /** + * @param AnnouncementObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Announcements/Standards/Validators/AnnouncementValidation.php b/app/Classes/Modules/Announcements/Standards/Validators/AnnouncementValidation.php new file mode 100644 index 00000000..f094b8aa --- /dev/null +++ b/app/Classes/Modules/Announcements/Standards/Validators/AnnouncementValidation.php @@ -0,0 +1,44 @@ + $object->getTitle(), + 'description' => $object->getDescription(), + 'starting_on' => $object->getStartingOn(), + 'ending_on' => $object->getEndingOn() + ]; + } + + /** + * @return array + */ + protected function rules(): array + { + return [ + 'title' => 'required', + 'description' => 'required', + 'starting_on' => 'required', + 'ending_on' => 'required' + ]; + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/ControllersLogic/CreateSegmentLogic.php b/app/Classes/Modules/Segments/ControllersLogic/CreateSegmentLogic.php new file mode 100644 index 00000000..32eeb217 --- /dev/null +++ b/app/Classes/Modules/Segments/ControllersLogic/CreateSegmentLogic.php @@ -0,0 +1,65 @@ + 'Created Segment', + 'message' => 'You have successfully created a new Segment' + ]; + } + + /** @var CanCreateSegment */ + private $canCreateSegment; + + /** @var CreatesSegment */ + private $createsSegment; + + + /** + * CreateSegmentLogic constructor. + * @param CanCreateSegment $canCreateSegment + * @param CreatesSegment $createsSegment + */ + public function __construct(CanCreateSegment $canCreateSegment, CreatesSegment $createsSegment) + { + $this->canCreateSegment = $canCreateSegment; + $this->createsSegment = $createsSegment; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + $segment_object = new SegmentObject($request->input('name')); + + $this->canCreateSegment->passes($segment_object); + $segment = $this->createsSegment->execute($segment_object); + + return $this->resourceResponse(new SegmentResource($segment)); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/ControllersLogic/DeleteSegmentLogic.php b/app/Classes/Modules/Segments/ControllersLogic/DeleteSegmentLogic.php new file mode 100644 index 00000000..ac441bb0 --- /dev/null +++ b/app/Classes/Modules/Segments/ControllersLogic/DeleteSegmentLogic.php @@ -0,0 +1,74 @@ + 'Delete Segment', + 'message' => 'You have successfully deleted the Segment' + ]; + } + + /** @var CanDeleteSegment */ + private $canDeleteSegment; + + /** @var DeletesSegment */ + private $deletesSegment; + + /** @var FetchesSegment */ + private $fetchesSegment; + + + /** + * DeleteSegmentLogic constructor. + * @param CanDeleteSegment $canDeleteSegment + * @param DeletesSegment $deletesSegment + * @param FetchesSegment $fetchesSegment + */ + public function __construct( + CanDeleteSegment $canDeleteSegment, + DeletesSegment $deletesSegment, + FetchesSegment $fetchesSegment + ) + { + $this->canDeleteSegment = $canDeleteSegment; + $this->deletesSegment = $deletesSegment; + $this->fetchesSegment = $fetchesSegment; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + + $segment_query = $this->fetchesSegment->execute(['id' => $request->route('id')]); + $this->canDeleteSegment->passes(); + $this->deletesSegment->execute($segment_query); + + return $this->resourceResponse(new SegmentResource($segment_query)); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/ControllersLogic/FetchConstantLogic.php b/app/Classes/Modules/Segments/ControllersLogic/FetchConstantLogic.php new file mode 100644 index 00000000..6c5c5b0f --- /dev/null +++ b/app/Classes/Modules/Segments/ControllersLogic/FetchConstantLogic.php @@ -0,0 +1,52 @@ + 'Fetch Segment Constant', + 'message' => 'You have successfully retrieved the Segment Constant' + ]; + } + + + /** @var FetchesConstant */ + private $fetchesConstant; + + /** + * FetchConstantLogic constructor. + * @param FetchesConstant $fetchesConstant + */ + public function __construct(FetchesConstant $fetchesConstant) + { + $this->fetchesConstant = $fetchesConstant; + } + + + /** + * @param Request $request + * @return JsonResponse + */ + public function logic(Request $request) : JsonResponse + { + + $constant = $this->fetchesConstant->execute(['segment_id' => $request->route('id'), 'reference' => $request->route('reference')]); + + return $this->resourceResponse(new ConstantResource($constant)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/ControllersLogic/FetchSegmentLogic.php b/app/Classes/Modules/Segments/ControllersLogic/FetchSegmentLogic.php new file mode 100644 index 00000000..d5c35fdc --- /dev/null +++ b/app/Classes/Modules/Segments/ControllersLogic/FetchSegmentLogic.php @@ -0,0 +1,59 @@ + 'Retrieved Segment', + 'message' => 'You have successfully retrieved a segment' + ]; + } + + /** @var CanFetchSegment */ + private $canFetchSegment; + + /** @var FetchesSegment */ + private $fetchesSegment; + + /** + * FetchSegmentLogic constructor. + * @param CanFetchSegment $canFetchSegment + * @param FetchesSegment $fetchesSegment + */ + public function __construct(CanFetchSegment $canFetchSegment, FetchesSegment $fetchesSegment) + { + $this->canFetchSegment = $canFetchSegment; + $this->fetchesSegment = $fetchesSegment; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + $this->canFetchSegment->passes(); + + $query = $this->fetchesSegment->execute(['id' => $request->route('id')]); + + return $this->resourceResponse(new SegmentResource($query)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/ControllersLogic/ListSegmentLogic.php b/app/Classes/Modules/Segments/ControllersLogic/ListSegmentLogic.php new file mode 100644 index 00000000..d8299424 --- /dev/null +++ b/app/Classes/Modules/Segments/ControllersLogic/ListSegmentLogic.php @@ -0,0 +1,52 @@ + 'Retrieved Segment', + 'message' => 'You have successfully retrieved a list of Segment' + ]; + } + + + /** @var ListsSegments */ + private $listsSegments; + + /** + * ListSegmentLogic constructor. + * @param ListsSegments $listsSegments + */ + public function __construct(ListsSegments $listsSegments) + { + $this->listsSegments = $listsSegments; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + + $query = $this->listsSegments->execute($this->listsSegments->deserializeFilters($request->input('filters'))); + + return $this->collectionResponse(SegmentResource::collection($query)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/ControllersLogic/UpdateConstantLogic.php b/app/Classes/Modules/Segments/ControllersLogic/UpdateConstantLogic.php new file mode 100644 index 00000000..dac04ec7 --- /dev/null +++ b/app/Classes/Modules/Segments/ControllersLogic/UpdateConstantLogic.php @@ -0,0 +1,104 @@ + 'Updated Segment Constant', + 'message' => 'You have successfully updated the Segment Constant' + ]; + } + + /** @var CanUpdateConstant */ + private $canUpdateConstant; + + /** @var UpdatesConstant */ + private $updatesConstant; + + /** @var FetchesSegment */ + private $fetchesSegment; + + /** @var FetchesConstant */ + private $fetchesConstant; + + /** @var CanCreateConstant */ + private $canCreateConstant; + + /** @var CreatesConstant */ + private $createsConstant; + + + /** + * UpdateConstantLogic constructor. + * @param CanUpdateConstant $canUpdateConstant + * @param UpdatesConstant $updatesConstant + * @param FetchesSegment $fetchesSegment + * @param FetchesConstant $fetchesConstant + * @param CanCreateConstant $canCreateConstant + * @param CreatesConstant $createsConstant + */ + public function __construct(CanUpdateConstant $canUpdateConstant, UpdatesConstant $updatesConstant, FetchesSegment $fetchesSegment, FetchesConstant $fetchesConstant, CanCreateConstant $canCreateConstant, CreatesConstant $createsConstant) + { + $this->canUpdateConstant = $canUpdateConstant; + $this->updatesConstant = $updatesConstant; + $this->fetchesSegment = $fetchesSegment; + $this->fetchesConstant = $fetchesConstant; + $this->canCreateConstant = $canCreateConstant; + $this->createsConstant = $createsConstant; + } + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + + $object = new ConstantObject($request->input('name'), $request->input('reference'), $request->input('detail')); + + $segment = $this->fetchesSegment->execute(['id' => $request->route('id')]); + + try { + + $constant = $this->fetchesConstant->execute(['segment_id' => $segment->id, 'reference' => $object->getReference()]); + $this->canUpdateConstant->passes($object); + + /** @var SegmentConstant $constant */ + $constant = $this->updatesConstant->execute($constant, $object); + + } catch (ResourceNotFoundException $exception){ + + $this->canCreateConstant->passes($object); + + /** @var SegmentConstant $constant */ + $constant = $this->createsConstant->execute($segment, $object); + + } + + + return $this->resourceResponse(new ConstantResource($constant)); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/ControllersLogic/UpdateSegmentLogic.php b/app/Classes/Modules/Segments/ControllersLogic/UpdateSegmentLogic.php new file mode 100644 index 00000000..43eaa54e --- /dev/null +++ b/app/Classes/Modules/Segments/ControllersLogic/UpdateSegmentLogic.php @@ -0,0 +1,87 @@ + 'Updated Segment', + 'message' => 'You have successfully updated the Segment' + ]; + } + + /** @var CanUpdateSegment */ + private $canUpdateSegment; + + /** @var UpdatesSegment */ + private $updatesSegment; + + /** @var FetchesSegment */ + private $fetchesSegment; + + + /** + * UpdateSegmentLogic constructor. + * @param CanUpdateSegment $canUpdateSegment + * @param UpdatesSegment $updatesSegment + * @param FetchesSegment $fetchesSegment + */ + public function __construct( + CanUpdateSegment $canUpdateSegment, + UpdatesSegment $updatesSegment, + FetchesSegment $fetchesSegment + ) + { + $this->canUpdateSegment = $canUpdateSegment; + $this->updatesSegment = $updatesSegment; + $this->fetchesSegment = $fetchesSegment; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $segment_query = $this->fetchesSegment->execute(['id' => $request->route('id')]); + + $segment_object = new SegmentObject( + $request->input('name', $segment_query->name) + ); + $this->canUpdateSegment->passes($segment_object); + $segment_query = $this->updatesSegment->execute($segment_query, $segment_object); + + DB::commit(); + + return $this->resourceResponse(new SegmentResource($segment_query)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/DataTransferObjects/SegmentObject.php b/app/Classes/Modules/Segments/DataTransferObjects/SegmentObject.php new file mode 100644 index 00000000..06045943 --- /dev/null +++ b/app/Classes/Modules/Segments/DataTransferObjects/SegmentObject.php @@ -0,0 +1,48 @@ +name = $name; + $this->type = $type; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @return int + */ + public function getType(): int + { + return $this->type; + } + + + + + + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Services/ConvertsConstantDetailsToResource.php b/app/Classes/Modules/Segments/Services/ConvertsConstantDetailsToResource.php new file mode 100644 index 00000000..4489da1f --- /dev/null +++ b/app/Classes/Modules/Segments/Services/ConvertsConstantDetailsToResource.php @@ -0,0 +1,38 @@ +fetchesCurrency = $fetchesCurrency; + } + + + public function execute(SegmentConstant $constant){ + + if($constant->reference === SegmentConstants::SUPPLIER_CURRENCIES) { + return property_exists($constant->detail, 'id') ? new CurrencyResource($this->fetchesCurrency->execute(['id' => $constant->detail->id])) : ''; + } + + return $constant->detail; + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Services/CreatesSegment.php b/app/Classes/Modules/Segments/Services/CreatesSegment.php new file mode 100644 index 00000000..b18a8db5 --- /dev/null +++ b/app/Classes/Modules/Segments/Services/CreatesSegment.php @@ -0,0 +1,25 @@ +name = $object->getName(); + $model->type = SegmentConstants::CUSTOM_SEGMENT; + + return $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Services/DeletesSegment.php b/app/Classes/Modules/Segments/Services/DeletesSegment.php new file mode 100644 index 00000000..9cc78c59 --- /dev/null +++ b/app/Classes/Modules/Segments/Services/DeletesSegment.php @@ -0,0 +1,19 @@ +handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Services/FetchesConstant.php b/app/Classes/Modules/Segments/Services/FetchesConstant.php new file mode 100644 index 00000000..bfa1b2cb --- /dev/null +++ b/app/Classes/Modules/Segments/Services/FetchesConstant.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Services/ListsConstants.php b/app/Classes/Modules/Segments/Services/ListsConstants.php new file mode 100644 index 00000000..733a6db7 --- /dev/null +++ b/app/Classes/Modules/Segments/Services/ListsConstants.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Services/ListsSegments.php b/app/Classes/Modules/Segments/Services/ListsSegments.php new file mode 100644 index 00000000..af44820d --- /dev/null +++ b/app/Classes/Modules/Segments/Services/ListsSegments.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Services/UpdatesConstant.php b/app/Classes/Modules/Segments/Services/UpdatesConstant.php new file mode 100644 index 00000000..13fb22c1 --- /dev/null +++ b/app/Classes/Modules/Segments/Services/UpdatesConstant.php @@ -0,0 +1,26 @@ +name = $object->getName(); + $model->reference = $object->getReference(); + $model->detail = json_encode($object->getDetail()); + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Services/UpdatesSegment.php b/app/Classes/Modules/Segments/Services/UpdatesSegment.php new file mode 100644 index 00000000..17f13efb --- /dev/null +++ b/app/Classes/Modules/Segments/Services/UpdatesSegment.php @@ -0,0 +1,23 @@ +name = $object->getName(); + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Standards/Rules/CanCreateConstant.php b/app/Classes/Modules/Segments/Standards/Rules/CanCreateConstant.php new file mode 100644 index 00000000..55f9c61a --- /dev/null +++ b/app/Classes/Modules/Segments/Standards/Rules/CanCreateConstant.php @@ -0,0 +1,54 @@ +constantValidation = $constantValidation; + } + + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + + + } + + /** + * @param ConstantObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->constantValidation->validate($object, 'POST'); + } + + /** + * @param ConstantObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Standards/Rules/CanCreateSegment.php b/app/Classes/Modules/Segments/Standards/Rules/CanCreateSegment.php new file mode 100644 index 00000000..3590cbec --- /dev/null +++ b/app/Classes/Modules/Segments/Standards/Rules/CanCreateSegment.php @@ -0,0 +1,55 @@ +segmentValidation = $segmentValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + // if (!\Auth::user()->can('add segment')) { + // return false; + // } + + return true; + } + + /** + * @param SegmentObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->segmentValidation->validate($object); + } + + /** + * @param SegmentObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Standards/Rules/CanDeleteSegment.php b/app/Classes/Modules/Segments/Standards/Rules/CanDeleteSegment.php new file mode 100644 index 00000000..197b0a5f --- /dev/null +++ b/app/Classes/Modules/Segments/Standards/Rules/CanDeleteSegment.php @@ -0,0 +1,45 @@ +can('delete segment')) { + return false; + } + + return true; + + } + + /** + * @param SegmentObject $object + * @return bool + */ + protected function validators($object): bool + { + return true; + + } + + + /** + * @param SegmentObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Standards/Rules/CanFetchSegment.php b/app/Classes/Modules/Segments/Standards/Rules/CanFetchSegment.php new file mode 100644 index 00000000..e6756305 --- /dev/null +++ b/app/Classes/Modules/Segments/Standards/Rules/CanFetchSegment.php @@ -0,0 +1,43 @@ +ConstantValidation = $ConstantValidation; + } + + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + } + + /** + * @param ConstantObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->ConstantValidation->validate($object, 'PUT'); + } + + /** + * @param ConstantObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Standards/Rules/CanUpdateSegment.php b/app/Classes/Modules/Segments/Standards/Rules/CanUpdateSegment.php new file mode 100644 index 00000000..58a8c0ca --- /dev/null +++ b/app/Classes/Modules/Segments/Standards/Rules/CanUpdateSegment.php @@ -0,0 +1,59 @@ +segmentValidation = $segmentValidation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + + if (!\Auth::user()->can('edit segment')) { + return false; + } + + return true; + } + + /** + * @param SegmentObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->segmentValidation->validate($object); + } + + /** + * @param SegmentObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Standards/Validators/ConstantValidation.php b/app/Classes/Modules/Segments/Standards/Validators/ConstantValidation.php new file mode 100644 index 00000000..d5ac8819 --- /dev/null +++ b/app/Classes/Modules/Segments/Standards/Validators/ConstantValidation.php @@ -0,0 +1,44 @@ + $object->getName(), + 'reference' => $object->getReference(), + 'detail' => $object->getDetail() + ]; + + return $data; + } + + /** + * @return array + */ + protected function rules(): array { + return [ + 'name' => 'required', + 'reference' => 'required', + 'detail' => 'required' + ]; + } + + /** + * @return array + */ + protected function messages(): array { + return []; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Segments/Standards/Validators/SegmentValidation.php b/app/Classes/Modules/Segments/Standards/Validators/SegmentValidation.php new file mode 100644 index 00000000..364a4c88 --- /dev/null +++ b/app/Classes/Modules/Segments/Standards/Validators/SegmentValidation.php @@ -0,0 +1,38 @@ + $object->getName(), + ]; + } + + /** + * @return array + */ + protected function rules(): array + { + return [ + 'name' => 'required', + ]; + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/ControllersLogic/CreateServiceTypeLogic.php b/app/Classes/Modules/ServiceTypes/ControllersLogic/CreateServiceTypeLogic.php new file mode 100644 index 00000000..07672f85 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/ControllersLogic/CreateServiceTypeLogic.php @@ -0,0 +1,105 @@ + 'Created Service Type', + 'message' => 'You have successfully created a new Service Type' + ]; + } + + /** @var CanCreateServiceType */ + private $canCreateServiceType; + + /** @var CreatesServiceType */ + private $createsServiceType; + + /** @var CreatesServiceTypeConstantDetails */ + private $createsServiceTypeConstantDetails; + + /** @var UpdatesServiceCurrencyRates */ + private $updatesServiceCurrencyRates; + + /** @var FetchesSegment */ + private $fetchesSegment; + + /** @var CreatesConstant */ + private $createsConstant; + + + /** + * CreateServiceTypeLogic constructor. + * @param CanCreateServiceType $canCreateServiceType + * @param CreatesServiceType $createsServiceType + * @param CreatesServiceTypeConstantDetails $createsServiceTypeConstantDetails + * @param UpdatesServiceCurrencyRates $updatesServiceCurrencyRates + * @param FetchesSegment $fetchesSegment + * @param CreatesConstant $createsConstant + */ + public function __construct(CanCreateServiceType $canCreateServiceType, CreatesServiceType $createsServiceType, CreatesServiceTypeConstantDetails $createsServiceTypeConstantDetails, UpdatesServiceCurrencyRates $updatesServiceCurrencyRates, FetchesSegment $fetchesSegment, CreatesConstant $createsConstant) + { + $this->canCreateServiceType = $canCreateServiceType; + $this->createsServiceType = $createsServiceType; + $this->createsServiceTypeConstantDetails = $createsServiceTypeConstantDetails; + $this->updatesServiceCurrencyRates = $updatesServiceCurrencyRates; + $this->fetchesSegment = $fetchesSegment; + $this->createsConstant = $createsConstant; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + + $object = new ServiceTypeObject($request->input('name')); + + $this->canCreateServiceType->passes($object); + + /** @var ServiceType $service */ + $service = $this->createsServiceType->execute($object); + + $object = new ServiceDetailObject($service->id, (int) $request->input('configurations.bank_id'), + $request->input('configurations.service_charge'), $request->input('configurations.minimum_charge'), $request->input('configurations.tax'), + $request->input('configurations.po_limit'), $request->input('configurations.currencies'), false, $request->input('configurations.billable')); + + $this->updatesServiceCurrencyRates->execute($service, $object->getCurrencies()); + + $constantObject = new ConstantObject('Service Type', SegmentConstants::SERVICE_TYPE, $this->createsServiceTypeConstantDetails->execute($object)); + + $this->createsConstant->execute($this->fetchesSegment->execute(['type' => SegmentConstants::STANDARD_SEGMENT]), $constantObject); + + + return $this->resourceResponse(new ServiceTypeResource($service)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/ControllersLogic/DeleteServiceTypeLogic.php b/app/Classes/Modules/ServiceTypes/ControllersLogic/DeleteServiceTypeLogic.php new file mode 100644 index 00000000..c45c49d9 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/ControllersLogic/DeleteServiceTypeLogic.php @@ -0,0 +1,68 @@ + 'Deleted Service Type', + 'message' => 'You have successfully deleted a Service Type' + ]; + } + + + /** @var CanDeleteServiceType */ + private $canDeleteServiceType; + + /** @var DeletesServiceType */ + private $deletesServiceType; + + /** @var FetchesServiceType */ + private $fetchesServiceType; + + /** + * DeleteServiceTypeLogic constructor. + * @param CanDeleteServiceType $canDeleteServiceType + * @param DeletesServiceType $deletesServiceType + * @param FetchesServiceType $fetchesServiceType + */ + public function __construct(CanDeleteServiceType $canDeleteServiceType, DeletesServiceType $deletesServiceType, FetchesServiceType $fetchesServiceType) + { + $this->canDeleteServiceType = $canDeleteServiceType; + $this->deletesServiceType = $deletesServiceType; + $this->fetchesServiceType = $fetchesServiceType; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + + $this->canDeleteServiceType->passes(); + + $query = $this->fetchesServiceType->execute(['id' => $request->route('id')]); + + $this->deletesServiceType->execute($query); + + return $this->response([]); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/ControllersLogic/FetchServiceTypeLogic.php b/app/Classes/Modules/ServiceTypes/ControllersLogic/FetchServiceTypeLogic.php new file mode 100644 index 00000000..f7835d34 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/ControllersLogic/FetchServiceTypeLogic.php @@ -0,0 +1,62 @@ + 'Retrieved Service Type', + 'message' => 'You have successfully retrieved a Service Type' + ]; + } + + /** @var CanFetchServiceType */ + private $canFetchServiceType; + + /** @var FetchesServiceType */ + private $fetchesServiceType; + + /** + * FetchServiceTypeLogic constructor. + * @param CanFetchServiceType $canFetchServiceType + * @param FetchesServiceType $fetchesServiceType + */ + public function __construct(CanFetchServiceType $canFetchServiceType, FetchesServiceType $fetchesServiceType) + { + $this->canFetchServiceType = $canFetchServiceType; + $this->fetchesServiceType = $fetchesServiceType; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + $this->canFetchServiceType->passes(); + + $query = $this->fetchesServiceType->execute(['id' => $request->route('id')]); + + return $this->resourceResponse(new ServiceTypeResource($query)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/ControllersLogic/ListServiceTypesLogic.php b/app/Classes/Modules/ServiceTypes/ControllersLogic/ListServiceTypesLogic.php new file mode 100644 index 00000000..10b390ae --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/ControllersLogic/ListServiceTypesLogic.php @@ -0,0 +1,62 @@ + 'Retrieved Service Types', + 'message' => 'You have successfully retrieved a list of Service Types' + ]; + } + + /** @var CanListServiceTypes */ + private $canListServiceTypes; + + /** @var ListsServiceTypes */ + private $listsServiceTypes; + + /** + * ListServiceTypesControllerLogic constructor. + * @param CanListServiceTypes $canListServiceTypes + * @param ListsServiceTypes $listsServiceTypes + */ + public function __construct(CanListServiceTypes $canListServiceTypes, ListsServiceTypes $listsServiceTypes) + { + $this->canListServiceTypes = $canListServiceTypes; + $this->listsServiceTypes = $listsServiceTypes; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + $this->canListServiceTypes->passes(); + + $query = $this->listsServiceTypes->execute($this->listsServiceTypes->deserializeFilters($request->input('filters'))); + + return $this->collectionResponse(ServiceTypeResource::collection($query)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateCustomServiceConstantLogic.php b/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateCustomServiceConstantLogic.php new file mode 100644 index 00000000..e08ef598 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateCustomServiceConstantLogic.php @@ -0,0 +1,110 @@ + 'Update Segment Service', + 'message' => 'You have successfully update a segments service configuration' + ]; + } + + /** @var FetchesServiceType */ + private $fetchesServiceType; + + /** @var CreatesServiceTypeConstantDetails */ + private $createsServiceTypeConstantDetails; + + /** @var FetchesSegment */ + private $fetchesSegment; + + /** @var FetchesConstant */ + private $fetchesConstant; + + /** @var UpdatesConstant */ + private $updatesConstant; + + /** @var CreatesConstant */ + private $createsConstant; + + /** + * UpdateCustomServiceConstantLogic constructor. + * @param FetchesServiceType $fetchesServiceType + * @param CreatesServiceTypeConstantDetails $createsServiceTypeConstantDetails + * @param FetchesSegment $fetchesSegment + * @param FetchesConstant $fetchesConstant + * @param UpdatesConstant $updatesConstant + * @param CreatesConstant $createsConstant + */ + public function __construct(FetchesServiceType $fetchesServiceType, CreatesServiceTypeConstantDetails $createsServiceTypeConstantDetails, FetchesSegment $fetchesSegment, FetchesConstant $fetchesConstant, UpdatesConstant $updatesConstant, CreatesConstant $createsConstant) + { + $this->fetchesServiceType = $fetchesServiceType; + $this->createsServiceTypeConstantDetails = $createsServiceTypeConstantDetails; + $this->fetchesSegment = $fetchesSegment; + $this->fetchesConstant = $fetchesConstant; + $this->updatesConstant = $updatesConstant; + $this->createsConstant = $createsConstant; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + + $service = $this->fetchesServiceType->execute(['id' => $request->input('id')]); + + $customFields = $request->input('custom_fields'); + + $object = new ServiceDetailObject($service->id, $customFields['bank_id'], $customFields['service_charge'], + $customFields['minimum_charge'], $customFields['tax'], $customFields['po_limit'], $request->input('configurations.currencies'), + $request->input('configurations.active'), true); + + $constantObject = new ConstantObject('Custom Service Type', SegmentConstants::CUSTOM_SERVICE_TYPE, $this->createsServiceTypeConstantDetails->execute($object, true)); + + /** @var Segment $segment */ + $segment = $this->fetchesSegment->execute(['id' => $request->route('id')]); + + try { + + $constant = $this->fetchesConstant->execute(['segment_id' => $segment->id, 'custom_service_type' => $object->getId()]); + + $this->updatesConstant->execute($constant, $constantObject); + + } catch (ResourceNotFoundException $exception){ + + $constant = $this->createsConstant->execute($segment, $constantObject); + } + + + return $this->resourceResponse(new CustomServiceTypeResource($constant)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateServiceTypeLogic.php b/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateServiceTypeLogic.php new file mode 100644 index 00000000..51b88051 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateServiceTypeLogic.php @@ -0,0 +1,112 @@ + 'Updated Service Type', + 'message' => 'You have successfully updated the Service Type' + ]; + } + + /** @var CanUpdateServiceType */ + private $canUpdateServiceType; + + /** @var UpdatesServiceType */ + private $updatesServiceType; + + /** @var FetchesServiceType */ + private $fetchesServiceType; + + /** @var CreatesServiceTypeConstantDetails */ + private $createsServiceTypeConstantDetails; + + /** @var UpdatesServiceCurrencyRates */ + private $updatesServiceCurrencyRates; + + /** @var UpdatesConstant */ + private $updatesConstant; + + /** @var FetchesConstant */ + private $fetchesConstant; + + + /** + * UpdateServiceTypeLogic constructor. + * @param CanUpdateServiceType $canUpdateServiceType + * @param UpdatesServiceType $updatesServiceType + * @param FetchesServiceType $fetchesServiceType + * @param CreatesServiceTypeConstantDetails $createsServiceTypeConstantDetails + * @param UpdatesServiceCurrencyRates $updatesServiceCurrencyRates + * @param UpdatesConstant $updatesConstant + * @param FetchesConstant $fetchesConstant + */ + public function __construct(CanUpdateServiceType $canUpdateServiceType, UpdatesServiceType $updatesServiceType, FetchesServiceType $fetchesServiceType, CreatesServiceTypeConstantDetails $createsServiceTypeConstantDetails, UpdatesServiceCurrencyRates $updatesServiceCurrencyRates, UpdatesConstant $updatesConstant, FetchesConstant $fetchesConstant) + { + $this->canUpdateServiceType = $canUpdateServiceType; + $this->updatesServiceType = $updatesServiceType; + $this->fetchesServiceType = $fetchesServiceType; + $this->createsServiceTypeConstantDetails = $createsServiceTypeConstantDetails; + $this->updatesServiceCurrencyRates = $updatesServiceCurrencyRates; + $this->updatesConstant = $updatesConstant; + $this->fetchesConstant = $fetchesConstant; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + $object = new ServiceTypeObject($request->input('name')); + + $this->canUpdateServiceType->passes($object); + + $service = $this->fetchesServiceType->execute(['id' => $request->route('id')]); + + /** @var ServiceType $service */ + $service = $this->updatesServiceType->execute($service, $object); + + $object = new ServiceDetailObject($service->id, (int) $request->input('configurations.bank_id'), + $request->input('configurations.service_charge'), $request->input('configurations.minimum_charge'), $request->input('configurations.tax'), + $request->input('configurations.po_limit'), $request->input('configurations.currencies'), $request->input('configurations.active'), $request->input('configurations.billable')); + + $this->updatesServiceCurrencyRates->execute($service, $object->getCurrencies()); + + $constantObject = new ConstantObject('Service Type', SegmentConstants::SERVICE_TYPE, $this->createsServiceTypeConstantDetails->execute($object)); + + $this->updatesConstant->execute($this->fetchesConstant->execute(['service_type' => $service->id]), $constantObject); + + return $this->resourceResponse(new ServiceTypeResource($service)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateServiceTypeStatusLogic.php b/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateServiceTypeStatusLogic.php new file mode 100644 index 00000000..f1d75665 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/ControllersLogic/UpdateServiceTypeStatusLogic.php @@ -0,0 +1,59 @@ + 'Update Service Type', + 'message' => 'You have successfully updated a Service Type status' + ]; + } + + /** @var FetchesServiceType */ + private $fetchesServiceType; + + /** @var UpdatesServiceTypeStatus */ + private $updatesServiceTypeStatus; + + /** + * UpdateServiceTypeStatusLogic constructor. + * @param FetchesServiceType $fetchesServiceType + * @param UpdatesServiceTypeStatus $updatesServiceTypeStatus + */ + public function __construct(FetchesServiceType $fetchesServiceType, UpdatesServiceTypeStatus $updatesServiceTypeStatus) + { + $this->fetchesServiceType = $fetchesServiceType; + $this->updatesServiceTypeStatus = $updatesServiceTypeStatus; + } + + /** + * @param Request $request + * @return JsonResponse + */ + public function logic(Request $request) : JsonResponse + { + + + $query = $this->fetchesServiceType->execute(['id' => $request->route('id')]); + + $this->updatesServiceTypeStatus->execute($query, $request->route('status') === 'active' ? ApprovalStatus::APPROVED : ApprovalStatus::SUSPENDED); + + return $this->response([]); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/DataTransferObjects/CustomConfigurationsObject.php b/app/Classes/Modules/ServiceTypes/DataTransferObjects/CustomConfigurationsObject.php new file mode 100644 index 00000000..b14caa8c --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/DataTransferObjects/CustomConfigurationsObject.php @@ -0,0 +1,75 @@ +configurations = $configurations; + $this->customOptions = $customOptions; + } + + /** + * @return SegmentConstant + */ + public function getConfigurations(): SegmentConstant + { + return $this->configurations; + } + + /** + * @return SegmentConstant + */ + public function getCustomOptions(): SegmentConstant + { + return $this->customOptions; + } + + + /** + * @param string $name + * @return mixed + */ + public function getConfigurationValue(string $name) { + return property_exists($this->getCustomOptions()->detail, $name) ? + $this->getCustomOptions()->detail->$name: $this->configurations->detail->$name; + } + + + /** + * @return mixed + */ + public function calculateServiceCharge(){ + return ($this->getConfigurationValue('service_charge')->value * 0.01) > $this->getConfigurationValue('minimum_charge')->value ? + $this->getConfigurationValue('service_charge')->value : $this->getConfigurationValue('minimum_charge')->value; + } + + /** + * @return float + */ + public function calculateTax(){ + return $this->getConfigurationValue('tax')->value * 0.01; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceCurrenciesObject.php b/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceCurrenciesObject.php new file mode 100644 index 00000000..fa32e5dd --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceCurrenciesObject.php @@ -0,0 +1,90 @@ +id = $id; + $this->isActive = $isActive; + $this->maxLimit = $maxLimit; + $this->minLimit = $minLimit; + $this->rates = $rates; + } + + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @return bool + */ + public function isActive(): bool + { + return $this->isActive; + } + + /** + * @return array + */ + public function getMaxLimit(): array + { + return $this->maxLimit; + } + + /** + * @return array + */ + public function getMinLimit(): array + { + return $this->minLimit; + } + + + /** + * @return array + */ + public function getRates(): array + { + return array_map(function($rate){ + return new RateObject($rate['selling'], $rate['payment_method']); + }, $this->rates); + } + + + + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceDetailObject.php b/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceDetailObject.php new file mode 100644 index 00000000..233d1fb3 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceDetailObject.php @@ -0,0 +1,138 @@ +id = $id; + $this->bankId = $bankId; + $this->serviceCharge = $serviceCharge; + $this->minimumCharge = $minimumCharge; + $this->tax = $tax; + $this->poLimit = $poLimit; + $this->currencies = $currencies; + $this->isActive = $isActive; + $this->isBillable = $isBillable; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @return int|null + */ + public function getBankId(): ?int + { + return $this->bankId; + } + + /** + * @return array|null + */ + public function getServiceCharge(): ?array + { + return $this->serviceCharge; + } + + /** + * @return array|null + */ + public function getMinimumCharge(): ?array + { + return $this->minimumCharge; + } + + /** + * @return array|null + */ + public function getTax(): ?array + { + return $this->tax; + } + + /** + * @return array|null + */ + public function getPoLimit(): ?array + { + return $this->poLimit; + } + + /** + * @return bool + */ + public function isActive(): bool + { + return $this->isActive; + } + + /** + * @return bool + */ + public function isBillable(): bool + { + return $this->isBillable; + } + + + /** + * @return array|null + */ + public function getCurrencies(): ?array + { + return array_map(function($currency){ + return new ServiceCurrenciesObject($currency['id'], $currency['active'], $currency['maximum_limit'], $currency['minimum_limit'], $currency['rates']); + }, $this->currencies); + } + + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceTypeObject.php b/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceTypeObject.php new file mode 100644 index 00000000..f65b7262 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/DataTransferObjects/ServiceTypeObject.php @@ -0,0 +1,33 @@ +name = $name; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Services/CreatesServiceType.php b/app/Classes/Modules/ServiceTypes/Services/CreatesServiceType.php new file mode 100644 index 00000000..e9c05e94 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Services/CreatesServiceType.php @@ -0,0 +1,19 @@ +name = $object->getName(); + + return $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Services/CreatesServiceTypeConstantDetails.php b/app/Classes/Modules/ServiceTypes/Services/CreatesServiceTypeConstantDetails.php new file mode 100644 index 00000000..aacf66f1 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Services/CreatesServiceTypeConstantDetails.php @@ -0,0 +1,141 @@ +mapCurrencies($object->$methodName(), $isCustomSegment); + + continue; + } + + $this->addToConstantDetails($methodName, $this->cleanValue($object->$methodName())); + + } + + return $this->ConstantDetails; + + } + + /** + * @param array $currencies + * @param bool $isCustomSegment + */ + private function mapCurrencies(array $currencies, bool $isCustomSegment){ + + $isEmpty = true; + foreach ($currencies as $currency){ + + if(!$currency->isActive()) { continue; } + + $currencyObject = []; + + + foreach (Helper::getClassMethodsArray(ServiceCurrenciesObject::class) as $methodName){ + + if($methodName === 'isActive') continue; + if($methodName === 'getRates') { + $currencyObject['rates'] = $this->mapRates($currency->$methodName(), $isCustomSegment); + continue; + } + + $value = $this->cleanValue($currency->$methodName()); + + if($this->isAddable($value)) { + $isEmpty = false; + $currencyObject[Helper::getPropertyName($methodName)] = $value; + } + + } + + $this->addToCurrencyDetails($currencyObject); + + } + + if($isEmpty) $this->ConstantDetails['currencies'] = []; + + } + + private function mapRates(array $rates, bool $isCustomSegment){ + + if(!$isCustomSegment) return []; + + $ratesObject = []; + + /** @var RateObject $rate */ + foreach ($rates as $rate){ + + $selling = $this->cleanValue($rate->getSelling()); + + if(!$selling['value']) continue; + + $ratesObject[] = [ + 'payment_type' => $rate->getPaymentMethodType(), + 'payment_method' => PaymentMethodType::PAYMENT_METHODS_ID[$rate->getPaymentMethodType()], + 'selling' => $rate->getSelling() + ]; + + } + return $ratesObject; + + } + + + /** + * @param string $methodName + * @param $value + */ + private function addToConstantDetails(string $methodName, $value){ + $this->isAddable($value) ? $this->ConstantDetails[Helper::getPropertyName($methodName)] = $value : null; + } + + /** + * @param $value + * @return bool + */ + private function isAddable($value){ + + return $value !== '' && $value !== null; + } + + private function cleanValue($value){ + + if(is_array($value)) { + if(array_key_exists('value', $value)) $value['value'] = floatval(str_replace(',', '', $value['value'])); + } + + return $value; + } + + /** + * @param array $value + */ + private function addToCurrencyDetails(array $value){ + $this->ConstantDetails['currencies'][] = $value; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Services/DeletesServiceType.php b/app/Classes/Modules/ServiceTypes/Services/DeletesServiceType.php new file mode 100644 index 00000000..3cc4d69d --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Services/DeletesServiceType.php @@ -0,0 +1,15 @@ +handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Services/FetchesServiceBankConfigurations.php b/app/Classes/Modules/ServiceTypes/Services/FetchesServiceBankConfigurations.php new file mode 100644 index 00000000..28843e4d --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Services/FetchesServiceBankConfigurations.php @@ -0,0 +1,27 @@ +fetchesBank = $fetchesBank; + } + + public function execute(SegmentConstant $constants) + { + return $this->fetchesBank->execute(['id' => $constants->detail->bank_id]); + } +} diff --git a/app/Classes/Modules/ServiceTypes/Services/FetchesServiceConfigurations.php b/app/Classes/Modules/ServiceTypes/Services/FetchesServiceConfigurations.php new file mode 100644 index 00000000..d641d641 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Services/FetchesServiceConfigurations.php @@ -0,0 +1,65 @@ +fetchesConstant = $fetchesConstant; + $this->fetchesServiceCurrenciesConfigurations = $fetchesServiceCurrenciesConfigurations; + $this->fetchesServiceBankConfigurations = $fetchesServiceBankConfigurations; + } + + + public function execute(SegmentConstant $constant, string $type){ + + return array_merge([ + 'active' => (int) $constant->detail->is_active ?? false, + 'billable' => (int) $constant->detail->is_billable ?? false, + 'bank_id' => property_exists($constant->detail, 'bank_id') ? $constant->detail->bank_id : '', + 'bank_info' => property_exists($constant->detail, 'bank_id') ? $this->fetchesServiceBankConfigurations->execute($constant) : '', + 'currencies' => $this->fetchesServiceCurrenciesConfigurations->execute($constant) + ], $this->addConfigurations($constant)->toArray()); + + } + + private function addConfigurations(SegmentConstant $constant) { + + $configurations = collect(['service_charge', 'minimum_charge', 'tax', 'po_limit']); + + return $configurations->flatMap(function($configuration) use($constant) { + if(!property_exists($constant->detail, $configuration)) return []; + + return [$configuration => [ + 'type' => $constant->detail->$configuration->type, + 'value' => $configuration !== 'po_limit' ? $this->covertToDecimal($constant->detail->$configuration->value) : $constant->detail->$configuration->value + ]]; + + }); + + } + + private function covertToDecimal($value){ + return number_format((float)$value, 2, '.', ''); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Services/FetchesServiceCurrenciesConfigurations.php b/app/Classes/Modules/ServiceTypes/Services/FetchesServiceCurrenciesConfigurations.php new file mode 100644 index 00000000..7d00225a --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Services/FetchesServiceCurrenciesConfigurations.php @@ -0,0 +1,69 @@ +fetchesCurrency = $fetchesCurrency; + } + + public function execute(SegmentConstant $constants){ + + $currencies = array_map(function($configuration) use($constants){ + + $currency = $this->fetchesCurrency->execute(['id' => $configuration->id]); + + if(! $currency->exists()) return []; + + return json_decode(json_encode([ + 'currency_object' => new CurrencyResource($currency), + 'id' => $configuration->id, + 'active' => true, + 'maximum_limit' => [ + 'type' => $configuration->max_limit->type, + 'value' => number_format((float)$configuration->max_limit->value, 2, '.', ',') + ], + 'minimum_limit' => [ + 'type' => $configuration->min_limit->type, + 'value' => number_format((float)$configuration->min_limit->value, 2, '.', ',') + ], + 'rates' => $constants->reference === SegmentConstants::SERVICE_TYPE ? $this->standardRates($currency->rates->where('service_id', $constants->detail->id)) : $configuration->rates + ])); + + }, $constants->detail->currencies); + + return array_filter($currencies); + + } + + private function standardRates(Collection $rates){ + return $rates->map(function($rate){ + return [ + 'payment_method' => PaymentMethodType::PAYMENT_METHODS_ID[$rate->payment_method_type], + 'selling' => [ + 'type' => 'rate', + 'value' => $rate->selling + ] + ]; + }); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Services/FetchesServiceType.php b/app/Classes/Modules/ServiceTypes/Services/FetchesServiceType.php new file mode 100644 index 00000000..7b5899fa --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Services/FetchesServiceType.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Services/ListsServiceTypes.php b/app/Classes/Modules/ServiceTypes/Services/ListsServiceTypes.php new file mode 100644 index 00000000..344d6c4d --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Services/ListsServiceTypes.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceCurrencyRates.php b/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceCurrencyRates.php new file mode 100644 index 00000000..019d30b4 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceCurrencyRates.php @@ -0,0 +1,55 @@ +createsRateLog = $createsRateLog; + } + + + /** + * @param ServiceType $service + * @param array $currencies + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function execute(ServiceType $service, array $currencies){ + + /** @var ServiceCurrenciesObject $currency */ + foreach ($currencies as $currency) { + + /** @var RateObject $rate */ + foreach ($currency->getRates() as $rate){ + if($rate->getSelling()['value'] > 0){ + /** @var CurrencyRate $query */ + $query = $service->rates()->updateOrCreate([ + 'currency_id' => $currency->getId(), + 'payment_method_type' => $rate->getPaymentMethodType() + ], ['selling' => $rate->getSelling()['value']]); + + $this->createsRateLog->execute($query); + } + + } + + } + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceType.php b/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceType.php new file mode 100644 index 00000000..06bd1e4f --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceType.php @@ -0,0 +1,19 @@ +name = $object->getName(); + + return $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceTypeStatus.php b/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceTypeStatus.php new file mode 100644 index 00000000..065b218e --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Services/UpdatesServiceTypeStatus.php @@ -0,0 +1,19 @@ +status = $status; + + return $this->handler($model); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Standards/Rules/CanCreateServiceType.php b/app/Classes/Modules/ServiceTypes/Standards/Rules/CanCreateServiceType.php new file mode 100644 index 00000000..0fb57c32 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Standards/Rules/CanCreateServiceType.php @@ -0,0 +1,57 @@ +serviceTypeValidation = $serviceTypeValidation; + } + + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + + } + + /** + * @param ServiceTypeObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->serviceTypeValidation->validate($object); + + } + + + /** + * @param ServiceTypeObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Standards/Rules/CanDeleteServiceType.php b/app/Classes/Modules/ServiceTypes/Standards/Rules/CanDeleteServiceType.php new file mode 100644 index 00000000..1a832257 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Standards/Rules/CanDeleteServiceType.php @@ -0,0 +1,43 @@ +serviceTypeValidation = $serviceTypeValidation; + } + + + /** + * @return bool + */ + protected function authorized(): bool + { + // TODO Set Authorization rules + return true; + + } + + /** + * @param ServiceTypeObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->serviceTypeValidation->validate($object); + + } + + + /** + * @param ServiceTypeObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/ServiceTypes/Standards/Validators/ServiceTypeValidation.php b/app/Classes/Modules/ServiceTypes/Standards/Validators/ServiceTypeValidation.php new file mode 100644 index 00000000..86946a39 --- /dev/null +++ b/app/Classes/Modules/ServiceTypes/Standards/Validators/ServiceTypeValidation.php @@ -0,0 +1,39 @@ + $object->getName() + ]; + } + + /** + * @return array + */ + protected function rules(): array { + return [ + 'name' => 'required' + ]; + } + + /** + * @return array + */ + protected function messages(): array { + return []; + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Announcements/AssignAnnouncementToSegmentController.php b/app/Http/Controllers/Announcements/AssignAnnouncementToSegmentController.php new file mode 100644 index 00000000..8f6d7734 --- /dev/null +++ b/app/Http/Controllers/Announcements/AssignAnnouncementToSegmentController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Announcements/CreateAnnouncementController.php b/app/Http/Controllers/Announcements/CreateAnnouncementController.php new file mode 100644 index 00000000..84da07cf --- /dev/null +++ b/app/Http/Controllers/Announcements/CreateAnnouncementController.php @@ -0,0 +1,20 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Announcements/DeleteAnnouncementController.php b/app/Http/Controllers/Announcements/DeleteAnnouncementController.php new file mode 100644 index 00000000..257640d3 --- /dev/null +++ b/app/Http/Controllers/Announcements/DeleteAnnouncementController.php @@ -0,0 +1,20 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Announcements/ListAnnouncementsController.php b/app/Http/Controllers/Announcements/ListAnnouncementsController.php new file mode 100644 index 00000000..2dcee4d7 --- /dev/null +++ b/app/Http/Controllers/Announcements/ListAnnouncementsController.php @@ -0,0 +1,20 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Announcements/RemoveSegmentFromAnnouncementController.php b/app/Http/Controllers/Announcements/RemoveSegmentFromAnnouncementController.php new file mode 100644 index 00000000..2b65ad98 --- /dev/null +++ b/app/Http/Controllers/Announcements/RemoveSegmentFromAnnouncementController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Announcements/UpdateAnnouncementController.php b/app/Http/Controllers/Announcements/UpdateAnnouncementController.php new file mode 100644 index 00000000..8d406632 --- /dev/null +++ b/app/Http/Controllers/Announcements/UpdateAnnouncementController.php @@ -0,0 +1,20 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Segments/CreateSegmentController.php b/app/Http/Controllers/Segments/CreateSegmentController.php new file mode 100644 index 00000000..2950bdc3 --- /dev/null +++ b/app/Http/Controllers/Segments/CreateSegmentController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Segments/DeleteSegmentController.php b/app/Http/Controllers/Segments/DeleteSegmentController.php new file mode 100644 index 00000000..adf0043b --- /dev/null +++ b/app/Http/Controllers/Segments/DeleteSegmentController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Segments/FetchConstantController.php b/app/Http/Controllers/Segments/FetchConstantController.php new file mode 100644 index 00000000..e3658802 --- /dev/null +++ b/app/Http/Controllers/Segments/FetchConstantController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Segments/FetchSegmentController.php b/app/Http/Controllers/Segments/FetchSegmentController.php new file mode 100644 index 00000000..91961689 --- /dev/null +++ b/app/Http/Controllers/Segments/FetchSegmentController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Segments/ListSegmentsController.php b/app/Http/Controllers/Segments/ListSegmentsController.php new file mode 100644 index 00000000..3dc14ebd --- /dev/null +++ b/app/Http/Controllers/Segments/ListSegmentsController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Segments/UpdateConstantController.php b/app/Http/Controllers/Segments/UpdateConstantController.php new file mode 100644 index 00000000..47def571 --- /dev/null +++ b/app/Http/Controllers/Segments/UpdateConstantController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Segments/UpdateCustomServiceConstantController.php b/app/Http/Controllers/Segments/UpdateCustomServiceConstantController.php new file mode 100644 index 00000000..29bb6655 --- /dev/null +++ b/app/Http/Controllers/Segments/UpdateCustomServiceConstantController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Segments/UpdateSegmentController.php b/app/Http/Controllers/Segments/UpdateSegmentController.php new file mode 100644 index 00000000..51dfe25e --- /dev/null +++ b/app/Http/Controllers/Segments/UpdateSegmentController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Resources/ConstantResource.php b/app/Http/Resources/ConstantResource.php new file mode 100644 index 00000000..c6bcf344 --- /dev/null +++ b/app/Http/Resources/ConstantResource.php @@ -0,0 +1,27 @@ + $this->id, + 'name' => $this->name, + 'reference' => $this->reference, + 'detail' => (App()->make(ConvertsConstantDetailsToResource::class))->execute($this->resource) + ]; + } +} diff --git a/app/Http/Resources/CustomServiceTypeResource.php b/app/Http/Resources/CustomServiceTypeResource.php new file mode 100644 index 00000000..8ec26e47 --- /dev/null +++ b/app/Http/Resources/CustomServiceTypeResource.php @@ -0,0 +1,27 @@ + $this->detail->id, + 'name' => ServiceType::where('id', $this->detail->id)->first()->name, + 'detail' => $this->detail, + 'configurations' => (App()->make(FetchesServiceConfigurations::class))->execute($this->resource, SegmentConstants::CUSTOM_SERVICE_TYPE) + ]; + } +} diff --git a/app/Models/Announcement.php b/app/Models/Announcement.php new file mode 100644 index 00000000..b0094a6c --- /dev/null +++ b/app/Models/Announcement.php @@ -0,0 +1,26 @@ +BelongsToMany(Segment::class); + } +} diff --git a/resources/assets/vue/components/settings/elements/CurrenciesListComponent.vue b/resources/assets/vue/components/settings/elements/CurrenciesListComponent.vue new file mode 100644 index 00000000..3554a8f2 --- /dev/null +++ b/resources/assets/vue/components/settings/elements/CurrenciesListComponent.vue @@ -0,0 +1,218 @@ + + \ No newline at end of file diff --git a/resources/assets/vue/components/settings/elements/PaymentAttemptComponent.vue b/resources/assets/vue/components/settings/elements/PaymentAttemptComponent.vue new file mode 100644 index 00000000..6266afbe --- /dev/null +++ b/resources/assets/vue/components/settings/elements/PaymentAttemptComponent.vue @@ -0,0 +1,151 @@ + + + + diff --git a/resources/assets/vue/components/settings/forms/PaymentAttemptLimitFormComponent.vue b/resources/assets/vue/components/settings/forms/PaymentAttemptLimitFormComponent.vue new file mode 100644 index 00000000..63be0142 --- /dev/null +++ b/resources/assets/vue/components/settings/forms/PaymentAttemptLimitFormComponent.vue @@ -0,0 +1,111 @@ + + \ No newline at end of file diff --git a/resources/assets/vue/components/settings/forms/SegmentFormComponent.vue b/resources/assets/vue/components/settings/forms/SegmentFormComponent.vue new file mode 100644 index 00000000..c8f114cf --- /dev/null +++ b/resources/assets/vue/components/settings/forms/SegmentFormComponent.vue @@ -0,0 +1,59 @@ + + \ No newline at end of file diff --git a/resources/views/pages/settings.blade.php b/resources/views/pages/settings.blade.php index 0ba32f33..56da9e67 100644 --- a/resources/views/pages/settings.blade.php +++ b/resources/views/pages/settings.blade.php @@ -53,7 +53,7 @@ - - + @@ -165,7 +188,7 @@ - - + diff --git a/routes/announcement.php b/routes/announcement.php new file mode 100644 index 00000000..b6016706 --- /dev/null +++ b/routes/announcement.php @@ -0,0 +1,15 @@ + 'announcement', 'as' => 'announcement.', 'namespace' => 'Announcements'], function () { + Route::get('/list', 'ListAnnouncementsController@list')->name('list'); + Route::post('/create', 'CreateAnnouncementController@create')->name('create'); + Route::put('/update/{id}', 'UpdateAnnouncementController@update')->name('update'); + Route::delete('/delete/{id}', 'DeleteAnnouncementController@delete')->name('delete'); + + Route::group(['prefix' => '{id}/segment', 'as' => 'segment.'], function () { + Route::post('/assign', 'AssignAnnouncementToSegmentController@assign')->name('assign'); + Route::delete('/detach/{segment_id}', 'RemoveSegmentFromAnnouncementController@detach')->name('detach'); + }); +}); \ No newline at end of file diff --git a/routes/api.php b/routes/api.php index b8c43155..3c2583ff 100644 --- a/routes/api.php +++ b/routes/api.php @@ -50,6 +50,10 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function require __DIR__ . '/schedule.php'; + require __DIR__ . '/segment.php'; + + require __DIR__ . '/announcement.php'; + Route::get('/report/customer/{marking}/{from?}/{to?}', 'Reports\MonthlyReportController@customerReport')->name('report.customer'); Route::get('/report/sales/{from?}/{to?}', 'Reports\MonthlyReportController@salesReport')->name('report.sales'); Route::get('/report/profit/{model}/{value}/{from?}/{to?}', 'Reports\MonthlyReportController@profitModelReport')->name('report.profit'); diff --git a/routes/segment.php b/routes/segment.php new file mode 100644 index 00000000..b248ea1f --- /dev/null +++ b/routes/segment.php @@ -0,0 +1,17 @@ + 'segment', 'as' => 'segment.', 'namespace' => 'Segments'], function () { + Route::get('/{id}/show', 'FetchSegmentController@fetch')->name('show'); + Route::post('/create', 'CreateSegmentController@create')->name('create'); + Route::put('/update/{id}', 'UpdateSegmentController@update')->name('update'); + Route::delete('/delete/{id}', 'DeleteSegmentController@delete')->name('delete'); + Route::get('/list', 'ListSegmentsController@list')->name('list'); + + Route::group(['prefix' => '{id}/constant', 'as' => 'constant.'], function () { + Route::put('/service/update', 'UpdateCustomServiceConstantController@update')->name('service.update'); + Route::put('/update', 'UpdateConstantController@update')->name('update'); + Route::get('/show/{reference}', 'FetchConstantController@fetch')->name('show'); + }); +}); \ No newline at end of file