Skip to content

Commit

Permalink
Merge pull request #239 from codex-team/recent-note-list
Browse files Browse the repository at this point in the history
Recent note list
  • Loading branch information
e11sy authored Apr 3, 2024
2 parents 39093c8 + 94643c4 commit f100ad3
Show file tree
Hide file tree
Showing 14 changed files with 441 additions and 267 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
DROP INDEX IF EXISTS note_visits_user_id_idx;

CREATE INDEX note_visits_user_id_idx ON public.note_visits (user_id);
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@types/pg": "^8.10.2",
"@vitest/coverage-v8": "^0.34.5",
"eslint": "^8.41.0",
"eslint-config-codex": "^1.8.3",
"eslint-config-codex": "^1.9.2",
"eslint-plugin-vitest": "^0.3.1",
"nodemon": "^2.0.22",
"pino-pretty": "^10.0.0",
Expand Down
10 changes: 1 addition & 9 deletions src/domain/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import NoteService from '@domain/service/note.js';
import NoteListService from '@domain/service/noteList.js';
import NoteSettingsService from './service/noteSettings.js';
import type { Repositories } from '@repository/index.js';
import AuthService from '@domain/service/auth.js';
Expand All @@ -19,11 +18,6 @@ export interface DomainServices {
*/
noteService: NoteService,

/**
* Note List service instance
*/
noteListService: NoteListService,

/**
* Note settings service instance
*/
Expand Down Expand Up @@ -67,16 +61,15 @@ export interface DomainServices {
* @param appConfig - app config
*/
export function init(repositories: Repositories, appConfig: AppConfig): DomainServices {
const noteListService = new NoteListService(repositories.noteRepository);
const noteService = new NoteService(repositories.noteRepository, repositories.noteRelationsRepository);
const noteVisitsService = new NoteVisitsService(repositories.noteVisitsRepository);

const authService = new AuthService(
appConfig.auth.accessSecret,
appConfig.auth.accessExpiresIn,
appConfig.auth.refreshExpiresIn,
repositories.userSessionRepository
);
const noteVisitsService = new NoteVisitsService(repositories.noteVisitsRepository);

const editorToolsService = new EditorToolsService(repositories.editorToolsRepository);

Expand All @@ -97,7 +90,6 @@ export function init(repositories: Repositories, appConfig: AppConfig): DomainSe
return {
fileUploaderService,
noteService,
noteListService,
noteSettingsService,
userService,
authService,
Expand Down
24 changes: 23 additions & 1 deletion src/domain/service/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import type NoteRepository from '@repository/note.repository.js';
import { createPublicId } from '@infrastructure/utils/id.js';
import { DomainError } from '@domain/entities/DomainError.js';
import type NoteRelationsRepository from '@repository/noteRelations.repository.js';
import type User from '@domain/entities/user.js';
import type { NoteList } from '@domain/entities/noteList.js';

/**
* Note service
Expand All @@ -18,6 +20,12 @@ export default class NoteService {
*/
public noteRelationsRepository: NoteRelationsRepository;

/**
* Number of the notes to be displayed on one page
* it is used to calculate offset and limit for getting notes that the user has recently opened
*/
private readonly noteListPortionSize = 30;

/**
* Note service constructor
*
Expand Down Expand Up @@ -57,7 +65,6 @@ export default class NoteService {
return note;
}


/**
* @todo Build a note tree and delete all descendants of a deleted note
*/
Expand Down Expand Up @@ -164,6 +171,21 @@ export default class NoteService {
return await this.noteRelationsRepository.getParentNoteIdByNoteId(noteId);
}

/**
* Returns note list by creator id
*
* @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<NoteList> {
const offset = (page - 1) * this.noteListPortionSize;

return {
items: await this.noteRepository.getNoteListByUserId(userId, offset, this.noteListPortionSize),
};
}

/**
* Update note relation
*
Expand Down
42 changes: 0 additions & 42 deletions src/domain/service/noteList.ts

This file was deleted.

5 changes: 2 additions & 3 deletions src/presentation/http/http-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export default class HttpApi implements Api {

await this.server?.register(NoteListRouter, {
prefix: '/notes',
noteListService: domainServices.noteListService,
noteService: domainServices.noteService,
});

await this.server?.register(JoinRouter, {
Expand Down Expand Up @@ -362,5 +362,4 @@ export default class HttpApi implements Api {
throw error;
});
}
}

}
Loading

0 comments on commit f100ad3

Please sign in to comment.