Skip to content

Commit

Permalink
πŸ” Clarify Response dto (#23)
Browse files Browse the repository at this point in the history
* πŸ” Refactor responseDto.ts

* πŸ” Refactor `/request` dto

* πŸ” Refactor `/request` `/response` dto

* πŸ” Refactor response.http-response.dto.ts

* πŸ” Refactor `/user` dto

* πŸ“œ Remove /user/create description

* πŸ”¨ Remove /user/create header

* πŸ“œ Add HTTP Exception description
  • Loading branch information
w8385 authored Jul 13, 2023
1 parent 3114f26 commit 55be1f3
Show file tree
Hide file tree
Showing 24 changed files with 601 additions and 946 deletions.
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

0 comments on commit 55be1f3

Please sign in to comment.