A RESTful API service for managing computers and their assignments to employees, built with Go and PostgreSQL.
- Computer CRUD Operations: Create, read, update, and delete computers
- Employee-Computer Management: Assign and remove computers from employees
- Data Validation: Comprehensive input validation for all endpoints
- Pagination Support: Efficient data retrieval with pagination
- Health Monitoring: Health check endpoint for service monitoring
- Notification System: Integrated notification system for threshold monitoring
- Security Middleware: Rate limiting, CORS, and security headers
- Comprehensive Testing: Full test suite with integration tests
- Go 1.23+: Download and install Go
- PostgreSQL 13+: Download and install PostgreSQL
- Docker & Docker Compose (optional): For containerized deployment
docker-compose up -d
# Run all tests
go test ./...
# Run tests with verbose output
go test -v ./...
# Run tests with coverage
go test -cover ./...
# Run integration tests
go test ./internal/integration/... -v
# Run specific integration test
go test ./internal/integration/... -v -run="TestIntegration_ComputerCRUD"
# Run performance tests
go test ./internal/integration/... -v -run="TestIntegration_DatabasePerformance"
http://localhost:8089/api/v1
Currently, the API doesn't require authentication, but security middleware is applied.
All endpoints under api/v1
GET /health
Get All Computers
GET /computers?page=1&limit=10
Get Computer by ID
GET /computers/{id}
Create Computer
POST /computers
Content-Type: application/json
{
"name": "Dell-Laptop-001",
"computer_name": "Test Name",
"mac_address": "AA:BB:CC:DD:EE:FF",
"ip_address": "192.168.1.100",
"employee_abbreviation": "ABC",
"description": "Dell Latitude 5520"
}
Update Computer
PUT /computers/{id}
Content-Type: application/json
{
"name": "Updated-Dell-Laptop-001",
"computer_name": "Test Name",
"mac_address": "AA:BB:CC:DD:EE:FF",
"ip_address": "192.168.1.101",
"employee_abbreviation": "XYZ",
"description": "Updated Dell Latitude 5520"
}
Delete Computer
DELETE /computers/{id}
Get Employee's Computers
GET /employees/{employee_abbreviation}/computers
Assign Computer to Employee
PUT /employees/{employee_abbreviation}/computers/{computer_id}
Remove Computer from Employee
DELETE /employees/{employee_abbreviation}/computers/{computer_id}
# Create a computer
curl -X POST http://localhost:8089/api/v1/computers \
-H "Content-Type: application/json" \
-d '{
"name": "MacBook-Pro-001",
"mac_address": "AA:BB:CC:DD:EE:FF",
"computer_name": "Test Name",
"ip_address": "192.168.1.100",
"employee_abbreviation": "JDO",
"description": "MacBook Pro 16-inch"
}'
# Get all computers
curl http://localhost:8089/api/v1/computers
# Assign computer to employee
curl -X PUT http://localhost:8089/api/v1/employees/ABC/computers/550e8400-e29b-41d4-a716-446655440000
# Remove computer from employee
curl -X DELETE http://localhost:8089/api/v1/employees/ABC/computers/550e8400-e29b-41d4-a716-446655440000
The application supports configuration through environment variables:
Variable | Description | Default |
---|---|---|
DB_HOST |
Database host | localhost |
DB_PORT |
Database port | 5432 |
DB_USER |
Database username | postgres |
DB_PASSWORD |
Database password | password |
DB_NAME |
Database name | computer_management |
DB_SSLMODE |
SSL mode | disable |
PORT |
Server port | 8089 |
NOTIFICATION_ENDPOINT |
Notification service URL | (optional) |
computer-management-api/
├── cmd/
│ └── api/
│ └── main.go # Application entry point
├── internal/
│ ├── config/
│ │ └── config.go # Configuration management
│ ├── database/
│ │ └── database.go # Database connection
│ ├── handler/
│ │ ├── computer.go # HTTP handlers
│ │ └── interface.go # Handler interfaces
│ ├── model/
│ │ └── computer.go # Data models
│ ├── notification/
│ │ └── client.go # Notification client
│ ├── repository/
│ │ └── computer.go # Data access layer
│ ├── router/
│ │ └── router.go # HTTP routing
│ └── integration/
│ └── *_test.go # Integration tests
├── docker-compose.yml # Docker services
├── Dockerfile # Container definition
├── go.mod # Go modules
├── go.sum # Dependency checksums
└── README.md # Project documentation
The API returns appropriate HTTP status codes:
200 OK
: Successful operation201 Created
: Resource created successfully400 Bad Request
: Invalid input data404 Not Found
: Resource not found409 Conflict
: Resource conflict (e.g., duplicate MAC address)500 Internal Server Error
: Server error
Error responses include descriptive messages:
{
"error": "computer with this MAC address already exists: AA:BB:CC:DD:EE:FF"
}