From 1ae3b500e5633bb816d72c64bf590bcd39350018 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B0=AC=EA=B8=B0?= Date: Thu, 13 Jun 2024 08:30:47 +0900 Subject: [PATCH 1/2] =?UTF-8?q?hotfix:=20Project=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=9E=84=EC=8B=9C=EB=B0=A9=ED=8E=B8..=20=EC=88=98=EC=A0=95?= =?UTF-8?q?=ED=95=B4=EC=95=BC=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/playground-project-response.dto.ts | 6 ++ .../playground/playground.repository.ts | 63 +++++++++++-------- src/utils/compare.ts | 13 ++-- 3 files changed, 51 insertions(+), 31 deletions(-) diff --git a/src/internal/playground/dto/playground-project-response.dto.ts b/src/internal/playground/dto/playground-project-response.dto.ts index 7887bd3..ced5ad4 100644 --- a/src/internal/playground/dto/playground-project-response.dto.ts +++ b/src/internal/playground/dto/playground-project-response.dto.ts @@ -18,3 +18,9 @@ export class PlaygroundProjectResponseDto { isFounding: boolean; links: PlaygroundLink[]; } + +export class PlaygroundProjectAxiosResponseDto { + projectList: PlaygroundProjectResponseDto[]; + hasNext: boolean; + totalCount: number; +} diff --git a/src/internal/playground/playground.repository.ts b/src/internal/playground/playground.repository.ts index b7452d3..1ff1890 100644 --- a/src/internal/playground/playground.repository.ts +++ b/src/internal/playground/playground.repository.ts @@ -8,7 +8,10 @@ import { ConfigService } from '@nestjs/config'; import { catchError, lastValueFrom, map, of } from 'rxjs'; import { EnvConfig } from '../../configs/env.config'; import { GetPlaygroundUserInfoResponseDto } from './dto/get-playground-user-info-response.dto'; -import { PlaygroundProjectResponseDto } from './dto/playground-project-response.dto'; +import { + PlaygroundProjectAxiosResponseDto, + PlaygroundProjectResponseDto, +} from './dto/playground-project-response.dto'; import { PlaygroundProjectDetailResponseDto } from './dto/playground-project-detail-response.dto'; import { MemberListResponseDto } from 'src/members/dtos/member-response.dto'; import { MemberRequestDto } from 'src/members/dtos/member-request.dto'; @@ -54,27 +57,40 @@ export class PlaygroundRepository { validate: (value: any) => !(value instanceof Error), }) async getAllProjects(): Promise { - return await lastValueFrom( - await this.httpService - .get( - `${this.API_URL}/internal/api/v1/projects`, - { - headers: { - Authorization: this.jwtToken, + // TODO. 이거 무조오오오오오오오오건 수정해야한다...!!!!!!!!!!!!!!!!!! + const limit = 20; + let hasNext = true; + let cursor = 0; + const response: PlaygroundProjectResponseDto[] = []; + while (hasNext) { + const projectData = await lastValueFrom( + await this.httpService + .get( + `${this.API_URL}/api/v1/projects`, + { + headers: { + Authorization: this.jwtToken, + }, + params: { + limit, + cursor, + }, }, - }, - ) - .pipe( - map((res) => res.data), - catchError((error) => { - console.error('project api error', error); - throw new HttpException( - 'Projcet API ' + error.response.data.error, - error.response.data.status, - ); - }), - ), - ); + ) + .pipe( + map((res) => res.data), + catchError((error) => { + throw new InternalServerErrorException('Projcet API ' + error); + }), + ), + ); + if (projectData.projectList.length === 0) break; + response.push(...projectData.projectList); + hasNext = projectData.hasNext; + const lastDataIdx = projectData.projectList.length - 1; + cursor = projectData.projectList[lastDataIdx].id; + } + return response; } async getProjectDetail( @@ -93,10 +109,7 @@ export class PlaygroundRepository { .pipe( map((res) => res.data), catchError((error) => { - throw new HttpException( - 'API ' + error.response.data.error, - error.response.data.status, - ); + throw new InternalServerErrorException('API ' + error); }), ), ); diff --git a/src/utils/compare.ts b/src/utils/compare.ts index 3773d43..6912b0f 100644 --- a/src/utils/compare.ts +++ b/src/utils/compare.ts @@ -5,10 +5,11 @@ export function compareProjects( b: ProjectsResponseDto, ) { if (a.generation > b.generation) return -1; - else if (a.generation < b.generation) return 1; - else { - if (a.name > b.name) return 1; - else if (a.name < b.name) return -1; - else return 0; - } + else return 1; + // if (a.generation < b.generation) return 1; + // else { + // if (a.name > b.name) return 1; + // else if (a.name < b.name) return -1; + // else return 0; + // } } From 3bef97f2f7a1c6899819d764aed8ed496c74c84a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B0=AC=EA=B8=B0?= Date: Thu, 13 Jun 2024 08:37:44 +0900 Subject: [PATCH 2/2] =?UTF-8?q?hotfix:=20Project=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=9E=84=EC=8B=9C=EB=B0=A9=ED=8E=B8=20=EA=B0=9C=EC=84=A0..=20?= =?UTF-8?q?=EC=97=AD=EC=8B=9C=20=EC=88=98=EC=A0=95=20=ED=95=84=EC=9A=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/internal/playground/playground.repository.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/internal/playground/playground.repository.ts b/src/internal/playground/playground.repository.ts index 1ff1890..2f9a7f1 100644 --- a/src/internal/playground/playground.repository.ts +++ b/src/internal/playground/playground.repository.ts @@ -59,10 +59,10 @@ export class PlaygroundRepository { async getAllProjects(): Promise { // TODO. 이거 무조오오오오오오오오건 수정해야한다...!!!!!!!!!!!!!!!!!! const limit = 20; - let hasNext = true; let cursor = 0; + let totalCount = 10; const response: PlaygroundProjectResponseDto[] = []; - while (hasNext) { + for (let i = 0; i < totalCount + 1; i = i + limit) { const projectData = await lastValueFrom( await this.httpService .get( @@ -85,10 +85,11 @@ export class PlaygroundRepository { ), ); if (projectData.projectList.length === 0) break; + totalCount = projectData.totalCount; response.push(...projectData.projectList); - hasNext = projectData.hasNext; const lastDataIdx = projectData.projectList.length - 1; cursor = projectData.projectList[lastDataIdx].id; + if (!projectData.hasNext) break; } return response; }