UI objects for UserSharingsGet and FingerprintPut added

This commit is contained in:
Mal 2020-09-10 11:46:31 +02:00
parent b5184b9b3c
commit 22e27ed899
7 changed files with 111 additions and 3 deletions

View File

@ -113,10 +113,10 @@ paths:
example:
- sharingId: 8
userId: 25
userSharingId: 42
userSharedId: 42
- sharingId: 9
userId: 25
userSharingId:
userSharedId: 7
default:
$ref: '#/components/responses/Error'

View File

@ -31,7 +31,7 @@ final class FingerprintPutController extends AbstractController
try {
$fingerprint = new Fingerprint($this->fingerprintId);
if ($this->hasUserPermission($fingerprint->getUserId()) || $this->handleFingerprint($fingerprint)) {
if ($this->hasUserPermission($fingerprint->getUserId()) && $this->handleFingerprint($fingerprint)) {
return;
}

View File

@ -0,0 +1,18 @@
import ApiRequest from "./ApiRequest.js";
import Fingerprint from "../types/Fingerprint.js";
import RequestMethod from "./RequestMethod.js";
import FingerprintChangedEvent from "../event/FingerprintChangedEvent.js";
export default class FingerprintPutApiRequest extends ApiRequest
{
public constructor(fingerprint: Fingerprint) {
super('fingerprint/' + fingerprint.getFingerprintId(), RequestMethod.PUT);
this.addParameter('fingerprint', fingerprint.getFingerprint());
this.onSuccess = (responseText: string) => {
console.log(responseText);
window.dispatchEvent(new FingerprintChangedEvent(fingerprint));
};
}
}

View File

@ -0,0 +1,26 @@
import ApiRequest from "./ApiRequest.js";
import RequestMethod from "./RequestMethod.js";
import Sharing from "../types/Sharing.js";
import UserSharingsGetEvent from "../event/UserSharingsGetEvent.js";
export default class UserSharingsGetApiRequest extends ApiRequest
{
public constructor(userId: number)
{
super('user/' + userId + '/sharings', RequestMethod.GET);
this.onSuccess = (response: string) => {
let json = JSON.parse(response);
let sharings: Array<Sharing> = [];
json.sharings.forEach(
(result: any) => {
sharings.push(new Sharing(result.sharingId, result.userId, result.userSharedId));
}
);
window.dispatchEvent(new UserSharingsGetEvent(sharings));
}
}
}

View File

@ -0,0 +1,18 @@
import RingfingerEvent from "./RingfingerEvent.js";
import Fingerprint from "../types/Fingerprint.js";
export default class FingerprintChangedEvent extends RingfingerEvent
{
private fingerprint: Fingerprint;
public constructor(fingerprint: Fingerprint) {
super(FingerprintChangedEvent.name);
this.fingerprint = fingerprint;
}
public getFingerprint(): Fingerprint
{
return this.fingerprint;
}
}

View File

@ -0,0 +1,18 @@
import RingfingerEvent from "./RingfingerEvent.js";
import Sharing from "../types/Sharing.js";
export default class UserSharingsGetEvent extends RingfingerEvent
{
private sharings: Array<Sharing>;
public constructor(sharings: Array<Sharing>) {
super(UserSharingsGetEvent.name);
this.sharings = sharings;
}
public getSharings(): Array<Sharing>
{
return this.sharings;
}
}

28
js/types/Sharing.ts Normal file
View File

@ -0,0 +1,28 @@
export default class Sharing
{
private readonly sharingId: number;
private readonly userId: number;
private readonly userSharingId: number;
public constructor(sharingId: number, userId: number, userSharingId: number)
{
this.sharingId = sharingId;
this.userId = userId;
this.userSharingId = userSharingId;
}
public getSharingId(): number
{
return this.sharingId;
}
public getUserId(): number
{
return this.userId;
}
public getUserSharingId(): number
{
return this.userSharingId;
}
}