An open API service indexing awesome lists of open source software.

https://github.com/subliker/user-bookings-service

Simple rest-api service to manage users and bookings
https://github.com/subliker/user-bookings-service

docker golang postgresql rest-api swagger

Last synced: 2 months ago
JSON representation

Simple rest-api service to manage users and bookings

Awesome Lists containing this project

README

          

# user-bookings-service
> RESTful API based on Go, PostgreSQL and Docker

### Docs (Sweagger):
```
https://localhost:8000/docs/index.html
```

### Requirements:
#### With Docker:
![docker](https://badgen.net/static/docker/@latest/purple)

You can install Docker there

#### Without Docker:
![golang](https://badgen.net/static/go/1.21.1/green?icon=github) ![postgresql](https://badgen.net/static/postgresql/@latest/)

You can install Golang there

You can install PostgreSQL there

### Installing:
1. Clone repository
2. In main directory:

With Docker:
for Windows users:
```bash
docker-compose build
docker-compose up -d postgresdb
docker-compose up -d app
```
for Linux users:
```bash
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