Employee management system
-
Create Department
If parent_name is empty, assumes rootcurl -d '{"name": "subadmin", "parent_name": "admin"}' "http://localhost:8080/departments"
-
Create Employee
If department_name is empty, assumes rootcurl -d '{"name": "kiran", "department_name": "admin"}' "http://localhost:8080/employees"
-
Get Employees
For getting employees under root, use department_name as rootcurl -d "http://localhost:8080/employees/{empname}/{department_name}"
There is an executable in the repository.Clone the repo and run the executable.
./ems
- Clone this app and
cd
into it. - Ensure dependencies
dep init and dep ensure
- Build :
go build .
- After this step, executable ems is generated in same directory
- Run :
./ems
curl -d '{"name": "admin", "parent_name": ""}' "http://localhost:8080/departments"
curl -d '{"name": "subadmin", "parent_name": "admin"}' "http://localhost:8080/departments"
curl -d '{"name": "subadmin1", "parent_name": "admin"}' "http://localhost:8080/departments"
Create Employee
curl -d '{"name": "kiran", "department_name": "admin"}' "http://localhost:8080/employees"
curl -d '{"name": "kiran", "department_name": "subadmin"}' "http://localhost:8080/employees"
Get Employees
curl -d "http://localhost:8080/employees/kiran/admin"
{"employee":[{"name":"kiran","department_name":"admin"},{"name":"kiran","department_name":"subadmin"}]}
- More domain specific handling or use cases are not covered
- Employee creation can be done only with a pre-exsiting department
- Improve locking code by using channels and verify race conditions
- Write tests for all packages and comprehensively.
- Return more meaningful errors
- The tree code is not clean.Can be segregated more
- Model propagation between packages can be cleaned up.
- The performance of department lookup can be optimized by using a hashmap index into the tree nodes.