2021-06-27 11:19:26 +00:00
|
|
|
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace OCA\GPodderSync\Controller;
|
|
|
|
|
|
|
|
use DateTime;
|
|
|
|
use GuzzleHttp\Psr7\Response;
|
2021-10-06 12:02:31 +00:00
|
|
|
use OCA\GPodderSync\Core\EpisodeAction\EpisodeAction;
|
2021-08-22 20:45:34 +00:00
|
|
|
use OCA\GPodderSync\Core\EpisodeAction\EpisodeActionSaver;
|
2021-06-27 11:19:26 +00:00
|
|
|
use OCA\GPodderSync\Db\EpisodeAction\EpisodeActionRepository;
|
|
|
|
use OCP\AppFramework\Controller;
|
|
|
|
use OCP\AppFramework\Http\JSONResponse;
|
|
|
|
use OCP\IRequest;
|
|
|
|
|
|
|
|
class EpisodeActionController extends Controller {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var EpisodeActionRepository
|
|
|
|
*/
|
|
|
|
private EpisodeActionRepository $episodeActionRepository;
|
2021-08-22 20:45:34 +00:00
|
|
|
|
2021-06-27 11:19:26 +00:00
|
|
|
private $userId;
|
2021-08-22 20:45:34 +00:00
|
|
|
private EpisodeActionSaver $episodeActionSaver;
|
2021-06-27 11:19:26 +00:00
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
string $AppName,
|
|
|
|
IRequest $request,
|
|
|
|
$UserId,
|
|
|
|
EpisodeActionRepository $episodeActionRepository,
|
2021-08-22 20:45:34 +00:00
|
|
|
EpisodeActionSaver $episodeActionSaver
|
2021-06-27 11:19:26 +00:00
|
|
|
) {
|
|
|
|
parent::__construct($AppName, $request);
|
|
|
|
$this->episodeActionRepository = $episodeActionRepository;
|
|
|
|
$this->userId = $UserId;
|
2021-08-22 20:45:34 +00:00
|
|
|
$this->episodeActionSaver = $episodeActionSaver;
|
2021-06-27 11:19:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @NoAdminRequired
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*
|
|
|
|
* @return Response
|
|
|
|
*/
|
|
|
|
public function create($data) {
|
2021-08-25 17:33:00 +00:00
|
|
|
return $this->episodeActionSaver->saveEpisodeActions($data, $this->userId);
|
2021-06-27 11:19:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @NoAdminRequired
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*
|
|
|
|
* @param int $since
|
|
|
|
* @return JSONResponse
|
|
|
|
*/
|
2021-07-11 20:52:30 +00:00
|
|
|
public function list(int $since): JSONResponse {
|
2021-10-06 12:02:31 +00:00
|
|
|
$episodeActions = $this->episodeActionRepository->findAll($since, $this->userId);
|
|
|
|
$untypedEpisodeActionData = [];
|
|
|
|
|
|
|
|
foreach ($episodeActions as $episodeAction) {
|
|
|
|
$untypedEpisodeActionData[] = $episodeAction->toArray();
|
|
|
|
}
|
|
|
|
|
2021-06-27 11:19:26 +00:00
|
|
|
return new JSONResponse([
|
2021-10-06 12:02:31 +00:00
|
|
|
"actions" => $untypedEpisodeActionData,
|
2021-06-27 11:19:26 +00:00
|
|
|
"timestamp" => time()
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|