A robust Go API for a scheduling portal where suppliers can schedule appointments with employees for product deliveries.
This API provides functionality for managing a scheduling system for suppliers to deliver products to company operations. Key features include:
- β User authentication and authorization
- β Appointment scheduling with conflict detection
- β Role-based access control
- β Comprehensive appointment management
- β Statistics and reporting
- β Availability checking
- Go (Golang) 1.20+
- Gin Web Framework
- GORM (with PostgreSQL)
- JWT Authentication
- Clean Architecture Pattern
``` schedulingAPI/ βββ cmd/ β βββ api/ β βββ main.go # Application entry point βββ internal/ β βββ api/ β β βββ handlers/ # HTTP request handlers β β βββ middleware/ # HTTP middleware β β βββ routes/ # Route definitions β βββ config/ # Application configuration β βββ models/ # Domain models β βββ repository/ # Data access layer β βββ service/ # Business logic layer βββ pkg/ β βββ auth/ # Authentication utilities β βββ utils/ # Common utilities βββ scripts/ # Build and deployment scripts βββ go.mod # Go module definition βββ README.md # Project documentation ```
- Go 1.20 or higher
- PostgreSQL database
- Git
- Clone the repository:
```bash git clone https://github.com/bernardofernandezz/scheduling-api.git cd scheduling-api ```
- Install dependencies:
```bash go mod download ```
- Create a `.env` file in the root directory:
```
SERVER_ADDRESS=:8080 GIN_MODE=debug
DB_HOST=localhost DB_PORT=5432 DB_USER=postgres DB_PASSWORD=postgres DB_NAME=scheduling_db DB_SSLMODE=disable
JWT_SECRET=your-secret-key JWT_EXPIRE_HOURS=24 ```
- Run the application:
```bash go run cmd/api/main.go ```
- For Unix/Linux/MacOS:
```bash ./scripts/run.sh ```
- For Windows:
```powershell .\scripts un.ps1 ```
You can also run the application using Docker:
- Build the Docker image:
```bash docker build -t scheduling-api . ```
- Run the container:
```bash docker run -p 8080:8080 scheduling-api ```
For production deployment, use environment variables:
```bash
docker run -p 8080:8080
-e SERVER_ADDRESS=:8080
-e GIN_MODE=release
-e DB_HOST=your-db-host
-e DB_PORT=5432
-e DB_USER=your-db-user
-e DB_PASSWORD=your-db-password
-e DB_NAME=scheduling_db
-e DB_SSLMODE=require
-e JWT_SECRET=your-very-secure-jwt-secret
-e JWT_EXPIRE_HOURS=24
-e CORS_ALLOWED_ORIGINS=https://your-frontend-domain.com
scheduling-api
```
- `POST /api/auth/register` - Register a new user
- `POST /api/auth/login` - Authenticate and get tokens
- `POST /api/auth/refresh` - Refresh authentication token
- `POST /api/auth/password-reset` - Request password reset
- `GET /api/users/profile` - Get authenticated user profile
- `POST /api/users/change-password` - Change user password
- `POST /api/appointments` - Create a new appointment
- `GET /api/appointments` - List appointments with filters
- `GET /api/appointments/:id` - Get appointment details
- `PUT /api/appointments/:id` - Update an appointment
- `DELETE /api/appointments/:id` - Delete an appointment
- `POST /api/appointments/:id/status` - Update appointment status
- `POST /api/appointments/check-availability` - Check time slot availability
- `GET /api/appointments/upcoming` - Get upcoming appointments
- `GET /api/appointments/by-date-range` - Get appointments within date range
- `GET /api/appointments/by-supplier/:supplier_id` - Get supplier appointments
- `GET /api/appointments/by-employee/:employee_id` - Get employee appointments
- `GET /api/appointments/by-operation/:operation_id` - Get operation appointments
- `GET /api/admin/statistics/appointments` - Get appointment statistics
The API uses JWT (JSON Web Token) for authentication. To access protected endpoints:
- Obtain a token via the login endpoint.
- Include the token in the Authorization header:
``` Authorization: Bearer ```
Roles:
- Admin: System administrator
- Employee: Company employee who receives deliveries
- Supplier: External supplier who schedules deliveries
Statuses:
- Pending: Initial state when created
- Confirmed: Approved by employee
- Cancelled: Cancelled by either party
- Completed: Delivery successfully completed
- Rescheduled: Appointment time changed
Β© 2025 Your Company Name. All rights reserved.
docker-compose up -d
docker-compose logs -f api
docker-compose down- Ensure Go 1.20+ is installed.
- Create a PostgreSQL database.
- Copy `.env.example` to `.env` and configure.
- Run:
go mod download
go run ./cmd/apior
make runmake build
make run
make test
make test-coverage
make dockerdocker build -t scheduling-api .
docker run -p 8080:8080 \
-e DB_HOST=your-db-host \
-e DB_PORT=5432 \
-e DB_USER=your-db-user \
-e DB_PASSWORD=your-db-password \
-e DB_NAME=scheduling_db \
-e DB_SSLMODE=require \
-e JWT_SECRET=your-secret-key \
-e GIN_MODE=release \
scheduling-apiIncludes GitHub Actions for:
- Automated testing
- Docker image build/push
- Automated deployment
- Fork the repository.
- Create your feature branch.
- Commit changes.
- Push to branch.
- Open a Pull Request.