Skip to content

Commit

Permalink
feat: 전화번호 및 학번 검색어 유형 추가 (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
Coalery authored Jan 29, 2025
2 parents eee09df + 3941348 commit b8f1723
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/app/application/user/query/listUser/ListUserQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import { Typeof } from '@khlug/util/types';

export class ListUserQuery implements IQuery {
readonly email: string | null;
readonly phone: string | null;
readonly name: string | null;
readonly number: string | null;
readonly college: string | null;
readonly grade: number | null;
readonly state: UserState | null;
Expand All @@ -15,7 +17,9 @@ export class ListUserQuery implements IQuery {

constructor(params: Typeof<ListUserQuery>) {
this.email = params.email;
this.phone = params.phone;
this.name = params.name;
this.number = params.number;
this.college = params.college;
this.grade = params.grade;
this.state = params.state;
Expand Down
11 changes: 10 additions & 1 deletion src/app/application/user/query/listUser/ListUserQueryHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,27 @@ export class ListUserQueryHandler
) {}

async execute(query: ListUserQuery): Promise<ListUserQueryResult> {
const { email, name, college, grade, state, limit, offset } = query;
const { email, phone, name, number, college, grade, state, limit, offset } =
query;

const qb = this.userRepository.createQueryBuilder('user');

if (email) {
qb.andWhere('email LIKE ?', [`%${email}%`]);
}

if (phone) {
qb.andWhere('phone LIKE ?', [`%${phone}%`]);
}

if (name) {
qb.andWhere('realname LIKE ?', [`%${name}%`]);
}

if (number) {
qb.andWhere('number LIKE ?', [`%${number}%`]);
}

if (college) {
qb.andWhere('college LIKE ?', [`%${college}%`]);
}
Expand Down
1 change: 1 addition & 0 deletions src/app/domain/user/model/Profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class Profile {
@IsInt()
readonly grade: number;

// TODO: 현재는 숫자 컬럼인데 문자열 컬럼으로 수정해야 함
@Property({ type: 'int', name: 'number', nullable: true })
@IsInt()
@IsOptional()
Expand Down
4 changes: 3 additions & 1 deletion src/app/interface/user/manager/UserManageController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ export class UserManageController {
constructor(private readonly queryBus: QueryBus) {}

@Get('/manager/users')
// @Auth([UserRole.MANAGER])
@Auth([UserRole.MANAGER])
@ApiOperation({ summary: '회원 목록 조회' })
@ApiResponse({ status: HttpStatus.OK, type: ListUserResponseDto })
async listUser(
@Query() dto: ListUserRequestDto,
): Promise<ListUserResponseDto> {
const query = new ListUserQuery({
email: dto.email,
phone: dto.phone,
name: dto.name,
number: dto.number,
college: dto.college,
grade: dto.grade,
state: dto.state,
Expand Down
12 changes: 12 additions & 0 deletions src/app/interface/user/manager/dto/ListUserRequestDto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
IsOptional,
IsString,
Length,
Matches,
Max,
Min,
} from 'class-validator';
Expand All @@ -17,11 +18,22 @@ export class ListUserRequestDto {
@Length(1, 255)
email: string | null = null;

@IsOptional()
@IsString()
@Length(1, 20)
phone: string | null = null;

@IsOptional()
@IsString()
@Length(1, 255)
name: string | null = null;

@IsOptional()
@IsString()
@Length(1, 10)
@Matches(/^\d+$/)
number: string | null = null;

@IsOptional()
@IsString()
@Length(1, 255)
Expand Down

0 comments on commit b8f1723

Please sign in to comment.