This repository contains the source code for the SF Delivery Delay Report application. The application is designed to manage and report delays in delivery services. Below is an overview of the project structure, modules, and API endpoints.
The project is organized into several main components:
- app : Contains the main application logic, including API handlers, services, and repository implementations.
- db : Manages the database models and repository interfaces.
- handler : Implements HTTP request handlers for different entities (orders, users, vendors, etc.).
- service : Provides business logic services, including order management, user services, and more.
- repository : Implements the repository interfaces, defining the database operations for each entity.
The application uses GORM as the ORM library to interact with the database. Database models are defined in the db/models
package.
- API Endpoints :
POST /api/orders/register
: Create a new order.GET /api/orders/:id
: Retrieve an order by ID.GET /api/orders/user/:id
: Retrieve a list of orders for a specific user.
- API Endpoints :
GET /api/users/:id
: Retrieve a list of orders for a specific user.
- API Endpoints :
GET /api/vendors/all
: Retrieve a list of all vendors.GET /api/vendors/:id
: Retrieve a vendor by ID.GET /api/vendors/:id/delayed-orders
: Retrieve delayed orders for a specific vendor.
- API Endpoints :
GET /api/report-delay/:id
: Retrieve delay reports for a specific order.GET /api/report-delay/between?id=VENDOR_ID&start_time=EPOCH_TIME&end_time=EPOCH_TIME
: Retrieve all delayed data for a specific vendor between two different time
- API Endpoints :
GET /api/agent/assign/:id
: Assign a delay report to an agent.GET /api/agent/done/:agent_id/:order_id
: Mark a delay report as done.
- API Endpoints :
POST /api/trips
: Create a new trip.
- Go installed on your machine
- A PostgreSQL database
- Or Docker + Docker compose
-
Create a user in PostgreSQL and then create DB and assign that user to the DB and then grant privileges:
create user sf_agent with password 'SomePassword' CREATEDB; create database sf_delivery_delay_report with owner = sf_agent; grant all privileges on database sf_delivery_delay_report to sf_agent;
-
Create new environment variables to store DB's authentication details:
DB_HOST=localhost DB_USER=sf_agent DB_PASSWORD=SomePassword DB_NAME=sf_delivery_delay_report DB_PORT=5432 DB_SSL_MODE=disable
-
Clone the repository:
git clone https://github.com/your-username/sf-delivery-delay-report.git
-
Change into the project directory:
cd sf-delivery-delay-report
-
Run this shell file:
bash ./init_db.sh
-
Run the application:
go run main.go
The API will be available at http://localhost:8080.
migrate -source file://internal/db/migrations -database "postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}/${DB_NAME}?sslmode=${DB_SSL_MODE}" down -all
migrate -source file://internal/db/migrations -database "postgres://${DB_USER}:${DB_PASSWORD}@${DB_HOST}/${DB_NAME}?sslmode=${DB_SSL_MODE}" up
go test -v -cover ./test
Before running on docker, create a .env file or export these environment variables:
DB_HOST=sf_postgres_db
DB_USER=sf_user
POSTGRES_USER=postgres
DB_PASSWORD=OmidRasouli
POSTGRES_PASSWORD=OmidRasouli
DB_NAME=sf_delivery_delay_report
DB_PORT=6543
DB_SSL_MODE=disable
Now it is time to start docker:
sudo docker compose up -d