Compare commits
No commits in common. "2fe693f07d6b9e7430b2c2cb208566909ded1f83" and "2080de7a10d8a07a285d686f78f8c3467ce61a76" have entirely different histories.
2fe693f07d
...
2080de7a10
@ -92,34 +92,6 @@ paths:
|
||||
default:
|
||||
$ref: '#/components/responses/Error'
|
||||
|
||||
'/api/v1/user/{userId}/sharings':
|
||||
get:
|
||||
tags:
|
||||
- User
|
||||
summary: A list of all sharings with other users.
|
||||
responses:
|
||||
200:
|
||||
description: Returns the success state and a list with all sharings of the user.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
properties:
|
||||
success:
|
||||
$ref: '#/components/schemas/Success'
|
||||
sharings:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
example:
|
||||
- sharingId: 8
|
||||
userId: 25
|
||||
userSharingId: 42
|
||||
- sharingId: 9
|
||||
userId: 25
|
||||
userSharingId:
|
||||
default:
|
||||
$ref: '#/components/responses/Error'
|
||||
|
||||
'/api/v1/user/{userId}/fingerprints':
|
||||
get:
|
||||
tags:
|
||||
@ -138,15 +110,13 @@ paths:
|
||||
type: array
|
||||
items:
|
||||
type: object
|
||||
example:
|
||||
- fingerprintId: 8
|
||||
fingerprint: '5BDF1668E59F2184582591699F55D9158DEF400A48772887A8F61531ED36B2A'
|
||||
userId: 25
|
||||
- fingerprintId: 42
|
||||
fingerprint: '6FF8842B6D17F5C2098A3DD8AB55D9158DEF400A48772887A8F61531ED36B2A'
|
||||
userId: 25
|
||||
default:
|
||||
$ref: '#/components/responses/Error'
|
||||
example:
|
||||
- fingerprintId: 8
|
||||
fingerprint: '5BDF1668E59F2184582591699F55D9158DEF400A48772887A8F61531ED36B2A'
|
||||
userId: 25
|
||||
- fingerprintId: 42
|
||||
fingerprint: '6FF8842B6D17F5C2098A3DD8AB55D9158DEF400A48772887A8F61531ED36B2A'
|
||||
userId: 25
|
||||
|
||||
'/api/v1/user/{userId}/email':
|
||||
get:
|
||||
|
@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
final class UserSharingsGetController extends AbstractController
|
||||
{
|
||||
protected string $route = '/api/v1/user/{userId}/sharings';
|
||||
|
||||
private int $userId;
|
||||
|
||||
public function __construct(string $url)
|
||||
{
|
||||
parent::__construct($url);
|
||||
|
||||
$this->userId = (int)$this->getUrlParamInt('userId');
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$user = new User($this->userId);
|
||||
|
||||
try {
|
||||
$this->response = new ApiJsonResponse();
|
||||
$this->response->setParameter('sharings', $user->getSharings());
|
||||
} catch (Throwable $e) {
|
||||
$this->response = new ApiJsonResponse($e->getCode() !== 0 ? $e->getCode() : ServerStatus::BAD_REQUEST);
|
||||
$this->response->setSuccess(false);
|
||||
$this->response->setMessage($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,6 @@ declare(strict_types=1);
|
||||
|
||||
final class Sharing extends MySqlTable implements JsonSerializable
|
||||
{
|
||||
public const FIELD_ID = 'SharingId';
|
||||
public const FIELD_USER = 'User';
|
||||
public const FIELD_USER_SHARED = 'UserShared';
|
||||
|
||||
@ -32,11 +31,6 @@ final class Sharing extends MySqlTable implements JsonSerializable
|
||||
return $this->getField(self::FIELD_USER_SHARED);
|
||||
}
|
||||
|
||||
public function setId(int $id): void
|
||||
{
|
||||
$this->setField(self::FIELD_ID, $id);
|
||||
}
|
||||
|
||||
public function setUserId(int $userId): void
|
||||
{
|
||||
$this->setField(self::FIELD_USER, $userId);
|
||||
|
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
final class SharingCollection implements Iterator, JsonSerializable
|
||||
{
|
||||
private int $position = 0;
|
||||
|
||||
/** @var Sharing[] */
|
||||
private array $sharings = [];
|
||||
|
||||
public function add(Sharing $userId): void
|
||||
{
|
||||
$this->sharings[] = $userId;
|
||||
}
|
||||
|
||||
public function current(): Sharing
|
||||
{
|
||||
return $this->sharings[$this->position];
|
||||
}
|
||||
|
||||
public function next(): void
|
||||
{
|
||||
$this->position++;
|
||||
}
|
||||
|
||||
public function key(): int
|
||||
{
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
public function valid(): bool
|
||||
{
|
||||
return isset($this->sharings[$this->position]);
|
||||
}
|
||||
|
||||
public function rewind(): void
|
||||
{
|
||||
$this->position = 0;
|
||||
}
|
||||
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return $this->sharings;
|
||||
}
|
||||
}
|
@ -90,7 +90,9 @@ final class User extends MySqlTable implements JsonSerializable
|
||||
|
||||
$id = $database->Select(self::class, [self::FIELD_ID], [self::FIELD_USERNAME => $username])[0][self::FIELD_ID];
|
||||
|
||||
return $databaseGiven ? new User((int)$id, $database) : new User((int)$id);
|
||||
$user = $databaseGiven ? new User((int)$id, $database) : new User((int)$id);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
public static function getFromEmail(string $email, DatabaseInterface &$database = null): self
|
||||
@ -108,7 +110,9 @@ final class User extends MySqlTable implements JsonSerializable
|
||||
|
||||
$id = $database->Select(self::class, [self::FIELD_ID], [self::FIELD_EMAIL => $email])[0][self::FIELD_ID];
|
||||
|
||||
return $databaseGiven ? new User((int)$id, $database) : new User((int)$id);
|
||||
$user = $databaseGiven ? new User((int)$id, $database) : new User((int)$id);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
public function getFingerprintIds(): array
|
||||
@ -136,29 +140,6 @@ final class User extends MySqlTable implements JsonSerializable
|
||||
);
|
||||
}
|
||||
|
||||
public function getSharings(): SharingCollection
|
||||
{
|
||||
$result = $this->database->Select(
|
||||
Sharing::class,
|
||||
[],
|
||||
[Sharing::FIELD_USER => $this->getUserId()]
|
||||
);
|
||||
|
||||
$sharings = new SharingCollection();
|
||||
|
||||
foreach ($result as $record) {
|
||||
$sharing = new Sharing(null, $this->database);
|
||||
|
||||
$sharing->setId((int)$record[Sharing::FIELD_ID]);
|
||||
$sharing->setUserId((int)$record[Sharing::FIELD_USER]);
|
||||
$sharing->setUserShared((int)$record[Sharing::FIELD_USER_SHARED]);
|
||||
|
||||
$sharings->add($sharing);
|
||||
}
|
||||
|
||||
return $sharings;
|
||||
}
|
||||
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return [
|
||||
|
@ -70,7 +70,7 @@ echo 'Let\'s create an admin account...' . PHP_EOL;
|
||||
$user = new User(null, $db);
|
||||
|
||||
$user->setUsername(getUserInput('Username: '));
|
||||
$user->setPassword(Password::GetHash(getUserInput('Password: ')));
|
||||
$user->setPassword(getUserInput('Password: '));
|
||||
$user->setEmail(getUserInput('Email: '));
|
||||
$user->setJabberAddress(getUserInput('Jabber address: '));
|
||||
$user->setAdmin(true);
|
||||
|
Loading…
x
Reference in New Issue
Block a user