The Library Management System is a powerful and flexible server application built with Go (Golang) and the Gin framework, designed to efficiently manage books. It provides a RESTful API for performing various book-related operations such as adding, updating, deleting, and retrieving books. Additionally, it offers functionality to process URLs for redirection and canonicalization
- API Documentation
- Features
- Installation
- Project Structure
- Endpoints
- Running Tests
- Generating Swagger documentation
- Screenshots
- Contributing
- License
- Live swagger Documentation
- Documented each endpoint using Swagger to provide an interactive API reference.
- Swagger documentation can be accessed at
http://localhost:7000/docs/index.html#/
endpoint when the server is running locally.
- Add, update, delete, and retrieve books.
- URL processing for redirection and canonicalization.
- Interactive API documentation using Swagger.
- Comprehensive unit tests focusing on different edge cases.
- Smooth local setup for development and testing.
To get started with the Book Management System, follow these steps:
- Clone the repository:
bash git clone https://github.com/mwafrika/byfood-test-backend.git
cd byfood-test-backend
- Install dependencies:
go mod tidy
-
Setup the development and test database using postgresql.
-
Create a .env file (check the .env.example in the root of the project directory) then provide the values for the following variables in .env file:
PORT=7000
DB_URL=url for your local postgres database
TEST_DB_URL=url for your postgres test database
- Run the local server (CompileDaemon is used for continually running the server in the development environment)
CompileDaemon -command="./byfood-test-backend"
.
├── main.go
├── go.mod
├── go.sum
├── .env
├── README.md
├── controllers
│ ├── book_controller.go
│ └── url_controller.go
├── models
│ └── book.go
├── services
│ ├── response_formatter_service.go
│ └── url_service.go
├── tests
│ ├── book_controller_test.go
│ └── url_controller_test.go
├── config
│ ├── database.go
│ ├── loadEnvVariables.go
│ └── logger.go
│
└── swagger
├── docs.go
├── swagger.json
└── swagger.yaml
The API provides the following endpoints for managing books:
- Method: POST
- Endpoint:
POST /api/books
- Description: Add a new book to the system.
- Request Body:
{
"Title": "Going back to the beginning",
"Author": "Mwafrika",
"Year": 2003
}
- Response:
{
"message": "Book added successfully",
"data": {
"id": 1,
"title": "Going back to the beginning",
"author": "Mwafrika",
"Year": 2003
}
}
- Method: PUT
- Endpoint:
PUT /api/books/:id
- Description: Update an existing book.
- Request Body:
{
"title": "Going back to the beginning updated",
"author": "Mwafrika",
"Year": 2003,
}
- Response:
{
"message": "Book updated successfully",
"data": {
"id": 1,
"title": "Going back to the beginning updated",
"author": "Mwafrika",
"created_at": "2024-06-11T11:46:14.39208+03:00",
"updated_at": "2024-06-11T11:46:14.39208+03:00",
}
}
- Method: DELETE
- Endpoint:
DELETE /api/books/:id
- Description: Delete a book.
- Request Body:
{
"message": "Book deleted successfully"
}
- Method: GET
- Endpoint:
GET /api/books/:id
- Description: Retrieve a book by its ID.
- Request Body:
{
"data": {
"id": 1,
"title": "Book Title",
"author": "Author Name",
"created_at": "2024-06-11T11:46:14.39208+03:00",
"updated_at": "2024-06-11T11:46:14.39208+03:00",
}
}
- Method: GET
- Endpoint:
GET /api/books
- Description: List all books.
- Request Body:
{
"data": [
{
"id": 3,
"created_at": "2024-06-11T11:46:14.39208+03:00",
"updated_at": "2024-06-11T11:46:14.39208+03:00",
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"year": 1925
},
{
"id": 2,
"created_at": "2024-06-10T16:22:09.660146+03:00",
"updated_at": "2024-06-10T16:22:09.660146+03:00",
"title": "Not Well formated book",
"author": "Mwafrika",
"year": 202
}
],
"pagination": {
"limit": 10,
"page": 1,
"total_count": 2
}
}
To run the tests for the Book Management System, use the following command:
go test ./tests -v
run the following command to generate the swagger documentation then visit the documentation on: http://localhost:7000/api/docs/index.html#/
swag init
This project is licensed under the MIT License - see the LICENSE file for details.