mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 03:06:31 -05:00
Add PublicAPIModule
This adds all controllers needed in the public API (at least as currently specified) and implements some routes under `/me` Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
80e018692b
commit
4799f65aff
9 changed files with 164 additions and 0 deletions
26
src/api/public/me/me.controller.spec.ts
Normal file
26
src/api/public/me/me.controller.spec.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { getRepositoryToken } from '@nestjs/typeorm';
|
||||
import { HistoryModule } from '../../../history/history.module';
|
||||
import { User } from '../../../users/user.entity';
|
||||
import { UsersModule } from '../../../users/users.module';
|
||||
import { MeController } from './me.controller';
|
||||
|
||||
describe('Me Controller', () => {
|
||||
let controller: MeController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [MeController],
|
||||
imports: [UsersModule, HistoryModule],
|
||||
})
|
||||
.overrideProvider(getRepositoryToken(User))
|
||||
.useValue({})
|
||||
.compile();
|
||||
|
||||
controller = module.get<MeController>(MeController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
54
src/api/public/me/me.controller.ts
Normal file
54
src/api/public/me/me.controller.ts
Normal file
|
@ -0,0 +1,54 @@
|
|||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
HttpCode,
|
||||
Logger,
|
||||
NotFoundException,
|
||||
Param,
|
||||
Put,
|
||||
} from '@nestjs/common';
|
||||
import { HistoryEntryUpdateDto } from '../../../history/history-entry-update.dto';
|
||||
import { HistoryEntryDto } from '../../../history/history-entry.dto';
|
||||
import { HistoryService } from '../../../history/history.service';
|
||||
import { UserInfoDto } from '../../../users/user-info.dto';
|
||||
import { UsersService } from '../../../users/users.service';
|
||||
|
||||
@Controller('me')
|
||||
export class MeController {
|
||||
private readonly logger = new Logger(MeController.name);
|
||||
|
||||
constructor(
|
||||
private usersService: UsersService,
|
||||
private historyService: HistoryService,
|
||||
) {}
|
||||
|
||||
@Get()
|
||||
getMe(): UserInfoDto {
|
||||
return this.usersService.getUserInfo();
|
||||
}
|
||||
|
||||
@Get('history')
|
||||
getUserHistory(): HistoryEntryDto[] {
|
||||
return this.historyService.getUserHistory('someone');
|
||||
}
|
||||
|
||||
@Put('history/:note')
|
||||
updateHistoryEntry(
|
||||
@Param('note') note: string,
|
||||
@Body() entryUpdateDto: HistoryEntryUpdateDto,
|
||||
): HistoryEntryDto {
|
||||
return this.historyService.updateHistoryEntry(note, entryUpdateDto);
|
||||
}
|
||||
|
||||
@Delete('history/:note')
|
||||
@HttpCode(204)
|
||||
deleteHistoryEntry(@Param('note') note: string) {
|
||||
try {
|
||||
return this.historyService.deleteHistoryEntry(note);
|
||||
} catch (e) {
|
||||
throw new NotFoundException(e.message);
|
||||
}
|
||||
}
|
||||
}
|
18
src/api/public/media/media.controller.spec.ts
Normal file
18
src/api/public/media/media.controller.spec.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { MediaController } from './media.controller';
|
||||
|
||||
describe('Media Controller', () => {
|
||||
let controller: MediaController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [MediaController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<MediaController>(MediaController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
4
src/api/public/media/media.controller.ts
Normal file
4
src/api/public/media/media.controller.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
import { Controller } from '@nestjs/common';
|
||||
|
||||
@Controller('media')
|
||||
export class MediaController {}
|
18
src/api/public/monitoring/monitoring.controller.spec.ts
Normal file
18
src/api/public/monitoring/monitoring.controller.spec.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { MonitoringController } from './monitoring.controller';
|
||||
|
||||
describe('Monitoring Controller', () => {
|
||||
let controller: MonitoringController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [MonitoringController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<MonitoringController>(MonitoringController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
4
src/api/public/monitoring/monitoring.controller.ts
Normal file
4
src/api/public/monitoring/monitoring.controller.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
import { Controller } from '@nestjs/common';
|
||||
|
||||
@Controller('monitoring')
|
||||
export class MonitoringController {}
|
18
src/api/public/notes/notes.controller.spec.ts
Normal file
18
src/api/public/notes/notes.controller.spec.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { NotesController } from './notes.controller';
|
||||
|
||||
describe('Notes Controller', () => {
|
||||
let controller: NotesController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [NotesController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<NotesController>(NotesController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
4
src/api/public/notes/notes.controller.ts
Normal file
4
src/api/public/notes/notes.controller.ts
Normal file
|
@ -0,0 +1,4 @@
|
|||
import { Controller } from '@nestjs/common';
|
||||
|
||||
@Controller('notes')
|
||||
export class NotesController {}
|
18
src/api/public/public-api.module.ts
Normal file
18
src/api/public/public-api.module.ts
Normal file
|
@ -0,0 +1,18 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { HistoryModule } from '../../history/history.module';
|
||||
import { UsersModule } from '../../users/users.module';
|
||||
import { MeController } from './me/me.controller';
|
||||
import { NotesController } from './notes/notes.controller';
|
||||
import { MediaController } from './media/media.controller';
|
||||
import { MonitoringController } from './monitoring/monitoring.controller';
|
||||
|
||||
@Module({
|
||||
imports: [UsersModule, HistoryModule],
|
||||
controllers: [
|
||||
MeController,
|
||||
NotesController,
|
||||
MediaController,
|
||||
MonitoringController,
|
||||
],
|
||||
})
|
||||
export class PublicApiModule {}
|
Loading…
Reference in a new issue