Skip to content

Commit

Permalink
Merge pull request #134 from sopt-makers/develop
Browse files Browse the repository at this point in the history
Project 조회 Axios Error 임시방편
  • Loading branch information
Lim-Changi authored Jun 12, 2024
2 parents 183879e + 3bef97f commit 52a5e91
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ export class PlaygroundProjectResponseDto {
isFounding: boolean;
links: PlaygroundLink[];
}

export class PlaygroundProjectAxiosResponseDto {
projectList: PlaygroundProjectResponseDto[];
hasNext: boolean;
totalCount: number;
}
64 changes: 39 additions & 25 deletions src/internal/playground/playground.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -54,27 +57,41 @@ export class PlaygroundRepository {
validate: (value: any) => !(value instanceof Error),
})
async getAllProjects(): Promise<PlaygroundProjectResponseDto[]> {
return await lastValueFrom(
await this.httpService
.get<PlaygroundProjectResponseDto[]>(
`${this.API_URL}/internal/api/v1/projects`,
{
headers: {
Authorization: this.jwtToken,
// TODO. 이거 무조오오오오오오오오건 수정해야한다...!!!!!!!!!!!!!!!!!!
const limit = 20;
let cursor = 0;
let totalCount = 10;
const response: PlaygroundProjectResponseDto[] = [];
for (let i = 0; i < totalCount + 1; i = i + limit) {
const projectData = await lastValueFrom(
await this.httpService
.get<PlaygroundProjectAxiosResponseDto>(
`${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;
totalCount = projectData.totalCount;
response.push(...projectData.projectList);
const lastDataIdx = projectData.projectList.length - 1;
cursor = projectData.projectList[lastDataIdx].id;
if (!projectData.hasNext) break;
}
return response;
}

async getProjectDetail(
Expand All @@ -93,10 +110,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);
}),
),
);
Expand Down
13 changes: 7 additions & 6 deletions src/utils/compare.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
// }
}

0 comments on commit 52a5e91

Please sign in to comment.