mehkey / go-echo-pastebin-web-service

Go version of pastebin web service with postgresql database for CRUD using pgx, goku, echo.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Coverage Go

The CI/CD Badges for Build Success and Percentage of Lines of code Coverage for Tests were created using using Github Actions

Go Echo Pastebin Web Service

Original Design Github Repo Link

Functional Requirements

  1. As a user I should be able to create a Pastebin
  2. As a user I should be able to share the Pastebin with a unique URL
  3. Once the pastebin is created, it cannot be modified
  4. As a user I should be able to login
  5. No password to the pastebin
  6. How long is it going to stay up on the website? 90 days. User should be able to set a custom time on the pastebin
  7. All the content in pastebin is Text only.
  8. Is there a character limit? Maximum words is 1000 words.

API

GET /api/v1/users

Retrieves a list of all users

GET /api/v1/pastebins

Retrieves a list of all pastebins

GET /api/v1/user/:id

Retrieves a specific user by ID

GET /api/v1/pastebin/:id

Retrieves a specific pastebin by ID

GET /api/v1/pastebins/user/:userID

Retrieves all pastebins created by a specific user

POST /api/v1/user

Creates a new user

POST /api/v1/pastebin

Creates a new pastebin

API Details

GET /api/v1/pastebins

Retrieves a list of all pastebins

Example response:

[
    {
        "id": 1,
        "content": "Lorem Ipsum",
        "user_id": 1
    },
    {
        "id": 2,
        "content": "Dolor sit amet",
        "user_id": 2
    }
]

GET /api/v1/user/:id

Retrieves a specific user by ID

Example request: GET /api/v1/user/1

Example response:

{
    "id": 1,
    "name": "John Doe",
    "email": "johndoe@example.com",
    "pastebins": [1, 2]
}

GET /api/v1/pastebin/:id

Retrieves a specific pastebin by ID

Example request: GET /api/v1/pastebin/1

Example response:

{
    "id": 1,
    "content": "Lorem Ipsum",
    "user_id": 1
}

GET /api/v1/pastebins/user/:userID

Retrieves all pastebins created by a specific user

Example request: GET /api/v1/pastebins/user/1

Example response:

[
    {
        "id": 1,
        "content": "Lorem Ipsum",
        "user_id": 1
    },
    {
        "id": 2,
        "content": "Dolor sit amet",
        "user_id": 1
    }
]

POST /api/v1/users

Create a new user

Example request:

{
    "name": "John Doe",
    "email": "johndoe@example.com"
}

Example response

{
    "id": 1,
    "name": "John Doe",
    "email": "johndoe@example.com",
    "pastebins": []
}

POST /api/v1/pastebin

Create a new pastebin

Example request:

{
    "content": "Lorem Ipsum",
    "user_id": 1
}

Example Response:

{
    "id": 1,
    "content": "Lorem Ipsum",
    "user_id": 1
}

Data Schema

Users:

  • "id" SERIAL PRIMARY KEY
  • "name" varchar
  • "email" varchar
  • "password" varchar
  • "created_at" timestamp DEFAULT CURRENT_TIMESTAMP
  • "updated_at" timestamp DEFAULT CURRENT_TIMESTAMP

Pastebins

  • "id" SERIAL PRIMARY KEY
  • "content" varchar
  • "user_id" int
  • "password" varchar
  • "created_at" timestamp DEFAULT CURRENT_TIMESTAMP
  • "updated_at" timestamp DEFAULT CURRENT_TIMESTAMP

go-pastebin-web-service

Pastebin System Design

Pastebin Design

Commands


go mod tidy

go build ./cmd/web

go build ./...

go run ./cmd/web

go test -v   ./internal/datasource 
go test -v   ./internal/datasource 

go test -v ./...

psql -U postgres -h localhost postgres

Front-End React NEXT Typescript

./Screen1

./Screen2

./Screen3

About

Go version of pastebin web service with postgresql database for CRUD using pgx, goku, echo.


Languages

Language:Go 99.7%Language:Shell 0.3%