-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #224 from boostcampwm2023/develop
v0.1 배포
- Loading branch information
Showing
136 changed files
with
4,939 additions
and
530 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
virtualenv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import os | ||
|
||
import boto3 | ||
from PIL import Image | ||
|
||
service_name: str = 's3' | ||
endpoint_url: str = 'https://kr.object.ncloudstorage.com' | ||
|
||
|
||
def downsample_image(input_path: str, output_path: str, downsample_size: tuple[int, int] = (500, 500)): | ||
if not os.path.exists(os.path.dirname(output_path)): | ||
os.makedirs(os.path.dirname(output_path), exist_ok=True) | ||
with Image.open(input_path) as img: | ||
downsampled_img: Image.Image = img.resize(downsample_size, Image.Resampling.LANCZOS) | ||
downsampled_img.save(output_path) | ||
|
||
|
||
def main(args): | ||
bucket_name: str = args['container_name'] | ||
object_name: str = args['object_name'] | ||
|
||
s3: boto3 = boto3.client( | ||
service_name, | ||
endpoint_url=endpoint_url, | ||
aws_access_key_id=args['access_key'], | ||
aws_secret_access_key=args['scret_key'], | ||
) | ||
|
||
object_path: str = f"./{object_name}" | ||
thumbnail_path: str = f"./thumbnail/{object_name}" | ||
|
||
s3.download_file(bucket_name, object_name, object_path) | ||
downsample_image(object_path, thumbnail_path) | ||
s3.upload_file(thumbnail_path, bucket_name, thumbnail_path) | ||
|
||
return args |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
boto3==1.29.5 | ||
botocore==1.32.5 | ||
jmespath==1.0.1 | ||
Pillow==10.1.0 | ||
python-dateutil==2.8.2 | ||
s3transfer==0.7.0 | ||
six==1.16.0 | ||
urllib3==2.0.7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { AchievementController } from './controller/achievement.controller'; | ||
import { AchievementService } from './application/achievement.service'; | ||
import { CustomTypeOrmModule } from '../config/typeorm/custom-typeorm.module'; | ||
import { AchievementRepository } from './entities/achievement.repository'; | ||
|
||
@Module({ | ||
imports: [CustomTypeOrmModule.forCustomRepository([AchievementRepository])], | ||
controllers: [AchievementController], | ||
providers: [AchievementService], | ||
}) | ||
export class AchievementModule {} |
151 changes: 151 additions & 0 deletions
151
BE/src/achievement/application/achievement.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { AchievementService } from './achievement.service'; | ||
import { CustomTypeOrmModule } from '../../config/typeorm/custom-typeorm.module'; | ||
import { AchievementRepository } from '../entities/achievement.repository'; | ||
import { ConfigModule } from '@nestjs/config'; | ||
import { configServiceModuleOptions } from '../../config/config'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { typeOrmModuleOptions } from '../../config/typeorm'; | ||
import { UsersTestModule } from '../../../test/user/users-test.module'; | ||
import { UsersFixture } from '../../../test/user/users-fixture'; | ||
import { CategoryFixture } from '../../../test/category/category-fixture'; | ||
import { AchievementFixture } from '../../../test/achievement/achievement-fixture'; | ||
import { CategoryTestModule } from '../../../test/category/category-test.module'; | ||
import { AchievementTestModule } from '../../../test/achievement/achievement-test.module'; | ||
import { PaginateAchievementRequest } from '../dto/paginate-achievement-request'; | ||
import { NoSuchAchievementException } from '../exception/no-such-achievement.exception'; | ||
|
||
describe('AchievementService Test', () => { | ||
let achievementService: AchievementService; | ||
let usersFixture: UsersFixture; | ||
let categoryFixture: CategoryFixture; | ||
let achievementFixture: AchievementFixture; | ||
beforeAll(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
imports: [ | ||
ConfigModule.forRoot(configServiceModuleOptions), | ||
TypeOrmModule.forRootAsync(typeOrmModuleOptions), | ||
CustomTypeOrmModule.forCustomRepository([AchievementRepository]), | ||
UsersTestModule, | ||
CategoryTestModule, | ||
AchievementTestModule, | ||
], | ||
providers: [AchievementService], | ||
}).compile(); | ||
|
||
achievementService = module.get<AchievementService>(AchievementService); | ||
usersFixture = module.get<UsersFixture>(UsersFixture); | ||
categoryFixture = module.get<CategoryFixture>(CategoryFixture); | ||
achievementFixture = module.get<AchievementFixture>(AchievementFixture); | ||
}); | ||
|
||
test('개인 달성 기록 리스트에 대한 페이지네이션 조회를 할 수 있다.', async () => { | ||
// given | ||
const user = await usersFixture.getUser('ABC'); | ||
const category = await categoryFixture.getCategory(user, 'ABC'); | ||
const achievements = []; | ||
for (let i = 0; i < 10; i++) { | ||
achievements.push( | ||
await achievementFixture.getAchievement(user, category), | ||
); | ||
} | ||
|
||
// when | ||
const firstRequest = new PaginateAchievementRequest(category.id, 4); | ||
const firstResponse = await achievementService.getAchievements( | ||
user.id, | ||
firstRequest, | ||
); | ||
|
||
const nextRequest = new PaginateAchievementRequest( | ||
category.id, | ||
4, | ||
firstResponse.next.whereIdLessThan, | ||
); | ||
const nextResponse = await achievementService.getAchievements( | ||
user.id, | ||
nextRequest, | ||
); | ||
|
||
const lastRequest = new PaginateAchievementRequest( | ||
category.id, | ||
4, | ||
nextResponse.next.whereIdLessThan, | ||
); | ||
const lastResponse = await achievementService.getAchievements( | ||
user.id, | ||
lastRequest, | ||
); | ||
|
||
expect(firstResponse.count).toEqual(4); | ||
expect(firstResponse.data.length).toEqual(4); | ||
expect(firstResponse.next.whereIdLessThan).toEqual(7); | ||
|
||
expect(nextResponse.count).toEqual(4); | ||
expect(nextResponse.data.length).toEqual(4); | ||
expect(nextResponse.next.whereIdLessThan).toEqual(3); | ||
|
||
expect(lastResponse.count).toEqual(2); | ||
expect(lastResponse.data.length).toEqual(2); | ||
expect(lastResponse.next).toEqual(null); | ||
}); | ||
|
||
test('달성 기록 상세정보를 조회를 할 수 있다.', async () => { | ||
// given | ||
const user = await usersFixture.getUser('ABC'); | ||
const category = await categoryFixture.getCategory(user, 'ABC'); | ||
const achievements = []; | ||
for (let i = 0; i < 10; i++) { | ||
achievements.push( | ||
await achievementFixture.getAchievement(user, category), | ||
); | ||
} | ||
// when | ||
const detail = await achievementService.getAchievementDetail( | ||
user.id, | ||
achievements[7].id, | ||
); | ||
|
||
expect(detail.id).toBeDefined(); | ||
expect(detail.title).toBeDefined(); | ||
expect(detail.content).toBeDefined(); | ||
expect(detail.imageUrl).toBeDefined(); | ||
expect(detail.category.id).toEqual(category.id); | ||
expect(detail.category.name).toEqual(category.name); | ||
expect(detail.category.achieveCount).toEqual(8); | ||
}); | ||
|
||
test('자신이 소유하지 않은 달성 기록 정보를 조회하면 NoSuchAchievementException을 던진다.', async () => { | ||
// given | ||
const user = await usersFixture.getUser('ABC'); | ||
const category = await categoryFixture.getCategory(user, 'ABC'); | ||
const achievements = []; | ||
for (let i = 0; i < 10; i++) { | ||
achievements.push( | ||
await achievementFixture.getAchievement(user, category), | ||
); | ||
} | ||
// when | ||
// then | ||
await expect( | ||
achievementService.getAchievementDetail(user.id + 1, achievements[7].id), | ||
).rejects.toThrow(NoSuchAchievementException); | ||
}); | ||
|
||
test('유효하지 않은 달성 기록 id를 통해 조회하면 NoSuchAchievementException를 던진다.', async () => { | ||
// given | ||
const user = await usersFixture.getUser('ABC'); | ||
const category = await categoryFixture.getCategory(user, 'ABC'); | ||
const achievements = []; | ||
for (let i = 0; i < 10; i++) { | ||
achievements.push( | ||
await achievementFixture.getAchievement(user, category), | ||
); | ||
} | ||
// when | ||
// then | ||
await expect( | ||
achievementService.getAchievementDetail(user.id, achievements[9].id + 1), | ||
).rejects.toThrow(NoSuchAchievementException); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { AchievementRepository } from '../entities/achievement.repository'; | ||
import { AchievementResponse } from '../dto/achievement-response'; | ||
import { PaginateAchievementRequest } from '../dto/paginate-achievement-request'; | ||
import { PaginateAchievementResponse } from '../dto/paginate-achievement-response'; | ||
import { AchievementDetailResponse } from '../dto/achievement-detail-response'; | ||
import { Transactional } from '../../config/transaction-manager'; | ||
import { NoSuchAchievementException } from '../exception/no-such-achievement.exception'; | ||
|
||
@Injectable() | ||
export class AchievementService { | ||
constructor(private readonly achievementRepository: AchievementRepository) {} | ||
async getAchievements( | ||
userId: number, | ||
paginateAchievementRequest: PaginateAchievementRequest, | ||
) { | ||
const achievements = await this.achievementRepository.findAll( | ||
userId, | ||
paginateAchievementRequest, | ||
); | ||
return new PaginateAchievementResponse( | ||
paginateAchievementRequest, | ||
achievements.map((achievement) => AchievementResponse.from(achievement)), | ||
); | ||
} | ||
|
||
@Transactional({ readonly: true }) | ||
async getAchievementDetail(userId: number, achievementId: number) { | ||
const achievement: AchievementDetailResponse = | ||
await this.achievementRepository.findAchievementDetail( | ||
userId, | ||
achievementId, | ||
); | ||
if (!achievement) { | ||
throw new NoSuchAchievementException(); | ||
} | ||
return achievement; | ||
} | ||
} |
Oops, something went wrong.