mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-28 20:20:56 -05:00
Implement /notes API routes
This adds all currently specified routes under /notes. Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
4cd574306e
commit
82f03152a8
3 changed files with 97 additions and 4 deletions
|
@ -1,4 +1,9 @@
|
||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { getRepositoryToken } from '@nestjs/typeorm';
|
||||||
|
import { Note } from '../../../notes/note.entity';
|
||||||
|
import { NotesService } from '../../../notes/notes.service';
|
||||||
|
import { Revision } from '../../../revisions/revision.entity';
|
||||||
|
import { RevisionsModule } from '../../../revisions/revisions.module';
|
||||||
import { NotesController } from './notes.controller';
|
import { NotesController } from './notes.controller';
|
||||||
|
|
||||||
describe('Notes Controller', () => {
|
describe('Notes Controller', () => {
|
||||||
|
@ -7,7 +12,14 @@ describe('Notes Controller', () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
controllers: [NotesController],
|
controllers: [NotesController],
|
||||||
}).compile();
|
providers: [NotesService],
|
||||||
|
imports: [RevisionsModule],
|
||||||
|
})
|
||||||
|
.overrideProvider(getRepositoryToken(Note))
|
||||||
|
.useValue({})
|
||||||
|
.overrideProvider(getRepositoryToken(Revision))
|
||||||
|
.useValue({})
|
||||||
|
.compile();
|
||||||
|
|
||||||
controller = module.get<NotesController>(NotesController);
|
controller = module.get<NotesController>(NotesController);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,4 +1,84 @@
|
||||||
import { Controller } from '@nestjs/common';
|
import {
|
||||||
|
Body,
|
||||||
|
Controller,
|
||||||
|
Delete,
|
||||||
|
Get,
|
||||||
|
Header,
|
||||||
|
Param,
|
||||||
|
Post,
|
||||||
|
Put,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
import { NotePermissionsUpdateDto } from '../../../notes/note-permissions.dto';
|
||||||
|
import { NotesService } from '../../../notes/notes.service';
|
||||||
|
import { RevisionsService } from '../../../revisions/revisions.service';
|
||||||
|
|
||||||
@Controller('notes')
|
@Controller('notes')
|
||||||
export class NotesController {}
|
export class NotesController {
|
||||||
|
constructor(
|
||||||
|
private noteService: NotesService,
|
||||||
|
private revisionsService: RevisionsService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
@Post()
|
||||||
|
createNote(@Body() noteContent: string) {
|
||||||
|
return this.noteService.createNote(noteContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get(':noteIdOrAlias')
|
||||||
|
getNote(@Param('noteIdOrAlias') noteIdOrAlias: string) {
|
||||||
|
return this.noteService.getNoteByIdOrAlias(noteIdOrAlias);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Post(':noteAlias')
|
||||||
|
createNamedNote(
|
||||||
|
@Param('noteAlias') noteAlias: string,
|
||||||
|
@Body() noteContent: string,
|
||||||
|
) {
|
||||||
|
return this.noteService.createNote(noteContent, noteAlias);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete(':noteIdOrAlias')
|
||||||
|
deleteNote(@Param('noteIdOrAlias') noteIdOrAlias: string) {
|
||||||
|
return this.noteService.deleteNoteByIdOrAlias(noteIdOrAlias);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Put(':noteIdOrAlias')
|
||||||
|
updateNote(
|
||||||
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
|
@Body() noteContent: string,
|
||||||
|
) {
|
||||||
|
return this.noteService.updateNoteByIdOrAlias(noteIdOrAlias, noteContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get(':noteIdOrAlias/content')
|
||||||
|
@Header('content-type', 'text/markdown')
|
||||||
|
getNoteContent(@Param('noteIdOrAlias') noteIdOrAlias: string) {
|
||||||
|
return this.noteService.getNoteContent(noteIdOrAlias);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get(':noteIdOrAlias/metadata')
|
||||||
|
getNoteMetadata(@Param('noteIdOrAlias') noteIdOrAlias: string) {
|
||||||
|
return this.noteService.getNoteMetadata(noteIdOrAlias);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Put(':noteIdOrAlias/permissions')
|
||||||
|
updateNotePermissions(
|
||||||
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
|
@Body() updateDto: NotePermissionsUpdateDto,
|
||||||
|
) {
|
||||||
|
return this.noteService.updateNotePermissions(noteIdOrAlias, updateDto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get(':noteIdOrAlias/revisions')
|
||||||
|
getNoteRevisions(@Param('noteIdOrAlias') noteIdOrAlias: string) {
|
||||||
|
return this.revisionsService.getNoteRevisionMetadatas(noteIdOrAlias);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Get(':noteIdOrAlias/revisions/:revisionId')
|
||||||
|
getNoteRevision(
|
||||||
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
|
@Param('revisionId') revisionId: string,
|
||||||
|
) {
|
||||||
|
return this.revisionsService.getNoteRevision(noteIdOrAlias, revisionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { HistoryModule } from '../../history/history.module';
|
import { HistoryModule } from '../../history/history.module';
|
||||||
import { NotesModule } from '../../notes/notes.module';
|
import { NotesModule } from '../../notes/notes.module';
|
||||||
|
import { RevisionsModule } from '../../revisions/revisions.module';
|
||||||
import { UsersModule } from '../../users/users.module';
|
import { UsersModule } from '../../users/users.module';
|
||||||
import { MeController } from './me/me.controller';
|
import { MeController } from './me/me.controller';
|
||||||
import { NotesController } from './notes/notes.controller';
|
import { NotesController } from './notes/notes.controller';
|
||||||
|
@ -8,7 +9,7 @@ import { MediaController } from './media/media.controller';
|
||||||
import { MonitoringController } from './monitoring/monitoring.controller';
|
import { MonitoringController } from './monitoring/monitoring.controller';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [UsersModule, HistoryModule, NotesModule],
|
imports: [UsersModule, HistoryModule, NotesModule, RevisionsModule],
|
||||||
controllers: [
|
controllers: [
|
||||||
MeController,
|
MeController,
|
||||||
NotesController,
|
NotesController,
|
||||||
|
|
Loading…
Reference in a new issue