-
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.
- Loading branch information
Showing
8 changed files
with
158 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,3 @@ | ||
import type { Note } from '@domain/entities/note'; | ||
|
||
export type NoteList = Note[]; |
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,29 @@ | ||
import type NoteRepository from '@repository/note.repository'; | ||
import type { NoteCreatorId } from '@domain/entities/note'; | ||
import type { NoteList } from '@domain/entities/noteList'; | ||
|
||
export default class NoteListService { | ||
/** | ||
* Note repository | ||
*/ | ||
public repository: NoteRepository; | ||
|
||
/** | ||
* Note service constructor | ||
* | ||
* @param repository - note repository | ||
*/ | ||
constructor(repository: NoteRepository) { | ||
this.repository = repository; | ||
} | ||
|
||
/** | ||
* Gets note list by creator id | ||
* | ||
* @param id - note creator id | ||
* @returns { Promise<NoteList | null> } note | ||
*/ | ||
public async getNoteListByCreatorId(id: NoteCreatorId): Promise<NoteList | null> { | ||
return await this.repository.getNoteListByCreatorId(id); | ||
} | ||
} |
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,73 @@ | ||
import type { FastifyPluginCallback } from 'fastify'; | ||
import type NoteListService from '@domain/service/noteList'; | ||
import type { Middlewares } from '@presentation/http/middlewares/index.js'; | ||
import type { NoteCreatorId } from '@domain/entities/note'; | ||
import type { ErrorResponse } from '@presentation/http/types/HttpResponse'; | ||
import { StatusCodes } from 'http-status-codes'; | ||
import type { NoteList } from '@domain/entities/noteList'; | ||
|
||
|
||
interface GetNoteListById { | ||
/** | ||
* Note id | ||
*/ | ||
id: NoteCreatorId; | ||
}; | ||
|
||
/** | ||
* Interface for the noteList router. | ||
*/ | ||
interface NoteListRouterOptions { | ||
/** | ||
* Note service instance | ||
*/ | ||
noteListService: NoteListService, | ||
|
||
/** | ||
* Middlewares | ||
*/ | ||
middlewares: Middlewares, | ||
}; | ||
|
||
|
||
/** | ||
* Note router plugin | ||
* | ||
* @param fastify - fastify instance | ||
* @param opts - empty options | ||
* @param done - callback | ||
*/ | ||
const NoteListRouter: FastifyPluginCallback<NoteListRouterOptions> = (fastify, opts, done) => { | ||
|
||
const noteListService = opts.noteListService; | ||
|
||
/** | ||
* Get note by id | ||
*/ | ||
fastify.get<{ Params: GetNoteListById }>('/', { preHandler: [opts.middlewares.authRequired, opts.middlewares.withUser] }, async (request, reply) => { | ||
const userId = request.ctx.auth.id; | ||
|
||
const noteList = await noteListService.getNoteListByCreatorId(userId); | ||
|
||
/** | ||
* Check if noteList does not exist | ||
*/ | ||
if (!noteList) { | ||
const response: ErrorResponse = { | ||
code: StatusCodes.NOT_FOUND, | ||
message: 'Note not found Test Answer', | ||
}; | ||
|
||
return reply.send(response); | ||
} | ||
|
||
const response: {data:NoteList} = { | ||
data: noteList, | ||
}; | ||
|
||
return reply.send(response); | ||
}); | ||
|
||
done(); | ||
}; | ||
export default NoteListRouter; |
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