Skip to content

feat(be): implement polygon tool upload#3527

Open
zero1177 wants to merge 5 commits intomainfrom
t2630-implement-file-upload
Open

feat(be): implement polygon tool upload#3527
zero1177 wants to merge 5 commits intomainfrom
t2630-implement-file-upload

Conversation

@zero1177
Copy link
Copy Markdown
Contributor

@zero1177 zero1177 commented Apr 3, 2026

Description

조만간 정리할게요!!!! 일단 지금까지 작업내용 요약해달라 했음 클로드한테

개요
Polygon Tool(Generator/Validator/Checker)의 파일 업로드 및 Iris 서버와의 RabbitMQ 통신 레이어를 구현했습니다.

변경 사항
libs/constants/src/rabbitmq.constants.ts

Polygon 관련 RabbitMQ 상수 추가
Exchange: POLYGON_EXCHANGE
Generator/Validator routing key, message type, result queue 상수
libs/amqp/src/interface/polygonToolRequest.interface.ts (신규)

Iris로 전송하는 메시지 body 타입 정의
GeneratorRequest: problemId, generatorLanguage, generatorCode, generatorArgs, solutionLanguage, solutionCode, testCaseCount
ValidatorRequest: problemId, language, validatorCode
libs/amqp/src/amqp.service.ts

PolygonAMQPService 클래스 추가
startGeneratorSubscription() / startValidatorSubscription(): 결과 메시지 구독
publishGeneratorMessage() / publishValidatorMessage(): 실행 요청 publish (validator는 priority 2 적용)
setMessageHandlers(): 결과 수신 콜백 등록
apps/admin/src/polygon/file/file.service.ts

uploadPolygonToolFile(): 파일 스트림을 읽어 DB에 upsert (10MB 제한)
deletePolygonFile(): DB에서 파일 삭제
apps/admin/src/polygon/polygon-pub.service.ts (신규)

DB에서 PolygonTool/PolygonSolution 조회 후 RabbitMQ 메시지 조립·발행
publishGeneratorMessage(problemId, generatorArgs, testCaseCount)
publishValidatorMessage(problemId)
apps/admin/src/polygon/polygon-sub.service.ts (신규)

OnModuleInit에서 구독 시작 및 핸들러 등록
onGenerateResult / onValidateResult 비즈니스 로직은 Iris 팀의 결과 메시지 스펙 확정 후 작성 예정
apps/admin/src/polygon/polygon.service.ts

uploadPolygonTool(): FileService에 위임하여 DB 저장
runGenerator() / runValidator(): PolygonPublicationService에 위임하여 실행 요청 publish
업로드와 실행을 별도 Mutation으로 분리
미완료 / 확인 필요 사항
polygon.module.ts에 PolygonPublicationService, PolygonSubscriptionService 등록 필요
PolygonSolution이 S3 filePath 기반으로 설계되어 있어 fileContent 조회 방식 확정 필요
Iris 팀과 결과 메시지 구조(routing key, queue 이름, 결과 필드) 확인 필요
Generator의 priority 값 결정 필요 (현재 미설정, Validator는 2 적용)
Language 필드 형식 Iris 스펙과 통일 필요

  1. 스키마 변경
    filePath -> fileContent (필드명 변경)

  2. amqp.service.ts에 PolygonAMQPService 추가 -> polygon tool을 업로드 했다는 메시지를 iris로 발행
    -> 여기 문제가 좀 있어서 아직 커밋을 못했습니다

  3. rabbitmq.constants.ts에 상수 추가
    POLYGON_EXCHANGE = 'iris.e.direct.polygon'
    POLYGON_TOOL_KEY = 'polygon.tool'
    POLYGON_TOOL_MESSAGE_TYPE = 'polygonTool'

  4. admin/src/polygon/file/file.service.ts 에 polygon tool DB 저장 및 삭제 로직 작성
    DB 저장 과정: 소스코드(.cpp) -> createReadStream -> [chunk1, chunk2, chunk3, ...] → Buffer.concat.toString('utf-8') → DB(PostgreSQL)에 저장
    upsert 사용해서 최초 업로드, 파일 변경 한번에 되도록 작성

  5. admin/src/polygon/polygon.service.ts
    DB 저장 로직 + RabbitMQ 메세지 발행 로직 같이 실행

  6. admin/src/polygon/polygon.resolver.ts 작성

@zero1177 zero1177 self-assigned this Apr 3, 2026
@zero1177 zero1177 added ⛳️ team-backend 🍊squad-유자차 스쿼드 유자차 작업물입니다 labels Apr 3, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces functionality for managing Polygon tool files, including uploading and deleting tools with content stored directly in the database and notifying other services via RabbitMQ. Key feedback includes addressing a missing class definition for PolygonAMQPService that prevents compilation, implementing file type validation to avoid data corruption when converting uploads to UTF-8 strings, and adding error handling for the deletion of non-existent records to prevent runtime exceptions.

Comment thread apps/backend/libs/amqp/src/amqp.module.ts
}
chunks.push(chunk)
}
const fileContent = Buffer.concat(chunks).toString('utf-8')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

파일 내용을 utf-8 문자열로 변환하여 DB에 저장하고 있습니다. PR 설명에 따르면 .cpp 소스코드를 상정하고 있으나, 사용자가 바이너리 파일 등 의도하지 않은 형식의 파일을 업로드할 경우 데이터가 손상될 수 있습니다. 업로드된 파일의 mimetype이나 확장자를 검증하는 로직을 추가하여 의도한 형식의 파일만 처리하도록 하는 것이 안전합니다.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확장자 검증 추가하겠습니다..!

}

async deletePolygonFile(problemId: number, toolType: ToolType) {
return await this.prisma.polygonTool.delete({
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

prisma.polygonTool.delete는 삭제하려는 레코드가 존재하지 않을 경우 에러를 발생시킵니다. 해당 도구가 이미 삭제되었거나 존재하지 않는 경우를 대비하여 예외 처리를 추가하거나, 존재 여부를 먼저 확인하는 것이 좋습니다. 단순히 삭제 여부만 중요하다면 deleteMany를 사용하는 것도 방법이지만, 현재 리턴 타입이 PolygonTool이므로 에러 발생 시 적절한 GraphQL 에러(예: NotFoundException)를 던지도록 처리하는 것이 더 명확합니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🍊squad-유자차 스쿼드 유자차 작업물입니다 ⛳️ team-backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant