From 22e27ed899e901611df29aee3cf1b6b84fad9fac Mon Sep 17 00:00:00 2001 From: Mal <=> Date: Thu, 10 Sep 2020 11:46:31 +0200 Subject: [PATCH] UI objects for UserSharingsGet and FingerprintPut added --- api/openapi.yaml | 4 +-- .../controller/FingerprintPutController.php | 2 +- js/api/FingerprintPutApiRequest.ts | 18 ++++++++++++ js/api/UserSharingsGetApiRequest.ts | 26 +++++++++++++++++ js/event/FingerprintChangedEvent.ts | 18 ++++++++++++ js/event/UserSharingsGetEvent.ts | 18 ++++++++++++ js/types/Sharing.ts | 28 +++++++++++++++++++ 7 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 js/api/FingerprintPutApiRequest.ts create mode 100644 js/api/UserSharingsGetApiRequest.ts create mode 100644 js/event/FingerprintChangedEvent.ts create mode 100644 js/event/UserSharingsGetEvent.ts create mode 100644 js/types/Sharing.ts diff --git a/api/openapi.yaml b/api/openapi.yaml index b515104..e93eb8a 100644 --- a/api/openapi.yaml +++ b/api/openapi.yaml @@ -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' diff --git a/backend/classes/controller/FingerprintPutController.php b/backend/classes/controller/FingerprintPutController.php index 4f42f00..1af8468 100644 --- a/backend/classes/controller/FingerprintPutController.php +++ b/backend/classes/controller/FingerprintPutController.php @@ -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; } diff --git a/js/api/FingerprintPutApiRequest.ts b/js/api/FingerprintPutApiRequest.ts new file mode 100644 index 0000000..eaad24c --- /dev/null +++ b/js/api/FingerprintPutApiRequest.ts @@ -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)); + }; + } +} \ No newline at end of file diff --git a/js/api/UserSharingsGetApiRequest.ts b/js/api/UserSharingsGetApiRequest.ts new file mode 100644 index 0000000..a8b99c5 --- /dev/null +++ b/js/api/UserSharingsGetApiRequest.ts @@ -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 = []; + + json.sharings.forEach( + (result: any) => { + sharings.push(new Sharing(result.sharingId, result.userId, result.userSharedId)); + } + ); + + window.dispatchEvent(new UserSharingsGetEvent(sharings)); + } + } +} diff --git a/js/event/FingerprintChangedEvent.ts b/js/event/FingerprintChangedEvent.ts new file mode 100644 index 0000000..a387aaf --- /dev/null +++ b/js/event/FingerprintChangedEvent.ts @@ -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; + } +} diff --git a/js/event/UserSharingsGetEvent.ts b/js/event/UserSharingsGetEvent.ts new file mode 100644 index 0000000..4196876 --- /dev/null +++ b/js/event/UserSharingsGetEvent.ts @@ -0,0 +1,18 @@ +import RingfingerEvent from "./RingfingerEvent.js"; +import Sharing from "../types/Sharing.js"; + +export default class UserSharingsGetEvent extends RingfingerEvent +{ + private sharings: Array; + + public constructor(sharings: Array) { + super(UserSharingsGetEvent.name); + + this.sharings = sharings; + } + + public getSharings(): Array + { + return this.sharings; + } +} diff --git a/js/types/Sharing.ts b/js/types/Sharing.ts new file mode 100644 index 0000000..093f73c --- /dev/null +++ b/js/types/Sharing.ts @@ -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; + } +}