Commit 636e8f4b authored by SpinShare's avatar SpinShare

api updates

parent d9f70425
...@@ -134,12 +134,19 @@ ...@@ -134,12 +134,19 @@
<div class="alert alert-primary" role="alert"> <div class="alert alert-primary" role="alert">
<h4 class="alert-heading">Last Update</h4> <h4 class="alert-heading">Last Update</h4>
This documentation was last updated on 08/12/2020 at 15:01 CEST This documentation was last updated on 09/09/2020 at 16:58 CEST
</div> </div>
<div class="card"> <div class="card">
<h2 class="card-title">08/12/2020</h2> <h2 class="card-title">09/09/2020</h2>
Initial release. <ul>
<li>Removed Charts, Reviews and SpinPlays from the UserDetail endpoint</li>
<li>Renamed the UserDetail endpoint to UserOverview</li>
<li>Added an endpoint for UserCharts</li>
<li>Added an endpoint for UserReviews</li>
<li>Added an endpoint for UserSpinPlays</li>
<li>Added counts of charts, reviews and spinplays to the UserOverview endpoint</li>
</ul>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -119,8 +119,8 @@ ...@@ -119,8 +119,8 @@
</h1> </h1>
<div class="card" id="detail"> <div class="card" id="detail">
<h2 class="card-title">Detail</h2> <h2 class="card-title">Overview</h2>
<p>Returns more detailled information about a user.</p> <p>Returns a general overview of information about a user.</p>
<table class="table table-bordered"> <table class="table table-bordered">
<tr> <tr>
...@@ -146,7 +146,57 @@ ...@@ -146,7 +146,57 @@
"isVerified":true, "isVerified":true,
"isPatreon":null, "isPatreon":null,
"avatar":"https:\/\/spinsha.re\/uploads\/avatar\/5ef8cddb50106.png", "avatar":"https:\/\/spinsha.re\/uploads\/avatar\/5ef8cddb50106.png",
"songs":[ "songs":0,
"reviews":0,
"spinplays":0,
"cards":[
{
"id":1,
"icon":"http:\/\/localhost\/www\/spinshare\/server\/public\/uploads\/card\/card_b4bcc0b27340a10b012a1ba8a6fd04b0.png",
"title":"SSSO Spring 2020 Player",
"description":"This card was given out to every player of the Spring 2020 SpinShare Speen Open tournament."
},
...
]
}
}
</pre>
<br />
<strong>Output Body (Not Found)</strong>
<pre class="code">
{
"version":1,
"status":404,
"data":[]
}
</pre>
</div>
<div class="card" id="charts">
<h2 class="card-title">Charts</h2>
<p>Returns all public charts of a user.</p>
<table class="table table-bordered">
<tr>
<th>Method</th>
<td>GET</td>
</tr>
<tr>
<th>Endpoint</th>
<td>/user/<code class="code">userID</code>/charts</td>
</tr>
</table>
<br /><br />
<strong>Output Body (Success)</strong>
<pre class="code">
{
"version":1,
"status":200,
"data":{[
{ {
"id":1018, "id":1018,
"title":"Keyboard Combos", "title":"Keyboard Combos",
...@@ -163,8 +213,45 @@ ...@@ -163,8 +213,45 @@
"zip":"https:\/\/spinsha.re\/api\/song\/1018\/download" "zip":"https:\/\/spinsha.re\/api\/song\/1018\/download"
}, },
... ...
], ]}
"reviews":[ }
</pre>
<br />
<strong>Output Body (Not Found)</strong>
<pre class="code">
{
"version":1,
"status":404,
"data":[]
}
</pre>
</div>
<div class="card" id="reviews">
<h2 class="card-title">Reviews</h2>
<p>Returns all reviews of a user.</p>
<table class="table table-bordered">
<tr>
<th>Method</th>
<td>GET</td>
</tr>
<tr>
<th>Endpoint</th>
<td>/user/<code class="code">userID</code>/reviews</td>
</tr>
</table>
<br /><br />
<strong>Output Body (Success)</strong>
<pre class="code">
{
"version":1,
"status":200,
"data":{[
{ {
"id":22, "id":22,
"user":{ "user":{
...@@ -183,8 +270,45 @@ ...@@ -183,8 +270,45 @@
} }
}, },
... ...
], ]}
"spinplays":[ }
</pre>
<br />
<strong>Output Body (Not Found)</strong>
<pre class="code">
{
"version":1,
"status":404,
"data":[]
}
</pre>
</div>
<div class="card" id="spinplays">
<h2 class="card-title">SpinPlays</h2>
<p>Returns all SpinPlays of a user.</p>
<table class="table table-bordered">
<tr>
<th>Method</th>
<td>GET</td>
</tr>
<tr>
<th>Endpoint</th>
<td>/user/<code class="code">userID</code>/spinplays</td>
</tr>
</table>
<br /><br />
<strong>Output Body (Success)</strong>
<pre class="code">
{
"version":1,
"status":200,
"data":{[
{ {
"id":13, "id":13,
"user":{ "user":{
...@@ -204,17 +328,7 @@ ...@@ -204,17 +328,7 @@
"isActive":true "isActive":true
}, },
... ...
], ]}
"cards":[
{
"id":1,
"icon":"http:\/\/localhost\/www\/spinshare\/server\/public\/uploads\/card\/card_b4bcc0b27340a10b012a1ba8a6fd04b0.png",
"title":"SSSO Spring 2020 Player",
"description":"This card was given out to every player of the Spring 2020 SpinShare Speen Open tournament."
},
...
]
}
} }
</pre> </pre>
...@@ -235,7 +349,10 @@ ...@@ -235,7 +349,10 @@
<div class="content"> <div class="content">
<div class="on-this-page-nav"> <div class="on-this-page-nav">
<div class="title">On this page</div> <div class="title">On this page</div>
<a href="#detail">Detail</a> <a href="#overview">Overview</a>
<a href="#charts">Charts</a>
<a href="#reviews">Reviews</a>
<a href="#spinplays">SpinPlays</a>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -52,11 +52,48 @@ class APIUserController extends AbstractController ...@@ -52,11 +52,48 @@ class APIUserController extends AbstractController
$resultsSpinPlays = $em->getRepository(SongSpinPlay::class)->findBy(array('user' => $result->getId(), 'isActive' => true), array('submitDate' => 'DESC')); $resultsSpinPlays = $em->getRepository(SongSpinPlay::class)->findBy(array('user' => $result->getId(), 'isActive' => true), array('submitDate' => 'DESC'));
$resultsCards = $em->getRepository(UserCard::class)->findBy(array('user' => $result->getId()), array('givenDate' => 'DESC')); $resultsCards = $em->getRepository(UserCard::class)->findBy(array('user' => $result->getId()), array('givenDate' => 'DESC'));
$data['songs'] = []; $data['songs'] = count($resultsSongs);
$data['reviews'] = []; $data['reviews'] = count($resultsReviews);
$data['spinplays'] = []; $data['spinplays'] = count($resultsSpinPlays);
$data['cards'] = []; $data['cards'] = [];
foreach($resultsCards as $result) {
$oneResult = [];
$oneResult['id'] = $result->getId();
$oneResult['icon'] = $baseUrl."/uploads/card/".$result->getCard()->getIcon();
$oneResult['title'] = $result->getCard()->getTitle();
$oneResult['givenDate'] = $result->getGivenDate();
$oneResult['description'] = $result->getCard()->getDescription();
$data['cards'][] = $oneResult;
}
$response = new JsonResponse(['version' => $this->getParameter('api_version'), 'status' => 200, 'data' => $data]);
$response->headers->set('Access-Control-Allow-Origin', '*');
return $response;
}
}
/**
* @Route("/api/user/{userId}/charts", name="api.users.detail.charts")
*/
public function userDetailCharts(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) {
$response = new JsonResponse(['version' => $this->getParameter('api_version'), 'status' => 404, 'data' => []]);
$response->headers->set('Access-Control-Allow-Origin', '*');
return $response;
} else {
// Get User Lists
$resultsSongs = $em->getRepository(Song::class)->findBy(array('uploader' => $result->getId()), array('uploadDate' => 'DESC'));
foreach($resultsSongs as $result) { foreach($resultsSongs as $result) {
$oneResult = []; $oneResult = [];
...@@ -74,26 +111,63 @@ class APIUserController extends AbstractController ...@@ -74,26 +111,63 @@ class APIUserController extends AbstractController
$oneResult['cover'] = $baseUrl."/uploads/thumbnail/".$result->getFileReference().".jpg"; $oneResult['cover'] = $baseUrl."/uploads/thumbnail/".$result->getFileReference().".jpg";
$oneResult['zip'] = $this->generateUrl('api.songs.download', array('id' => $result->getId()), UrlGeneratorInterface::ABSOLUTE_URL); $oneResult['zip'] = $this->generateUrl('api.songs.download', array('id' => $result->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
$data['songs'][] = $oneResult; $data[] = $oneResult;
}
$response = new JsonResponse(['version' => $this->getParameter('api_version'), 'status' => 200, 'data' => $data]);
$response->headers->set('Access-Control-Allow-Origin', '*');
return $response;
}
} }
/**
* @Route("/api/user/{userId}/reviews", name="api.users.detail.reviews")
*/
public function userDetailReviews(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) {
$response = new JsonResponse(['version' => $this->getParameter('api_version'), 'status' => 404, 'data' => []]);
$response->headers->set('Access-Control-Allow-Origin', '*');
return $response;
} else {
$resultsReviews = $em->getRepository(SongReview::class)->findBy(array('user' => $result->getId()), array('reviewDate' => 'DESC'));
foreach($resultsReviews as $result) { foreach($resultsReviews as $result) {
$data['reviews'][] = $result->getJSON(); $data[] = $result->getJSON();
} }
foreach($resultsSpinPlays as $result) { $response = new JsonResponse(['version' => $this->getParameter('api_version'), 'status' => 200, 'data' => $data]);
$data['spinplays'][] = $result->getJSON(); $response->headers->set('Access-Control-Allow-Origin', '*');
return $response;
}
} }
foreach($resultsCards as $result) { /**
$oneResult = []; * @Route("/api/user/{userId}/spinplays", name="api.users.detail.spinplays")
*/
public function userDetailSpinPlays(Request $request, int $userId)
{
$em = $this->getDoctrine()->getManager();
$data = [];
$oneResult['id'] = $result->getId(); $result = $em->getRepository(User::class)->findOneBy(array('id' => $userId));
$oneResult['icon'] = $baseUrl."/uploads/card/".$result->getCard()->getIcon(); $baseUrl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
$oneResult['title'] = $result->getCard()->getTitle();
$oneResult['description'] = $result->getCard()->getDescription();
$data['cards'][] = $oneResult; if(!$result) {
$response = new JsonResponse(['version' => $this->getParameter('api_version'), 'status' => 404, 'data' => []]);
$response->headers->set('Access-Control-Allow-Origin', '*');
return $response;
} else {
$resultsSpinPlays = $em->getRepository(SongSpinPlay::class)->findBy(array('user' => $result->getId(), 'isActive' => true), array('submitDate' => 'DESC'));
foreach($resultsSpinPlays as $result) {
$data[] = $result->getJSON();
} }
$response = new JsonResponse(['version' => $this->getParameter('api_version'), 'status' => 200, 'data' => $data]); $response = new JsonResponse(['version' => $this->getParameter('api_version'), 'status' => 200, 'data' => $data]);
......
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