Develop a software to account for maintenance tasks performed during a working day. This application has two types of users (Manager, Technician). The technician performs tasks and is only able to see, create or update his own performed tasks. The manager can see tasks from all the technicians, delete them, and should be notified when some tech performs a task. A task has a summary (max: 2500 characters) and a date when it was performed, the summary from the task can contain personal information.
- Clone https://github.com/elixsantana/maintenance-tasks.git
- cd
/path/to/project
i.e. ~/maintenance-tasks - Download MySQL 5.7 or above and configure the root password and set it to
test
- Start the MySQL server (port 3306).
go run main.go
- Use localhost on port 3000 for HTTP requests.
- Since Auth was not a requirement,
Role
and/orTechId
headers key-values are needed (This is playing the role of an authentication and authorization system. This is not safe for production environments). - HTTP requests examples below.
Installations
- Install golang
- Install docker desktop
- Install minikube
- For Windows users: install git bash
Run the following commands in Bash:
- Open Docker Desktop and wait for Docker Engine to start
- cd /path/to/project
minikube start
go mod init maintenance-tasks
go mod tidy
docker build -t maintenance-deployment:latest .
docker build -t maintenance-deployment:latest .
eval $(minikube docker-env)
docker save -o maintenance-deployment.tar maintenance-deployment:latest
OR (docker images -q maintenance-deployment:latest | xargs docker save | docker load)docker load -i maintenance-deployment.tar
(Skip if you ran the command with xargs in step 9)kubectl create namespace maintenance
kubectl apply -f config/mysql-deployment.yaml --namespace maintenance
kubectl apply -f config/deployment.yaml --namespace maintenance
Setting up requests from local machine:
kubectl config set-context --current --namespace=maintenance
kubectl get services
kubectl port-forward service/maintenance-deployment 3000:3000
Now you can make requests from localhost:3000/ to the containarized app
If you need to restart the deployment:
kubectl get deployments
kubectl rollout restart deployment maintenance-runner
GET localhost:3000/tasks
Header requirements: Role
Role: manager
GET localhost:3000/task?id=1
Header requirements: Role, TechId (only for technician)
Role: manager OR Role: technician
TechId: 1 (Only for technician)
QueryParams requirement: id
(task id)
POST localhost:3000/task
Header requirements: Role
Role: technician
Body:
{
"summary": "Test Te34313223sttt\n",
"technician_id": 2,
"role": "technician"
}
PUT localhost:3000/task
Header requirements: Role and TechId
Role: technician
TechId: 2
Body:
{
"id": 1,
"summary": "Test Te34313223sttt\n",
"performed_date": "2023-05-14T00:00:00Z",
"technician_id": 2,
"role": "technician"
}
DELETE localhost:3000/task?id=1
Header requirements: Role
Role: manager
- More unit tests.
- Hash summary information to protect sensitive data and not persist plain text in database.
- Implement a message broker with either RabbitMQ or Redis for the notification system.
- Implement an init container to create the database and tables instead of doing it through the code.
- Implement authentication logic. Right now, I am assuming the header of the HTTP request contains the Role and TechId. This is not safe.
- Create script to automatically run all commands for the Kubernetes setup
- Load config for Vault or OS env. This will avoid having to rebuild the docker image if the creds are wrong or need to be updated.
- Better logging.