@christianriedl/media 1.0.169 → 1.0.171

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ import { IRest } from '@christianriedl/rest';
2
+ import { ILogger, IStatistics, InjectionKey } from '@christianriedl/utils';
3
+ import { IBook, IAuthor, IAuthorShort, IBooksService } from "./iBooks";
4
+ export declare const getBooksSymbol: InjectionKey<() => BooksService>;
5
+ export declare class BooksService implements IBooksService {
6
+ rest: IRest;
7
+ mediaUrl: string;
8
+ user: string;
9
+ log: ILogger;
10
+ cachedAuthors?: IAuthorShort[];
11
+ constructor(rest: IRest, user: string, statistics: IStatistics, log: ILogger);
12
+ getAuthors(surName?: string, givenName?: string, withBooks?: boolean, id?: number): Promise<IAuthor[]>;
13
+ getAuthorsShort(): Promise<IAuthorShort[]>;
14
+ addAuthor(author: IAuthor): Promise<number>;
15
+ updateAuthor(author: IAuthor): Promise<boolean>;
16
+ deleteAuthor(id: number): Promise<boolean>;
17
+ getBooks(authorId?: number, bookId?: number): Promise<IBook[]>;
18
+ addBook(book: IBook): Promise<number>;
19
+ updateBook(book: IBook): Promise<boolean>;
20
+ deleteBook(id: number): Promise<boolean>;
21
+ }
@@ -0,0 +1,68 @@
1
+ export const getBooksSymbol = Symbol("get-books");
2
+ export class BooksService {
3
+ rest;
4
+ mediaUrl;
5
+ user;
6
+ log;
7
+ cachedAuthors;
8
+ constructor(rest, user, statistics, log) {
9
+ this.log = log;
10
+ this.rest = rest;
11
+ this.user = user;
12
+ this.mediaUrl = rest.serviceUrl;
13
+ }
14
+ async getAuthors(surName, givenName, withBooks, id) {
15
+ const info = await this.rest.getData('apibooks/authors', { surName, givenName, withBooks, id });
16
+ return info.result;
17
+ }
18
+ async getAuthorsShort() {
19
+ if (!this.cachedAuthors) {
20
+ const info = await this.rest.getData('apibooks/authors/short');
21
+ this.cachedAuthors = info.result;
22
+ }
23
+ return this.cachedAuthors;
24
+ }
25
+ async addAuthor(author) {
26
+ const url = `apibooks/authors`;
27
+ const res = await this.rest.postDataEx(url, author);
28
+ this.cachedAuthors = undefined;
29
+ this.log.info(`Add author ${author.surName} : ${res.result}`);
30
+ return res.result;
31
+ }
32
+ async updateAuthor(author) {
33
+ const url = `apibooks/authors`;
34
+ const res = await this.rest.putData(url, author);
35
+ this.log.info(`Update author ${author.surName} : ${res.result}`);
36
+ return res.result;
37
+ }
38
+ async deleteAuthor(id) {
39
+ const url = `apibooks/authors?id=${id}`;
40
+ const res = await this.rest.deleteData(url);
41
+ this.cachedAuthors = undefined;
42
+ this.log.info(`Delete author ${id} : ${res.result}`);
43
+ return res.result;
44
+ }
45
+ async getBooks(authorId, bookId) {
46
+ const info = await this.rest.getData('apibooks/books', { authorId, bookId });
47
+ return info.result;
48
+ }
49
+ async addBook(book) {
50
+ const url = `apibooks/books`;
51
+ const res = await this.rest.postDataEx(url, book);
52
+ this.log.info(`Add book ${book.title} : ${res.result}`);
53
+ return res.result;
54
+ }
55
+ async updateBook(book) {
56
+ const url = `apibooks/books`;
57
+ const res = await this.rest.putData(url, book);
58
+ this.log.info(`Update book ${book.title} : ${res.result}`);
59
+ return res.result;
60
+ }
61
+ async deleteBook(id) {
62
+ const url = `apibooks/books?id=${id}`;
63
+ const res = await this.rest.deleteData(url);
64
+ this.log.info(`Add book ${id} : ${res.result}`);
65
+ return res.result;
66
+ }
67
+ }
68
+ //# sourceMappingURL=booksService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"booksService.js","sourceRoot":"","sources":["../src/booksService.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,cAAc,GAAqC,MAAM,CAAC,WAAW,CAAC,CAAC;AACpF,MAAM,OAAO,YAAY;IACrB,IAAI,CAAQ;IACZ,QAAQ,CAAS;IACjB,IAAI,CAAS;IACb,GAAG,CAAU;IACb,aAAa,CAAkB;IAC/B,YAAY,IAAW,EAAE,IAAY,EAAE,UAAuB,EAAE,GAAY;QACxE,IAAI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,CAAC,IAAI,CAAC,OAAO,CAAiB,GAAG,EAAE,IAAI,CAAC,CAAC;QAC/D,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,eAAe,IAAI,CAAC,KAAK,MAAM,GAAG,CAAC,MAAM,EAAE,CAAC,CAAA;QAC1D,OAAO,GAAG,CAAC,MAAiB,CAAC;IACjC,CAAC;IACD,KAAK,CAAC,UAAU,CAAC,EAAU;QACvB,MAAM,GAAG,GAAG,qBAAqB,EAAE,EAAE,CAAC;QACtC,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,UAAU,CAAmB,GAAG,CAAC,CAAC;QAC9D,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,CAAC,MAAM,EAAE,CAAC,CAAA;QAC/C,OAAO,GAAG,CAAC,MAAiB,CAAC;IACjC,CAAC;CACJ"}
@@ -0,0 +1,34 @@
1
+ export interface IAuthor {
2
+ id: number;
3
+ surName: string;
4
+ givenName: string;
5
+ yearOfBirth: number;
6
+ yearOfDeath?: number;
7
+ country?: string;
8
+ books?: IBook[];
9
+ }
10
+ export interface IAuthorShort {
11
+ id: number;
12
+ sN: string;
13
+ gN: string;
14
+ }
15
+ export interface IBook {
16
+ id: number;
17
+ title: string;
18
+ authorId: number;
19
+ description?: string;
20
+ year?: number;
21
+ comment?: string;
22
+ rating?: number;
23
+ }
24
+ export interface IBooksService {
25
+ getAuthors(surName?: string, givenName?: string, withBooks?: boolean, id?: number): Promise<IAuthor[]>;
26
+ getAuthorsShort(): Promise<IAuthorShort[]>;
27
+ addAuthor(author: IAuthor): Promise<number>;
28
+ updateAuthor(author: IAuthor): Promise<boolean>;
29
+ deleteAuthor(id: number): Promise<boolean>;
30
+ getBooks(authorId?: number, bookId?: number): Promise<IBook[]>;
31
+ addBook(book: IBook): Promise<number>;
32
+ updateBook(book: IBook): Promise<boolean>;
33
+ deleteBook(id: number): Promise<boolean>;
34
+ }
package/dist/iBooks.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=iBooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iBooks.js","sourceRoot":"","sources":["../src/iBooks.ts"],"names":[],"mappings":""}