mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-15 23:54:42 -04: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
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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue