A Twirp-based API for managing health provider availability and client reservations. This system supports provider availability management, slot reservations, confirmation, and cleanup of expired reservations.
- Providers can set their availability.
- Clients can reserve available slots and confirm reservations.
- Retrieve reserved slots by provider or client.
- Automatic cleanup of expired reservations.
- SQLite database backend with GORM.
- Go 1.21 or higher
- SQLite database
protoc
for generating gRPC and Twirp code (if modifying the.proto
file)
-
Clone the repository:
git clone https://github.com/mdelreal/health-reservation-system.git cd health-reservation-system
-
Use the
Makefile
for streamlined setup and operations.
Install dependencies:
make setup
Compile the server:
make build
Start the server:
make run
The server will start on http://localhost:8080
.
Run all tests:
make test
Generate Twirp and Go code from .proto
files:
make generate
Remove build artifacts:
make clean
Ensure protoc
is installed:
make protoc-check
The system uses SQLite with GORM for database management. The database file is health_reservation.db
, and migrations are applied automatically.
Twirp service base URL: http://localhost:8080/twirp/reservation.ReservationService/
- Description: Creates a provider in the system. Availability cannot be set without a provider.
- Endpoint:
CreateProvider
- Request:
{ "id": "provider_123", "name": "Dr. John Doe" }
- Response:
{ "message": "Provider created successfully" }
- Description: Allows a provider to set availability.
- Endpoint:
SetAvailability
- Request:
{ "provider_id": "provider_123", "time_slots": [ { "start_time": "2024-12-20T08:00:00Z", "end_time": "2024-12-20T09:00:00Z" } ] }
- Response:
{ "message": "Availability set successfully" }
- Description: Retrieves available slots for a provider.
- Endpoint:
GetAvailableSlots
- Request:
{ "provider_id": "provider_123", "date": "2024-12-20" }
- Response:
{ "slots": [ { "id": "slot_123", "start_time": "2024-12-20T08:00:00Z", "end_time": "2024-12-20T08:15:00Z", "status": "Available" } ] }
- Description: Reserves an available slot.
- Endpoint:
ReserveSlot
- Request:
{ "slot_id": "slot_123", "client_id": "client_456" }
- Response:
{ "reservation_id": "slot_123", "message": "Slot reserved successfully" }
- Description: Confirms a reservation.
- Endpoint:
ConfirmReservation
- Request:
{ "reservation_id": "reservation_123" }
- Response:
{ "message": "Reservation confirmed" }
- Description: Retrieves reservations for a provider, optionally filtered by date.
- Endpoint:
GetReservedSlotsByProvider
- Request:
{ "provider_id": "provider_123", "date": "2024-12-20" }
- Response:
{ "reservations": [ { "reservation_id": "reservation_123", "client_id": "client_456", "provider_id": "provider_123", "status": "Confirmed", "start_time": "2024-12-20T08:00:00Z", "end_time": "2024-12-20T08:15:00Z" } ] }
- Description: Retrieves reservations for a client, optionally filtered by date.
- Endpoint:
GetReservedSlotsByClient
- Request:
{ "client_id": "client_456", "date": "2024-12-20" }
- Response:
{ "reservations": [ { "reservation_id": "reservation_123", "client_id": "client_456", "provider_id": "provider_123", "status": "Confirmed", "start_time": "2024-12-20T08:00:00Z", "end_time": "2024-12-20T08:15:00Z" } ] }
The server includes an automated task to clean up expired reservations every minute. Expired reservations are marked as "Available" and moved back to the slots table.
MIT License