This is a simple RESTful API to manage loan of e-book in an electronic library. The API allow users to:
- Search for availability based on book title.
- Borrow a book.
- Extend a book loan.
- Return a book.
- Each user may only borrow one copy per book.
- Each user may only extend each book loan once.
psql -U postgres
CREATE USER myuser WITH PASSWORD 'mypassword';
CREATE DATABASE elib WITH OWNER myuser;
GRANT ALL PRIVILEGES ON DATABASE elib TO myuser;
psql -d elib -U myuser
\l # List databases
\du # List users
\dt # List tables
SELECT * FROM users LIMIT 10;
SELECT * FROM books LIMIT 10;
SELECT * FROM loans LIMIT 10;
\d loans # Describe the table
\d+ loans # Describe the tabledbdocs db2dbml postgres "postgresql://myuser:mypassword@localhost/elib" -o database.dbmlRefer to Makefile for all the commands.
make devGET:localhost:3000/Book?title=BadlandsPOST:localhost:3000/Borrow(with JSON body)POST:localhost:3000/Extend(with JSON body)POST:localhost:3000/Return(with JSON body)
JSON Body Example (Common for POST requests):
{
"title": "Badlands"
}Mocking Google OAuth2 in our integration tests allows us to rigorously validate how our backend handles user profile retrieval for seamless session management. By simulating scenarios like service unavailability or incomplete data, we ensure reliable testing of our logic without external dependencies that introduce unpredictability. This approach accelerates test cycles, reduces maintenance costs tied to third-party changes, and safeguards against disruptions in our development workflow. It complements broader validations by isolating critical authentication paths, ensuring we focus engineering effort where it matters most while maintaining confidence in system-wide integrity.
chmod +x ./deployment/scripts/integration_test.sh
chmod +x ./deployment/scripts/wrap_test_for_coverage.sh
# Get Postgres container id
docker ps
# Execute a command inside a running Docker container
docker exec -it <your_container_id> psql -U <your_username> -d elib- Implement simple in-memory storage with pre-populated books on startup.
- Integrate PostgreSQL for persistent data storage.
- Implement logging for API requests and responses.
- Add validation for each API (e.g., missing or invalid input).
- Write tests for coverage and regression.
- Integrate Google OAuth2 for user authentication.
- Implement session management with Redis.
| Tool | Description |
|---|---|
| mockaroo | Mock data generator |
| Package | Description |
|---|---|
| Fiber | Fast and lightweight web framework for Go |
| zerolog | Zero-allocation JSON logger for Go |
| testify | Go testing toolkit |
| validator | Value validations for structs and individual fields based on tags |
| redis | Golang Redis client for Redis Server and Redis Cluster |
| dbdiagram.io | A free, simple tool to draw ER diagrams |