-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add the feature to be able to select document
- Loading branch information
Olasunkanmi Oyinlola
authored and
Olasunkanmi Oyinlola
committed
Apr 19, 2024
1 parent
bc6d0a5
commit 8d257bb
Showing
21 changed files
with
246 additions
and
81 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,31 @@ | ||
import * as express from "express"; | ||
import { Result } from "../lib/result"; | ||
import { generateErrorResponse } from "../utils/utils"; | ||
import { GetDocumentsHandler } from "../handlers/get-documents-handler"; | ||
|
||
export class DocumentController { | ||
path = "/documents"; | ||
router = express.Router(); | ||
|
||
constructor() { | ||
this.initializeRoute(); | ||
} | ||
|
||
initializeRoute() { | ||
this.router.get(this.path, this.getDocument); | ||
} | ||
|
||
async getDocument(req: express.Request, res: any, next: express.NextFunction) { | ||
try { | ||
const documentHandler = new GetDocumentsHandler(); | ||
const data = await documentHandler.handle(); | ||
if (data) { | ||
const result = Result.ok(data.getValue()); | ||
res.status(200).json(result); | ||
} | ||
} catch (error) { | ||
generateErrorResponse(error, res, next); | ||
next(error); | ||
} | ||
} | ||
} |
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,17 @@ | ||
import { IRequestHandler } from "../interfaces/handler"; | ||
import { Result } from "../lib/result"; | ||
import { DocumentRepository } from "../repositories/document.repository"; | ||
import { IDocumentModel } from "../repositories/model"; | ||
|
||
export class GetDocumentsHandler implements IRequestHandler<{}, Result<IDocumentModel[]>> { | ||
async handle(): Promise<Result<IDocumentModel[]>> { | ||
try { | ||
let response: IDocumentModel[]; | ||
const documentRespository: DocumentRepository = new DocumentRepository(); | ||
response = await documentRespository.getDocuments(); | ||
return Result.ok(response); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// Todo, refactor IRequestHandler< TResponse, TRequest = any> so as to make TRequest optional type | ||
export interface IRequestHandler<TRequest, TResponse> { | ||
handle(request?: TRequest): Promise<TResponse>; | ||
} |
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
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 function ErrorFallBackComponent() { | ||
return ( | ||
<div> | ||
<h1>Oops! Something went wrong.</h1> | ||
<p>Please try again later.</p> | ||
</div> | ||
); | ||
} |
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
Oops, something went wrong.