-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #464 from BinaryStudioAcademy/release-1.4.0
Release 1.4.0
- Loading branch information
Showing
193 changed files
with
5,943 additions
and
640 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Actions\ErrorReport; | ||
|
||
use App\Entities\Error; | ||
use App\Entities\Page; | ||
use App\Repositories\Contracts\ErrorReport\ErrorReportRepository; | ||
use App\Repositories\Contracts\PageRepository; | ||
use App\Repositories\Contracts\VisitorRepository; | ||
use App\Repositories\Contracts\WebsiteRepository; | ||
use Tymon\JWTAuth\Facades\JWTAuth; | ||
use Illuminate\Support\Str; | ||
|
||
final class AddErrorReportAction | ||
{ | ||
private $errorReportRepository; | ||
private $websiteRepository; | ||
private $pageRepository; | ||
private $visitorRepository; | ||
|
||
public function __construct( | ||
ErrorReportRepository $errorReportsRepository, | ||
PageRepository $pageRepository, | ||
WebsiteRepository $websiteRepository, | ||
VisitorRepository $visitorRepository | ||
) { | ||
$this->errorReportRepository = $errorReportsRepository; | ||
$this->websiteRepository = $websiteRepository; | ||
$this->pageRepository = $pageRepository; | ||
$this->visitorRepository = $visitorRepository; | ||
} | ||
|
||
public function execute(AddErrorReportActionRequest $request): void | ||
{ | ||
$visitorId = null; | ||
$websiteId = null; | ||
|
||
if ($request->token()) { | ||
JWTAuth::setToken(Str::after($request->token(), 'Bearer ')); | ||
$visitorId = JWTAuth::getPayload()->get('visitor_id'); | ||
$visitor = $this->visitorRepository->getById($visitorId); | ||
$websiteId = $visitor->website_id; | ||
} | ||
|
||
if (!$websiteId) { | ||
$websiteId = $this->websiteRepository | ||
->getByTrackNumber($request->trackNumber())->id; | ||
} | ||
|
||
$page = $this->getOrCreatePage( | ||
$websiteId, | ||
$request->pageTitle(), | ||
$request->page() | ||
); | ||
|
||
$error = new Error(); | ||
|
||
$error->message = $request->message(); | ||
$error->stack_trace = $request->stackTrace(); | ||
$error->visitor_id = $visitorId; | ||
$error->page_id = $page->id; | ||
|
||
$this->errorReportRepository->save($error); | ||
} | ||
|
||
private function getOrCreatePage(int $websiteId, string $pageTitle, string $pageUrl): Page | ||
{ | ||
$page = $this->pageRepository->getByParameters($websiteId, $pageTitle, $pageUrl); | ||
|
||
if ($page !== null) { | ||
return $page; | ||
} | ||
|
||
$page = new Page(); | ||
|
||
$page->name = $pageTitle; | ||
$page->url = $pageUrl; | ||
$page->previews = 0; | ||
$page->website_id = $websiteId; | ||
|
||
return $this->pageRepository->save($page); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
backend/app/Actions/ErrorReport/AddErrorReportActionRequest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Actions\ErrorReport; | ||
|
||
use App\Http\Requests\ErrorReport\AddErrorReportsHttpRequest; | ||
|
||
final class AddErrorReportActionRequest | ||
{ | ||
private $page; | ||
private $token; | ||
private $message; | ||
private $trackNumber; | ||
private $stackTrace; | ||
private $pageTitle; | ||
|
||
private function __construct( | ||
string $page, | ||
string $message, | ||
int $trackNumber, | ||
string $stackTrace, | ||
string $pageTitle, | ||
?string $token | ||
) { | ||
$this->page = $page; | ||
$this->message = $message; | ||
$this->trackNumber = $trackNumber; | ||
$this->stackTrace = $stackTrace; | ||
$this->pageTitle = $pageTitle; | ||
$this->token = $token; | ||
} | ||
|
||
public static function fromRequest(AddErrorReportsHttpRequest $request): self | ||
{ | ||
return new static( | ||
$request->page(), | ||
$request->message(), | ||
(int) $request->trackNumber(), | ||
$request->stackTrace(), | ||
$request->pageTitle(), | ||
$request->token() | ||
); | ||
} | ||
|
||
public function page(): string | ||
{ | ||
return $this->page; | ||
} | ||
|
||
public function message(): string | ||
{ | ||
return $this->message; | ||
} | ||
public function trackNumber(): int | ||
{ | ||
return $this->trackNumber; | ||
} | ||
|
||
public function stackTrace(): string | ||
{ | ||
return $this->stackTrace; | ||
} | ||
public function pageTitle(): string | ||
{ | ||
return $this->pageTitle; | ||
} | ||
|
||
public function token(): ?string | ||
{ | ||
return $this->token; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
backend/app/Actions/ErrorReport/GetChartErrorByDateRangeAction.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Actions\ErrorReport; | ||
|
||
use App\Repositories\Contracts\ErrorReport\ErrorReportRepository; | ||
use Carbon\Carbon; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
final class GetChartErrorByDateRangeAction | ||
{ | ||
private $repository; | ||
|
||
public function __construct(ErrorReportRepository $repository) | ||
{ | ||
$this->repository = $repository; | ||
} | ||
|
||
public function execute(GetChartErrorByDateRangeRequest $request): GetChartErrorByDateRangeResponse | ||
{ | ||
$startData = Carbon::createFromTimestampUTC( | ||
$request->period()->getStartDate()->getTimestamp() | ||
)->toDateTimeString(); | ||
|
||
$endData = Carbon::createFromTimestampUTC( | ||
$request->period()->getEndDate()->getTimestamp() | ||
)->toDateTimeString(); | ||
|
||
$response = $this->repository->getErrorsCountByDate( | ||
$startData, | ||
$endData, | ||
$request->interval(), | ||
Auth::user()->website->id | ||
); | ||
return new GetChartErrorByDateRangeResponse($response); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
backend/app/Actions/ErrorReport/GetChartErrorByDateRangeRequest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Actions\ErrorReport; | ||
|
||
use App\Actions\ChartDataRequest; | ||
use App\Http\Requests\ErrorReport\GetChartErrorByDateRangeHttpRequest; | ||
|
||
final class GetChartErrorByDateRangeRequest extends ChartDataRequest | ||
{ | ||
public static function fromRequest(GetChartErrorByDateRangeHttpRequest $request): self | ||
{ | ||
return new static( | ||
$request->getStartDate(), | ||
$request->getEndDate(), | ||
$request->getPeriod() | ||
); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
backend/app/Actions/ErrorReport/GetChartErrorByDateRangeResponse.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Actions\ErrorReport; | ||
|
||
use Illuminate\Support\Collection; | ||
|
||
final class GetChartErrorByDateRangeResponse | ||
{ | ||
private $errorsByDateRange; | ||
|
||
public function __construct(Collection $errorsByDateRange) | ||
{ | ||
$this->errorsByDateRange = $errorsByDateRange; | ||
} | ||
|
||
public function getErrorCountByDateRange(): Collection | ||
{ | ||
return $this->errorsByDateRange; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
backend/app/Actions/ErrorReport/GetErrorTableItemsAction.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Actions\ErrorReport; | ||
|
||
use App\Repositories\Contracts\ErrorReport\ErrorReportRepository; | ||
use Illuminate\Support\Facades\Auth; | ||
|
||
class GetErrorTableItemsAction | ||
{ | ||
private $repository; | ||
|
||
public function __construct(ErrorReportRepository $repository) | ||
{ | ||
$this->repository = $repository; | ||
} | ||
|
||
public function execute(GetErrorTableItemsRequest $request): GetErrorTableItemsResponse | ||
{ | ||
$period = $request->period(); | ||
$website_id = Auth::user()->website->id; | ||
|
||
$errors = $this->repository->getErrorItemsGroupByPage($website_id, $period); | ||
|
||
return new GetErrorTableItemsResponse($errors); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
backend/app/Actions/ErrorReport/GetErrorTableItemsRequest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Actions\ErrorReport; | ||
|
||
use App\Http\Requests\ErrorReport\GetErrorTableItemsHttpRequest; | ||
use App\Actions\TableDataRequest; | ||
|
||
class GetErrorTableItemsRequest extends TableDataRequest | ||
{ | ||
public static function fromRequest(GetErrorTableItemsHttpRequest $request): self | ||
{ | ||
return new static ( | ||
$request->startDate(), | ||
$request->endDate(), | ||
$request->parameter() | ||
); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
backend/app/Actions/ErrorReport/GetErrorTableItemsResponse.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Actions\ErrorReport; | ||
|
||
use Illuminate\Support\Collection; | ||
|
||
class GetErrorTableItemsResponse | ||
{ | ||
private $errors; | ||
|
||
public function __construct(Collection $errors) | ||
{ | ||
$this->errors = $errors; | ||
} | ||
|
||
public function getGroupedErrors(): Collection | ||
{ | ||
return $this->errors; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace App\Actions\User; | ||
|
||
use App\Exceptions\ResetPasswordException; | ||
use App\Exceptions\UserNotFoundException; | ||
use App\Repositories\Contracts\UserRepository; | ||
use Illuminate\Database\Eloquent\ModelNotFoundException; | ||
use Illuminate\Support\Facades\Hash; | ||
|
||
class UpdateUserPasswordAction | ||
{ | ||
private $userRepository; | ||
|
||
public function __construct(UserRepository $userRepository) | ||
{ | ||
$this->userRepository = $userRepository; | ||
} | ||
|
||
public function execute(UpdateUserPasswordRequest $request): UpdateUserPasswordResponse | ||
{ | ||
$user = auth()->user(); | ||
if (!$user) { | ||
throw new ResetPasswordException(); | ||
} | ||
try { | ||
$user = $this->userRepository->getByEmail($user->email); | ||
} catch (ModelNotFoundException $exception) { | ||
throw new UserNotFoundException(); | ||
} | ||
$user->password = Hash::make($request->getPassword()); | ||
$this->userRepository->save($user); | ||
return new UpdateUserPasswordResponse(); | ||
} | ||
} |
Oops, something went wrong.