mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-23 10:16:32 -05:00
Add API decorator to reduce clutter
Signed-off-by: Thomas Snowden <zapperchamp1@gmail.com>
This commit is contained in:
parent
15e51f1244
commit
95df1525a9
3 changed files with 31 additions and 31 deletions
|
@ -39,7 +39,6 @@ import {
|
||||||
ApiForbiddenResponse,
|
ApiForbiddenResponse,
|
||||||
ApiHeader,
|
ApiHeader,
|
||||||
ApiNoContentResponse,
|
ApiNoContentResponse,
|
||||||
ApiNotFoundResponse,
|
|
||||||
ApiSecurity,
|
ApiSecurity,
|
||||||
ApiTags,
|
ApiTags,
|
||||||
ApiUnauthorizedResponse,
|
ApiUnauthorizedResponse,
|
||||||
|
@ -47,10 +46,10 @@ import {
|
||||||
import { MediaUploadUrlDto } from '../../../media/media-upload-url.dto';
|
import { MediaUploadUrlDto } from '../../../media/media-upload-url.dto';
|
||||||
import {
|
import {
|
||||||
forbiddenDescription,
|
forbiddenDescription,
|
||||||
notFoundDescription,
|
|
||||||
successfullyDeletedDescription,
|
successfullyDeletedDescription,
|
||||||
unauthorizedDescription,
|
unauthorizedDescription,
|
||||||
} from '../../utils/descriptions';
|
} from '../../utils/descriptions';
|
||||||
|
import { FullApi } from '../../utils/fullapi-decorator';
|
||||||
|
|
||||||
@ApiTags('media')
|
@ApiTags('media')
|
||||||
@ApiSecurity('token')
|
@ApiSecurity('token')
|
||||||
|
@ -127,9 +126,7 @@ export class MediaController {
|
||||||
@Delete(':filename')
|
@Delete(':filename')
|
||||||
@HttpCode(204)
|
@HttpCode(204)
|
||||||
@ApiNoContentResponse({ description: successfullyDeletedDescription })
|
@ApiNoContentResponse({ description: successfullyDeletedDescription })
|
||||||
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
@FullApi
|
||||||
@ApiForbiddenResponse({ description: forbiddenDescription })
|
|
||||||
@ApiNotFoundResponse({ description: notFoundDescription })
|
|
||||||
async deleteMedia(
|
async deleteMedia(
|
||||||
@Req() req: Request,
|
@Req() req: Request,
|
||||||
@Param('filename') filename: string,
|
@Param('filename') filename: string,
|
||||||
|
|
|
@ -34,13 +34,13 @@ import {
|
||||||
} from '../../../notes/note-permissions.dto';
|
} from '../../../notes/note-permissions.dto';
|
||||||
import { NotesService } from '../../../notes/notes.service';
|
import { NotesService } from '../../../notes/notes.service';
|
||||||
import { RevisionsService } from '../../../revisions/revisions.service';
|
import { RevisionsService } from '../../../revisions/revisions.service';
|
||||||
|
import { FullApi } from '../../utils/fullapi-decorator';
|
||||||
import { MarkdownBody } from '../../utils/markdownbody-decorator';
|
import { MarkdownBody } from '../../utils/markdownbody-decorator';
|
||||||
import { TokenAuthGuard } from '../../../auth/token-auth.guard';
|
import { TokenAuthGuard } from '../../../auth/token-auth.guard';
|
||||||
import {
|
import {
|
||||||
ApiCreatedResponse,
|
ApiCreatedResponse,
|
||||||
ApiForbiddenResponse,
|
ApiForbiddenResponse,
|
||||||
ApiNoContentResponse,
|
ApiNoContentResponse,
|
||||||
ApiNotFoundResponse,
|
|
||||||
ApiOkResponse,
|
ApiOkResponse,
|
||||||
ApiProduces,
|
ApiProduces,
|
||||||
ApiSecurity,
|
ApiSecurity,
|
||||||
|
@ -57,7 +57,6 @@ import { Note } from '../../../notes/note.entity';
|
||||||
import { Request } from 'express';
|
import { Request } from 'express';
|
||||||
import {
|
import {
|
||||||
forbiddenDescription,
|
forbiddenDescription,
|
||||||
notFoundDescription,
|
|
||||||
successfullyDeletedDescription,
|
successfullyDeletedDescription,
|
||||||
unauthorizedDescription,
|
unauthorizedDescription,
|
||||||
} from '../../utils/descriptions';
|
} from '../../utils/descriptions';
|
||||||
|
@ -109,9 +108,7 @@ export class NotesController {
|
||||||
description: 'Get information about the newly created note',
|
description: 'Get information about the newly created note',
|
||||||
type: NoteDto,
|
type: NoteDto,
|
||||||
})
|
})
|
||||||
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
@FullApi
|
||||||
@ApiForbiddenResponse({ description: forbiddenDescription })
|
|
||||||
@ApiNotFoundResponse({ description: notFoundDescription })
|
|
||||||
async getNote(
|
async getNote(
|
||||||
@Req() req: Request,
|
@Req() req: Request,
|
||||||
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
|
@ -180,9 +177,7 @@ export class NotesController {
|
||||||
@Delete(':noteIdOrAlias')
|
@Delete(':noteIdOrAlias')
|
||||||
@HttpCode(204)
|
@HttpCode(204)
|
||||||
@ApiNoContentResponse({ description: successfullyDeletedDescription })
|
@ApiNoContentResponse({ description: successfullyDeletedDescription })
|
||||||
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
@FullApi
|
||||||
@ApiForbiddenResponse({ description: forbiddenDescription })
|
|
||||||
@ApiNotFoundResponse({ description: notFoundDescription })
|
|
||||||
async deleteNote(
|
async deleteNote(
|
||||||
@Req() req: Request,
|
@Req() req: Request,
|
||||||
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
|
@ -226,9 +221,7 @@ export class NotesController {
|
||||||
description: 'The new, changed note',
|
description: 'The new, changed note',
|
||||||
type: NoteDto,
|
type: NoteDto,
|
||||||
})
|
})
|
||||||
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
@FullApi
|
||||||
@ApiForbiddenResponse({ description: forbiddenDescription })
|
|
||||||
@ApiNotFoundResponse({ description: notFoundDescription })
|
|
||||||
async updateNote(
|
async updateNote(
|
||||||
@Req() req: Request,
|
@Req() req: Request,
|
||||||
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
|
@ -264,9 +257,7 @@ export class NotesController {
|
||||||
@ApiOkResponse({
|
@ApiOkResponse({
|
||||||
description: 'The raw markdown content of the note',
|
description: 'The raw markdown content of the note',
|
||||||
})
|
})
|
||||||
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
@FullApi
|
||||||
@ApiForbiddenResponse({ description: forbiddenDescription })
|
|
||||||
@ApiNotFoundResponse({ description: notFoundDescription })
|
|
||||||
@Header('content-type', 'text/markdown')
|
@Header('content-type', 'text/markdown')
|
||||||
async getNoteContent(
|
async getNoteContent(
|
||||||
@Req() req: Request,
|
@Req() req: Request,
|
||||||
|
@ -299,9 +290,7 @@ export class NotesController {
|
||||||
description: 'The metadata of the note',
|
description: 'The metadata of the note',
|
||||||
type: NoteMetadataDto,
|
type: NoteMetadataDto,
|
||||||
})
|
})
|
||||||
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
@FullApi
|
||||||
@ApiForbiddenResponse({ description: forbiddenDescription })
|
|
||||||
@ApiNotFoundResponse({ description: notFoundDescription })
|
|
||||||
async getNoteMetadata(
|
async getNoteMetadata(
|
||||||
@Req() req: Request,
|
@Req() req: Request,
|
||||||
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
|
@ -336,9 +325,7 @@ export class NotesController {
|
||||||
description: 'The updated permissions of the note',
|
description: 'The updated permissions of the note',
|
||||||
type: NotePermissionsDto,
|
type: NotePermissionsDto,
|
||||||
})
|
})
|
||||||
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
@FullApi
|
||||||
@ApiForbiddenResponse({ description: forbiddenDescription })
|
|
||||||
@ApiNotFoundResponse({ description: notFoundDescription })
|
|
||||||
async updateNotePermissions(
|
async updateNotePermissions(
|
||||||
@Req() req: Request,
|
@Req() req: Request,
|
||||||
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
|
@ -374,9 +361,7 @@ export class NotesController {
|
||||||
isArray: true,
|
isArray: true,
|
||||||
type: RevisionMetadataDto,
|
type: RevisionMetadataDto,
|
||||||
})
|
})
|
||||||
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
@FullApi
|
||||||
@ApiForbiddenResponse({ description: forbiddenDescription })
|
|
||||||
@ApiNotFoundResponse({ description: notFoundDescription })
|
|
||||||
async getNoteRevisions(
|
async getNoteRevisions(
|
||||||
@Req() req: Request,
|
@Req() req: Request,
|
||||||
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
|
@ -413,9 +398,7 @@ export class NotesController {
|
||||||
description: 'Revision of the note for the given id or alias',
|
description: 'Revision of the note for the given id or alias',
|
||||||
type: RevisionDto,
|
type: RevisionDto,
|
||||||
})
|
})
|
||||||
@ApiUnauthorizedResponse({ description: unauthorizedDescription })
|
@FullApi
|
||||||
@ApiForbiddenResponse({ description: forbiddenDescription })
|
|
||||||
@ApiNotFoundResponse({ description: notFoundDescription })
|
|
||||||
async getNoteRevision(
|
async getNoteRevision(
|
||||||
@Req() req: Request,
|
@Req() req: Request,
|
||||||
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
|
|
20
src/api/utils/fullapi-decorator.ts
Normal file
20
src/api/utils/fullapi-decorator.ts
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { applyDecorators } from '@nestjs/common';
|
||||||
|
import {
|
||||||
|
ApiForbiddenResponse,
|
||||||
|
ApiNotFoundResponse,
|
||||||
|
ApiUnauthorizedResponse,
|
||||||
|
} from '@nestjs/swagger';
|
||||||
|
import { forbiddenDescription, notFoundDescription } from './descriptions';
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||||
|
export const FullApi = applyDecorators(
|
||||||
|
ApiForbiddenResponse({ description: forbiddenDescription }),
|
||||||
|
ApiNotFoundResponse({ description: notFoundDescription }),
|
||||||
|
ApiUnauthorizedResponse({ description: forbiddenDescription }),
|
||||||
|
);
|
Loading…
Reference in a new issue