mirror of
https://github.com/jikan-me/jikan-rest.git
synced 2025-02-20 11:23:35 +08:00
- updated api docs - fixed top reviews endpoint - fixed reviews parsing - added "contextual" boolean query string parameters, so params without value can be interpreted as "boolean". E.g. ?sfw or ?kid in the url would add "true" value to their corresponding field in the DTO - fixed typesense issues
76 lines
1.6 KiB
PHP
76 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use App\Concerns\FilteredByLetter;
|
|
use Jikan\Request\User\UserProfileRequest;
|
|
|
|
class Profile extends JikanApiSearchableModel
|
|
{
|
|
use FilteredByLetter;
|
|
protected array $filters = [];
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'mal_id', 'username', 'url', 'images', 'last_online', 'gender', 'birthday', 'location', 'joined', 'anime_stats', 'manga_stats', 'favorites', 'about'
|
|
];
|
|
|
|
/**
|
|
* The table associated with the model.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $table = 'users';
|
|
|
|
/**
|
|
* The attributes excluded from the model's JSON form.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $hidden = [
|
|
'_id',
|
|
];
|
|
|
|
public function __construct(array $attributes = [])
|
|
{
|
|
parent::__construct($attributes);
|
|
$this->displayNameFieldName = "username";
|
|
}
|
|
|
|
public static function scrape(string $username)
|
|
{
|
|
$data = app('JikanParser')->getUserProfile(new UserProfileRequest($username));
|
|
|
|
return json_decode(
|
|
app('SerializerV4')
|
|
->serialize($data, 'json'),
|
|
true
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Converts the model to an index-able data array.
|
|
*
|
|
* @return array
|
|
*/
|
|
public function toSearchableArray(): array
|
|
{
|
|
return [
|
|
'id' => (string) $this->mal_id,
|
|
'mal_id' => (int) $this->mal_id,
|
|
'username' => $this->username
|
|
];
|
|
}
|
|
|
|
public function typesenseQueryBy(): array
|
|
{
|
|
return [
|
|
"username"
|
|
];
|
|
}
|
|
}
|