# README
EasyPark
EasyPark is a backend built with Clean Architecture principles. It provides REST API endpoints for drivers and admins to be able to use and manage parking through our UI.
API Specification and Design
Before reading the API Specification, read our design docs to understand the states, rules and assumptions regarding entities within the EasyPark system.
API Specification can be found here.
Running locally
Prerequisites
Mac
- Linux environment(normal terminal on MacOS)
- VS Code with:
- Docker Desktop for Mac
- GoLang (Follow instructions for Mac)
Windows
- Linux environment(WSL2)
- VS Code with:
- GoLang extension
- Remote extension (need to connect VS Code to WSL2)
- Docker Desktop for Windows (Download for Windows and enable integration with WSL2 in the settings)
- GoLang (Follow instructions for Linux and install in your WSL2)
Tools
- Wire for Dependecy Injection code generation.
- Mockery for Mocks generation for unit testing.
- PSQL(depends on what package manager your Linux distro uses, but if you try runnining
psql
it should give you a commad back to install it) for running scripts that interact with the database.
Setting up environment
Git clone to your Linux environment using git clone https://github.com/IgorSteps/easypark.git
.
Open the project in VS Code:
- On Mac: just open it like you would any project.
- On Windows: use your VS Code Remote Extension to connect to your WSL2 and locate your cloned project there.
From project root in your Linux Environment, run docker-compose up -d
to create required PostgreSQL image and optional PgAdmin image for DB user interface.
Starting the apps
From project root, run:
- Build the apps, run
make build
. - To run the rest app, run
make run
. - To run the websocket app, run
make run-ws
.
If changes to dependency graph have been made, you must edit wire.go
file and run make wire
to regenerate dependency injection code(wire_gen.go
file).
Troubleshooting
Failed to run make wire
or make mocks
- Make sure you have
wire
(https://github.com/google/wire) andmockery
(https://vektra.github.io/mockery/latest/installation/) installed. - If after installation it still doesn't work, add
GO BIN
to your PATH, runexport PATH="$HOME/go/bin:$PATH"
(given that your GO BIN is go/bin which it usual is).
Testing
-
To regenerate mocks for unit tests, run
make mocks
. -
To run unit tests, run
make unit
.- To see unit test coverage, run
make coverage-report
. This will output aunit-test-coverage.out
report that can be viewed in the browser usingmake coverage-interactive
.
- To see unit test coverage, run
-
To run functional tests, run
make functional
.
Useful things
CI pipeline (GitHub Actions)
For every commit you make to your PRs, a GitHub actions workflow will get triggered that automatically runs tasks such as:
- Building and running the app.
- Unit and functionally testing the app.
- Testing unit test coverage is above 70%.
If any of the steps fail, the checks will fail and you will not be able to merge your PR unti you fix the issue.
Config Management
Config values are specified in here. If edit it to include new key-value pairs, you must mirror that as respective struct fields in here. Note that the keys in the yaml must match struct field names.
Cleaning database tables
Run make clean-db
to truncate existing tables. Note, you need to add new table names to script.
Creating admin user
Run the make create-admin
runs this script to create an admin directly in the database and give you a JWT back.
This creates an admin with the following details:
{
"id": "a131a9a0-8d09-4166-b6fc-f8a08ba549e9",
"username": "adminUsername",
"email": "[email protected]",
"password": "securePassword",
"firstname": "Admin",
"lastname": "User",
"role": "admin"
}
Connecting to PgAdmin
PgAdming provides a nice UI for DB management and debugging.
- Go to
http://localhost:5050
to access PgAdmin - Log in with the
PGADMIN_DEFAULT_EMAIL
andPGADMIN_DEFAULT_PASSWORD
in the docker-compose.yml file - To connect to our PostgreSQL database from PgAdmin:
- Right-click on "Servers" in the left panel and choose "Create > Server".
- In the "Create Server" dialog, go to the "Connection" tab.
- Set "Hostname/address" to
database
, which is the name of our PostgreSQL service defined in our docker-compose.yml. - Fill in the "Username" and "Password" fields with the POSTGRES_USER and POSTGRES_PASSWORD specified in docker-compose.yml.
- Click "Save" to establish the connection.