Skip to content

Commit

Permalink
merge pull request #469 from kmi0817/be-feautre/#468-change-attachingโ€ฆ
Browse files Browse the repository at this point in the history
โ€ฆ-files

[feat] ํŒŒ์ผ ์‹œ์Šคํ…œ์œผ๋กœ ์ด๋ฏธ์ง€๋ฅผ ๊ด€๋ฆฌํ•˜๋„๋ก ํ•˜๋Š” ์„œ๋น„์Šค ์ƒ์„ฑ
  • Loading branch information
yaongmeow authored Sep 3, 2024
2 parents a886f8b + c7e37b4 commit aa3fe28
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 18 deletions.
6 changes: 4 additions & 2 deletions BE/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { TimelinesModule } from './timelines/timelines.module';
import { AuthModule } from './auth/auth.module';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { DatabaseModule } from './database/database.module';
import { StorageModule } from './storage/storage.module';
// import { StorageModule } from './storage/storage.module';
import { FileModule } from './file/file.module';
import { JwtModule } from '@nestjs/jwt';
import { EmailModule } from './email/email.module';

Expand All @@ -22,7 +23,8 @@ import { EmailModule } from './email/email.module';
secret: process.env.JWT_SECRET_ACCESS,
signOptions: { expiresIn: '30d' },
}),
StorageModule,
// StorageModule,
FileModule,
UsersModule,
PostingsModule,
TimelinesModule,
Expand Down
5 changes: 3 additions & 2 deletions BE/src/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { StorageService } from './storage/storage.service';
// import { StorageService } from './storage/storage.service';
import { FileService } from './file/file.service';
import { Injectable } from '@nestjs/common';

@Injectable()
export class AppService {
constructor(private readonly storageService: StorageService) {}
constructor(private readonly storageService: FileService) {}

getHello(): string {
return `
Expand Down
6 changes: 4 additions & 2 deletions BE/src/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { AuthService } from './auth.service';
import { AuthController } from './auth.controller';
import { UsersModule } from 'src/users/users.module';
import { UsersService } from 'src/users/users.service';
import { StorageService } from 'src/storage/storage.service';
// import { StorageService } from 'src/storage/storage.service';
import { FileService } from 'src/file/file.service';
import { HttpModule } from '@nestjs/axios';
import { AuthGuard } from './auth.guard';
import { EmailModule } from 'src/email/email.module';
Expand All @@ -16,7 +17,8 @@ import { AppleLoginStrategy } from 'src/socialLogin/apple-login-strategy';
providers: [
AuthService,
UsersService,
StorageService,
// StorageService,
FileService,
AuthGuard,
KakaoLoginStrategy,
AppleLoginStrategy,
Expand Down
8 changes: 8 additions & 0 deletions BE/src/file/file.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { FileService } from './file.service';
import { Module } from '@nestjs/common';

@Module({
providers: [FileService],
exports: [FileService],
})
export class FileModule {}
36 changes: 36 additions & 0 deletions BE/src/file/file.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Injectable } from '@nestjs/common';
import { mkdir, unlink, writeFile } from 'fs/promises';
import { v4 as uuidv4 } from 'uuid';

@Injectable()
export class FileService {
private readonly basePath = 'static/';

constructor() {}

private generateFilename(originalname: string) {
const extension = originalname.split('.').pop();
const uniqueId = uuidv4();
return `${uniqueId}.${extension}`;
}

async upload(path: string, file: Express.Multer.File) {
const filePath =
this.basePath + path + this.generateFilename(file.originalname);
await mkdir(this.basePath + path, { recursive: true });
await writeFile(filePath, file.buffer);

return {
imageUrl: filePath,
path: filePath,
};
}

async getImageUrl(key: string): Promise<string> {
return this.basePath + key;
}

async delete(path: string) {
await unlink(this.basePath + path);
}
}
5 changes: 3 additions & 2 deletions BE/src/postings/postings.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import { PostingsRepository } from './repositories/postings.repository';
import { LikedsRepository } from './repositories/likeds.repository';
import { ReportsRepository } from './repositories/reports.repository';
import { UsersModule } from '../users/users.module';
import { StorageModule } from 'src/storage/storage.module';
// import { StorageModule } from 'src/storage/storage.module';
import { FileModule } from 'src/file/file.module';

@Module({
imports: [DatabaseModule, UsersModule, StorageModule],
imports: [DatabaseModule, UsersModule, FileModule],
controllers: [PostingsController],
providers: [
...postingsProviders,
Expand Down
5 changes: 3 additions & 2 deletions BE/src/postings/postings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import { Liked } from './entities/liked.entity';
import { Report } from './entities/report.entity';
import { Period, Season } from './postings.types';
import { BLOCKING_LIMIT } from './postings.constants';
import { StorageService } from 'src/storage/storage.service';
// import { StorageService } from 'src/storage/storage.service';
import { FileService } from 'src/file/file.service';
import { BlockRepository } from 'src/users/block.repository';

@Injectable()
Expand All @@ -28,7 +29,7 @@ export class PostingsService {
private readonly postingsRepository: PostingsRepository,
private readonly likedsRepository: LikedsRepository,
private readonly reportsRepository: ReportsRepository,
private readonly storageService: StorageService
private readonly storageService: FileService
) {}

async create(userId: string, createPostingDto: CreatePostingDto) {
Expand Down
6 changes: 4 additions & 2 deletions BE/src/timelines/timelines.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ import { PostingsRepository } from '../postings/repositories/postings.repository
import { LikedsRepository } from '../postings/repositories/likeds.repository';
import { ReportsRepository } from '../postings/repositories/reports.repository';
import { postingsProviders } from '../postings/postings.providers';
import { StorageModule } from '../storage/storage.module';
// import { StorageModule } from '../storage/storage.module';
import { FileModule } from '../file/file.module';

@Module({
imports: [
DatabaseModule,
PostingsModule,
UsersModule,
StorageModule,
// StorageModule,
FileModule,
HttpModule,
],
controllers: [TimelinesController],
Expand Down
5 changes: 3 additions & 2 deletions BE/src/timelines/timelines.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import { CreateTimelineDto } from './dto/create-timeline.dto';
import { UpdateTimelineDto } from './dto/update-timeline.dto';
import { TimelinesRepository } from './timelines.repository';
import { Timeline } from './entities/timeline.entity';
import { StorageService } from '../storage/storage.service';
// import { StorageService } from '../storage/storage.service';
import { FileService } from '../file/file.service';
import { PostingsService } from '../postings/postings.service';
import { KAKAO_KEYWORD_SEARCH, PAPAGO_URL } from './timelines.constants';
import { PostingsRepository } from '../postings/repositories/postings.repository';
Expand All @@ -21,7 +22,7 @@ export class TimelinesService {
private readonly timelinesRepository: TimelinesRepository,
private readonly postingsRepository: PostingsRepository,
private readonly postingsService: PostingsService,
private readonly storageService: StorageService,
private readonly storageService: FileService,
private readonly httpService: HttpService
) {}

Expand Down
5 changes: 3 additions & 2 deletions BE/src/users/users.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import { UsersService } from './users.service';
import { UsersController } from './users.controller';
import { usersProvider } from './users.providers';
import { UserRepository } from './users.repository';
import { StorageModule } from '../storage/storage.module';
// import { StorageModule } from '../storage/storage.module';
import { FileModule } from '../file/file.module';
import { DatabaseModule } from '../database/database.module';
import { BlockRepository } from './block.repository';

@Module({
imports: [DatabaseModule, StorageModule],
imports: [DatabaseModule, FileModule],
controllers: [UsersController],
providers: [UsersService, ...usersProvider, UserRepository, BlockRepository],
exports: [UserRepository, UsersService, BlockRepository],
Expand Down
5 changes: 3 additions & 2 deletions BE/src/users/users.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BadRequestException, Injectable } from '@nestjs/common';
import { UserInfoDto } from './dto/user-info.dto';
import { StorageService } from 'src/storage/storage.service';
// import { StorageService } from 'src/storage/storage.service';
import { FileService } from 'src/file/file.service';
import { UserRepository } from './users.repository';
import { CheckDuplicatedNameResponseDto } from './dto/check-duplicated-name-response.dto';
import { UpdateUserDto } from './dto/update-user.dto';
Expand All @@ -12,7 +13,7 @@ export class UsersService {
constructor(
private userRepository: UserRepository,
private blockRepository: BlockRepository,
private readonly storageService: StorageService
private readonly storageService: FileService
) {}

nameGenerator() {
Expand Down

0 comments on commit aa3fe28

Please sign in to comment.