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

πŸ” HTTP Response DTO μ •μ˜ #23

Merged
merged 8 commits into from
Jul 13, 2023
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
125 changes: 125 additions & 0 deletions src/HttpResponseDto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import { ApiProperty } from '@nestjs/swagger';

export class HttpResponseDto {
statusCode?: number;
message: string;
error: boolean;
data?: object;

constructor(
statusCode: number,
message: string,
error: boolean,
data?: object,
) {
this.statusCode = statusCode;
this.message = message;
this.error = error;
this.data = data;
}
}

export class BadRequestDto extends HttpResponseDto {
@ApiProperty({
example: 400,
})
statusCode: number;

@ApiProperty({
example: 'Bad Request',
})
message: string;

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

constructor(message: string) {
super(400, message, true);
}
}

export class UnauthorizedDto extends HttpResponseDto {
@ApiProperty({
example: 401,
})
statusCode: number;

@ApiProperty({
example: 'Unauthorized',
})
message: string;

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

constructor(message: string) {
super(401, message, true);
}
}

export class ForbiddenDto extends HttpResponseDto {
@ApiProperty({
example: 403,
})
statusCode: number;

@ApiProperty({
example: 'Forbidden',
})
message: string;

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

constructor(message: string) {
super(403, message, true);
}
}

export class NotFoundDto extends HttpResponseDto {
@ApiProperty({
example: 404,
})
statusCode: number;

@ApiProperty({
example: 'Not Found',
})
message: string;

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

constructor(message: string) {
super(404, message, true);
}
}

export class ConflictDto extends HttpResponseDto {
@ApiProperty({
example: 409,
})
statusCode: number;

@ApiProperty({
example: 'Conflict',
})
message: string;

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

constructor(message: string) {
super(409, message, true);
}
}
53 changes: 0 additions & 53 deletions src/request/dto/create-request.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ApiProperty } from '@nestjs/swagger';
import { ResponseDto } from '../../responseDto';

export class CreateRequestDto {
@ApiProperty({
Expand Down Expand Up @@ -45,55 +44,3 @@ export class CreateRequestDto {
})
problem_difficulty;
}

export class Created_CreateRequestDto extends ResponseDto {
@ApiProperty({
default: 200,
})
statusCode: number;

@ApiProperty({
default: 'κ³Όμ™Έ μš”μ²­μ΄ μ„±κ³΅μ μœΌλ‘œ μƒμ„±λ˜μ—ˆμŠ΅λ‹ˆλ‹€.',
})
message: string;

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

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

constructor() {
super(200, 'κ³Όμ™Έ μš”μ²­μ΄ μ„±κ³΅μ μœΌλ‘œ μƒμ„±λ˜μ—ˆμŠ΅λ‹ˆλ‹€.', false);
}
}

export class Unauthorized_CreateRequestDto extends ResponseDto {
@ApiProperty({
default: 401,
})
statusCode: number;

@ApiProperty({
default: 'κ³Όμ™Έλ₯Ό μš”μ²­ν•  수 μžˆλŠ” κΆŒν•œμ΄ μ—†μŠ΅λ‹ˆλ‹€.',
})
message: string;

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

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

constructor() {
super(401, 'κ³Όμ™Έλ₯Ό μš”μ²­ν•  수 μžˆλŠ” κΆŒν•œμ΄ μ—†μŠ΅λ‹ˆλ‹€.', true);
}
}
54 changes: 0 additions & 54 deletions src/request/dto/delete-request.dto.ts

This file was deleted.

44 changes: 0 additions & 44 deletions src/request/dto/get-request.dto.ts

This file was deleted.

88 changes: 88 additions & 0 deletions src/request/dto/response-request.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { HttpResponseDto } from '../../HttpResponseDto';
import { ApiProperty } from '@nestjs/swagger';
import { RequestSchema } from '../entities/request.schema';

export class Created_CreateRequestDto extends HttpResponseDto {
@ApiProperty({
default: 200,
})
statusCode: number;

@ApiProperty({
default: 'κ³Όμ™Έ μš”μ²­μ΄ μ„±κ³΅μ μœΌλ‘œ μƒμ„±λ˜μ—ˆμŠ΅λ‹ˆλ‹€.',
})
message: string;

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

constructor() {
super(200, 'κ³Όμ™Έ μš”μ²­μ΄ μ„±κ³΅μ μœΌλ‘œ μƒμ„±λ˜μ—ˆμŠ΅λ‹ˆλ‹€.', false);
}
}

export class Success_GetRequestsDto extends HttpResponseDto {
@ApiProperty({
default: 200,
})
statusCode: number;

@ApiProperty({
default: 'κ³Όμ™Έ μš”μ²­ λͺ©λ‘μ„ μ„±κ³΅μ μœΌλ‘œ κ°€μ Έμ™”μŠ΅λ‹ˆλ‹€.',
})
@ApiProperty({
default: false,
})
error: boolean;

@ApiProperty({
type: RequestSchema,
default: {
requests: [
{
id: 'test-request-id',
studentId: 'test-student-id',
problem: {
description: 'test-description',
base64Image: 'test-base64-image',
schoolLevel: 'test-school-level',
schoolSubject: 'test-school-subject',
schoolChapter: 'test-school-chapter',
difficulty: 'test-difficulty',
},
status: 'pending',
tutoringId: null,
createdAt: '2021-01-01T00:00:00.000Z',
},
],
},
})
data: typeof RequestSchema;

constructor(data: object[]) {
super(200, 'κ³Όμ™Έ μš”μ²­ λͺ©λ‘μ„ μ„±κ³΅μ μœΌλ‘œ κ°€μ Έμ™”μŠ΅λ‹ˆλ‹€.', false, data);
}
}

export class Success_DeleteRequestDto extends HttpResponseDto {
@ApiProperty({
default: 200,
})
statusCode: number;

@ApiProperty({
default: 'κ³Όμ™Έ μš”μ²­μ΄ μ„±κ³΅μ μœΌλ‘œ μ‚­μ œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.',
})
message: string;

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

constructor() {
super(200, 'κ³Όμ™Έ μš”μ²­μ΄ μ„±κ³΅μ μœΌλ‘œ μ‚­μ œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.', false);
}
}
Loading