Commit d0983707 authored by Andreas Heimann's avatar Andreas Heimann

added playlist api

parent 80989c10
<?php
namespace App\Controller\API;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpClient\HttpClient;
use App\Entity\ClientRelease;
use App\Entity\Song;
use App\Entity\SongPlaylist;
use App\Entity\User;
use App\Entity\Promo;
class APISongPlaylistController extends AbstractController
{
/**
* @Route("/api/playlist/{id}", name="api.playlist.detail")
* @param Request $request
* @param $id
* @return JsonResponse
*/
public function playlistDetail(Request $request, $id)
{
$em = $this->getDoctrine()->getManager();
$data = [];
$result = $em->getRepository(SongPlaylist::class)->findOneBy(array('id' => $id));
$baseUrl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
if(!$result) {
$response = new JsonResponse(['version' => $this->getParameter('api_version'), 'status' => 404, 'data' => []]);
$response->headers->set('Access-Control-Allow-Origin', '*');
return $response;
} else {
$data = $result->getJSON();
$data['paths']['cover'] = $baseUrl."/uploads/cover/".$result->getFileReference().".png";
$response = new JsonResponse(['version' => $this->getParameter('api_version'), 'status' => 200, 'data' => $data]);
$response->headers->set('Access-Control-Allow-Origin', '*');
return $response;
}
}
}
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
namespace App\Controller\API\Tournament; namespace App\Controller\API\Tournament;
use App\Entity\SongPlaylist;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;
...@@ -24,9 +25,9 @@ class APITournamentController extends AbstractController ...@@ -24,9 +25,9 @@ class APITournamentController extends AbstractController
$baseUrl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath(); $baseUrl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
// Botch // Botch
$tournamentCharts = $em->getRepository(Song::class)->findBy(array('isTournament' => true)); $tournamentPlaylist = $em->getRepository(SongPlaylist::class)->findOneBy(array('id' => "2"));
foreach($tournamentCharts as $tournamentChart) { foreach($tournamentPlaylist->getSongs() as $tournamentChart) {
$chartItem = $tournamentChart->getJSON(); $chartItem = $tournamentChart->getJSON();
$chartItem['srtbMD5'] = md5_file($this->getParameter('srtb_path').DIRECTORY_SEPARATOR.$tournamentChart->getFileReference().".srtb"); $chartItem['srtbMD5'] = md5_file($this->getParameter('srtb_path').DIRECTORY_SEPARATOR.$tournamentChart->getFileReference().".srtb");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment