Skip to content

Commit

Permalink
feat: add search criteria repo
Browse files Browse the repository at this point in the history
  • Loading branch information
Katalam committed Jul 10, 2024
1 parent ce728ab commit 3fdd443
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog
## main

## v0.8.2
- Added search criteria repository

## v0.8.1
- Added a field repository fake

Expand Down
1 change: 1 addition & 0 deletions src/Enums/OnOfficeResourceType.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ enum OnOfficeResourceType: string
case FileRelation = 'fileRelation';
case Impressum = 'impressum';
case Activity = 'agentslog';
case SearchCriteria = 'searchcriterias';
}
29 changes: 29 additions & 0 deletions src/Facades/SearchCriteriaRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace Katalam\OnOfficeAdapter\Facades;

use Illuminate\Support\Facades\Facade;
use Katalam\OnOfficeAdapter\Facades\Testing\SearchCriteriaRepositoryFake;
use Katalam\OnOfficeAdapter\Query\SearchCriteriaBuilder;

/**
* @see \Katalam\OnOfficeAdapter\Repositories\SearchCriteriaRepository
*
* @method static SearchCriteriaBuilder query()
*/
class SearchCriteriaRepository extends Facade
{
public static function fake(array ...$fakeResponses): SearchCriteriaRepositoryFake
{
static::swap($fake = new SearchCriteriaRepositoryFake(...$fakeResponses));

return $fake;
}

protected static function getFacadeAccessor(): string
{
return \Katalam\OnOfficeAdapter\Repositories\SearchCriteriaRepository::class;
}
}
20 changes: 20 additions & 0 deletions src/Facades/Testing/SearchCriteriaRepositoryFake.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Katalam\OnOfficeAdapter\Facades\Testing;

use Katalam\OnOfficeAdapter\Query\Testing\SearchCriteriaBuilderFake;

class SearchCriteriaRepositoryFake
{
use FakeResponses;

/**
* Returns a new fake user builder instance.
*/
public function query(): SearchCriteriaBuilderFake
{
return new SearchCriteriaBuilderFake($this->fakeResponses);
}
}
78 changes: 78 additions & 0 deletions src/Query/SearchCriteriaBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

declare(strict_types=1);

namespace Katalam\OnOfficeAdapter\Query;

use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Katalam\OnOfficeAdapter\Enums\OnOfficeAction;
use Katalam\OnOfficeAdapter\Enums\OnOfficeResourceType;
use Katalam\OnOfficeAdapter\Exceptions\OnOfficeException;
use Katalam\OnOfficeAdapter\Services\OnOfficeService;

class SearchCriteriaBuilder extends Builder
{
private string $mode = 'internal';

public function __construct(
private readonly OnOfficeService $onOfficeService,
) {}

/**
* @throws OnOfficeException
*/
public function get(): Collection
{
throw new OnOfficeException('Not implemented');
}

/**
* @throws OnOfficeException
*/
public function first(): array
{
throw new OnOfficeException('Not implemented');
}

/**
* @throws OnOfficeException
*/
public function find(int|array $id): array
{
$response = $this->onOfficeService->requestApi(
OnOfficeAction::Get,
OnOfficeResourceType::SearchCriteria,
parameters: [
OnOfficeService::MODE => $this->mode,
OnOfficeService::IDS => Arr::wrap($id),
...$this->customParameters,
],
);

return $response->json('response.results.0.data.records');
}

/**
* @throws OnOfficeException
*/
public function each(callable $callback): void
{
throw new OnOfficeException('Not implemented');
}

/**
* @throws OnOfficeException
*/
public function modify(int $id): bool
{
throw new OnOfficeException('Not implemented');
}

public function mode(string $mode): self
{
$this->mode = $mode;

return $this;
}
}
7 changes: 7 additions & 0 deletions src/Query/Testing/SearchCriteriaBuilderFake.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

declare(strict_types=1);

namespace Katalam\OnOfficeAdapter\Query\Testing;

class SearchCriteriaBuilderFake extends BaseFake {}
23 changes: 23 additions & 0 deletions src/Repositories/SearchCriteriaRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Katalam\OnOfficeAdapter\Repositories;

use Katalam\OnOfficeAdapter\Query\SearchCriteriaBuilder;
use Katalam\OnOfficeAdapter\Services\OnOfficeService;

class SearchCriteriaRepository
{
public function __construct(
private readonly OnOfficeService $onOfficeService,
) {}

/**
* Returns a new user builder instance.
*/
public function query(): SearchCriteriaBuilder
{
return new SearchCriteriaBuilder($this->onOfficeService);
}
}
4 changes: 4 additions & 0 deletions src/Services/OnOfficeParameterConst.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ trait OnOfficeParameterConst
public const PARAMETERCACHEID = 'parameterCacheId';

public const EXTENDEDCLAIM = 'extendedclaim';

public const MODE = 'mode';

public const IDS = 'ids';
}

0 comments on commit 3fdd443

Please sign in to comment.