Skip to content

Commit

Permalink
Merge pull request #24 from J-Hoplin/docs/worker-docs
Browse files Browse the repository at this point in the history
Feat: Add dto to worker service
  • Loading branch information
J-Hoplin authored Jan 16, 2024
2 parents d3efdca + e617c05 commit 3790b78
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
1 change: 1 addition & 0 deletions libs/aws-sqs/src/dto/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './worker-dto';
14 changes: 14 additions & 0 deletions libs/aws-sqs/src/dto/worker-dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, IsString } from 'class-validator';
import { SQSMessageType, SQSTask } from '../type';

export class WorkerDto implements SQSTask {
@ApiProperty()
@IsString()
@IsNotEmpty()
message: SQSMessageType;

@ApiProperty()
@IsNotEmpty()
id: string | number;
}
7 changes: 6 additions & 1 deletion libs/aws-sqs/src/type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export type SQSMessageType = 'RE_CORRECTION' | 'CODE_SUBMIT';
export enum SQSMessageTypeEnum {
RE_CORRECTION,
CODE_SUBMIT,
}

export type SQSMessageType = keyof typeof SQSMessageTypeEnum;

export type SQSTask = {
message: SQSMessageType;
Expand Down
4 changes: 2 additions & 2 deletions src/worker/worker.controller.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Body, Controller, HttpCode, Post } from '@nestjs/common';
import { WorkerDto } from 'aws-sqs/aws-sqs/dto';
import { WorkerService } from './worker.service';
import { SQSTask } from 'aws-sqs/aws-sqs/type';

@Controller('worker')
export class WorkerController {
constructor(private workerService: WorkerService) {}

@HttpCode(200)
@Post()
workerController(@Body() dto: SQSTask) {
workerController(@Body() dto: WorkerDto) {
return this.workerService.worker(dto);
}
}
15 changes: 15 additions & 0 deletions src/worker/worker.docs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { applyDecorators } from '@nestjs/common';
import { ApiOkResponse, ApiOperation } from '@nestjs/swagger';

export class WorkerDocs {
public static WorkerController() {
return applyDecorators(
ApiOperation({
summary: 'AWS SQS worker Controller',
}),
ApiOkResponse({
description: 'If worker task success return 200',
}),
);
}
}
4 changes: 2 additions & 2 deletions src/worker/worker.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Injectable, Logger } from '@nestjs/common';
import { PrismaService } from 'app/prisma/prisma.service';
import { SQSTask } from 'aws-sqs/aws-sqs/type';
import { WorkerDto } from 'aws-sqs/aws-sqs/dto';
import { ProblemDomain, SubmissionDomain } from 'domains';
import { Judge0Service } from 'judge/judge0';

Expand All @@ -10,7 +10,7 @@ export class WorkerService {

constructor(private prisma: PrismaService, private judge0: Judge0Service) {}

async worker(dto: SQSTask) {
async worker(dto: WorkerDto) {
switch (dto.message) {
// Re-Correct if contributer modify example
case 'RE_CORRECTION':
Expand Down

0 comments on commit 3790b78

Please sign in to comment.