This repository contains the code of a simple backend application for scheduling book pickups from Open Library
Due to the nature of the pandemic, a local library is planning to reduce gatherings and crowds in its area by creating an online book pick up service. In order to borrow books from the library, users have to make an appointment at a specific time of day to come and pick up the books.
This backend application provides the necessary APIs to do so. Users can browse books from Open Library before making a schedule. Users can then submit a pick up schedule of the book they want to borrow. Librarians can get all appointed book pick up schedules with the book information. Librarians can also fetch a single appointment schedule. They can also update or delete an appointment.
Users do not have to login to use the backend application to browse books from Open Library or previouly submitted books. But an API Key (owned by a librarian) is needed to submit a pick up schedule, list, update, or delete schedules. This is done to prevent users from adding unnecessary schedules or changing submitted schedules without a librarian's verification.
For now, please copy the API Spec file (apispec.json) into a Swagger Editor to view the full API specifications.
- Golang
- MySQL
- Google Wire
go install github.com/google/wire/cmd/wire@latest
- Golang Migrate
go install -tags 'mysql' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
- Install the necessary tools to run / build the application
- Setup the .env file. The .env.example file can be found in the root folder.
- Setup a MySQL database, and migrate the schema using the command below.
make migrateup
- A separate database should be made for unit tests. Migrate the schema to the test database using the command below
make migrateup_test
- Optionally install an API testing tool such as Postman to manually test APIs with ease
-
Run server:
make run
-
Build application:
make build
-
Build and run application:
make build_run
-
Run tests:
make run_test
- Run db migration up all versions
make migrateup
- Run db migration up 1 version
make migrateup1
- Run db migration down all versions
make migratedown
- Run db migration down 1 version
make migratedown
- Run test db migration up all versions
make migrateup_test
- Run test db migration up 1 version
make migrateup1_test
- Run test db migration down all versions
make migratedown_test
- Run test db migration down 1 version
make migratedown_test
This software still has room for improvements:
- A virtual container tool like Docker can improve development by automating deployment of applications in isolated lightweight containers so applications can work efficiently in different environments (machines)
- API documentation should be more easily accessible
- MySQL Driver (github.com/go-sql-driver/mysql)
- Chi (github.com/go-chi/chi) - Golang Router library
- Validator (github.com/go-playground/validator) - Request / input validation
- Google Wire (github.com/google/wire) - Dependency Injection library
- Testify (github.com/stretchr/testify) - Unit testing library
- GoDotEnv (github.com/joho/godotenv) - Env loader library
- sqlmock (github.com/DATA-DOG/go-sqlmock) - SQL driver mock to simulate sql driver behavior in tests
- Golang Migrate (github.com/golang-migrate/migrate) - Library for database migration
- Gregorius Jovan Kresnadi - BaconLover307