Skip to content

Commit

Permalink
purge unneeded fields from ItemDetails return and fix an issue with d…
Browse files Browse the repository at this point in the history
…iscussion_id only allowing numbers in PostList and hence not filtering reddit posts correctly
  • Loading branch information
j0Shi82 committed Oct 14, 2022
1 parent 242dbf1 commit a82bef5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
23 changes: 19 additions & 4 deletions src/Controller/V1/Auctions/ItemDetails.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace App\Controller\V1\Auctions;

use \App\Controller\BaseController;
use App\Controller\BaseController;

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
Expand Down Expand Up @@ -41,12 +43,25 @@ public function get(Request $request, Response $response)
->withColumn("DATE_FORMAT(inserted, '%Y-%m-%d')", 'InsertedDate')
->withColumn('UNIX_TIMESTAMP(inserted)', 'InsertedTimestamp')
->withColumn("ROUND(AVG(Low))", 'AvgLow')
->withColumn("ROUND(AVG(Mean))", 'AvgMean')
->withColumn("ROUND(AVG(Median))", 'AvgMedian')
->withColumn("ROUND(AVG(Count))", 'AvgCount')
->orderBy('InsertedDate', 'asc')
->groupBy('InsertedDate')
->find();
->select('InsertedDate', 'InsertedTimestamp', 'AvgLow', 'AvgMean', 'AvgMedian', 'AvgCount')
->find()
->getData();

$result = array_map(function ($row) {
return array_merge($row, [
'AvgLow' => intval($row['AvgLow']),
'AvgMean' => intval($row['AvgMean']),
'AvgMedian' => intval($row['AvgMedian']),
'AvgCount' => intval($row['AvgCount']),
]);
}, $result);

$response->getBody()->write(json_encode($result->toArray()));
$response->getBody()->write(json_encode($result));
return $response
->withHeader('Content-Type', 'application/json')
->withHeader('charset', 'utf-8');
Expand Down
12 changes: 7 additions & 5 deletions src/Controller/V1/Devtracker/Postlist.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace App\Controller\V1\Devtracker;

use \App\Controller\BaseController;
use App\Controller\BaseController;

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
Expand All @@ -15,7 +17,7 @@ class Postlist extends BaseController
* @var \JBBCode\Parser
*/
private $jbb_parser;

/**
* @param \App\Helpers\RequestHelper $requestHelper
* @param \JBBCode\Parser $jbb_parser
Expand All @@ -28,7 +30,7 @@ public function __construct(\App\Helpers\RequestHelper $requestHelper, \JBBCode\
$this->jbb_parser = $jbb_parser;
$this->jbb_parser->addCodeDefinitionSet(new DefaultCodeDefinitionSet());
}

/**
* @param Request $request
* @param Response $response
Expand All @@ -42,7 +44,7 @@ public function get(Request $request, Response $response)
// define all possible GET data
$data_ary = array(
'dev' => $this->requestHelper->variable('dev', ''),
'discussion_id' => $this->requestHelper->variable('discussion_id', 0),
'discussion_id' => $this->requestHelper->variable('discussion_id', '0'),
'search_term' => $this->requestHelper->variable('search_term', ''),
'count' => $this->requestHelper->variable('count', 20),
'page' => $this->requestHelper->variable('page', 1)
Expand Down

0 comments on commit a82bef5

Please sign in to comment.