Commit 636e8f4b authored by SpinShare's avatar SpinShare

api updates

parent d9f70425
......@@ -134,12 +134,19 @@
<div class="alert alert-primary" role="alert">
<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 class="card">
<h2 class="card-title">08/12/2020</h2>
Initial release.
<h2 class="card-title">09/09/2020</h2>
<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>
......
......@@ -119,8 +119,8 @@
</h1>
<div class="card" id="detail">
<h2 class="card-title">Detail</h2>
<p>Returns more detailled information about a user.</p>
<h2 class="card-title">Overview</h2>
<p>Returns a general overview of information about a user.</p>
<table class="table table-bordered">
<tr>
......@@ -146,65 +146,9 @@
"isVerified":true,
"isPatreon":null,
"avatar":"https:\/\/spinsha.re\/uploads\/avatar\/5ef8cddb50106.png",
"songs":[
{
"id":1018,
"title":"Keyboard Combos",
"subtitle":"",
"artist":"Discord",
"charter":"taw.moe",
"uploader":4,
"hasEasyDifficulty":false,
"hasNormalDifficulty":false,
"hasHardDifficulty":true,
"hasExtremeDifficulty":false,
"hasXDDifficulty":false,
"cover":"https:\/\/spinsha.re\/uploads\/thumbnail\/spinshare_5f2c729b8ea3b.jpg",
"zip":"https:\/\/spinsha.re\/api\/song\/1018\/download"
},
...
],
"reviews":[
{
"id":22,
"user":{
"id":9,
"username":"testtest",
"coverReference":null,
"isVerified":null,
"isPatreon":null
},
"recommended":false,
"comment":"I did not enjoy this",
"reviewDate":{
"date":"2020-08-22 18:22:56.000000",
"timezone_type":3,
"timezone":"Europe\/Berlin"
}
},
...
],
"spinplays":[
{
"id":13,
"user":{
"id":1,
"username":"taw",
"coverReference":"5f4147b117c7b.png",
"isVerified":true,
"isPatreon":true
},
"videoUrl":"https:\/\/youtu.be\/tPycD9OwojQ",
"videoThumbnail":"https:\/\/i.ytimg.com\/vi\/tPycD9OwojQ\/maxresdefault.jpg",
"submitDate":{
"date":"2020-07-20 18:48:49.000000",
"timezone_type":3,
"timezone":"Europe\/Berlin"
},
"isActive":true
},
...
],
"songs":0,
"reviews":0,
"spinplays":0,
"cards":[
{
"id":1,
......@@ -227,6 +171,176 @@
"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,
"title":"Keyboard Combos",
"subtitle":"",
"artist":"Discord",
"charter":"taw.moe",
"uploader":4,
"hasEasyDifficulty":false,
"hasNormalDifficulty":false,
"hasHardDifficulty":true,
"hasExtremeDifficulty":false,
"hasXDDifficulty":false,
"cover":"https:\/\/spinsha.re\/uploads\/thumbnail\/spinshare_5f2c729b8ea3b.jpg",
"zip":"https:\/\/spinsha.re\/api\/song\/1018\/download"
},
...
]}
}
</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,
"user":{
"id":9,
"username":"testtest",
"coverReference":null,
"isVerified":null,
"isPatreon":null
},
"recommended":false,
"comment":"I did not enjoy this",
"reviewDate":{
"date":"2020-08-22 18:22:56.000000",
"timezone_type":3,
"timezone":"Europe\/Berlin"
}
},
...
]}
}
</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,
"user":{
"id":1,
"username":"taw",
"coverReference":"5f4147b117c7b.png",
"isVerified":true,
"isPatreon":true
},
"videoUrl":"https:\/\/youtu.be\/tPycD9OwojQ",
"videoThumbnail":"https:\/\/i.ytimg.com\/vi\/tPycD9OwojQ\/maxresdefault.jpg",
"submitDate":{
"date":"2020-07-20 18:48:49.000000",
"timezone_type":3,
"timezone":"Europe\/Berlin"
},
"isActive":true
},
...
]}
}
</pre>
<br />
<strong>Output Body (Not Found)</strong>
<pre class="code">
{
"version":1,
"status":404,
"data":[]
}
</pre>
</div>
</div>
......@@ -235,7 +349,10 @@
<div class="content">
<div class="on-this-page-nav">
<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>
......
......@@ -52,11 +52,48 @@ class APIUserController extends AbstractController
$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'));
$data['songs'] = [];
$data['reviews'] = [];
$data['spinplays'] = [];
$data['songs'] = count($resultsSongs);
$data['reviews'] = count($resultsReviews);
$data['spinplays'] = count($resultsSpinPlays);
$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) {
$oneResult = [];
......@@ -74,26 +111,63 @@ class APIUserController extends AbstractController
$oneResult['cover'] = $baseUrl."/uploads/thumbnail/".$result->getFileReference().".jpg";
$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) {
$data['reviews'][] = $result->getJSON();
$data[] = $result->getJSON();
}
foreach($resultsSpinPlays as $result) {
$data['spinplays'][] = $result->getJSON();
}
foreach($resultsCards as $result) {
$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}/spinplays", name="api.users.detail.spinplays")
*/
public function userDetailSpinPlays(Request $request, int $userId)
{
$em = $this->getDoctrine()->getManager();
$data = [];
$oneResult['id'] = $result->getId();
$oneResult['icon'] = $baseUrl."/uploads/card/".$result->getCard()->getIcon();
$oneResult['title'] = $result->getCard()->getTitle();
$oneResult['description'] = $result->getCard()->getDescription();
$result = $em->getRepository(User::class)->findOneBy(array('id' => $userId));
$baseUrl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
$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]);
......
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