Skip to content

Commit

Permalink
Merge pull request #138 from gsainfoteam/revert-137-revert-136-122-ksh
Browse files Browse the repository at this point in the history
Revert "Revert "get Grouplist by name query  from groups""
  • Loading branch information
kshmaker authored Nov 24, 2024
2 parents 3c4dcbb + 46e9a98 commit 4b01fd5
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 1 deletion.
36 changes: 36 additions & 0 deletions src/group/dto/req/getGroup.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Type } from 'class-transformer';
import { IsOptional, MaxLength, MinLength } from 'class-validator';
import { IsNumber, IsString } from 'class-validator';

export class GetGroupByNameQueryDto {
@ApiPropertyOptional({
example: '0',
description: '넘길 그룹 개수',
required: false,
})
@Type(() => Number)
@IsNumber()
@IsOptional()
offset?: number;

@ApiPropertyOptional({
example: '10',
description: '페이지당 그룹 개수',
required: false,
})
@Type(() => Number)
@IsNumber()
@IsOptional()
limit?: number;

@ApiProperty({
example: '인포',
description: '검색할 그룹 이름(일부)',
required: true,
})
@MaxLength(20)
@MinLength(1)
@IsString()
query: string;
}
41 changes: 41 additions & 0 deletions src/group/dto/res/groupsRes.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { ApiProperty } from '@nestjs/swagger';

export class GroupResDto {
@ApiProperty()
uuid: string;

@ApiProperty()
name: string;

@ApiProperty()
description: string | null;

@ApiProperty()
createdAt: Date;

@ApiProperty()
presidentUuid: string;

@ApiProperty()
verifiedAt: Date | null;

@ApiProperty()
notionPageId: string | null;

@ApiProperty()
profileImageKey: string | null;

@ApiProperty()
profileImageUrl: string | null;

@ApiProperty()
verified: boolean;

@ApiProperty()
deletedAt: Date | null;
}

export class GroupListResDto {
@ApiProperty({ type: [GroupResDto] })
list: GroupResDto[];
}
22 changes: 21 additions & 1 deletion src/group/group.controller.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import { Controller, Post, UseGuards } from '@nestjs/common';
import { Controller, Get, Post, Query, UseGuards } from '@nestjs/common';
import { GroupService } from './group.service';
import { IdPGuard } from 'src/user/guard/idp.guard';
import {
ApiCreatedResponse,
ApiInternalServerErrorResponse,
ApiOAuth2,
ApiOkResponse,
ApiOperation,
ApiTags,
ApiUnauthorizedResponse,
} from '@nestjs/swagger';
import { GetToken } from 'src/user/decorator/get-token.decorator';
import { GroupsTokenRes } from './dto/res/GroupsTokenRes.dto';
import { GroupListResDto } from './dto/res/GroupsRes.dto';
import { GetGroupByNameQueryDto } from './dto/req/getGroup.dto';

@ApiTags('Group')
@ApiOAuth2(['email', 'profile', 'openid'], 'oauth2')
Expand All @@ -33,4 +36,21 @@ export class GroupController {
async getGroupsToken(@GetToken() token: string): Promise<GroupsTokenRes> {
return this.groupService.getExternalTokenFromGroups(token);
}

@ApiOperation({
summary: 'Searching group list',
description: 'Searching group list by nmae query',
})
@ApiOkResponse({
type: GroupListResDto,
description: '검색된 그룹 목록',
})
@ApiUnauthorizedResponse()
@ApiInternalServerErrorResponse()
@Get('search')
async getGroupListByNamequeryFromGroups(
@Query() groupNameQuery: GetGroupByNameQueryDto,
): Promise<GroupListResDto> {
return this.groupService.getGroupListByNamequeryFromGroups(groupNameQuery);
}
}
32 changes: 32 additions & 0 deletions src/group/group.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { GroupsToken } from './types/groupsToken.type';
import { Loggable } from '@lib/logger/decorator/loggable';
import { GroupInfo } from './types/groupInfo.type';
import { CustomConfigService } from '@lib/custom-config';
import { GetGroupByNameQueryDto } from './dto/req/getGroup.dto';
import { GroupListResDto } from './dto/res/GroupsRes.dto';

@Injectable()
@Loggable()
Expand Down Expand Up @@ -89,4 +91,34 @@ export class GroupService {

return groupResponse.data.list;
}

async getGroupListByNamequeryFromGroups(
groupNameQuery: GetGroupByNameQueryDto,
): Promise<GroupListResDto> {
const groupResponse = await firstValueFrom(
this.httpService.get<GroupListResDto>(this.groupsUrl + '/group/search', {
params: groupNameQuery,
auth: {
username: this.groupsClientId,
password: this.groupsClientSecret,
},
}),
).catch((error) => {
if (error instanceof AxiosError) {
if (error.response?.status === 401) {
this.logger.debug('Unauthorized');
throw new UnauthorizedException();
} else if (error.response?.status === 500) {
this.logger.error('Internal Server Error');
throw new InternalServerErrorException();
}
}
this.logger.error(error);
throw new InternalServerErrorException();
});

return {
list: groupResponse.data.list,
};
}
}

0 comments on commit 4b01fd5

Please sign in to comment.