Skip to content

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

Notifications You must be signed in to change notification settings

fastworkco/swe-interview-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

REST API for Managing Items

This project demonstrates a REST API implementation for managing items, written in Golang. 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
  • 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-go/
├── data/                 # Directory for mount to docker
├── main.go               # Entry point
├── .env                  # env for database connection
├── docker-compose.yaml   # Docker for PostgreSQL
├── go.mod                # Dependencies
└── 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-go.git
    cd swe-interview-go
  2. Install dependencies:

    go get
  3. Run PostgreSQL Local:

    mkdir data
    docker-compose up -d
  4. Run the project:

    go run main.go
  5. Access the API at http://localhost:3000.

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages