Skip to content

Commit

Permalink
๐Ÿ”จ Response API exception (#22)
Browse files Browse the repository at this point in the history
* โญ๏ธ Add `DEV` /simulation/onlyTest

* ๐Ÿ”จ Fix response API exception
  • Loading branch information
w8385 authored Jul 13, 2023
1 parent 500c15e commit 3114f26
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/request/entities/request.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export const RequestSchema = new Schema({
status: {
type: String,
},
selectedTeacherId: {
type: String,
},
tutoringId: {
type: String,
},
Expand Down
3 changes: 2 additions & 1 deletion src/request/request.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export class RequestService {
status: 'pending',
studentId,
teacherIds: [],
createdAt: new Date().toISOString(),
problem: {
description: createRequestDto.problem_description,
schoolLevel: createRequestDto.problem_school_level,
Expand All @@ -46,6 +45,8 @@ export class RequestService {
schoolChapter: createRequestDto.problem_school_chapter,
difficulty: createRequestDto.problem_difficulty,
},
selectedTeacherId: '',
createdAt: new Date().toISOString(),
};
await this.requestModel.create(request);

Expand Down
4 changes: 2 additions & 2 deletions src/response/dto/select-response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ export class Conflict_SelectResponseDto extends ResponseDto {
})
statusCode: number;

constructor() {
super(304, '์ด๋ฏธ ์„ ์ƒ๋‹˜์„ ์„ ํƒํ–ˆ์Šต๋‹ˆ๋‹ค.', true);
constructor(message: string) {
super(304, message, true);
}
}

Expand Down
17 changes: 16 additions & 1 deletion src/response/response.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ export class ResponseService {
return new Conflict_CreateResponseDto('์ด๋ฏธ ์‘๋‹ตํ•œ ์„ ์ƒ๋‹˜์ž…๋‹ˆ๋‹ค.');
}

if (request.status !== 'pending') {
return new Conflict_CreateResponseDto('์ด๋ฏธ ๋งค์นญ๋œ ์š”์ฒญ์ž…๋‹ˆ๋‹ค.');
}

request.teacherIds.push(teacherId);
await this.requestModel.update(request);

Expand Down Expand Up @@ -101,7 +105,17 @@ export class ResponseService {
}

if (request.status === 'selected') {
return new Conflict_SelectResponseDto();
if (request.selectedTeacherId === selectResponseDto.teacherId) {
return new Conflict_SelectResponseDto('์ด๋ฏธ ์„ ํƒ๋œ ์„ ์ƒ๋‹˜์ž…๋‹ˆ๋‹ค.');
} else {
return new Conflict_SelectResponseDto(
'์ด๋ฏธ ๋‹ค๋ฅธ ์„ ์ƒ๋‹˜์„ ์„ ํƒํ–ˆ์Šต๋‹ˆ๋‹ค.',
);
}
}

if (!request.teacherIds.includes(selectResponseDto.teacherId)) {
return new NotFound_SelectResponseDto('์„ ์ƒ๋‹˜์„ ์ฐพ์„ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.');
}

const tutoringService = new TutoringService(
Expand All @@ -119,6 +133,7 @@ export class ResponseService {

request.status = 'selected';
request.selectedTeacherId = selectResponseDto.teacherId;
console.log(tutoringId, selectResponseDto.teacherId);
request.tutoringId = tutoringId;
await this.requestModel.update(request);

Expand Down
16 changes: 12 additions & 4 deletions src/simulation/simulation.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,24 @@ export class SimulationController {

@Get('createTest')
@ApiOperation({
summary: 'ํ…Œ์ŠคํŠธ ๋ฐ์ดํ„ฐ ์ƒ์„ฑ',
summary: '[DEV] ํ…Œ์ŠคํŠธ ๋ฐ์ดํ„ฐ ์ƒ์„ฑ',
description: '`DEV`\n\nํ…Œ์ŠคํŠธ ๋ฐ์ดํ„ฐ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.',
})
createTest() {
return this.testService.createTest();
}

@Get('onlyTest')
@ApiOperation({
summary: '[DEV] ์ดˆ๊ธฐํ™” ํ›„ ํ…Œ์ŠคํŠธ ๋ฐ์ดํ„ฐ ์ƒ์„ฑ',
})
onlyTest() {
return this.testService.onlyTest();
}

@Get('getAll')
@ApiOperation({
summary: '๋ชจ๋“  ๋ฐ์ดํ„ฐ ๋ฐ˜ํ™˜',
summary: '[DEV] ๋ชจ๋“  ๋ฐ์ดํ„ฐ ๋ฐ˜ํ™˜',
description: '`DEV`\n\n๋ชจ๋“  ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค.',
})
getAll() {
Expand All @@ -27,7 +35,7 @@ export class SimulationController {

@Delete('removeAll')
@ApiOperation({
summary: '๋ฐ์ดํ„ฐ ์ดˆ๊ธฐํ™”',
summary: '[DEV] ๋ฐ์ดํ„ฐ ์ดˆ๊ธฐํ™”',
description: '`DEV`\n\n๋ชจ๋“  ๋ฐ์ดํ„ฐ๋ฅผ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค.',
})
removeAll() {
Expand All @@ -36,7 +44,7 @@ export class SimulationController {

@Post('matching')
@ApiOperation({
summary: '๋งค์นญ ์‹œ๋ฎฌ๋ ˆ์ด์…˜',
summary: '[DEV] ๋งค์นญ ์‹œ๋ฎฌ๋ ˆ์ด์…˜',
description:
'ํ•™์ƒ๊ณผ ์„ ์ƒ๋‹˜์˜ ์ด๋ฆ„์„ ์ž…๋ ฅํ•˜๋ฉด ๋งค์นญ ๊ณผ์ •์„ ๋””์Šค์ฝ”๋“œ์—์„œ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.',
})
Expand Down
8 changes: 8 additions & 0 deletions src/simulation/simulation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,12 @@ export class SimulationService {
}
return this.getAll();
}

async onlyTest() {
await this.removeAll().then(async () => {
await this.createTest();
});

return await this.getAll();
}
}

0 comments on commit 3114f26

Please sign in to comment.