Skip to content

Commit

Permalink
feat(noteList): offset and limit parameters added
Browse files Browse the repository at this point in the history
* added offset and limit parameters for getNoteListByCreatorId func
  • Loading branch information
e11sy committed Oct 22, 2023
1 parent 6128b99 commit 90ed70a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
6 changes: 4 additions & 2 deletions src/domain/service/noteList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ export default class NoteListService {
* Returns note list by creator id
*
* @param id - note creator id
* @param offset - number of skipped notes
* @param limit - number of notes to get
* @returns { Promise<NoteList> } note
*/
public async getNoteListByCreatorId(id: number): Promise<NoteList> {
public async getNoteListByCreatorId(id: number, offset: number, limit: number): Promise<NoteList> {
return {
items: await this.repository.getNoteListByCreatorId(id),
items: await this.repository.getNoteListByCreatorId(id, offset, limit),
};
}
}
29 changes: 26 additions & 3 deletions src/presentation/http/router/noteList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,38 @@ const NoteListRouter: FastifyPluginCallback<NoteListRouterOptions> = (fastify, o
/**
* Get note list by userId
*/
fastify.get('/', {
fastify.get<{
Querystring: {
offset: number,
limit: number,
},
}>('/', {
config: {
policy: [
'authRequired',
],
},
schema: {
querystring: {
offset: {
type: 'number',
},
limit: {
type: 'number',
minimum: 1,
maximum: 30,
},
},
},
}, async (request, reply) => {
const { userId } = request;
const noteList = await noteListService.getNoteListByCreatorId(userId as number);
const userId = request.userId as number;
const offset = request.query.offset;

/**
* if limit > 30 or limit < 1 error throws (in scedule)
*/
const limit = request.query.limit;
const noteList = await noteListService.getNoteListByCreatorId(userId, offset, limit);

return reply.send(noteList);
});
Expand Down
6 changes: 4 additions & 2 deletions src/repository/note.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,11 @@ export default class NoteRepository {
* Gets note list by creator id
*
* @param id - note creator id
* @param offset - number of skipped notes
* @param limit - number of notes to get
* @returns { Promise<NoteList> } note
*/
public async getNoteListByCreatorId(id: number): Promise<Note[]> {
return await this.storage.getNoteListByCreatorId(id);
public async getNoteListByCreatorId(id: number, offset: number, limit: number): Promise<Note[]> {
return await this.storage.getNoteListByCreatorId(id, offset, limit);
}
}
6 changes: 5 additions & 1 deletion src/repository/storage/postgres/orm/sequelize/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,14 @@ export default class NoteSequelizeStorage {
* Gets note list by creator id
*
* @param creatorId - note creator id
* @param offset - number of skipped notes
* @param limit - number of notes to get
* @returns { Promise<NoteList> } note
*/
public async getNoteListByCreatorId(creatorId: number): Promise<Note[]> {
public async getNoteListByCreatorId(creatorId: number, offset: number, limit: number): Promise<Note[]> {
const noteList = await this.model.findAll({
offset: offset,
limit: limit,
where: {
creatorId,
},
Expand Down

0 comments on commit 90ed70a

Please sign in to comment.