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
- As a user I should be able to create a Pastebin
- As a user I should be able to share the Pastebin with a unique URL
- Once the pastebin is created, it cannot be modified
- As a user I should be able to login
- No password to the pastebin
- 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
- All the content in pastebin is Text only.
- 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
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