Fix tests and start on profile page
This commit is contained in:
parent
3e68fec704
commit
5605384b6a
@ -4,7 +4,7 @@
|
||||
<img class="cover" width="402" height="284" src="<?= $data['image']['original'] ?>" alt="" />
|
||||
</div>
|
||||
<div>
|
||||
<h3><?= $data['name'] ?></h3>
|
||||
<h2><?= $data['name'] ?></h2>
|
||||
|
||||
<p><?= $data['description'] ?></p>
|
||||
</div>
|
||||
|
25
app/views/me.php
Normal file
25
app/views/me.php
Normal file
@ -0,0 +1,25 @@
|
||||
<main class="details">
|
||||
<section class="flex flex-no-wrap">
|
||||
<div>
|
||||
<h2><?= $attributes['name'] ?></h2>
|
||||
<img src="<?= $attributes['avatar']['original'] ?>" alt="" />
|
||||
<br />
|
||||
<br />
|
||||
<table class="media_details">
|
||||
<tr>
|
||||
<td>Location</td>
|
||||
<td><?= $attributes['location'] ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div>
|
||||
<dl>
|
||||
<dt>About:</dt>
|
||||
<dd><?= $attributes['bio'] ?></dd>
|
||||
</dl>
|
||||
<pre><?= json_encode($attributes, \JSON_PRETTY_PRINT) ?></pre>
|
||||
<pre><?= json_encode($relationships, \JSON_PRETTY_PRINT) ?></pre>
|
||||
<pre><?= json_encode($included, \JSON_PRETTY_PRINT) ?></pre>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
@ -112,6 +112,31 @@ class JsonAPI {
|
||||
return $organized;
|
||||
}
|
||||
|
||||
public static function lightlyOrganizeIncludes(array $includes): array
|
||||
{
|
||||
$organized = [];
|
||||
|
||||
foreach($includes as $item)
|
||||
{
|
||||
$type = $item['type'];
|
||||
$id = $item['id'];
|
||||
$organized[$type] = $organized[$type] ?? [];
|
||||
$newItem = [];
|
||||
|
||||
foreach(['attributes', 'relationships'] as $key)
|
||||
{
|
||||
if (array_key_exists($key, $item))
|
||||
{
|
||||
$newItem[$key] = $item[$key];
|
||||
}
|
||||
}
|
||||
|
||||
$organized[$type][$id] = $newItem;
|
||||
}
|
||||
|
||||
return $organized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reorganize relationship mappings to make them simpler to use
|
||||
*
|
||||
|
@ -139,12 +139,18 @@ class Model {
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get profile information for the configured user
|
||||
*
|
||||
* @param string $username
|
||||
* @return array
|
||||
*/
|
||||
public function getUserData(string $username): array
|
||||
{
|
||||
$userId = $this->getUserIdByUsername($username);
|
||||
$data = $this->getRequest("/users/{$userId}", [
|
||||
'query' => [
|
||||
'include' => 'waifu,pinnedPost,blocks,linkedAccounts,profileLinks,mediaFollows,userRoles'
|
||||
'include' => 'waifu,pinnedPost,blocks,linkedAccounts,profileLinks,profileLinks.profileLinkSite,mediaFollows,userRoles'
|
||||
]
|
||||
]);
|
||||
// $data['included'] = JsonAPI::organizeIncludes($data['included']);
|
||||
|
@ -20,6 +20,7 @@ use const Aviat\AnimeClient\SESSION_SEGMENT;
|
||||
|
||||
use function Aviat\AnimeClient\_dir;
|
||||
|
||||
use Aviat\AnimeClient\API\JsonAPI;
|
||||
use Aviat\Ion\Di\{ContainerAware, ContainerInterface};
|
||||
use Aviat\Ion\View\{HtmlView, HttpView, JsonView};
|
||||
use InvalidArgumentException;
|
||||
@ -127,7 +128,14 @@ class Controller {
|
||||
{
|
||||
$username = $this->config->get(['kitsu_username']);
|
||||
$model = $this->container->get('kitsu-model');
|
||||
$this->outputJSON($model->getUserData($username));
|
||||
$data = $model->getUserData($username);
|
||||
$included = JsonAPI::lightlyOrganizeIncludes($data['included']);
|
||||
$this->outputHTML('me', [
|
||||
'title' => 'About' . $this->config->get('whose_list'),
|
||||
'attributes' => $data['data']['attributes'],
|
||||
'relationships' => $data['data']['relationships'],
|
||||
'included' => $included
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -39,7 +39,8 @@ class Util {
|
||||
'login',
|
||||
'logout',
|
||||
'details',
|
||||
'character'
|
||||
'character',
|
||||
'me'
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -234,6 +234,7 @@ class DispatcherTest extends AnimeClientTestCase {
|
||||
'anime' => 'Aviat\AnimeClient\Controller\Anime',
|
||||
'manga' => 'Aviat\AnimeClient\Controller\Manga',
|
||||
'collection' => 'Aviat\AnimeClient\Controller\Collection',
|
||||
'character' => 'Aviat\AnimeClient\Controller\Character',
|
||||
]
|
||||
],
|
||||
'empty_controller_list' => [
|
||||
@ -255,6 +256,7 @@ class DispatcherTest extends AnimeClientTestCase {
|
||||
'anime' => 'Aviat\AnimeClient\Controller\Anime',
|
||||
'manga' => 'Aviat\AnimeClient\Controller\Manga',
|
||||
'collection' => 'Aviat\AnimeClient\Controller\Collection',
|
||||
'character' => 'Aviat\AnimeClient\Controller\Character',
|
||||
]
|
||||
]
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user