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:
David Mehren 2020-07-25 20:13:06 +02:00
parent eeeacb8c67
commit 348cd3ffe1
No known key found for this signature in database
GPG key ID: 6017AF117F9756CB
9 changed files with 164 additions and 0 deletions

View 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();
});
});

View 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);
}
}
}

View 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();
});
});

View file

@ -0,0 +1,4 @@
import { Controller } from '@nestjs/common';
@Controller('media')
export class MediaController {}

View 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();
});
});

View file

@ -0,0 +1,4 @@
import { Controller } from '@nestjs/common';
@Controller('monitoring')
export class MonitoringController {}

View 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();
});
});

View file

@ -0,0 +1,4 @@
import { Controller } from '@nestjs/common';
@Controller('notes')
export class NotesController {}

View 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 {}