a Golang project | Letterboxd analog for books
Deployed on Render.com
Use this https://capybook.onrender.com
domain to send requests
Clone the project
git clone -b mastter https://github.com/shyndaliu/capybook
Go to the project directory
cd capybook
Up database service
docker compose up -d go_db
Build and up capybook service
docker compose build capybook
docker compose up capybook
To run this project locally, you will need to add the following environment variables to your .env file.
I used Mailtrap for catching emails, you can use any analog
CAPYBOOK_DB_USER
CAPYBOOK_DB_NAME
CAPYBOOK_DB_PASSWORD
CAPYBOOK_DB_DSN
SMTP_HOST
SMTP_USERNAME
SMTP_PASSWORD
JWT_SECRET
GET /api/v1/healthcheck
POST /api/v1/users
Body parameter | Type | Description |
---|---|---|
username |
string |
Required. unique username |
email |
string |
Required. valid email |
password |
string |
Required. user's password |
not supported in deployed version
PUT /api/v1/users/activated
Body parameter | Type | Description |
---|---|---|
code |
string |
Required. verification code sent to user's email |
GET /api/v1/users/${username}
Path parameter | Type | Description |
---|---|---|
username |
string |
Required. username |
Requirements : activated user
PATCH /api/v1/users/${username}
Path parameter | Type | Description |
---|---|---|
username |
string |
Required. username |
Body parameter | Type | Description |
---|---|---|
password |
string |
Required. new password |
Requirements : activated user who own given username |
DELETE /api/v1/users/${username}
Path parameter | Type | Description |
---|---|---|
username |
string |
Required. username |
Requirements : activated user who own given username
POST /api/v1/users/${id}/ban
Path parameter | Type | Description |
---|---|---|
id |
int |
Required. user's id |
Requirements : admin role
GET /api/v1/token
Body parameter | Type | Description |
---|---|---|
username |
string |
Required. unique username |
email |
string |
Required. valid email |
password |
string |
Required. user's password |
GET /api/v1/token/refresh
Authorization | Scope | Description |
---|---|---|
bearer |
refresh |
Required. valid refresh token |
POST /api/v1/books
Body parameter | Type | Description |
---|---|---|
title |
string |
Required. title of the book |
author |
string |
Required. author of the book |
year |
string |
Required. published year |
description |
string |
Required. smth about a book |
genres |
string[] |
Required. genres of the new book |
Requirements : admin role
GET /api/v1/books
Query parameter | Type | Description |
---|---|---|
title |
string |
full match the title |
author |
string |
full match the author |
limit |
int |
how many items in one page |
page |
int |
which page to get considering the limit size |
sort |
string |
sort by author, title, year, rating or add "-" to sort in descending order |
GET /api/v1/books/${id}
Path parameter | Type | Description |
---|---|---|
id |
int |
Required. Id of item to fetch |
PATCH /api/v1/books/${id}
Path parameter | Type | Description |
---|---|---|
id |
int |
Required. Id of item to update |
Body parameter | Type | Description |
---|---|---|
title |
string |
title of the book |
author |
string |
author of the book |
year |
string |
published year |
description |
string |
smth about a book |
genres |
string[] |
genres of the new book |
Requirements : admin role
DELETE /api/v1/books/${id}
Path parameter | Type | Description |
---|---|---|
id |
int |
Required. Id of item to delete |
Requirements : admin role
POST /api/v1/books/${id}/reviews
Path parameter | Type | Description |
---|---|---|
id |
int |
Required. id of book |
Body parameter | Type | Description |
---|---|---|
content |
string |
Required. review for a book |
rating |
int |
Required. number between 1 and 5 |
Requirements : activated user without an active ban
GET /api/v1/books/${id}/reviews
Path parameter | Type | Description |
---|---|---|
id |
int |
Required. id of book |
Query parameter | Type | Description |
---|---|---|
limit |
int |
how many items in one page |
page |
int |
which page to get considering the limit size |
sort |
string |
sort by created_at, rating or add "-" to sort in descending order |
PATCH /api/v1/books/${id}/reviews
Path parameter | Type | Description |
---|---|---|
id |
int |
Required. id of book |
Body parameter | Type | Description |
---|---|---|
content |
string |
Required. new review for a book |
rating |
int |
Required. number between 1 and 5 |
Requirements : activated user without an active ban
DELETE /api/v1/books/${id}/reviews
Path parameter | Type | Description |
---|---|---|
id |
int |
Required. Id of the book |
Requirements : activated user
DELETE /api/v1/reviews/${id}
Path parameter | Type | Description |
---|---|---|
id |
int |
Required. Id of the review |
Requirements : admin role
Table books {
id bigserial [primary key]
title text [not null]
author text [not null]
year int [not null]
description text [not null]
genres text[] [not null]
}
Table users {
id bigserial [primary key]
username citext [not null, unique]
email citext [not null, unique]
password bytea [not null]
token_hash text [not null]
activated bool [not null, default: false]
}
// one-to-one
Table admins {
id bigserial [primary key]
user_id bigserial [not null, unique]
}
Ref: admins.user_id < users.id
// one-to-one
Table bans {
id bigserial [primary key]
user_id bigserial [not null, unique]
expiry timestamp
}
Ref: bans.user_id < users.id
// many-to-many
Table reviews {
id bigserial [primary key]
created_at timestamp [not null, default: `now()`]
user_id bigserial [not null]
book_id bigserial [not null]
content text
rating integer
}
Ref: reviews.book_id < books.id
Ref: reviews.user_id < users.id
//one-to-one
Table verifications{
code bytea [primary key]
user_id bigint
expiry timestamp
}
Ref: verifications.user_id < users.id
- Uldana Shyndali 22B030473 @shyndaliu