fixed minor issues

This commit is contained in:
pushrbx 2023-01-28 21:13:57 +00:00
parent 9b5b5aad1e
commit 118fc4f84b
16 changed files with 72 additions and 23 deletions

View File

@ -19,7 +19,7 @@ class Club extends JikanApiSearchableModel
* @var array
*/
protected $fillable = [
'mal_id', 'url', 'images', 'title', 'members_count', 'pictures_count', 'category', 'created', 'type', 'staff', 'anime_relations', 'manga_relations', 'character_relations'
'mal_id', 'url', 'images', 'name', 'members', 'category', 'created', 'access', 'anime', 'manga'
];
/**
@ -79,15 +79,16 @@ class Club extends JikanApiSearchableModel
return [
'id' => (string) $this->mal_id,
'mal_id' => (string) $this->mal_id,
'title' => $this->title,
'name' => $this->name,
'category' => $this->category,
'created' => $this->convertToTimestamp($this->created),
'type' => $this->type
'access' => $this->type,
'members' => $this->members
];
}
public function typesenseQueryBy(): array
{
return ['title'];
return ['name'];
}
}

View File

@ -2,6 +2,7 @@
namespace App\Dto;
use App\Dto\Concerns\HasPageParameter;
use Illuminate\Http\JsonResponse;
use Spatie\LaravelData\Attributes\Validation\Min;
use Spatie\LaravelData\Attributes\Validation\Numeric;
@ -12,6 +13,7 @@ use Spatie\LaravelData\Optional;
*/
final class ClubMembersLookupCommand extends LookupDataCommand
{
// use HasPageParameter;
#[Numeric, Min(1)]
public int|Optional $page = 1;
}

View File

@ -10,6 +10,7 @@ use App\Rules\Attributes\EnumValidation;
use Spatie\Enum\Laravel\Rules\EnumRule;
use Spatie\LaravelData\Attributes\Validation\Alpha;
use Spatie\LaravelData\Attributes\Validation\Max;
use Spatie\LaravelData\Attributes\Validation\Prohibits;
use Spatie\LaravelData\Attributes\Validation\Size;
use Spatie\LaravelData\Attributes\Validation\StringType;
use Spatie\LaravelData\Attributes\WithCast;
@ -30,6 +31,6 @@ class SearchCommand extends Data
#[WithCast(EnumCast::class, SortDirection::class), EnumValidation(SortDirection::class)]
public SortDirection|Optional $sort;
#[Size(1), StringType, Alpha]
#[Size(1), StringType, Alpha, Prohibits("q")]
public string|Optional $letter;
}

View File

@ -6,18 +6,23 @@ use Spatie\Enum\Laravel\Enum;
/**
* @method static self mal_id()
* @method static self title()
* @method static self name()
* @method static self members_count()
* @method static self pictures_count()
* @method static self created()
*
* @OA\Schema(
* schema="club_search_query_orderby",
* description="Club Search Query OrderBy",
* type="string",
* enum={"mal_id","title","members_count","pictures_count","created"}
* enum={"mal_id","name","members_count","created"}
* )
*/
final class ClubOrderByEnum extends Enum
{
protected static function labels(): array
{
return [
"members_count" => "members"
];
}
}

View File

@ -2,7 +2,7 @@
namespace App\Features;
use App\Dto\AnimeStatsLookupCommand;
use App\Dto\AnimeMoreInfoLookupCommand;
use App\Http\Resources\V4\MoreInfoResource;
use App\Support\CachedData;
use Illuminate\Http\JsonResponse;
@ -12,7 +12,7 @@ use Jikan\MyAnimeList\MalClient;
use Jikan\Request\Anime\AnimeMoreInfoRequest;
/**
* @extends RequestHandlerWithScraperCache<AnimeStatsLookupCommand, JsonResponse>
* @extends RequestHandlerWithScraperCache<AnimeMoreInfoLookupCommand, JsonResponse>
*/
final class AnimeMoreInfoLookupHandler extends RequestHandlerWithScraperCache
{
@ -28,7 +28,7 @@ final class AnimeMoreInfoLookupHandler extends RequestHandlerWithScraperCache
*/
public function requestClass(): string
{
return AnimeStatsLookupCommand::class;
return AnimeMoreInfoLookupCommand::class;
}
protected function getScraperData(string $requestFingerPrint, Collection $requestParams): CachedData

View File

@ -9,6 +9,7 @@ use Illuminate\Http\JsonResponse;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Collection;
use Jikan\MyAnimeList\MalClient;
use Jikan\Request\Anime\AnimeStatsRequest;
/**
* @extends RequestHandlerWithScraperCache<AnimeStatsLookupCommand, JsonResponse>
@ -36,7 +37,7 @@ final class AnimeStatsLookupHandler extends RequestHandlerWithScraperCache
return $this->scraperService->findList(
$requestFingerPrint,
fn (MalClient $jikan, ?int $page = null) => $jikan->getAnimeStats($id)
fn (MalClient $jikan, ?int $page = null) => $jikan->getAnimeStats(new AnimeStatsRequest($id))
);
}
}

View File

@ -3,7 +3,7 @@
namespace App\Features;
use App\Dto\AnimeThemesLookupCommand;
use App\Http\Resources\V4\StreamingLinksResource;
use App\Http\Resources\V4\AnimeThemesResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Collection;
@ -16,7 +16,7 @@ final class AnimeThemesLookupHandler extends ItemLookupHandler
protected function resource(Collection $results): JsonResource
{
return new StreamingLinksResource(
return new AnimeThemesResource(
$results->first()
);
}

View File

@ -9,7 +9,7 @@ use Illuminate\Contracts\Pagination\LengthAwarePaginator;
/**
* @extends SearchRequestHandler<CharactersSearchCommand, CharacterCollection>
*/
class CharacterSearchHandler extends SearchRequestHandler
final class CharacterSearchHandler extends SearchRequestHandler
{
/**
* @inheritDoc

View File

@ -9,7 +9,7 @@ use Illuminate\Contracts\Pagination\LengthAwarePaginator;
/**
* @extends SearchRequestHandler<ClubSearchCommand, ClubCollection>
*/
class ClubSearchHandler extends SearchRequestHandler
final class ClubSearchHandler extends SearchRequestHandler
{
/**

View File

@ -14,6 +14,6 @@ trait ResolvesMediaReviewParams
$spoilers = $requestParams->get("spoilers", false);
$preliminary = $requestParams->get("preliminary", false);
return compact($id, $sort, $spoilers, $preliminary);
return compact("id", "sort", "spoilers", "preliminary");
}
}

View File

@ -9,7 +9,7 @@ use Illuminate\Contracts\Pagination\LengthAwarePaginator;
/**
* @extends SearchRequestHandler<MagazineSearchCommand, MagazineCollection>
*/
class MagazineSearchHandler extends SearchRequestHandler
final class MagazineSearchHandler extends SearchRequestHandler
{
/**
* @inheritDoc

View File

@ -9,6 +9,8 @@ use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Http\Resources\Json\ResourceCollection;
use Illuminate\Http\Response;
use Illuminate\Support\Collection;
use Spatie\Enum\Laravel\Enum;
/**
* @template TRequest of DataRequest<TResponse>
@ -28,7 +30,9 @@ abstract class SearchRequestHandler implements RequestHandler
{
// note: ->all() doesn't transform the dto, all the parsed data is returned as it was parsed. (and validated)
$requestData = collect($request->all());
$builder = $this->queryBuilderService->query($requestData);
$builder = $this->queryBuilderService->query(
$this->prepareOrderByParam($requestData)
);
$page = $requestData->get("page");
$limit = $requestData->get("limit");
$paginator = $this->queryBuilderService->paginateBuilder($builder, $page, $limit);
@ -41,4 +45,14 @@ abstract class SearchRequestHandler implements RequestHandler
* @return TResponse
*/
protected abstract function renderResponse(LengthAwarePaginator $paginator);
protected function prepareOrderByParam(Collection $requestData): Collection
{
if ($requestData->has("order_by") && $requestData->get("order_by") instanceof Enum)
{
$requestData->offsetSet("order_by", $requestData->get("order_by")->label);
}
return $requestData;
}
}

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers\V4DB;
use App\Dto\AnimeGenreListCommand;
use App\Dto\MangaGenreListCommand;
use App\Http\Resources\V4\GenreCollection;
class GenreController extends Controller
@ -63,7 +64,7 @@ class GenreController extends Controller
* ),
* )
*/
public function manga(AnimeGenreListCommand $command): GenreCollection
public function manga(MangaGenreListCommand $command): GenreCollection
{
return $this->mediator->send($command);
}

View File

@ -2,6 +2,7 @@
namespace App\Macros;
use App\JikanApiModel;
use Illuminate\Support\Collection;
/**
@ -19,7 +20,14 @@ final class CollectionOffsetGetFirst
$firstItem = $this->first();
if (is_array($firstItem)) {
$result = collect($firstItem)->get($offset, $default);
} else {
}
else if ($firstItem instanceof JikanApiModel) {
$result = $firstItem[$offset];
}
else if ($firstItem instanceof Collection) {
$result = $firstItem->get($offset, $default);
}
else {
$result = $default;
}

View File

@ -45,7 +45,7 @@ class DatabaseRepository extends RepositoryQuery implements Repository
// this is here because we have the "scrape" static method on models
public function scrape(int|string $id): array
{
$modelClass = get_class($this->queryable(true)->newModelInstance());
$modelClass = $this->getModelClass();
/** @noinspection PhpUndefinedMethodInspection */
return $modelClass::scrape($id);
@ -53,11 +53,21 @@ class DatabaseRepository extends RepositoryQuery implements Repository
public function insert(array $attributes): bool
{
return $this->queryable(true)->insert($attributes);
// this way we trigger scout to index records in the search index.
$modelClass = $this->getModelClass();
/** @noinspection PhpUndefinedMethodInspection */
$modelClass::create($attributes);
return true;
}
public function random(int $numberOfRandomItems = 1): Collection
{
return $this->queryable(true)->random($numberOfRandomItems);
}
private function getModelClass(): string
{
return get_class($this->queryable(true)->newModelInstance());
}
}

View File

@ -27,6 +27,12 @@ final class DocumentRepository extends DatabaseRepository
return $this->tableName;
}
public function insert(array $attributes): bool
{
// override the parent method, because these records are not search indexed
return $this->queryable(true)->insert($attributes);
}
public function createEntity()
{
throw new \Exception("Not supported");