Skip to content

fastworkco/swe-interview

Repository files navigation

REST API for Managing Items

This project demonstrates a REST API implementation for managing items, written in TypeScript. It includes endpoints for CRUD operations and other functionalities for evaluating candidates during interviews.

Features

  • CRUD operations for items
    • RESTful API design
  • Get list items with pagination
  • Input validation ex. class-validator
  • Modular and scalable project structure
  • Search and filter items (name, price range)
  • Sorting items

Additional Features

  • Cache result of each request for 60 seconds

Endpoints

Base URL

http://localhost:3000

Endpoints

1. Create an Item

  • POST /items
  • Request Body:
    [
      {
        "name": "string",
        "price": number
        "amount": number
      }
    ]
  • Response:
    [
      {
        "id": "string",
        "name": "string",
        "price": number,
        "amount": number
      }
    ]

2. Get All Items

  • GET /items
  • Response:
    [
      {
        "id": "string",
        "name": "string",
        "price": number,
        "amount": number
      }
    ]

3. Get an Item by ID

  • GET /items/:id
  • Response:
    {
      "id": "string",
      "name": "string",
      "price": number,
      "amount": number
    }

4. Update an Item

  • PUT /items/:id
  • Request Body:
    {
      "name": "string",
      "price": number,
      "amount": number
    }
  • Response:
    {
      "id": "string",
      "name": "string",
      "price": number,
      "amount": number
    }

5. Delete an Item

  • DELETE /items/:id
  • Response:
    {
      "message": "Item deleted successfully"
    }

Project Structure

swe-interview/
├── data/                # Directory for mount to docker
├── migrations/          # Database migration file
├── seeds/               # Seed file
├── src/
│   ├── index.ts         # Entry point
│   ├── knexfile.ts      # Knex configuration
├── .eslintrc.json       # ESLint configuration
├── .prettierrc          # Prettier configuration
├── package.json         # Dependencies and scripts
├── tsconfig.json        # TypeScript configuration
├── jest.config.js       # Jest configuration
├── docker-compose.yaml  # Docker for PostgreSQL
└── README.md            # Instructions for candidates

Setup and Run

Prerequisites

Ensure you have the following installed:

Steps

  1. Clone the repository:

    git clone https://github.com/your-repo/swe-interview.git
    cd swe-interview
  2. Install dependencies:

    yarn install
    # or
    npm install
  3. Run PostgreSQL Local:

    docker-compose up -d
  4. Run database migration:

    yarn run migrate
  5. Run seed data:

    yarn run seed
  6. Run the project:

    yarn dev
    # or
    npm run dev
  7. Access the API at http://localhost:3000.

About

This project demonstrates a REST API implementation for managing items, written in TypeScript. It includes endpoints for CRUD operations and other functionalities for evaluating candidates during interviews.

Resources

Stars

0 stars

Watchers

3 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors