From adccce1fca002a251a9f757782fc4c2a636f2a74 Mon Sep 17 00:00:00 2001 From: Dobrunia Kostrigin <48620984+Dobrunia@users.noreply.github.com> Date: Thu, 13 Nov 2025 20:16:52 +0300 Subject: [PATCH 1/6] refactor: rename getNoteListByUserId to getRecentNotesByUserId --- src/domain/service/note.ts | 6 +++--- src/presentation/http/router/noteList.ts | 2 +- src/repository/note.repository.ts | 6 +++--- .../storage/postgres/orm/sequelize/note.ts | 12 ++++++------ 4 files changed, 13 insertions(+), 13 deletions(-) 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", From 631fa48e6eb966e6619f74332b4722cd07f86542 Mon Sep 17 00:00:00 2001 From: Dobrunia Kostrigin <48620984+Dobrunia@users.noreply.github.com> Date: Sat, 15 Nov 2025 21:03:22 +0300 Subject: [PATCH 2/6] fix: api tests workflow comment volumes --- .github/workflows/run-tests.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index a0a6bf2b..1c3ceecb 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -38,8 +38,8 @@ jobs: --health-interval 10s --health-timeout 5s --health-retries 5 - volumes: - - ./database:/var/lib/postgresql/data + # volumes: + # - ./database:/var/lib/postgresql/data steps: - name: Wait for PostgreSQL @@ -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: From e3cfd235d095c2b32e8adc74e4ea17b7de65078e Mon Sep 17 00:00:00 2001 From: Dobrunia Kostrigin <48620984+Dobrunia@users.noreply.github.com> Date: Sat, 15 Nov 2025 21:10:02 +0300 Subject: [PATCH 3/6] chore: tests --- .github/workflows/run-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 1c3ceecb..73729968 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -38,8 +38,8 @@ jobs: --health-interval 10s --health-timeout 5s --health-retries 5 - # volumes: - # - ./database:/var/lib/postgresql/data + volumes: + - ./database:/var/lib/postgresql/data steps: - name: Wait for PostgreSQL From 157ad9ff64c9ac2f0f50f6fbc401de1a93fe4389 Mon Sep 17 00:00:00 2001 From: Dobrunia Kostrigin <48620984+Dobrunia@users.noreply.github.com> Date: Sat, 15 Nov 2025 21:14:29 +0300 Subject: [PATCH 4/6] fix: tests workflow --- .github/workflows/run-tests.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 73729968..afb564b8 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -31,15 +31,15 @@ jobs: POSTGRES_USER: codex POSTGRES_DB: notes POSTGRES_PASSWORD: postgres - ports: - - 127.0.0.1:5432:5432 + # ports: + # - 127.0.0.1:5432:5432 options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 - volumes: - - ./database:/var/lib/postgresql/data + # volumes: + # - ./database:/var/lib/postgresql/data steps: - name: Wait for PostgreSQL From d40877e7a1c44f1dd1ce43efe02ab8039473c822 Mon Sep 17 00:00:00 2001 From: Dobrunia Kostrigin <48620984+Dobrunia@users.noreply.github.com> Date: Sat, 15 Nov 2025 21:22:00 +0300 Subject: [PATCH 5/6] chore: move Checkout Repository before chown --- .github/workflows/run-tests.yml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index afb564b8..0446397b 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -42,19 +42,16 @@ jobs: # - ./database:/var/lib/postgresql/data steps: + - name: Checkout Repository + uses: actions/checkout@v4 + with: + ref: ${{ matrix.branch }} - name: Wait for PostgreSQL uses: jakejarvis/wait-action@master with: time: '20s' - - name: Make runner the owner of database folder run: sudo chown -R $USER database - - - name: Checkout Repository - uses: actions/checkout@v4 - with: - ref: ${{ matrix.branch }} - - name: Setup node uses: actions/setup-node@v3 with: From 4607b74991aa3f1e6958e08b1f630c28830579e0 Mon Sep 17 00:00:00 2001 From: Dobrunia Kostrigin <48620984+Dobrunia@users.noreply.github.com> Date: Sat, 15 Nov 2025 21:25:26 +0300 Subject: [PATCH 6/6] chore: add postgres version to tests workflow --- .github/workflows/run-tests.yml | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 0446397b..ded599e6 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -26,32 +26,35 @@ jobs: services: postgres: - image: postgres + image: postgres:14 env: POSTGRES_USER: codex POSTGRES_DB: notes POSTGRES_PASSWORD: postgres - # ports: - # - 127.0.0.1:5432:5432 + ports: + - 127.0.0.1:5432:5432 options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 - # volumes: - # - ./database:/var/lib/postgresql/data + volumes: + - ./database:/var/lib/postgresql/data steps: - - name: Checkout Repository - uses: actions/checkout@v4 - with: - ref: ${{ matrix.branch }} - name: Wait for PostgreSQL uses: jakejarvis/wait-action@master with: time: '20s' + - name: Make runner the owner of database folder run: sudo chown -R $USER database + + - name: Checkout Repository + uses: actions/checkout@v4 + with: + ref: ${{ matrix.branch }} + - name: Setup node uses: actions/setup-node@v3 with: