From a4f3fab033ca18352c0119061f2d0e64252d4bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jovan=20Kruni=C4=87?= Date: Tue, 18 Dec 2018 22:35:33 +0100 Subject: [PATCH] feat: add saveable thing for saving user/client data Closes #12 --- src/core/base/SaveableThing.ts | 30 +++++++++++++++++++ src/core/things/Favorite.ts | 55 ++++++++-------------------------- 2 files changed, 43 insertions(+), 42 deletions(-) create mode 100644 src/core/base/SaveableThing.ts diff --git a/src/core/base/SaveableThing.ts b/src/core/base/SaveableThing.ts new file mode 100644 index 00000000..2b2d6400 --- /dev/null +++ b/src/core/base/SaveableThing.ts @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2018, 2019 StApps + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation, version 3. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ +import {SCThing, SCThingUserOrigin} from '../Thing'; + +/** + * An encapsulation of the data (e.g. a thing) that is saved, which provides additional information. + */ +export interface SCSaveableThing extends SCThing { + /** + * The contained data + */ + data: T; + + /** + * Type of the origin + */ + origin: SCThingUserOrigin; +} diff --git a/src/core/things/Favorite.ts b/src/core/things/Favorite.ts index e80ff297..6ed75359 100644 --- a/src/core/things/Favorite.ts +++ b/src/core/things/Favorite.ts @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018 StApps + * Copyright (C) 2018, 2019 StApps * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the Free * Software Foundation, version 3. @@ -12,8 +12,8 @@ * You should have received a copy of the GNU General Public License along with * this program. If not, see . */ -import {SCThing, SCThingMeta, SCThingType} from '../Thing'; -import {SCISO8601Date} from '../types/Time'; +import {SCSaveableThing} from '../base/SaveableThing'; +import {SCThingMeta, SCThingType} from '../Thing'; import {SCAcademicEventWithoutReferences} from './AcademicEvent'; import {SCArticleWithoutReferences} from './Article'; import {SCBookWithoutReferences} from './Book'; @@ -24,52 +24,23 @@ import {SCRoomWithoutReferences} from './Room'; import {SCSportCourseWithoutReferences} from './SportCourse'; /** - * A favorite without references + * Types that can be made a favorite (added as a favorite) */ -export interface SCFavoriteWithoutReferences extends SCThing { - /** - * When the favorite was last changed. - */ - changed: SCISO8601Date; - - /** - * When the favorite was created. - */ - created: SCISO8601Date; - - /** - * If it is deleted or not, defaults to false. - */ - deleted?: boolean; - - /** - * Type of a favorite - */ - type: SCThingType.Favorite; -} +export type SCFavoriteDataTypes = SCAcademicEventWithoutReferences + | SCArticleWithoutReferences + | SCBookWithoutReferences + | SCBuildingWithoutReferences + | SCPersonWithoutReferences + | SCPointOfInterestWithoutReferences + | SCRoomWithoutReferences + | SCSportCourseWithoutReferences; /** * A favorite * * @validatable */ -export interface SCFavorite extends SCFavoriteWithoutReferences { - /** - * The contained thing. - */ - data: - SCAcademicEventWithoutReferences - | SCArticleWithoutReferences - | SCBookWithoutReferences - | SCBuildingWithoutReferences - | SCPersonWithoutReferences - | SCPointOfInterestWithoutReferences - | SCRoomWithoutReferences - | SCSportCourseWithoutReferences; - - /** - * Type of a favorite - */ +export interface SCFavorite extends SCSaveableThing { type: SCThingType.Favorite; }