Welcome to the documentation for the MyBooks API. MyBooks is a SaaS project designed to help users organize their personal library. This API provides endpoints for managing libraries, books, user profiles, billing, and loan status.
/myapp
|-- /cmd
| |-- /api
| | |-- main.go
| |
|-- /docs
| |-- main.go
| |-- swagger.json
| |-- swagger.yaml
| |
|-- /internal
| |-- /domain
| | |-- /models
| | | |-- auth_model.go
| | | |-- book_model.go
| | | |-- library_model.go
| | | |-- loan_model.go
| | | |-- user_model.go
| | |-- /repositories
| | | |-- auth_repository.go
| | | |-- book_repository.go
| | | |-- library_repository.go
| | | |-- loan_repository.go
| | |-- /services
| | | |-- auth_service.go
| | | |-- book_service.go
| | | |-- library_service.go
| | | |-- loan_service.go
| |
| |-- /infrastructure
| | |-- /api
| | | |-- /handlers
| | | | |-- auth_handler.go
| | | | |-- books_handler.go
| | | | |-- library_handler.go
| | | | |-- loans_handler.go
| | | |-- /middlewares
| | | | |-- auth_middleware.go
| | | | |-- cors_middleware.go
| | | |-- server.go
| | |-- /config
| | | |-- database.go
| | |-- /constants
| | | |-- constants.go
| | |-- /helpers
| | | |-- get_user_from_context.go
| | | |-- handle_error.go
| |
|-- /pkg
| |-- generate_random_id.go
| |-- send_email.go
| |-- validate_model_struct.go
|
|-- Dockerfile
|-- docker-compose.yml
|-- go.mod
|-- go.sum
|-- makefile
Authentication is required for most endpoints. MyBooks supports credentials authentication and authentication via Google account.
POST v1/auth/signup/credentials
: Create user with credentials.POST v1/auth/signin/credentials
: Authentication user with credentials.POST v1/auth/signout
: Logout user.POST v1/auth/forgot-password
: Forgot password.POST v1/auth/reset-password/{token}
: Create a new password.GET v1/auth/validate
: Validate access_token cookie.Manage libraries where users can organize their books.
GET v1/libraries
: Get all libraries.GET v1/libraries/{libraryId}
: Get library by ID.POST v1/libraries
: Create a new library.PUT v1/libraries/{libraryId}
: Update a library.DELETE v1/libraries/{libraryId}
: Delete a library.POST v1/libraries/{libraryId}/books/{bookId}
: Add book to a library.DELETE v1/libraries/{libraryId}/books/{bookId}
: Remove book from a library.Manage books within libraries.
GET v1/books
: Get all books.GET v1/books/{bookId}
: Get book by ID.POST v1/books
: Create a new book.PUT v1/books/{bookId}
: Update a book.DELETE v1/books/{bookId}
: Delete a book.Manage user profiles.
PUT v1/profile/photo
: Update profile photo.PUT v1/profile
: Update name, email, and password.DELETE v1/profile
: Delete the account.Manage billing details and subscription plans.
GET v1/billing
: Get billing details for the account ($5 per account).POST v1/subscribe
: Subscribe to a plan.Manage loan status of books.
POST v1/loans
: Create a loanGET v1/loans
: Get all loansPUT v1/loans/:loanId/return
: Mark loan as returnedTo use this project, you need to follow these steps:
git clone https://github.com/vinniciusgomes/mybooks-api
go mod download
go build
./cmd/api/main.go
To run the service locally, you can use Air for hot-reloading. Run the following command:
air
The project includes a Makefile to help you manage common tasks more easily. Here's a list of the available commands and a brief description of what they do:
make run
: Run the application without generating API documentation.make run-with-docs
: Generate the API documentation using Swag, then run the application.make build
: Build the application and create an executable file named gopportunities
.make test
: Run tests for all packages in the project.make docs
: Generate the API documentation using Swag.make clean
: Remove the gopportunities
executable and delete the ./docs
directory.To use these commands, simply type make
followed by the desired command in your terminal. For example:
make run
This project includes a Dockerfile
and docker-compose.yml
file for easy containerization and deployment. Here are the most common Docker and Docker Compose commands you may want to use:
docker build -t your-image-name .
: Build a Docker image for the project. Replace your-image-name
with a name for your image.docker run -p 8080:8080 -e PORT=8080 your-image-name
: Run a container based on the built image. Replace your-image-name
with the name you used when building the image. You can change the port number if necessary.If you want to use Docker Compose, follow these commands:
docker compose build
: Build the services defined in the docker-compose.yml
file.docker compose up
: Run the services defined in the docker-compose.yml
file.To stop and remove containers, networks, and volumes defined in the docker-compose.yml
file, run:
docker-compose down
For more information on Docker and Docker Compose, refer to the official documentation:
This project uses the following tools:
To contribute to this project, please follow these guidelines:
git checkout -b feature/your-feature-name
git push origin feature/your-feature-name
This project is licensed under the MIT License - see the LICENSE.md file for details.
This project was created by vinniciusgomes.