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 80e018692b
commit 4799f65aff
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
9 changed files with 164 additions and 0 deletions

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