From d63118c07db64d2f0b75bc6c8d2e698ecd028307 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Fri, 5 Mar 2021 11:45:38 +0900 Subject: [PATCH] Add document model --- frontend/models/document.ts | 69 +++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 frontend/models/document.ts diff --git a/frontend/models/document.ts b/frontend/models/document.ts new file mode 100644 index 00000000..2cd9dfbf --- /dev/null +++ b/frontend/models/document.ts @@ -0,0 +1,69 @@ +export class DocumentItemList { + constructor( + private _count: number, + private _next: string | null, + private _prev: string | null, + private _items: DocumentItem[] + ) {} + + static valueOf( + { count, next, previous, results }: + { + count : number, + next : string | null, + previous: string | null, + results : Array + } + ): DocumentItemList { + const items = results.map(item => DocumentItem.valueOf(item)) + return new DocumentItemList( + count, + next, + previous, + items + ) + } + + get count() { + return this._count + } + + get next() { + return this._next + } + + get prev() { + return this._prev + } + + get items(): DocumentItem[] { + return this._items + } +} + +export class DocumentItem { + constructor( + public id: number, + public text: string, + public meta: string, + public annotationApprover: boolean | null, + public commentCount: number + ) {} + + static valueOf( + { id, text, meta, annotation_approver, comment_count }: + { id: number, text: string, meta: string, annotation_approver: boolean | null, comment_count: number } + ): DocumentItem { + return new DocumentItem(id, text, meta, annotation_approver, comment_count) + } + + toObject(): Object { + return { + id: this.id, + text: this.text, + meta: this.meta, + annotation_approver: this.annotationApprover, + comment_count: this.commentCount + } + } +}