/user-bookings-service

Simple rest-api service to manage users and bookings

Primary LanguageGo

user-bookings-service

RESTful API based on Go, PostgreSQL and Docker

Docs (Sweagger):

https://localhost:8000/docs/index.html

Requirements:

With Docker:

docker
You can install Docker there

Without Docker:

golang postgresql
You can install Golang there
You can install PostgreSQL there

Installing:

  1. Clone repository

  2. In main directory:
    With Docker: for Windows users:

    docker-compose build
    docker-compose up -d postgresdb
    docker-compose up -d app

    for Linux users:

    sudo docker compose build
    sudo docker compose up -d postgresdb
    sudo docker compose up -d app

    Without Docker: Set PostgreSQL in pgAdmin (see in env file (.env)) and

    go build
    
    //for windows
    backendproj.exe
    
    //for linux
    ./backendproj
    

Entities:

  • User (example):
{
  "id": 906,
  "username": "Andrew",
  "password": "$2a$14$kv/sGmTWIlNYocbZqd88GuRsrOtKrs9bBFMM7N7HRNZ.qPxF.b.GG", //bcrypt hash
  "created_at": "2023-09-24T17:13:42Z",
  "updated_at": "2023-09-27T11:10:23Z"
}
  • Booking (example):
{
  "id": 1021,
  "user_id": 906,
  "end_time": "2023-10-01T14:30:00Z",
  "start_time": "2023-10-01T12:00:00Z",
  "comment": "I may be a little late"
}

Requests

  • /user/{id} [get]
    Get User by id

  • /user [post]
    Create User from postForm: username, password

  • /user/{user_id} [delete]
    Delete User and its bookings by user_id

  • /user/{id} [put]
    Update User data (optional: username, password) by id (set new timestamp in update_at)

  • /booking [get]
    Get all bookings ordered by id

  • /booking/{id} [get]
    Get Booking by id (optional: set limit, page(required limit), offset(required limit) in params)

  • /booking [post]
    Create User from postForm: user_id, start_time, end_time, comment(optional)

  • /booking/{id} [delete]
    Delete Booking by id

  • /booking/{id} [put]
    Update Booking data (optional: start_time, end_time, comments) by id