diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index a0a6bf2b..ded599e6 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -26,7 +26,7 @@ jobs: services: postgres: - image: postgres + image: postgres:14 env: POSTGRES_USER: codex POSTGRES_DB: notes @@ -65,7 +65,7 @@ jobs: - name: Run tests run: yarn coverage - + - name: Get an appropriate name for an artifact run: echo "ARTIFACT_NAME=coverage-${{ matrix.branch }}" | tr -d ':<>|*?\r\n\/\\' >> $GITHUB_ENV @@ -74,7 +74,7 @@ jobs: with: name: ${{ env.ARTIFACT_NAME }} path: coverage - + report-coverage: needs: tests @@ -98,7 +98,7 @@ jobs: with: name: ${{ env.ARTIFACT_NAME }} path: coverage - + - name: Download coverage artifacts for the main branch uses: actions/download-artifact@v4 with: diff --git a/src/domain/service/note.ts b/src/domain/service/note.ts index c4ae5b52..0065dd6f 100644 --- a/src/domain/service/note.ts +++ b/src/domain/service/note.ts @@ -225,16 +225,16 @@ export default class NoteService { } /** - * Returns note list by creator id + * Returns recent notes visited by user, ordered by time of last visit * @param userId - id of the user * @param page - number of current page * @returns list of the notes ordered by time of last visit */ - public async getNoteListByUserId(userId: User['id'], page: number): Promise { + public async getRecentNotesByUserId(userId: User['id'], page: number): Promise { const offset = (page - 1) * this.noteListPortionSize; return { - items: await this.noteRepository.getNoteListByUserId(userId, offset, this.noteListPortionSize), + items: await this.noteRepository.getRecentNotesByUserId(userId, offset, this.noteListPortionSize), }; } diff --git a/src/presentation/http/router/noteList.ts b/src/presentation/http/router/noteList.ts index 49507d2f..fd227028 100644 --- a/src/presentation/http/router/noteList.ts +++ b/src/presentation/http/router/noteList.ts @@ -64,7 +64,7 @@ const NoteListRouter: FastifyPluginCallback = (fastify, o const userId = request.userId as number; const page = request.query.page; - const noteList = await noteService.getNoteListByUserId(userId, page); + const noteList = await noteService.getRecentNotesByUserId(userId, page); /** * Wrapping Notelist for public use */ diff --git a/src/repository/note.repository.ts b/src/repository/note.repository.ts index 234c0741..680728b3 100644 --- a/src/repository/note.repository.ts +++ b/src/repository/note.repository.ts @@ -73,13 +73,13 @@ export default class NoteRepository { } /** - * Gets note list by creator id + * Gets recent notes visited by user, ordered by time of last visit * @param id - note creator id * @param offset - number of skipped notes * @param limit - number of notes to get */ - public async getNoteListByUserId(id: number, offset: number, limit: number): Promise { - return await this.storage.getNoteListByUserId(id, offset, limit); + public async getRecentNotesByUserId(id: number, offset: number, limit: number): Promise { + return await this.storage.getRecentNotesByUserId(id, offset, limit); } /** diff --git a/src/repository/storage/postgres/orm/sequelize/note.ts b/src/repository/storage/postgres/orm/sequelize/note.ts index 1b9ba87c..c8fd0935 100644 --- a/src/repository/storage/postgres/orm/sequelize/note.ts +++ b/src/repository/storage/postgres/orm/sequelize/note.ts @@ -224,13 +224,13 @@ export default class NoteSequelizeStorage { } /** - * Gets note list by creator id + * Gets recent notes visited by user, ordered by time of last visit * @param userId - id of certain user * @param offset - number of skipped notes * @param limit - number of notes to get - * @returns list of the notes + * @returns list of the notes ordered by last visit time */ - public async getNoteListByUserId(userId: number, offset: number, limit: number): Promise { + public async getRecentNotesByUserId(userId: number, offset: number, limit: number): Promise { if (this.visitsModel === null) { throw new Error('NoteStorage: NoteVisit model should be defined'); } @@ -356,7 +356,7 @@ export default class NoteSequelizeStorage { // Fetch all notes and relations in a recursive query const query = ` WITH RECURSIVE note_tree AS ( - SELECT + SELECT n.id AS "noteId", n.content, n.public_id AS "publicId", @@ -364,10 +364,10 @@ export default class NoteSequelizeStorage { FROM ${String(this.database.literal(this.tableName).val)} n LEFT JOIN ${String(this.database.literal('note_relations').val)} nr ON n.id = nr.note_id WHERE n.id = :startNoteId - + UNION ALL - SELECT + SELECT n.id AS "noteId", n.content, n.public_id AS "publicId",