Skip to content

Latest commit

 

History

History
324 lines (290 loc) · 5.85 KB

File metadata and controls

324 lines (290 loc) · 5.85 KB

Codemasters Project

Project Setup

Backend Setup

  1. Navigate to the backend directory:
    cd backend
  2. Install dependencies:
    npm install
  3. Create a .env file in the backend directory and add the following environment variables:
    REDIS_URL=redis://localhost:6379
    PORT=3000
    
    SUPABASE_URL=https://tdpgskzzgxitjofcunyh.supabase.co
    SUPABASE_KEY=
    
  4. Start the backend server:
    npm run dev

Redis Setup

  • Mac:
    redis-server
  • Windows:
    redis-server.exe

Frontend Setup

  1. Navigate to the frontend directory:
    cd frontend
  2. Install dependencies:
    npm install
  3. Start the frontend development server:
    npm run dev

PISTON API Calls

Get Available Runtimes

  • URL: GET https://emkc.org/api/v2/piston/runtimes

Execute Code

  • URL: POST https://emkc.org/api/v2/piston/execute
  • Example Request:
    {
      "language": "python",
      "version": "3.10.0",
      "files": [
        {
          "name": "dummy.py",
          "content": "a = 5\nb = 5\nprint(a + b)"
        }
      ]
    }

De-Queue Process

To start the de-queue process to dequeue from Redis and send responses to Piston. The response will be logged onto your console.

node sendPostRequestToPiston.js

API Endpoints

User Endpoints

  • Sign Up

    • URL: POST /user/signup
    • Body:
      {
        "username": "string",
        "email": "string",
        "password": "string"
      }
    • Response:
      {
        "message": "Account created successfully"
      }
  • Sign In

    • URL: POST /user/signin
    • Body:
      {
        "email": "string",
        "password": "string"
      }
    • Response:
      {
        "token": "string"
      }

Contest Endpoints

  • Get All Contest

    • URL: GET /contests/
    • Response:
      [
        {
          "id": "string",
          "name": "string",
          "desc": "string",
          "public": "bool",
          "start_time": "timestampz",
          "end_time": "timestampz"
        }
      ]
  • Get Question by ID

    • URL: GET /contests/:id
    • Response:
      {
          "id": "string",
          "name": "string",
          "desc": "string",
          "public": "bool",
          "start_time": "timestampz",
          "end_time": "timestampz"
      }
  • Add New Question

    • URL: POST /contests/
    • Body:
      {
          "name": "string",
          "desc": "string",
          "public": "bool",
          "start_time": "timestampz",
          "end_time": "timestampz"
      }
    • Response:
      {
      
      }

Question Endpoints

  • Get All Questions

    • URL: GET /question/
    • Response:
      [
        {
          "id": "string",
          "title": "string",
          "description": "string",
          "difficulty": "string",
          "category": "string",
          "timeLimit": "string",
          "acceptance": "string"
        }
      ]
  • Get Question by ID

    • URL: GET /question/:id
    • Response:
      {
        "id": "string",
        "title": "string",
        "description": "string",
        "difficulty": "string",
        "category": "string",
        "timeLimit": "string",
        "acceptance": "string",
        "example_input": "string",
        "expected_output": "string",
        "constraint_data": "string"
      }
  • Add New Question

    • URL: POST /question/
    • Body:
      {
        "title": "string",
        "description": "string",
        "difficulty": "string",
        "category": "string",
        "timeLimit": "string",
        "acceptance": "string",
        "exampleInput": "string",
        "expectedOutput": "string",
        "constraint_data": "string"
      }
    • Response:
      {
        "message": "Question added successfully"
      }

Task Endpoints

  • Create Task

    • URL: POST /task
    • Body:
      {
        "code": "string",
        "language": "string",
        "questionId": "string",
        "action": "run" | "submit",
        "userId": "string",
        "stdin": "string",
        "output": "string"
      }
    • Response:
      {
        "taskId": "string"
      }
  • Get Task Result

    • URL: GET /task/:taskId
    • Response:
      {
        "status": "completed" | "failed" | "pending",
        "output": "string"
      }

Frontend Pages

Sign Up Page

  • Route: /user/signup
  • Component: SignUp
  • Description: Provides a form for user registration.

Sign In Page

  • Route: /user/signin
  • Component: SignIn
  • Description: Provides a form for user login.

Questions List Page

  • Route: /questions
  • Component: QuestionsList
  • Description: Displays a list of all questions.

Add Question Form Page

  • Route: /addquestion
  • Component: AddQuestionForm
  • Description: Provides a form to add new questions.

Task Fetcher Page

  • Route: /solve/:questionId
  • Component: TaskFetcher
  • Description: Fetches and displays question details, allows code submission and execution.

Important Formats

Question Format

{
  "id": "string",
  "title": "string",
  "description": "string",
  "difficulty": "string",
  "category": "string",
  "timeLimit": "string",
  "acceptance": "string",
  "example_input": "string",
  "expected_output": "string",
  "constraint_data": "string"
}

Task Format

{
  "taskId": "string",
  "code": "string",
  "language": "string",
  "questionId": "string",
  "action": "run" | "submit",
  "userId": "string",
  "stdin": "string",
  "output": "string"
}

User Format

{
  "username": "string",
  "email": "string",
  "password": "string"
}