Skip to content

Commit

Permalink
Merge pull request #373 from boostcampwm2023/BE-feature/profile-auth
Browse files Browse the repository at this point in the history
Multer ๋™์ž‘ ๋ฏธ๋“ค์›จ์–ด๋กœ ์ด๋™
  • Loading branch information
Conut-1 authored Dec 27, 2024
2 parents 754c89b + ae40972 commit 4c73868
Show file tree
Hide file tree
Showing 4 changed files with 208 additions and 154 deletions.
16 changes: 16 additions & 0 deletions nestjs-BE/server/src/common/middlewares/multer-file.middleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Injectable, NestMiddleware } from '@nestjs/common';
import { Request, Response, NextFunction } from 'express';
import * as multer from 'multer';

export function MulterFileMiddleware(fieldName: string) {
@Injectable()
class MulterSingleMiddleware implements NestMiddleware {
readonly multerInstance = multer();

use(req: Request, res: Response, next: NextFunction) {
this.multerInstance.single(fieldName)(req, res, next);
}
}

return MulterSingleMiddleware;
}
4 changes: 0 additions & 4 deletions nestjs-BE/server/src/spaces/spaces.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ import {
Body,
Patch,
Param,
UseInterceptors,
UploadedFile,
ValidationPipe,
Header,
HttpStatus,
Delete,
UseGuards,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { ApiTags, ApiResponse, ApiOperation, ApiQuery } from '@nestjs/swagger';
import { SpacesService } from './spaces.service';
import { CreateSpaceDto } from './dto/create-space.dto';
Expand All @@ -28,7 +26,6 @@ export class SpacesController {

@Post()
@UseGuards(MatchUserProfileGuard)
@UseInterceptors(FileInterceptor('icon'))
@ApiOperation({ summary: 'Create space' })
@ApiResponse({
status: HttpStatus.CREATED,
Expand Down Expand Up @@ -104,7 +101,6 @@ export class SpacesController {
@Patch(':space_uuid')
@UseGuards(MatchUserProfileGuard)
@UseGuards(IsProfileInSpaceGuard)
@UseInterceptors(FileInterceptor('icon'))
@ApiOperation({ summary: 'Update space by space_uuid' })
@ApiResponse({
status: HttpStatus.OK,
Expand Down
19 changes: 17 additions & 2 deletions nestjs-BE/server/src/spaces/spaces.module.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
import { Module } from '@nestjs/common';
import {
MiddlewareConsumer,
Module,
NestModule,
RequestMethod,
} from '@nestjs/common';
import { SpacesService } from './spaces.service';
import { SpacesController } from './spaces.controller';
import { UploadModule } from '../upload/upload.module';
import { ProfileSpaceModule } from '../profile-space/profile-space.module';
import { AuthModule } from '../auth/auth.module';
import { MulterFileMiddleware } from '../common/middlewares/multer-file.middleware';

@Module({
imports: [ProfileSpaceModule, UploadModule, AuthModule],
controllers: [SpacesController],
providers: [SpacesService],
exports: [SpacesService],
})
export class SpacesModule {}
export class SpacesModule implements NestModule {
configure(consumer: MiddlewareConsumer) {
consumer
.apply(MulterFileMiddleware('icon'))
.forRoutes(
{ path: '/spaces', method: RequestMethod.POST },
{ path: '/spaces/:space_uuid', method: RequestMethod.PATCH },
);
}
}
Loading

0 comments on commit 4c73868

Please sign in to comment.