Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Project 조회 Axios Error 임시방편 #134

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
// }
}
Loading