Commit 4bce00ae authored by Andreas Heimann's avatar Andreas Heimann

added uploader reference to song entity, added userdetail api call

parent 5e75b767
......@@ -108,6 +108,7 @@ class APIController extends AbstractController
$data['subtitle'] = $result->getSubtitle();
$data['artist'] = $result->getArtist();
$data['charter'] = $result->getCharter();
$data['uploader'] = $result->getUploader();
$data['tags'] = explode(",", $result->getTags());
$data['paths']['ogg'] = $baseUrl."/uploads/audio/".$result->getFileReference().".ogg";
$data['paths']['cover'] = $baseUrl."/uploads/cover/".$result->getFileReference().".png";
......@@ -187,6 +188,45 @@ class APIController extends AbstractController
}
}
/**
* @Route("/api/user/{userId}", name="api.users.detail")
*/
public function userDetail(Request $request, int $userId)
{
$em = $this->getDoctrine()->getManager();
$data = [];
$result = $em->getRepository(User::class)->findOneBy(array('id' => $userId));
$baseUrl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
if(!$result) {
return new JsonResponse(['version' => $this->currentVersion, 'status' => 404, 'data' => []]);
} else {
$data['id'] = $result->getId();
$data['username'] = $result->getUsername();
$data['avatar'] = $baseUrl."/uploads/avatar/".$result->getUsername().".png";
// Get User Songs
$resultsSongs = $em->getRepository(Song::class)->findBy(array('uploader' => $result->getId()));
foreach($resultsSongs as $result) {
$oneResult = [];
$oneResult['id'] = $result->getId();
$oneResult['title'] = $result->getTitle();
$oneResult['subtitle'] = $result->getSubtitle();
$oneResult['artist'] = $result->getArtist();
$oneResult['charter'] = $result->getCharter();
$oneResult['uploader'] = $result->getUploader();
$oneResult['cover'] = $baseUrl."/uploads/cover/".$result->getFileReference().".png";
$data['songs'][] = $oneResult;
}
return new JsonResponse(['version' => $this->currentVersion, 'status' => 200, 'data' => $data]);
}
}
/**
* @Route("/api/search/{searchQuery}", name="api.search")
*/
......
......@@ -36,6 +36,11 @@ class Song
*/
private $charter;
/**
* @ORM\Column(type="integer")
*/
private $uploader;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
......@@ -114,6 +119,18 @@ class Song
return $this;
}
public function getUploader(): ?int
{
return $this->uploader;
}
public function setUploader(int $uploader): self
{
$this->uploader = $uploader;
return $this;
}
public function getFileReference(): ?string
{
return $this->fileReference;
......
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