Skip to content

Commit

Permalink
Adding new endpoint for the institution detail view (#313)
Browse files Browse the repository at this point in the history
Added new Endpoint for the repositories in the institution detail view as the repos were filtered with full text search instead of only filtering the institutions

see #311

Co-authored-by: Joel <[email protected]>
  • Loading branch information
roblesjoel and Joel authored Sep 25, 2023
1 parent 5948299 commit 64f1d57
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
19 changes: 19 additions & 0 deletions frontend/src/app/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,25 @@ export class DataService {
return repoData;
}

async loadRepoDataDetailView(config: {
search?: string;
sort?: string;
direction?: 'ASC' | 'DESC';
page?: string;
count?: string;
includeForks?: string;
}) {
const repoData = await this.http
.get<{
repositories: Repository[];
total: number;
}>(`${environment.api}institutionRepositories`, {
params: config,
})
.toPromise();
return repoData;
}

async loadUserData(config: {
search: string;
sort: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export class InstitutionDetailViewComponent implements OnInit {

reloadData() {
this.dataService
.loadRepoData({
.loadRepoDataDetailView({
sort: this.activeSort,
direction: this.sortDirection,
page: this.page.toString(),
Expand Down
18 changes: 16 additions & 2 deletions oss-api/src/api/api.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class ApiController {
@Query() queryDto: RepositoryQueryDto,
): Promise<RepositoryApiResponse> {
const queryConfig = queryDto;
return await this.handleRepositories(queryConfig);
return await this.handleRepositories(queryConfig, false);
}

@Get('paginatedUsers')
Expand All @@ -83,6 +83,15 @@ export class ApiController {
return await this.handleUsers(queryConfig);
}

@Get('institutionRepositories')
@UsePipes(new RepositoryQueryPipe(), new ValidationPipe({ transform: true }))
async findRepositoriesDetailView(
@Query() queryDto: RepositoryQueryDto,
): Promise<RepositoryApiResponse> {
const queryConfig = queryDto;
return await this.handleRepositories(queryConfig, true);
}

@Get('latestUpdate')
async findLatestUpdate() {
return (await this.mongoDbService.latestUpdate())[0];
Expand Down Expand Up @@ -139,17 +148,22 @@ export class ApiController {
*/
private async handleRepositories(
queryConfig: RepositoryQueryConfig,
detailedView: boolean,
): Promise<RepositoryApiResponse> {
const includeForks = queryConfig.includeForks ? [false, true] : [false];
let condition: Object[] = [
{
fork: { $in: includeForks },
},
];
if (queryConfig.search.length > 0) {
if (queryConfig.search.length > 0 && !detailedView) {
condition.push({
$text: { $search: queryConfig.search },
});
} else if (detailedView) {
condition.push({
institution: queryConfig.search,
});
}
let repositories = await this.mongoDbService.findRepositoryWithConditions(
queryConfig.sort,
Expand Down

0 comments on commit 64f1d57

Please sign in to comment.