From 5bc02f13cbc8ef4eb6463d1873992ecaf245fb3f Mon Sep 17 00:00:00 2001 From: Son Daehyeon Date: Sat, 14 Sep 2024 12:45:26 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20File=20Upload=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/domain/activity/activity.module.ts | 7 +++++- .../controller/activity.admin.controller.ts | 24 +++++++++++++++++++ .../activity/common/controller/index.ts | 1 + src/domain/activity/common/dto/index.ts | 2 ++ .../dto/response/upload.response.dto.ts | 10 ++++++++ .../common/service/activity.admin.service.ts | 21 ++++++++++++++++ src/domain/activity/common/service/index.ts | 1 + src/domain/activity/controller.ts | 2 ++ src/domain/activity/dto.ts | 2 ++ src/domain/activity/service.ts | 2 ++ 10 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 src/domain/activity/common/controller/activity.admin.controller.ts create mode 100644 src/domain/activity/common/controller/index.ts create mode 100644 src/domain/activity/common/dto/index.ts create mode 100644 src/domain/activity/common/dto/response/upload.response.dto.ts create mode 100644 src/domain/activity/common/service/activity.admin.service.ts create mode 100644 src/domain/activity/common/service/index.ts diff --git a/src/domain/activity/activity.module.ts b/src/domain/activity/activity.module.ts index a837bb5..d712f23 100644 --- a/src/domain/activity/activity.module.ts +++ b/src/domain/activity/activity.module.ts @@ -37,6 +37,7 @@ import { } from '@wink/activity/service'; import { MongoModelFactory } from '@wink/mongo'; +import { S3Module } from '@wink/s3'; const modelFactory1 = MongoModelFactory.generateRecursive(Activity.name, ActivitySchema, [ { type: ActivityType.Project, schema: ProjectSchema }, @@ -47,7 +48,11 @@ const modelFactory1 = MongoModelFactory.generateRecursive(Activity.nam const modelFactory2 = MongoModelFactory.generate(Category.name, CategorySchema); @Module({ - imports: [MongooseModule.forFeature([modelFactory1, modelFactory2]), MemberModule], + imports: [ + MongooseModule.forFeature([modelFactory1, modelFactory2]), + S3Module.forRoot({ directory: 'activity' }), + MemberModule, + ], controllers: [ ProjectController, ProjectAdminController, diff --git a/src/domain/activity/common/controller/activity.admin.controller.ts b/src/domain/activity/common/controller/activity.admin.controller.ts new file mode 100644 index 0000000..9e9b39b --- /dev/null +++ b/src/domain/activity/common/controller/activity.admin.controller.ts @@ -0,0 +1,24 @@ +import { Controller, Post, UploadedFile } from '@nestjs/common'; +import { ApiOperation, ApiTags } from '@nestjs/swagger'; + +import { AuthAdminAccount, AuthAdminAccountException } from '@wink/auth/guard'; + +import { UploadResponseDto } from '@wink/activity/common/dto'; +import { ActivityAdminService } from '@wink/activity/service'; + +import { ApiCustomErrorResponse, ApiCustomResponse } from '@wink/swagger'; + +@Controller('/admin/activity') +@ApiTags('[Admin] Activity [공통]') +export class ActivityAdminController { + constructor(private readonly activityAdminService: ActivityAdminService) {} + + @Post('/upload') + @AuthAdminAccount() + @ApiOperation({ summary: '업로드' }) + @ApiCustomResponse() + @ApiCustomErrorResponse([...AuthAdminAccountException]) + async upload(@UploadedFile() file: Express.Multer.File): Promise { + return this.activityAdminService.upload(file); + } +} diff --git a/src/domain/activity/common/controller/index.ts b/src/domain/activity/common/controller/index.ts new file mode 100644 index 0000000..7485bc6 --- /dev/null +++ b/src/domain/activity/common/controller/index.ts @@ -0,0 +1 @@ +export * from './activity.admin.controller'; diff --git a/src/domain/activity/common/dto/index.ts b/src/domain/activity/common/dto/index.ts new file mode 100644 index 0000000..1c2564e --- /dev/null +++ b/src/domain/activity/common/dto/index.ts @@ -0,0 +1,2 @@ +// Response +export * from './response/upload.response.dto'; diff --git a/src/domain/activity/common/dto/response/upload.response.dto.ts b/src/domain/activity/common/dto/response/upload.response.dto.ts new file mode 100644 index 0000000..c06bf1e --- /dev/null +++ b/src/domain/activity/common/dto/response/upload.response.dto.ts @@ -0,0 +1,10 @@ +import { ApiProperty } from '@nestjs/swagger'; + +export class UploadResponseDto { + @ApiProperty({ + description: '파일 URL', + example: + 'https://kmu-wink.s3.ap-northeast-2.amazonaws.com/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee.jpeg', + }) + link!: string; +} diff --git a/src/domain/activity/common/service/activity.admin.service.ts b/src/domain/activity/common/service/activity.admin.service.ts new file mode 100644 index 0000000..83c5bd2 --- /dev/null +++ b/src/domain/activity/common/service/activity.admin.service.ts @@ -0,0 +1,21 @@ +import { Inject, Injectable } from '@nestjs/common'; + +import { MemberRepository } from '@wink/member/repository'; + +import { UploadResponseDto } from '@wink/activity/common/dto'; + +import { S3Service } from '@wink/s3'; + +@Injectable() +export class ActivityAdminService { + constructor( + private readonly memberRepository: MemberRepository, + @Inject('S3_SERVICE_ACTIVITY') private readonly avatarService: S3Service, + ) {} + + async upload(file: Express.Multer.File): Promise { + const link = await this.avatarService.upload(file); + + return { link }; + } +} diff --git a/src/domain/activity/common/service/index.ts b/src/domain/activity/common/service/index.ts new file mode 100644 index 0000000..d7013af --- /dev/null +++ b/src/domain/activity/common/service/index.ts @@ -0,0 +1 @@ +export * from './activity.admin.service'; diff --git a/src/domain/activity/controller.ts b/src/domain/activity/controller.ts index 5f03e7c..3207f98 100644 --- a/src/domain/activity/controller.ts +++ b/src/domain/activity/controller.ts @@ -1,3 +1,5 @@ +export * from './common/controller'; + export * from './project/controller'; export * from './study/controller'; export * from './social/controller'; diff --git a/src/domain/activity/dto.ts b/src/domain/activity/dto.ts index d30f0d9..169080f 100644 --- a/src/domain/activity/dto.ts +++ b/src/domain/activity/dto.ts @@ -1,3 +1,5 @@ +export * from './common/dto'; + export * from './project/dto'; export * from './study/dto'; export * from './social/dto'; diff --git a/src/domain/activity/service.ts b/src/domain/activity/service.ts index 213ef90..7ae4fdf 100644 --- a/src/domain/activity/service.ts +++ b/src/domain/activity/service.ts @@ -1,3 +1,5 @@ +export * from './common/service'; + export * from './project/service'; export * from './study/service'; export * from './social/service';