mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 01:35:18 -04:00
Refactoring of controllers and service interfaces
DTO should only be used for sending information to and from user. Services now have methods which return normal internal objects and methods which convert them to DTOs. This conversion is done in the controlers Signed-off-by: Yannick Bungers <git@innay.de>
This commit is contained in:
parent
3431934ceb
commit
b07d6d478c
8 changed files with 175 additions and 147 deletions
|
@ -29,6 +29,7 @@ import { MediaService } from '../../../media/media.service';
|
|||
import { MulterFile } from '../../../media/multer-file.interface';
|
||||
import { TokenAuthGuard } from '../../../auth/token-auth.guard';
|
||||
import { ApiSecurity } from '@nestjs/swagger';
|
||||
import { MediaUploadUrlDto } from '../../../media/media-upload-url.dto';
|
||||
|
||||
@ApiSecurity('token')
|
||||
@Controller('media')
|
||||
|
@ -47,7 +48,7 @@ export class MediaController {
|
|||
@Request() req,
|
||||
@UploadedFile() file: MulterFile,
|
||||
@Headers('HedgeDoc-Note') noteId: string,
|
||||
) {
|
||||
) : Promise<MediaUploadUrlDto> {
|
||||
const username = req.user.userName;
|
||||
this.logger.debug(
|
||||
`Recieved filename '${file.originalname}' for note '${noteId}' from user '${username}'`,
|
||||
|
@ -59,9 +60,7 @@ export class MediaController {
|
|||
username,
|
||||
noteId,
|
||||
);
|
||||
return {
|
||||
link: url,
|
||||
};
|
||||
return this.mediaService.toMediaUploadUrlDto(url)
|
||||
} catch (e) {
|
||||
if (e instanceof ClientError || e instanceof NotInDBError) {
|
||||
throw new BadRequestException(e.message);
|
||||
|
@ -72,7 +71,7 @@ export class MediaController {
|
|||
|
||||
@UseGuards(TokenAuthGuard)
|
||||
@Delete(':filename')
|
||||
async deleteMedia(@Request() req, @Param('filename') filename: string) {
|
||||
async deleteMedia(@Request() req, @Param('filename') filename: string) : Promise<void> {
|
||||
const username = req.user.userName;
|
||||
try {
|
||||
await this.mediaService.deleteFile(filename, username);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue