Skip to content

Commit

Permalink
#57 캠페인 리스트 조회 시 ResourceProvider 검색 옵션 추가 (#58)
Browse files Browse the repository at this point in the history
* feat: 캠페인 조회 시 ResourceProvider 옵션 추가

* test: 테스트 케이스 추가
  • Loading branch information
argon1025 authored Feb 20, 2024
1 parent c4f3245 commit e6fdec4
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 1 deletion.
54 changes: 54 additions & 0 deletions src/campaign/campaign.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,60 @@ describe('CampaignService', () => {
expect(result.list[0].category).toBe('category1');
});

it('특정 캠페인 정보 제공자를 검색 했을 경우', async () => {
// given
// 캠페인 데이터 등록
await prismaService.campaign.createMany({
data: [
{
id: 'campaign1',
duplicateId: 'duplicateId1',
resourceProvider: 'resourceProvider1',
originUrl: 'originUrl1',
title: 'title1',
category: 'category1',
targetPlatforms: 'targetPlatforms1',
thumbnail: 'thumbnail1',
address: 'address1',
recruitCount: 1,
applyCount: 1,
drawAt: null,
startedAt: null,
endedAt: null,
deletedAt: null,
updatedAt: new Date(),
createdAt: new Date(),
},
{
id: 'campaign2',
duplicateId: 'duplicateId2',
resourceProvider: 'resourceProvider12',
originUrl: 'originUrl1',
title: 'title1',
category: 'category1',
targetPlatforms: 'targetPlatforms1',
thumbnail: 'thumbnail1',
address: 'address1',
recruitCount: 1,
applyCount: 1,
drawAt: null,
startedAt: null,
endedAt: null,
deletedAt: null,
updatedAt: new Date(),
createdAt: new Date(),
},
],
});

// when
const result = await campaignService.findMany({ resourceProvider: 'resourceProvider1', size: 10, page: 1 });

// then
expect(result.total).toBe(1);
expect(result.list[0].resourceProvider).toBe('resourceProvider1');
});

it('신청 진행중인 캠페인을 검색했을 경우', async () => {
// given
jest.useFakeTimers({ advanceTimers: true });
Expand Down
3 changes: 2 additions & 1 deletion src/campaign/campaign.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class CampaignService implements ICampaignService.Base {
* 전체 캠페인 목록을 조회합니다.
*/
async findMany(options: ICampaignService.FindManyOptions): Promise<ICampaignService.FindManyResult> {
const { title, address, category, hasAvailable, size, page } = options;
const { title, address, category, hasAvailable, resourceProvider, size, page } = options;
const whereQuery = {
title: {
contains: title,
Expand All @@ -30,6 +30,7 @@ export class CampaignService implements ICampaignService.Base {
category: {
contains: category,
},
...(resourceProvider && { resourceProvider }),
...(hasAvailable && {
startedAt: {
lte: DateTime.utc().toJSDate(),
Expand Down
6 changes: 6 additions & 0 deletions src/campaign/dto/get-campaign-list.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ export class GetCampaignListRequest {
@ApiProperty({ description: '도시 검색', example: '서울' })
address?: string;

@IsEnum(ICampaignService.ResourceProvider)
@IsNotEmpty()
@IsOptional()
@ApiProperty({ description: '리소스 제공자', example: 'DINNER_QUEEN', enum: ICampaignService.ResourceProvider })
resourceProvider?: ICampaignService.ResourceProvider;

@IsString()
@IsNotEmpty()
@IsOptional()
Expand Down
10 changes: 10 additions & 0 deletions src/campaign/type/campaign.service.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export namespace ICampaignService {
export interface FindManyOptions {
/** 캠페인 제목 */
title?: string;
/** 캠페인 정보 제공자 */
resourceProvider?: string;
/** 주소 */
address?: string;
/** 카테고리 */
Expand Down Expand Up @@ -109,4 +111,12 @@ export namespace ICampaignService {
/** 캠페인 아이디 */
id: string;
}

/**
* 리소스 제공자
*/
export enum ResourceProvider {
/** 디너의 여왕 */
DINNER_QUEEN = 'DINNER_QUEEN',
}
}

0 comments on commit e6fdec4

Please sign in to comment.