Skip to content

Commit

Permalink
Merge pull request #464 from BinaryStudioAcademy/release-1.4.0
Browse files Browse the repository at this point in the history
Release 1.4.0
  • Loading branch information
lenchvolodymyr authored Sep 11, 2019
2 parents 5dc69f8 + b6ec9fd commit 4476d68
Show file tree
Hide file tree
Showing 193 changed files with 5,943 additions and 640 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ script:
- docker-compose -f docker-compose.test.yml exec app composer install
- docker-compose -f docker-compose.test.yml exec app php artisan key:generate
- docker-compose -f docker-compose.test.yml exec app php artisan jwt:secret
- until curl --silent -XGET --fail http://localhost:9200; do printf '.'; sleep 1; done
- docker-compose -f docker-compose.test.yml exec app php artisan migrate
- docker-compose -f docker-compose.test.yml exec app php artisan db:seed --class=DefaultUserAndWebsiteSeeder
- docker-compose -f docker-compose.test.yml exec app ./vendor/bin/phpunit
Expand Down
85 changes: 85 additions & 0 deletions backend/app/Actions/ErrorReport/AddErrorReportAction.php
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 backend/app/Actions/ErrorReport/AddErrorReportActionRequest.php
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 backend/app/Actions/ErrorReport/GetChartErrorByDateRangeAction.php
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);
}
}
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()
);
}
}
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 backend/app/Actions/ErrorReport/GetErrorTableItemsAction.php
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 backend/app/Actions/ErrorReport/GetErrorTableItemsRequest.php
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 backend/app/Actions/ErrorReport/GetErrorTableItemsResponse.php
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ public function execute(GetGeoLocationItemsRequest $request): GetGeoLocationItem
$response = $collection->map(function ($item) {
$bounce_rate = 0;

if (isset($item['bounced_visitors_count']) && isset($item['all_visitors_count']) && $item['all_visitors_count'] > 0) {
if (
isset($item['bounced_visitors_count'], $item['all_visitors_count']) &&
$item['all_visitors_count'] > 0
) {
$bounce_rate = $item['bounced_visitors_count'] / $item['all_visitors_count'];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace App\Actions\PageTimings;

use App\Actions\TableDataRequest;
use App\Http\Request\PageTimingTableHttpRequest;
use App\Http\Requests\PageTimings\PageTimingTableHttpRequest;

class GetAverageTimingByParamRequest extends TableDataRequest
{
Expand Down
36 changes: 36 additions & 0 deletions backend/app/Actions/User/UpdateUserPasswordAction.php
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();
}
}
Loading

0 comments on commit 4476d68

Please sign in to comment.