Skip to content

Commit

Permalink
⭐ Wrap response APIs' response
Browse files Browse the repository at this point in the history
  • Loading branch information
w8385 committed Jul 13, 2023
1 parent 8963085 commit 9de7921
Show file tree
Hide file tree
Showing 7 changed files with 349 additions and 322 deletions.
66 changes: 12 additions & 54 deletions src/response/dto/check-response.dto.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ApiProperty } from '@nestjs/swagger';
import { ResponseDto } from '../../responseDto';

export class Success_CheckDto extends ResponseDto {
export class Success_CheckResponseDto extends ResponseDto {
@ApiProperty({
default: 'Get selected successfully.',
default: '학생이 선생님을 선택했습니다. 과외를 시작하세요.',
})
message: string;

Expand All @@ -19,66 +19,20 @@ export class Success_CheckDto extends ResponseDto {

@ApiProperty({
default: {
id: 'test-request-id',
student_id: 'test-student-id',
status: 'selected',
tutoring_id: 'test-tutoring-id',
tutoringId: 'test-tutoring-id',
},
})
data: object;
}

export class Not_checkDto extends ResponseDto {
@ApiProperty({
default: 'Get selected successfully.',
})
message: string;

@ApiProperty({
default: false,
})
error: boolean;

@ApiProperty({
default: 200,
})
statusCode: number;

@ApiProperty({
default: {
status: 'not selected',
},
})
data: object;
}

export class Yet_checkDto extends ResponseDto {
@ApiProperty({
default: 'Get selected successfully.',
})
message: string;

@ApiProperty({
default: false,
})
error: boolean;

@ApiProperty({
default: 200,
})
statusCode: number;

@ApiProperty({
default: {
status: 'pending',
},
})
data: object;
constructor(message: string, data: object) {
super(200, message, false, data);
}
}

export class NotFound_checkDto extends ResponseDto {
export class NotFound_CheckResponseDto extends ResponseDto {
@ApiProperty({
default: 'Request not found.',
default: '리소스를 찾을 수 없습니다.',
})
message: string;

Expand All @@ -91,4 +45,8 @@ export class NotFound_checkDto extends ResponseDto {
default: 404,
})
statusCode: number;

constructor(message: string) {
super(404, message, true);
}
}
117 changes: 22 additions & 95 deletions src/response/dto/create-response.dto.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
import { ApiProperty } from '@nestjs/swagger';
import { ResponseDto } from '../../responseDto';

export class SelectResponseDto {
@ApiProperty({
description: '요청의 id',
default: 'test-request-id',
})
requestId: string;

@ApiProperty({
description: '학생의 id',
default: 'test-student-id',
})
studentId: string;

@ApiProperty({
description: '선생님의 id',
default: 'test-teacher-id',
})
teacherId: string;
}

export class NotModified_SelectResponseDto extends ResponseDto {
export class NotFound_SelectResponseDto extends ResponseDto {
@ApiProperty({
default: 'Already selected.',
default: '리소스를 찾을 수 없습니다.',
})
message: string;

Expand All @@ -33,19 +13,18 @@ export class NotModified_SelectResponseDto extends ResponseDto {
error: boolean;

@ApiProperty({
default: 304,
default: 404,
})
statusCode: number;

@ApiProperty({
default: null,
})
data: object;
constructor(message: string) {
super(404, message, true);
}
}

export class Success_SelectResponseDto extends ResponseDto {
export class Created_CreateResponseDto extends ResponseDto {
@ApiProperty({
default: 'Select response successfully.',
default: '응답을 성공적으로 추가했습니다.',
})
message: string;

Expand All @@ -59,40 +38,14 @@ export class Success_SelectResponseDto extends ResponseDto {
})
statusCode: number;

@ApiProperty({
default: {
requestId: 'test-request-id',
tutoringId: 'test-tutoring-id',
},
})
data: SelectResponseDto;
constructor() {
super(200, '응답을 성공적으로 추가했습니다.', false);
}
}

export class BadRequest_SelectResponseDto extends ResponseDto {
@ApiProperty({
default: 'Request not found.',
})
message: string;

@ApiProperty({
default: true,
})
error: boolean;

@ApiProperty({
default: 400,
})
statusCode: number;

@ApiProperty({
default: null,
})
data: object;
}

export class NotFound_SelectResponseDto extends ResponseDto {
export class NotFound_CreateResponseDto extends ResponseDto {
@ApiProperty({
default: 'Teacher not found.',
default: '리소스를 찾을 수 없습니다.',
})
message: string;

Expand All @@ -106,39 +59,14 @@ export class NotFound_SelectResponseDto extends ResponseDto {
})
statusCode: number;

@ApiProperty({
default: null,
})
data: object;
}

export class Created_CreateResponseDto extends ResponseDto {
@ApiProperty({
default: 'Append response successfully.',
})
message: string;

@ApiProperty({
default: false,
})
error: boolean;

@ApiProperty({
default: 200,
})
statusCode: number;

@ApiProperty({
default: {
id: 'test-request-id',
},
})
data: object;
constructor(message: string) {
super(404, message, true);
}
}

export class NotFound_CreateResponseDto extends ResponseDto {
export class Conflict_CreateResponseDto extends ResponseDto {
@ApiProperty({
default: 'Request not found.',
default: '이미 답변이 존재합니다.',
})
message: string;

Expand All @@ -148,12 +76,11 @@ export class NotFound_CreateResponseDto extends ResponseDto {
error: boolean;

@ApiProperty({
default: 404,
default: 409,
})
statusCode: number;

@ApiProperty({
default: null,
})
data: object;
constructor(message: string) {
super(409, message, true);
}
}
20 changes: 8 additions & 12 deletions src/response/dto/delete-response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ResponseDto } from '../../responseDto';

export class Success_DeleteResponseDto extends ResponseDto {
@ApiProperty({
default: 'Append response successfully.',
default: '응답을 성공적으로 삭제했습니다.',
})
message: string;

Expand All @@ -17,17 +17,14 @@ export class Success_DeleteResponseDto extends ResponseDto {
})
statusCode: number;

@ApiProperty({
default: {
id: 'test-request-id',
},
})
data: object;
constructor() {
super(200, '응답을 성공적으로 삭제했습니다.', false);
}
}

export class NotFound_DeleteResponseDto extends ResponseDto {
@ApiProperty({
default: 'Request not found.',
default: '리소스를 찾을 수 없습니다.',
})
message: string;

Expand All @@ -41,8 +38,7 @@ export class NotFound_DeleteResponseDto extends ResponseDto {
})
statusCode: number;

@ApiProperty({
default: null,
})
data: object;
constructor(message: string) {
super(404, message, true);
}
}
12 changes: 10 additions & 2 deletions src/response/dto/get-response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ResponseDto } from '../../responseDto';

export class Success_GetTeachersDTO extends ResponseDto {
@ApiProperty({
default: 'Get teachers successfully.',
default: '응답한 선생님 목록을 성공적으로 가져왔습니다.',
})
message: string;

Expand All @@ -31,11 +31,15 @@ export class Success_GetTeachersDTO extends ResponseDto {
],
})
data: User[];

constructor(data: User[]) {
super(200, '응답한 선생님 목록을 성공적으로 가져왔습니다.', false, data);
}
}

export class NotFound_GetTeachersDTO extends ResponseDto {
@ApiProperty({
default: 'Request not found.',
default: '과외 요청을 찾을 수 없습니다.',
})
message: string;

Expand All @@ -48,4 +52,8 @@ export class NotFound_GetTeachersDTO extends ResponseDto {
default: 404,
})
statusCode: number;

constructor() {
super(404, '과외 요청을 찾을 수 없습니다.', true);
}
}
Loading

0 comments on commit 9de7921

Please sign in to comment.