mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-15 07:34:42 -04:00
Refactoring of controllers and service interfaces
DTO should only be used for sending information to and from user. Services now have methods which return normal internal objects and methods which convert them to DTOs. This conversion is done in the controlers Signed-off-by: Yannick Bungers <git@innay.de>
This commit is contained in:
parent
e8e269b1bb
commit
0d5b9dea00
8 changed files with 175 additions and 147 deletions
|
@ -24,30 +24,28 @@ export class RevisionsService {
|
|||
this.logger.setContext(RevisionsService.name);
|
||||
}
|
||||
|
||||
async getNoteRevisionMetadatas(
|
||||
async getAllRevisions(
|
||||
noteIdOrAlias: string,
|
||||
): Promise<RevisionMetadataDto[]> {
|
||||
): Promise<Revision[]> {
|
||||
const note = await this.notesService.getNoteByIdOrAlias(noteIdOrAlias);
|
||||
const revisions = await this.revisionRepository.find({
|
||||
return await this.revisionRepository.find({
|
||||
where: {
|
||||
note: note.id,
|
||||
note: note,
|
||||
},
|
||||
});
|
||||
return revisions.map((revision) => this.toMetadataDto(revision));
|
||||
}
|
||||
|
||||
async getNoteRevision(
|
||||
async getRevision(
|
||||
noteIdOrAlias: string,
|
||||
revisionId: number,
|
||||
): Promise<RevisionDto> {
|
||||
): Promise<Revision> {
|
||||
const note = await this.notesService.getNoteByIdOrAlias(noteIdOrAlias);
|
||||
const revision = await this.revisionRepository.findOne({
|
||||
return await this.revisionRepository.findOne({
|
||||
where: {
|
||||
id: revisionId,
|
||||
note: note,
|
||||
},
|
||||
});
|
||||
return this.toDto(revision);
|
||||
}
|
||||
|
||||
getLatestRevision(noteId: string): Promise<Revision> {
|
||||
|
@ -73,7 +71,7 @@ export class RevisionsService {
|
|||
});
|
||||
}
|
||||
|
||||
toMetadataDto(revision: Revision): RevisionMetadataDto {
|
||||
toRevisionMetadataDto(revision: Revision): RevisionMetadataDto {
|
||||
return {
|
||||
id: revision.id,
|
||||
length: revision.length,
|
||||
|
@ -81,7 +79,7 @@ export class RevisionsService {
|
|||
};
|
||||
}
|
||||
|
||||
toDto(revision: Revision): RevisionDto {
|
||||
toRevisionDto(revision: Revision): RevisionDto {
|
||||
return {
|
||||
id: revision.id,
|
||||
content: revision.content,
|
||||
|
@ -90,7 +88,7 @@ export class RevisionsService {
|
|||
};
|
||||
}
|
||||
|
||||
createRevision(content: string) {
|
||||
createRevision(content: string) : Revision {
|
||||
// TODO: Add previous revision
|
||||
// TODO: Calculate patch
|
||||
// TODO: Save metadata
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue