generated from PluteoJS/pluteojs-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): implement news prediction api with mock ml function
- Loading branch information
1 parent
b31bcd1
commit a447fd2
Showing
11 changed files
with
246 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import {asTypeIServiceError} from "@customTypes/commonServiceTypes"; | ||
|
||
const newsServiceError = asTypeIServiceError({ | ||
predictAnnotations: { | ||
NewsDoesNotExists: { | ||
error: "NewsDoesNotExists", | ||
|
||
message: "News doesn't exists", | ||
}, | ||
}, | ||
}); | ||
|
||
export {newsServiceError}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export interface iNewsAnnotationMapModel { | ||
id: string; | ||
news_id: string; | ||
annotation_id: string; | ||
annotated_by: string; | ||
user_id: string; | ||
created_at: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import {IDatabase, IMain} from "pg-promise"; | ||
|
||
import {iNewsAnnotationMapModel} from "db/models/newsAnnotationMap.model"; | ||
|
||
import {newsAnnotationMap as sql} from "@db/sql"; | ||
import {NullableString} from "customTypes/commonTypes"; | ||
|
||
/* | ||
This repository mixes hard-coded and dynamic SQL, just to show how to use both. | ||
*/ | ||
export default class NewsAnnotationRepository { | ||
/** | ||
* @param db | ||
* Automated database connection context/interface. | ||
* | ||
* If you ever need to access other repositories from this one, | ||
* you will have to replace type 'IDatabase<any>' with 'any'. | ||
* | ||
* @param pgp | ||
* Library's root, if ever needed, like to access 'helpers' | ||
* or other namespaces available from the root. | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
constructor(private db: IDatabase<any>, private pgp: IMain) { | ||
/* | ||
If your repository needs to use helpers like ColumnSet, | ||
you should create it conditionally, inside the constructor, | ||
i.e. only once, as a singleton. | ||
*/ | ||
} | ||
|
||
/** | ||
* Creates the news_annotation_map table. | ||
* | ||
* @returns null | ||
*/ | ||
async create(): Promise<null> { | ||
return this.db.none(sql.create); | ||
} | ||
|
||
// Returns all news_annotation_map records; | ||
async all(): Promise<iNewsAnnotationMapModel[]> { | ||
return this.db.any("SELECT * FROM news_annotation_map"); | ||
} | ||
|
||
// Finds a news_annotation_map record by its ID; | ||
async findById(id: string): Promise<iNewsAnnotationMapModel | null> { | ||
return this.db.oneOrNone( | ||
"SELECT * FROM news_annotation_map WHERE id = $1", | ||
id | ||
); | ||
} | ||
|
||
// Adds a new news_annotation_map record, and returns the new object; | ||
async add( | ||
id: string, | ||
newsId: string, | ||
annotationId: string, | ||
annotatedBy: string, | ||
userId: NullableString | ||
): Promise<iNewsAnnotationMapModel> { | ||
return this.db.one(sql.add, { | ||
id, | ||
newsId, | ||
annotationId, | ||
annotatedBy, | ||
userId, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/* | ||
Inserts a new news_annotation_map record. | ||
*/ | ||
INSERT INTO news_annotations_map(id, news_id, annotation_id, annotated_by, user_id, created_at) | ||
VALUES(${id}, ${newsId}, ${annotationId}, ${annotatedBy}, ${userId}, CURRENT_TIMESTAMP) | ||
RETURNING *; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CREATE TABLE news_annotations_map | ||
( | ||
id UUID PRIMARY KEY, | ||
news_id UUID NOT NULL, | ||
annotation_id UUID NOT NULL, | ||
annotated_by VARCHAR(10) NOT NULL, | ||
user_id UUID, -- This column will be filled with the user's ID when annotated_by is 'user' | ||
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW() | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters