mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 18:04:08 +02:00
use userprovider to get uploader data
This commit is contained in:
parent
0d803526d8
commit
9bf9721190
8 changed files with 47 additions and 17 deletions
|
|
@ -10,14 +10,15 @@ FROM icewind1991/php-alpine-apcu
|
|||
|
||||
COPY --from=build /root/build/parser/target/x86_64-unknown-linux-musl/release/parse_demo /app/parse_demo
|
||||
COPY composer.json /app
|
||||
COPY src /app/src
|
||||
|
||||
ENV PARSER_PATH /app/parse_demo
|
||||
|
||||
RUN wget https://getcomposer.org/composer.phar \
|
||||
&& php composer.phar --working-dir=/app install --no-dev --no-interaction --ignore-platform-reqs \
|
||||
&& rm composer.phar
|
||||
|
||||
COPY src /app/src
|
||||
|
||||
ENV PARSER_PATH /app/parse_demo
|
||||
|
||||
RUN echo "clear_env = no" >> /usr/local/etc/php/php-fpm.conf \
|
||||
&& echo "post_max_size = 150M" >> /usr/local/etc/php/php.ini \
|
||||
&& echo "upload_max_filesize = 150M" >> /usr/local/etc/php/php.ini
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ class Container {
|
|||
}
|
||||
|
||||
public function getDemoProvider(): DemoProvider {
|
||||
return new DemoProvider($this->connection);
|
||||
return new DemoProvider($this->connection, $this->getUserProvider());
|
||||
}
|
||||
|
||||
public function getInfoProvider(): InfoProvider {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
|||
|
||||
namespace Demostf\API\Providers;
|
||||
|
||||
use Doctrine\DBAL\Connection;
|
||||
use LessQL\Database;
|
||||
use const DATE_ATOM;
|
||||
use Demostf\API\Data\DemoPlayer;
|
||||
use Demostf\API\Data\User;
|
||||
|
|
@ -13,6 +15,14 @@ use PDO;
|
|||
class DemoProvider extends BaseProvider {
|
||||
const VERSION = 4;
|
||||
|
||||
private $userProvider;
|
||||
|
||||
public function __construct(Connection $connection, UserProvider $userProvider) {
|
||||
parent::__construct($connection);
|
||||
|
||||
$this->userProvider = $userProvider;
|
||||
}
|
||||
|
||||
public function get(int $id, bool $fetchDetails = true): ?Demo {
|
||||
$demo = $this->db->demo()->where('id', $id);
|
||||
|
||||
|
|
@ -23,7 +33,7 @@ class DemoProvider extends BaseProvider {
|
|||
(SELECT COUNT(*) FROM demokills WHERE assister_id=players.user_id) AS assists,
|
||||
(SELECT COUNT(*) FROM demokills WHERE victim_id=players.user_id) AS deaths
|
||||
FROM players
|
||||
INNER JOIN users_named ON players.user_id = users.id
|
||||
INNER JOIN users ON players.user_id = users.id
|
||||
WHERE demo_id = ?';
|
||||
|
||||
$demoData = $demo->fetch();
|
||||
|
|
@ -33,16 +43,11 @@ class DemoProvider extends BaseProvider {
|
|||
$formattedDemo = Demo::fromRow($demoData);
|
||||
|
||||
if ($fetchDetails) {
|
||||
$uploader = $demo->user()->via('uploader')->fetch();
|
||||
$uploader = $this->userProvider->getById($demoData['uploader']);
|
||||
$playerQuery = $this->query($sql, [$formattedDemo->getId(), $formattedDemo->getId()]);
|
||||
$players = $playerQuery->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
$formattedDemo->setUploaderUser(User::fromRow([
|
||||
'id' => $uploader['id'],
|
||||
'steamid' => $uploader['steamid'],
|
||||
'name' => $uploader['name'],
|
||||
'avatar' => $uploader['avatar'],
|
||||
]));
|
||||
$formattedDemo->setUploaderUser($uploader);
|
||||
$uniquePlayers = [];
|
||||
foreach ($players as $player) {
|
||||
$key = $player['steamid'] . $player['team'];
|
||||
|
|
|
|||
|
|
@ -70,6 +70,30 @@ class UserProvider extends BaseProvider {
|
|||
return $row ? User::fromRow($row) : null;
|
||||
}
|
||||
|
||||
public function getById(int $userId): ?User {
|
||||
// first search in the view which contains the most used name for the users
|
||||
|
||||
$query = $this->getQueryBuilder();
|
||||
$query->select(['id', 'steamid', 'name', 'avatar', 'token'])
|
||||
->from('users_named')
|
||||
->where($query->expr()->eq('id', $query->createNamedParameter($userId, \PDO::PARAM_INT)));
|
||||
|
||||
$row = $query->execute()->fetch();
|
||||
|
||||
if (!$row) {
|
||||
// if the user is newly inserted it wont be in our view yet
|
||||
|
||||
$query = $this->getQueryBuilder();
|
||||
$query->select(['id', 'steamid', 'name', 'avatar', 'token'])
|
||||
->from('users')
|
||||
->where($query->expr()->eq('id', $query->createNamedParameter($userId, \PDO::PARAM_INT)));
|
||||
|
||||
$row = $query->execute()->fetch();
|
||||
}
|
||||
|
||||
return $row ? User::fromRow($row) : null;
|
||||
}
|
||||
|
||||
private function searchBySteamId(string $steamId): ?array {
|
||||
$query = $this->getQueryBuilder();
|
||||
$query->select('u.id', 'p.name', 'count(demo_id) as count', 'steamid')
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class DemoSaverTest extends TestCase {
|
|||
$steamId2 = $this->getSteamId('2345678', 'user2');
|
||||
|
||||
$userProvider = new UserProvider($this->getDatabaseConnection(), $this->getRandomGenerator());
|
||||
$demoProvider = new DemoProvider($this->getDatabaseConnection());
|
||||
$demoProvider = new DemoProvider($this->getDatabaseConnection(), $userProvider);
|
||||
$chatProvider = new ChatProvider($this->getDatabaseConnection());
|
||||
|
||||
$userProvider->store($steamId1);
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@ class DemoListProviderTest extends TestCase {
|
|||
parent::setUp();
|
||||
|
||||
$this->demoListProvider = new DemoListProvider($this->getDatabaseConnection());
|
||||
$this->demoProvider = new DemoProvider($this->getDatabaseConnection());
|
||||
$this->playerProvider = new PlayerProvider($this->getDatabaseConnection());
|
||||
$this->userProvider = new UserProvider($this->getDatabaseConnection(), $this->getRandomGenerator());
|
||||
$this->demoProvider = new DemoProvider($this->getDatabaseConnection(), $this->userProvider);
|
||||
$this->playerProvider = new PlayerProvider($this->getDatabaseConnection());
|
||||
}
|
||||
|
||||
private function getDemo(int $uploaderId, $map = 'map', $playerCount = 18) {
|
||||
|
|
|
|||
|
|
@ -30,8 +30,8 @@ class DemoProviderTest extends TestCase {
|
|||
public function setUp(): void {
|
||||
parent::setUp();
|
||||
|
||||
$this->provider = new DemoProvider($this->getDatabaseConnection());
|
||||
$this->userProvider = new UserProvider($this->getDatabaseConnection(), $this->getRandomGenerator());
|
||||
$this->provider = new DemoProvider($this->getDatabaseConnection(), $this->userProvider);
|
||||
$this->playerProvider = new PlayerProvider($this->getDatabaseConnection());
|
||||
$this->killProvider = new KillProvider($this->getDatabaseConnection());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ class UploadProviderTest extends TestCase {
|
|||
$this->parser = new Parser($this->rawParser);
|
||||
$this->demoStore = new DemoStore($targetDir, 'example.com');
|
||||
$this->userProvider = new UserProvider($this->getDatabaseConnection(), $this->getRandomGenerator());
|
||||
$this->demoProvider = new DemoProvider($this->getDatabaseConnection());
|
||||
$this->demoProvider = new DemoProvider($this->getDatabaseConnection(), $this->userProvider);
|
||||
$this->demoSaver = new DemoSaver(
|
||||
new KillProvider($this->getDatabaseConnection()),
|
||||
new PlayerProvider($this->getDatabaseConnection()),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue