Skip to content

Commit

Permalink
feat: File Upload 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
son-daehyeon committed Sep 14, 2024
1 parent b0541bb commit 5bc02f1
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/domain/activity/activity.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
} from '@wink/activity/service';

import { MongoModelFactory } from '@wink/mongo';
import { S3Module } from '@wink/s3';

const modelFactory1 = MongoModelFactory.generateRecursive<Activity>(Activity.name, ActivitySchema, [
{ type: ActivityType.Project, schema: ProjectSchema },
Expand All @@ -47,7 +48,11 @@ const modelFactory1 = MongoModelFactory.generateRecursive<Activity>(Activity.nam
const modelFactory2 = MongoModelFactory.generate<Category>(Category.name, CategorySchema);

@Module({
imports: [MongooseModule.forFeature([modelFactory1, modelFactory2]), MemberModule],
imports: [
MongooseModule.forFeature([modelFactory1, modelFactory2]),
S3Module.forRoot({ directory: 'activity' }),
MemberModule,
],
controllers: [
ProjectController,
ProjectAdminController,
Expand Down
24 changes: 24 additions & 0 deletions src/domain/activity/common/controller/activity.admin.controller.ts
Original file line number Diff line number Diff line change
@@ -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<UploadResponseDto> {
return this.activityAdminService.upload(file);
}
}
1 change: 1 addition & 0 deletions src/domain/activity/common/controller/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './activity.admin.controller';
2 changes: 2 additions & 0 deletions src/domain/activity/common/dto/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Response
export * from './response/upload.response.dto';
10 changes: 10 additions & 0 deletions src/domain/activity/common/dto/response/upload.response.dto.ts
Original file line number Diff line number Diff line change
@@ -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;
}
21 changes: 21 additions & 0 deletions src/domain/activity/common/service/activity.admin.service.ts
Original file line number Diff line number Diff line change
@@ -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<UploadResponseDto> {
const link = await this.avatarService.upload(file);

return { link };
}
}
1 change: 1 addition & 0 deletions src/domain/activity/common/service/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './activity.admin.service';
2 changes: 2 additions & 0 deletions src/domain/activity/controller.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './common/controller';

export * from './project/controller';
export * from './study/controller';
export * from './social/controller';
2 changes: 2 additions & 0 deletions src/domain/activity/dto.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './common/dto';

export * from './project/dto';
export * from './study/dto';
export * from './social/dto';
2 changes: 2 additions & 0 deletions src/domain/activity/service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from './common/service';

export * from './project/service';
export * from './study/service';
export * from './social/service';

0 comments on commit 5bc02f1

Please sign in to comment.