diff --git a/.gitignore b/.gitignore index ad3a2b01..c3818c2c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,8 @@ # Test binary, built with `go test -c` *.test +./.DS_Store +.DS_Store # Output of the go coverage tool, specifically when used with LiteIDE *.out .DS_Store diff --git a/db/schema.sql b/db/schema.sql index 26722f9d..84cc0e7b 100644 --- a/db/schema.sql +++ b/db/schema.sql @@ -23,12 +23,12 @@ DROP TABLE IF EXISTS `companies`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!50503 SET character_set_client = utf8mb4 */; CREATE TABLE `companies` ( - `id` int NOT NULL AUTO_INCREMENT, - `name` varchar(45) NOT NULL, - `description` varchar(45) DEFAULT NULL, - `domain` varchar(45) NOT NULL, - `email` varchar(45) NOT NULL, - PRIMARY KEY (`id`) + `id` int NOT NULL AUTO_INCREMENT, + `name` varchar(45) NOT NULL, + `description` varchar(45) DEFAULT NULL, + `domain` varchar(45) NOT NULL, + `email` varchar(45) NOT NULL, + PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -49,16 +49,16 @@ DROP TABLE IF EXISTS `employees`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!50503 SET character_set_client = utf8mb4 */; CREATE TABLE `employees` ( - `id` int NOT NULL AUTO_INCREMENT, - `name` varchar(45) NOT NULL, - `email` varchar(45) NOT NULL, - `phone` bigint DEFAULT NULL, - `designation` varchar(45) NOT NULL, - `yoe` int NOT NULL DEFAULT '0', - `company_id` int DEFAULT NULL, - PRIMARY KEY (`id`), - KEY `comapny_id_idx` (`company_id`), - CONSTRAINT `company_id` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`) + `id` int NOT NULL AUTO_INCREMENT, + `name` varchar(45) NOT NULL, + `email` varchar(45) NOT NULL, + `phone` bigint DEFAULT NULL, + `designation` varchar(45) NOT NULL, + `yoe` int NOT NULL DEFAULT '0', + `company_id` int DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `comapny_id_idx` (`company_id`), + CONSTRAINT `company_id` FOREIGN KEY (`company_id`) REFERENCES `companies` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -79,9 +79,9 @@ DROP TABLE IF EXISTS `skills`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!50503 SET character_set_client = utf8mb4 */; CREATE TABLE `skills` ( - `id` int NOT NULL AUTO_INCREMENT, - `name` varchar(45) NOT NULL, - PRIMARY KEY (`id`) + `id` int NOT NULL AUTO_INCREMENT, + `name` varchar(45) NOT NULL, + PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -102,12 +102,12 @@ DROP TABLE IF EXISTS `skillsEmployees`; /*!40101 SET @saved_cs_client = @@character_set_client */; /*!50503 SET character_set_client = utf8mb4 */; CREATE TABLE `skillsEmployees` ( - `employee_id` int NOT NULL, - `skill_id` int NOT NULL, - PRIMARY KEY (`employee_id`,`skill_id`), - KEY `skill_id_idx` (`skill_id`), - CONSTRAINT `emp_skill_id` FOREIGN KEY (`skill_id`) REFERENCES `skills` (`id`), - CONSTRAINT `employee_id` FOREIGN KEY (`employee_id`) REFERENCES `employees` (`id`) + `employee_id` int NOT NULL, + `skill_id` int NOT NULL, + PRIMARY KEY (`employee_id`,`skill_id`), + KEY `skill_id_idx` (`skill_id`), + CONSTRAINT `employee_id` FOREIGN KEY (`employee_id`) REFERENCES `employees` (`id`), + CONSTRAINT `emp_skill_id` FOREIGN KEY (`skill_id`) REFERENCES `skills` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; /*!40101 SET character_set_client = @saved_cs_client */; @@ -129,4 +129,148 @@ UNLOCK TABLES; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2021-02-15 13:50:54 +-- Dump completed on 2021-02-12 16:03:51 + +DROP TABLE IF EXISTS `positions`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `positions` ( + `id` int NOT NULL AUTO_INCREMENT, + `noOfOpenings` int NOT NULL, + `description` varchar(45) NOT NULL, + `location` varchar(45) NOT NULL, + `currentNoOfOpenings` int NOT NULL, + `startDate` datetime NOT NULL, + `endDate` datetime NOT NULL, + `status` tinyint NOT NULL, + `title` varchar(45) NOT NULL, + `postDate` datetime NOT NULL, + `experience` float NOT NULL, + `companyId` int NOT NULL, + `pid` varchar(45) NOT NULL, + `is_deleted` datetime DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `id_idx` (`companyId`), + CONSTRAINT `id` FOREIGN KEY (`companyId`) REFERENCES `companies` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `positions` +-- + +LOCK TABLES `positions` WRITE; +/*!40000 ALTER TABLE `positions` DISABLE KEYS */; +/*!40000 ALTER TABLE `positions` ENABLE KEYS */; +UNLOCK TABLES; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!50503 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!50503 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `candidates` +-- + +DROP TABLE IF EXISTS `candidates`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `candidates` ( + `id` int NOT NULL AUTO_INCREMENT, + `name` varchar(45) NOT NULL, + `email` varchar(45) NOT NULL, + `phone` bigint NOT NULL, + `college_name` varchar(45) DEFAULT NULL, + `experience` float DEFAULT NULL, + `resume` varchar(60) NOT NULL, + `skills` int DEFAULT NULL, + `gender` varchar(10) NOT NULL, + `bio` varchar(45) DEFAULT NULL, + `dob` datetime NOT NULL, + `github` varchar(60) DEFAULT 'no Link', + `linkedin` varchar(60) DEFAULT 'no Link', + `others` varchar(100) DEFAULT 'no Links', + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + + + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!50503 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `candidates_skills` +-- + +DROP TABLE IF EXISTS `candidates_skills`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `candidates_skills` ( + `candidate_id` int NOT NULL, + `skill_id` int NOT NULL, + PRIMARY KEY (`candidate_id`,`skill_id`), + KEY `skill_id_idx` (`skill_id`), + CONSTRAINT `candidate_id` FOREIGN KEY (`candidate_id`) REFERENCES `candidates` (`id`), + CONSTRAINT `candidate_skill_id` FOREIGN KEY (`skill_id`) REFERENCES `skills` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2021-02-15 11:38:30 + diff --git a/panel/.DS_Store b/panel/.DS_Store deleted file mode 100644 index 597f1e1a..00000000 Binary files a/panel/.DS_Store and /dev/null differ diff --git a/panel/http/coverage.txt b/panel/http/coverage.txt index 1d092cb2..21ef1b5f 100644 --- a/panel/http/coverage.txt +++ b/panel/http/coverage.txt @@ -8,26 +8,30 @@ github.com/zopsmart/hiring-portal-api/panel/http/http.go:24.16,26.3 1 1 github.com/zopsmart/hiring-portal-api/panel/http/http.go:29.16,31.3 1 1 github.com/zopsmart/hiring-portal-api/panel/http/http.go:33.16,35.3 1 1 github.com/zopsmart/hiring-portal-api/panel/http/http.go:39.73,41.16 2 0 -github.com/zopsmart/hiring-portal-api/panel/http/http.go:45.2,46.16 2 0 -github.com/zopsmart/hiring-portal-api/panel/http/http.go:50.2,50.17 1 0 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:45.2,48.16 4 0 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:51.2,52.16 2 0 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:55.2,66.16 4 0 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:70.2,70.17 1 0 github.com/zopsmart/hiring-portal-api/panel/http/http.go:41.16,43.3 1 0 -github.com/zopsmart/hiring-portal-api/panel/http/http.go:46.16,48.3 1 0 -github.com/zopsmart/hiring-portal-api/panel/http/http.go:53.74,55.16 2 1 -github.com/zopsmart/hiring-portal-api/panel/http/http.go:58.2,59.16 2 1 -github.com/zopsmart/hiring-portal-api/panel/http/http.go:62.2,64.16 3 1 -github.com/zopsmart/hiring-portal-api/panel/http/http.go:67.2,67.17 1 1 -github.com/zopsmart/hiring-portal-api/panel/http/http.go:55.16,57.3 1 1 -github.com/zopsmart/hiring-portal-api/panel/http/http.go:59.16,61.3 1 1 -github.com/zopsmart/hiring-portal-api/panel/http/http.go:64.16,66.3 1 1 -github.com/zopsmart/hiring-portal-api/panel/http/http.go:70.71,72.16 2 1 -github.com/zopsmart/hiring-portal-api/panel/http/http.go:75.2,76.16 2 1 -github.com/zopsmart/hiring-portal-api/panel/http/http.go:79.2,82.16 4 1 -github.com/zopsmart/hiring-portal-api/panel/http/http.go:85.2,85.17 1 1 -github.com/zopsmart/hiring-portal-api/panel/http/http.go:72.16,74.3 1 1 -github.com/zopsmart/hiring-portal-api/panel/http/http.go:76.16,78.3 1 1 -github.com/zopsmart/hiring-portal-api/panel/http/http.go:82.16,84.3 1 1 -github.com/zopsmart/hiring-portal-api/panel/http/http.go:88.73,90.16 2 0 -github.com/zopsmart/hiring-portal-api/panel/http/http.go:93.2,94.16 2 0 -github.com/zopsmart/hiring-portal-api/panel/http/http.go:97.2,97.64 1 0 -github.com/zopsmart/hiring-portal-api/panel/http/http.go:90.16,92.3 1 0 -github.com/zopsmart/hiring-portal-api/panel/http/http.go:94.16,96.3 1 0 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:48.16,50.3 1 0 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:52.16,54.3 1 0 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:66.16,68.3 1 0 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:73.74,75.16 2 1 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:78.2,79.16 2 1 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:82.2,84.16 3 1 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:87.2,87.17 1 1 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:75.16,77.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:79.16,81.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:84.16,86.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:90.71,92.16 2 1 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:95.2,96.16 2 1 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:99.2,102.16 4 1 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:105.2,105.17 1 1 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:92.16,94.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:96.16,98.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:102.16,104.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:108.73,110.16 2 0 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:113.2,114.16 2 0 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:117.2,117.64 1 0 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:110.16,112.3 1 0 +github.com/zopsmart/hiring-portal-api/panel/http/http.go:114.16,116.3 1 0 diff --git a/panel/http/http.go b/panel/http/http.go index 66dde8f3..c0b1155a 100644 --- a/panel/http/http.go +++ b/panel/http/http.go @@ -7,7 +7,7 @@ import ( "github.com/zopsmart/hiring-portal-api/panel/models" "github.com/vikash/gofr/pkg/gofr" - customError "github.com/zopsmart/hiring-portal-api/panel/error" + customerror "github.com/zopsmart/hiring-portal-api/panel/error" "github.com/zopsmart/hiring-portal-api/panel/service" ) @@ -22,12 +22,12 @@ func New(service service.PanelEmployee) PanelHTTP { func (p PanelHTTP) CreateEmployee(c *gofr.Context) (interface{}, error) { companyID, err := strconv.Atoi(c.Request.PathParam("companyID")) if err != nil { - return models.Employee{}, customError.ErrInvalidCompanyID + return models.Employee{}, customerror.ErrInvalidCompanyID } var emp models.Employee err = c.Request.Bind(&emp) if err != nil { - return models.Employee{}, customError.ErrJSONFormat + return models.Employee{}, customerror.ErrJSONFormat } res, err := p.service.CreateEmployee(c, companyID, &emp) if err != nil { @@ -39,10 +39,30 @@ func (p PanelHTTP) CreateEmployee(c *gofr.Context) (interface{}, error) { func (p PanelHTTP) GetAllEmployee(c *gofr.Context) (interface{}, error) { companyID, err := strconv.Atoi(c.Request.PathParam("companyID")) if err != nil { - return "Invalid CompanyID", customError.ErrInvalidCompanyID + return nil, customerror.ErrInvalidCompanyID } - res, err := p.service.GetAllEmployee(c, companyID) + yoe, _ := strconv.Atoi(c.Param("yoe")) + designation := c.Param("designation") + page, err := strconv.Atoi(c.Param("page")) + if err != nil { + page = 1 + } + limit, err := strconv.Atoi(c.Param("limit")) + if err != nil { + limit = 20 + } + skills := []string{} + + queryParams := map[string]interface{}{ + "yoe": yoe, + "designation": designation, + "page": (page - 1) * limit, + "limit": limit, + "skills": skills, + } + + res, err := p.service.GetAllEmployee(c, companyID, queryParams) if err != nil { return nil, err } @@ -53,11 +73,11 @@ func (p PanelHTTP) GetAllEmployee(c *gofr.Context) (interface{}, error) { func (p PanelHTTP) GetEmployeeByID(c *gofr.Context) (interface{}, error) { companyID, err := strconv.Atoi(c.Request.PathParam("companyID")) if err != nil { - return models.Employee{}, customError.ErrInvalidCompanyID + return models.Employee{}, customerror.ErrInvalidCompanyID } employeeID, err := strconv.Atoi(c.Request.PathParam("employeeID")) if err != nil { - return models.Employee{}, customError.ErrInvalidEmployeeID + return models.Employee{}, customerror.ErrInvalidEmployeeID } fmt.Println(companyID, employeeID) res, err := p.service.GetEmployeeByID(c, companyID, employeeID) @@ -70,11 +90,11 @@ func (p PanelHTTP) GetEmployeeByID(c *gofr.Context) (interface{}, error) { func (p PanelHTTP) EditEmployee(c *gofr.Context) (interface{}, error) { companyID, err := strconv.Atoi(c.Request.PathParam("companyID")) if err != nil { - return models.Employee{}, customError.ErrInvalidCompanyID + return models.Employee{}, customerror.ErrInvalidCompanyID } employeeID, err := strconv.Atoi(c.Request.PathParam("employeeID")) if err != nil { - return models.Employee{}, customError.ErrInvalidEmployeeID + return models.Employee{}, customerror.ErrInvalidEmployeeID } var data models.Employee c.Request.Bind(&data) @@ -88,11 +108,11 @@ func (p PanelHTTP) EditEmployee(c *gofr.Context) (interface{}, error) { func (p PanelHTTP) DeleteEmployee(c *gofr.Context) (interface{}, error) { companyID, err := strconv.Atoi(c.Request.PathParam("companyID")) if err != nil { - return nil, customError.ErrInvalidCompanyID + return nil, customerror.ErrInvalidCompanyID } employeeID, err := strconv.Atoi(c.Request.PathParam("employeeID")) if err != nil { - return nil, customError.ErrInvalidEmployeeID + return nil, customerror.ErrInvalidEmployeeID } return nil, p.service.DeleteEmployee(c, companyID, employeeID) diff --git a/panel/http/http_test.go b/panel/http/http_test.go index 774ee506..f77e4f48 100644 --- a/panel/http/http_test.go +++ b/panel/http/http_test.go @@ -233,7 +233,7 @@ func (m mockService) GetEmployeeByID(c *gofr.Context, companyID int, employeeID return models.Employee{}, customerror.ErrDBServer } -func (m mockService) GetAllEmployee(c *gofr.Context, companyID int) ([]models.Employee, error) { +func (m mockService) GetAllEmployee(c *gofr.Context, companyID int, queryParams map[string]interface{}) ([]models.Employee, error) { return []models.Employee(nil), customerror.ErrDBServer } diff --git a/panel/service/coverage.txt b/panel/service/coverage.txt index f40eed11..98d8f90f 100644 --- a/panel/service/coverage.txt +++ b/panel/service/coverage.txt @@ -1,27 +1,29 @@ mode: set github.com/zopsmart/hiring-portal-api/panel/service/service.go:14.43,16.2 1 1 -github.com/zopsmart/hiring-portal-api/panel/service/service.go:18.105,19.20 1 1 -github.com/zopsmart/hiring-portal-api/panel/service/service.go:22.2,22.45 1 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:18.140,19.20 1 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:22.2,22.37 1 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:25.2,25.72 1 1 github.com/zopsmart/hiring-portal-api/panel/service/service.go:19.20,21.3 1 1 -github.com/zopsmart/hiring-portal-api/panel/service/service.go:25.116,26.20 1 1 -github.com/zopsmart/hiring-portal-api/panel/service/service.go:29.2,29.21 1 1 -github.com/zopsmart/hiring-portal-api/panel/service/service.go:32.2,32.58 1 1 -github.com/zopsmart/hiring-portal-api/panel/service/service.go:26.20,28.3 1 1 -github.com/zopsmart/hiring-portal-api/panel/service/service.go:29.21,31.3 1 1 -github.com/zopsmart/hiring-portal-api/panel/service/service.go:35.125,36.20 1 1 -github.com/zopsmart/hiring-portal-api/panel/service/service.go:39.2,40.16 2 1 -github.com/zopsmart/hiring-portal-api/panel/service/service.go:43.2,45.18 3 1 -github.com/zopsmart/hiring-portal-api/panel/service/service.go:36.20,38.3 1 1 -github.com/zopsmart/hiring-portal-api/panel/service/service.go:40.16,42.3 1 1 -github.com/zopsmart/hiring-portal-api/panel/service/service.go:48.135,49.20 1 1 -github.com/zopsmart/hiring-portal-api/panel/service/service.go:52.2,52.21 1 1 -github.com/zopsmart/hiring-portal-api/panel/service/service.go:55.2,56.16 2 1 -github.com/zopsmart/hiring-portal-api/panel/service/service.go:59.2,61.18 3 1 -github.com/zopsmart/hiring-portal-api/panel/service/service.go:49.20,51.3 1 1 -github.com/zopsmart/hiring-portal-api/panel/service/service.go:52.21,54.3 1 1 -github.com/zopsmart/hiring-portal-api/panel/service/service.go:56.16,58.3 1 1 -github.com/zopsmart/hiring-portal-api/panel/service/service.go:64.96,65.20 1 1 -github.com/zopsmart/hiring-portal-api/panel/service/service.go:68.2,68.21 1 1 -github.com/zopsmart/hiring-portal-api/panel/service/service.go:71.2,71.57 1 1 -github.com/zopsmart/hiring-portal-api/panel/service/service.go:65.20,67.3 1 1 -github.com/zopsmart/hiring-portal-api/panel/service/service.go:68.21,70.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:22.37,24.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:28.116,29.20 1 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:32.2,32.21 1 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:35.2,35.58 1 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:29.20,31.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:32.21,34.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:38.125,39.20 1 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:42.2,43.16 2 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:46.2,48.18 3 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:39.20,41.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:43.16,45.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:51.135,52.20 1 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:55.2,55.21 1 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:58.2,59.16 2 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:62.2,64.18 3 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:52.20,54.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:55.21,57.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:59.16,61.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:67.96,68.20 1 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:71.2,71.21 1 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:74.2,74.57 1 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:68.20,70.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/service/service.go:71.21,73.3 1 1 diff --git a/panel/service/interface.go b/panel/service/interface.go index 191cfc33..a9c88e09 100644 --- a/panel/service/interface.go +++ b/panel/service/interface.go @@ -6,7 +6,7 @@ import ( ) type PanelEmployee interface { - GetAllEmployee(*gofr.Context, int) ([]models.Employee, error) + GetAllEmployee(*gofr.Context, int, map[string]interface{}) ([]models.Employee, error) GetEmployeeByID(*gofr.Context, int, int) (models.Employee, error) CreateEmployee(*gofr.Context, int, *models.Employee) (models.Employee, error) EditEmployee(*gofr.Context, int, int, *models.Employee) (models.Employee, error) diff --git a/panel/service/service.go b/panel/service/service.go index 08656e70..c58fc560 100644 --- a/panel/service/service.go +++ b/panel/service/service.go @@ -7,22 +7,25 @@ import ( "github.com/zopsmart/hiring-portal-api/panel/store" ) -type PanelEmployeeService struct { +type panelEmployeeService struct { store store.Panel } func New(store store.Panel) PanelEmployee { - return PanelEmployeeService{store: store} + return panelEmployeeService{store: store} } -func (p PanelEmployeeService) GetAllEmployee(c *gofr.Context, companyID int) ([]models.Employee, error) { +func (p panelEmployeeService) GetAllEmployee(c *gofr.Context, companyID int, queryParam map[string]interface{}) ([]models.Employee, error) { if companyID <= 0 { return nil, customError.ErrInvalidCompanyID } - return p.store.GetAllEmployee(c, companyID) + if queryParam["designation"] == "" { + return p.store.GetAllEmployeeWithoutDesignation(c, companyID, queryParam) + } + return p.store.GetAllEmployeeWithDesignation(c, companyID, queryParam) } -func (p PanelEmployeeService) GetEmployeeByID(c *gofr.Context, companyID, employeeID int) (models.Employee, error) { +func (p panelEmployeeService) GetEmployeeByID(c *gofr.Context, companyID, employeeID int) (models.Employee, error) { if companyID <= 0 { return models.Employee{}, customError.ErrInvalidCompanyID } @@ -32,7 +35,7 @@ func (p PanelEmployeeService) GetEmployeeByID(c *gofr.Context, companyID, employ return p.store.GetEmployeeByID(c, companyID, employeeID) } -func (p PanelEmployeeService) CreateEmployee(c *gofr.Context, companyID int, emp *models.Employee) (models.Employee, error) { +func (p panelEmployeeService) CreateEmployee(c *gofr.Context, companyID int, emp *models.Employee) (models.Employee, error) { if companyID <= 0 { return models.Employee{}, customError.ErrInvalidCompanyID } @@ -45,7 +48,7 @@ func (p PanelEmployeeService) CreateEmployee(c *gofr.Context, companyID int, emp return *emp, nil } -func (p PanelEmployeeService) EditEmployee(c *gofr.Context, companyID, employeeID int, emp *models.Employee) (models.Employee, error) { +func (p panelEmployeeService) EditEmployee(c *gofr.Context, companyID, employeeID int, emp *models.Employee) (models.Employee, error) { if companyID <= 0 { return models.Employee{}, customError.ErrInvalidCompanyID } @@ -61,7 +64,7 @@ func (p PanelEmployeeService) EditEmployee(c *gofr.Context, companyID, employeeI return *emp, nil } -func (p PanelEmployeeService) DeleteEmployee(c *gofr.Context, companyID, employeeID int) error { +func (p panelEmployeeService) DeleteEmployee(c *gofr.Context, companyID, employeeID int) error { if companyID <= 0 { return customError.ErrInvalidCompanyID } diff --git a/panel/service/service_test.go b/panel/service/service_test.go index 60c91ea2..b49b65ef 100644 --- a/panel/service/service_test.go +++ b/panel/service/service_test.go @@ -7,7 +7,7 @@ import ( "github.com/DATA-DOG/go-sqlmock" "github.com/vikash/gofr/pkg/gofr" "github.com/vikash/gofr/pkg/gofr/logging" - customError "github.com/zopsmart/hiring-portal-api/panel/error" + customerror "github.com/zopsmart/hiring-portal-api/panel/error" "github.com/zopsmart/hiring-portal-api/panel/models" ) @@ -41,6 +41,7 @@ func testAllEmployeeService(t *testing.T, c *gofr.Context) { input int expectedOutput []models.Employee expectedErr error + queryParams map[string]interface{} }{ { input: 1, @@ -48,21 +49,53 @@ func testAllEmployeeService(t *testing.T, c *gofr.Context) { {2, "Bittu Ray", "bitturay@gmail.com", 7250073080, "sde2", 2, 1}, }, expectedErr: nil, + queryParams: map[string]interface{}{ + "yoe": 1, + "designation": "sde", + "page": 0, + "limit": 10, + "skills": []string{}, + }, }, { input: -1, expectedOutput: []models.Employee(nil), - expectedErr: customError.ErrInvalidCompanyID, + expectedErr: customerror.ErrInvalidCompanyID, + queryParams: map[string]interface{}{ + "yoe": 1, + "designation": "sde", + "page": 0, + "limit": 10, + "skills": []string{}, + }, }, { input: 2, - expectedErr: customError.ErrDBServer, + expectedErr: customerror.ErrDBServer, + queryParams: map[string]interface{}{ + "yoe": 1, + "designation": "sde", + "page": 0, + "limit": 10, + "skills": []string{}, + }, + }, + { + input: 2, + expectedErr: customerror.ErrDBServer, + queryParams: map[string]interface{}{ + "yoe": 1, + "designation": "", + "page": 0, + "limit": 10, + "skills": []string{}, + }, }, } for i := range testCases { dataService := New(mockStore{}) - output, err := dataService.GetAllEmployee(c, testCases[i].input) + output, err := dataService.GetAllEmployee(c, testCases[i].input, testCases[i].queryParams) CheckErrOutput(t, testCases[i].expectedErr, err, testCases[i].expectedOutput, output) } } @@ -85,18 +118,18 @@ func testEmployeeByIDService(t *testing.T, c *gofr.Context) { { input: inputData{1, -1}, expectedOutput: models.Employee{}, - expectedErr: customError.ErrInvalidCompanyID, + expectedErr: customerror.ErrInvalidCompanyID, }, { input: inputData{-2, 2}, expectedOutput: models.Employee{}, - expectedErr: customError.ErrInvalidEmployeeID, + expectedErr: customerror.ErrInvalidEmployeeID, }, { input: inputData{4, 3}, expectedOutput: models.Employee{}, - expectedErr: customError.ErrRecordNotFound, + expectedErr: customerror.ErrRecordNotFound, }, } @@ -129,13 +162,13 @@ func testCreateEmployeeService(t *testing.T, c *gofr.Context) { { input: InputData{-1, models.Employee{1, "Bittu", "bittu@gmail.com", 7250073079, "sde1", 2, 1}}, expectedOutput: models.Employee{}, - expectedErr: customError.ErrInvalidCompanyID, + expectedErr: customerror.ErrInvalidCompanyID, }, { input: InputData{1, models.Employee{1, "Bittu", "bittu@gmail.com", 7250073079, "sde1", 2, 2}}, expectedOutput: models.Employee{}, - expectedErr: customError.ErrDBServer, + expectedErr: customerror.ErrDBServer, }, } @@ -168,18 +201,18 @@ func testEditEmployeeService(t *testing.T, c *gofr.Context) { { input: InputData{-1, 2, models.Employee{1, "Bittu", "bittu@gmail.com", 7250073079, "sde1", 2, 1}}, expectedOutput: models.Employee{}, - expectedErr: customError.ErrInvalidCompanyID, + expectedErr: customerror.ErrInvalidCompanyID, }, { input: InputData{1, -1, models.Employee{1, "Bittu", "bittu@gmail.com", 7250073079, "sde1", 2, 2}}, expectedOutput: models.Employee{}, - expectedErr: customError.ErrInvalidEmployeeID, + expectedErr: customerror.ErrInvalidEmployeeID, }, { input: InputData{1, 2, models.Employee{1, "Bittu", "bittu@gmail.com", 7250073079, "sde1", 2, 2}}, expectedOutput: models.Employee{}, - expectedErr: customError.ErrDBServer, + expectedErr: customerror.ErrDBServer, }, } @@ -210,16 +243,16 @@ func testDeleteEmployeeService(t *testing.T, c *gofr.Context) { { input: InputData{-1, 2}, - expectedErr: customError.ErrInvalidCompanyID, + expectedErr: customerror.ErrInvalidCompanyID, }, { input: InputData{1, -1}, - expectedErr: customError.ErrInvalidEmployeeID, + expectedErr: customerror.ErrInvalidEmployeeID, }, { input: InputData{1, 2}, - expectedErr: customError.ErrDBServer, + expectedErr: customerror.ErrDBServer, }, } @@ -235,9 +268,21 @@ func testDeleteEmployeeService(t *testing.T, c *gofr.Context) { type mockStore struct { } -func (m mockStore) GetAllEmployee(c *gofr.Context, companyID int) ([]models.Employee, error) { +func (m mockStore) GetAllEmployeeWithDesignation(c *gofr.Context, companyID int, queryParams map[string]interface{}) ([]models.Employee, error) { + if companyID == 2 { + return nil, customerror.ErrDBServer + } + + res := []models.Employee{{1, "Bittu", "bittu@gmail.com", 7250073079, "sde1", 2, 1}, + {2, "Bittu Ray", "bitturay@gmail.com", 7250073080, "sde2", 2, 1}, + } + + return res, nil +} + +func (m mockStore) GetAllEmployeeWithoutDesignation(c *gofr.Context, companyID int, queryParams map[string]interface{}) ([]models.Employee, error) { if companyID == 2 { - return nil, customError.ErrDBServer + return nil, customerror.ErrDBServer } res := []models.Employee{{1, "Bittu", "bittu@gmail.com", 7250073079, "sde1", 2, 1}, @@ -252,7 +297,7 @@ func (m mockStore) GetEmployeeByID(c *gofr.Context, companyID, employeeID int) ( return models.Employee{1, "Bittu", "bittu@gmail.com", 7250073079, "sde1", 2, 1}, nil } if companyID != employeeID { - return models.Employee{}, customError.ErrRecordNotFound + return models.Employee{}, customerror.ErrRecordNotFound } return models.Employee{}, nil @@ -261,21 +306,21 @@ func (m mockStore) GetEmployeeByID(c *gofr.Context, companyID, employeeID int) ( func (m mockStore) CreateEmployee(c *gofr.Context, companyID int, emp *models.Employee) (int, error) { if companyID != emp.CompanyID { - return -1, customError.ErrDBServer + return -1, customerror.ErrDBServer } return companyID, nil } func (m mockStore) EditEmployee(c *gofr.Context, companyID, employeeID int, emp *models.Employee) (int, error) { if companyID != emp.CompanyID || employeeID != emp.ID { - return -1, customError.ErrDBServer + return -1, customerror.ErrDBServer } return companyID, nil } func (m mockStore) DeleteEmployee(c *gofr.Context, companyID, employeeID int) error { if companyID != employeeID { - return customError.ErrDBServer + return customerror.ErrDBServer } return nil } diff --git a/panel/store/coverage.txt b/panel/store/coverage.txt index fc22581a..fc4fed50 100644 --- a/panel/store/coverage.txt +++ b/panel/store/coverage.txt @@ -1,6 +1,6 @@ mode: set github.com/zopsmart/hiring-portal-api/panel/store/store.go:11.18,13.2 1 1 -github.com/zopsmart/hiring-portal-api/panel/store/store.go:15.95,20.16 5 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:15.146,20.16 5 1 github.com/zopsmart/hiring-portal-api/panel/store/store.go:23.2,25.18 3 1 github.com/zopsmart/hiring-portal-api/panel/store/store.go:32.2,32.19 1 1 github.com/zopsmart/hiring-portal-api/panel/store/store.go:35.2,35.17 1 1 @@ -9,26 +9,35 @@ github.com/zopsmart/hiring-portal-api/panel/store/store.go:25.18,27.109 2 1 github.com/zopsmart/hiring-portal-api/panel/store/store.go:30.3,30.23 1 1 github.com/zopsmart/hiring-portal-api/panel/store/store.go:27.109,29.4 1 1 github.com/zopsmart/hiring-portal-api/panel/store/store.go:32.19,34.3 1 1 -github.com/zopsmart/hiring-portal-api/panel/store/store.go:38.106,43.16 5 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:38.149,43.16 5 1 github.com/zopsmart/hiring-portal-api/panel/store/store.go:46.2,48.18 3 1 -github.com/zopsmart/hiring-portal-api/panel/store/store.go:53.2,53.17 1 1 -github.com/zopsmart/hiring-portal-api/panel/store/store.go:57.2,57.17 1 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:55.2,55.19 1 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:58.2,58.17 1 1 github.com/zopsmart/hiring-portal-api/panel/store/store.go:43.16,45.3 1 1 -github.com/zopsmart/hiring-portal-api/panel/store/store.go:48.18,49.123 1 1 -github.com/zopsmart/hiring-portal-api/panel/store/store.go:49.123,51.4 1 1 -github.com/zopsmart/hiring-portal-api/panel/store/store.go:53.17,56.3 1 1 -github.com/zopsmart/hiring-portal-api/panel/store/store.go:60.103,65.16 5 1 -github.com/zopsmart/hiring-portal-api/panel/store/store.go:68.2,69.14 2 1 -github.com/zopsmart/hiring-portal-api/panel/store/store.go:72.2,72.21 1 1 -github.com/zopsmart/hiring-portal-api/panel/store/store.go:65.16,67.3 1 1 -github.com/zopsmart/hiring-portal-api/panel/store/store.go:69.14,71.3 1 1 -github.com/zopsmart/hiring-portal-api/panel/store/store.go:75.113,80.16 5 1 -github.com/zopsmart/hiring-portal-api/panel/store/store.go:83.2,84.13 2 1 -github.com/zopsmart/hiring-portal-api/panel/store/store.go:87.2,87.21 1 1 -github.com/zopsmart/hiring-portal-api/panel/store/store.go:80.16,82.3 1 1 -github.com/zopsmart/hiring-portal-api/panel/store/store.go:84.13,86.3 1 1 -github.com/zopsmart/hiring-portal-api/panel/store/store.go:90.86,94.16 4 1 -github.com/zopsmart/hiring-portal-api/panel/store/store.go:98.2,99.12 2 1 -github.com/zopsmart/hiring-portal-api/panel/store/store.go:103.2,103.12 1 1 -github.com/zopsmart/hiring-portal-api/panel/store/store.go:94.16,97.3 1 1 -github.com/zopsmart/hiring-portal-api/panel/store/store.go:99.12,102.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:48.18,50.109 2 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:53.3,53.23 1 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:50.109,52.4 1 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:55.19,57.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:61.106,66.16 5 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:69.2,71.18 3 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:76.2,76.17 1 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:80.2,80.17 1 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:66.16,68.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:71.18,72.123 1 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:72.123,74.4 1 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:76.17,79.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:83.103,88.16 5 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:91.2,92.14 2 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:95.2,95.21 1 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:88.16,90.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:92.14,94.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:98.113,103.16 5 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:106.2,107.13 2 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:110.2,110.21 1 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:103.16,105.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:107.13,109.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:113.86,117.16 4 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:121.2,122.12 2 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:126.2,126.12 1 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:117.16,120.3 1 1 +github.com/zopsmart/hiring-portal-api/panel/store/store.go:122.12,125.3 1 1 diff --git a/panel/store/interface.go b/panel/store/interface.go index 8e2ba0be..124d7404 100644 --- a/panel/store/interface.go +++ b/panel/store/interface.go @@ -6,7 +6,8 @@ import ( ) type Panel interface { - GetAllEmployee(*gofr.Context, int) ([]models.Employee, error) + GetAllEmployeeWithDesignation(*gofr.Context, int, map[string]interface{}) ([]models.Employee, error) + GetAllEmployeeWithoutDesignation(*gofr.Context, int, map[string]interface{}) ([]models.Employee, error) GetEmployeeByID(*gofr.Context, int, int) (models.Employee, error) CreateEmployee(*gofr.Context, int, *models.Employee) (int, error) EditEmployee(*gofr.Context, int, int, *models.Employee) (int, error) diff --git a/panel/store/store.go b/panel/store/store.go index 21c8529f..a42840fb 100644 --- a/panel/store/store.go +++ b/panel/store/store.go @@ -2,103 +2,126 @@ package store import ( "github.com/vikash/gofr/pkg/gofr" - customError "github.com/zopsmart/hiring-portal-api/panel/error" + customerror "github.com/zopsmart/hiring-portal-api/panel/error" "github.com/zopsmart/hiring-portal-api/panel/models" ) -type PanelStore struct{} +type panelStore struct{} func New() Panel { - return PanelStore{} + return panelStore{} } -func (p PanelStore) GetAllEmployee(c *gofr.Context, companyID int) ([]models.Employee, error) { - const query = "select * from employee where company_id=? order by id, company_id asc" +func (p panelStore) GetAllEmployeeWithDesignation(c *gofr.Context, companyID int, queryParams map[string]interface{}) ([]models.Employee, error) { + const query = "select * from employees where company_id=? and designation=? and yoe>=? order by id desc limit ?,?" var inputInterface []interface{} - inputInterface = append(inputInterface, companyID) + inputInterface = append(inputInterface, companyID, queryParams["designation"], queryParams["yoe"], queryParams["page"], queryParams["limit"]) rows, err := c.DB.Query(query, inputInterface...) if err != nil { - return nil, customError.ErrDBServer + return nil, customerror.ErrDBServer } defer rows.Close() var res []models.Employee for rows.Next() { var e models.Employee if err := rows.Scan(&e.ID, &e.Name, &e.Email, &e.Phone, &e.Designation, &e.YOE, &e.CompanyID); err != nil { - return nil, customError.ErrDBServer + return nil, customerror.ErrDBServer } res = append(res, e) } if len(res) == 0 { - return res, customError.ErrRecordNotFound + return res, customerror.ErrRecordNotFound } return res, nil } -func (p PanelStore) GetEmployeeByID(c *gofr.Context, companyID, employeeID int) (models.Employee, error) { - const query = "select * from employee where company_id=? and id=?" +func (p panelStore) GetAllEmployeeWithoutDesignation(c *gofr.Context, companyID int, queryParams map[string]interface{}) ([]models.Employee, error) { + const query = "select * from employees where company_id=? and yoe>=? order by id desc limit ?,?" + var inputInterface []interface{} + inputInterface = append(inputInterface, companyID, queryParams["yoe"], queryParams["page"], queryParams["limit"]) + rows, err := c.DB.Query(query, inputInterface...) + if err != nil { + return nil, customerror.ErrDBServer + } + defer rows.Close() + var res []models.Employee + for rows.Next() { + var e models.Employee + if err := rows.Scan(&e.ID, &e.Name, &e.Email, &e.Phone, &e.Designation, &e.YOE, &e.CompanyID); err != nil { + return nil, customerror.ErrDBServer + } + res = append(res, e) + } + if len(res) == 0 { + return res, customerror.ErrRecordNotFound + } + return res, nil +} + +func (p panelStore) GetEmployeeByID(c *gofr.Context, companyID, employeeID int) (models.Employee, error) { + const query = "select * from employees where company_id=? and id=?" var inputInterface []interface{} inputInterface = append(inputInterface, companyID, employeeID) rows, err := c.DB.Query(query, inputInterface...) if err != nil { - return models.Employee{}, customError.ErrDBServer + return models.Employee{}, customerror.ErrDBServer } defer rows.Close() var res models.Employee for rows.Next() { if err := rows.Scan(&res.ID, &res.Name, &res.Email, &res.Phone, &res.Designation, &res.YOE, &res.CompanyID); err != nil { - return models.Employee{}, customError.ErrDBServer + return models.Employee{}, customerror.ErrDBServer } } if res.ID == 0 { //fmt.Println("res is ", res) - return res, customError.ErrRecordNotFound + return res, customerror.ErrRecordNotFound } return res, nil } -func (p PanelStore) CreateEmployee(c *gofr.Context, companyID int, emp *models.Employee) (int, error) { - const query = `insert into employee(name, email, phone, designation, yoe, company_id) values(?,?,?,?,?,?)` +func (p panelStore) CreateEmployee(c *gofr.Context, companyID int, emp *models.Employee) (int, error) { + const query = `insert into employees(name, email, phone, designation, yoe, company_id) values(?,?,?,?,?,?)` var inputInterface []interface{} inputInterface = append(inputInterface, emp.Name, emp.Email, emp.Phone, emp.Designation, emp.YOE, companyID) rows, err := c.DB.Exec(query, inputInterface...) if err != nil { - return -1, customError.ErrRecordNotFound + return -1, customerror.ErrRecordNotFound } id, _ := rows.LastInsertId() if id == -1 { - return -1, customError.ErrRecordNotFound + return -1, customerror.ErrRecordNotFound } return int(id), nil } -func (p PanelStore) EditEmployee(c *gofr.Context, companyID, employeeID int, emp *models.Employee) (int, error) { +func (p panelStore) EditEmployee(c *gofr.Context, companyID, employeeID int, emp *models.Employee) (int, error) { var inputInterface []interface{} - const query = "update employee set designation = ?, yoe = ?, phone = ? where company_id = ? and id = ?" + const query = "update employees set designation = ?, yoe = ?, phone = ? where company_id = ? and id = ?" inputInterface = append(inputInterface, emp.Designation, emp.YOE, emp.Phone, companyID, employeeID) row, err := c.DB.Exec(query, inputInterface...) if err != nil { - return -1, customError.ErrDBServer + return -1, customerror.ErrDBServer } - id, _ := row.RowsAffected() - if id == 0 { - return -1, customError.ErrRecordNotFound + r, _ := row.RowsAffected() + if r == 0 { + return -1, customerror.ErrRecordNotFound } - return int(id), nil + return int(r), nil } -func (p PanelStore) DeleteEmployee(c *gofr.Context, companyID, employeeID int) error { +func (p panelStore) DeleteEmployee(c *gofr.Context, companyID, employeeID int) error { var inputInterface []interface{} inputInterface = append(inputInterface, employeeID, companyID) - rows, err := c.DB.Exec("DELETE FROM employee WHERE id=? AND company_id=?", inputInterface...) + rows, err := c.DB.Exec("DELETE FROM employees WHERE id=? AND company_id=?", inputInterface...) if err != nil { // Happens in connection loose or if the query is wrong. - return customError.ErrDBServer + return customerror.ErrDBServer } r, _ := rows.RowsAffected() if r == 0 { // Some issue while deleting record. - return customError.ErrRecordNotFound + return customerror.ErrRecordNotFound } return err } diff --git a/panel/store/store_test.go b/panel/store/store_test.go index e0a29ddc..fc51dd44 100644 --- a/panel/store/store_test.go +++ b/panel/store/store_test.go @@ -6,7 +6,7 @@ import ( "regexp" "testing" - customError "github.com/zopsmart/hiring-portal-api/panel/error" + customerror "github.com/zopsmart/hiring-portal-api/panel/error" "github.com/zopsmart/hiring-portal-api/panel/models" @@ -26,7 +26,7 @@ func CheckErrOutput(t *testing.T, expectedErr, actualErr, expectedOutput, actual } } -func TestGetAllEmployeeMock(t *testing.T) { +func TestGetAllEmployeeWithDesignationMock(t *testing.T) { db, mock, err := sqlmock.New() if err != nil { fmt.Println(err) @@ -41,6 +41,7 @@ func TestGetAllEmployeeMock(t *testing.T) { input int expectedOutput []models.Employee expectedErr error + queryParams map[string]interface{} }{ { input: 1, @@ -49,23 +50,171 @@ func TestGetAllEmployeeMock(t *testing.T) { {2, "Bittu Ray", "bitturay@gmail.com", 7250073080, "sde2", 2, 1}, }, expectedErr: nil, + queryParams: map[string]interface{}{ + "yoe": 1, + "designation": "sde", + "page": 0, + "limit": 10, + "skills": []string{}, + }, + }, + + { + input: 2, + expectedOutput: []models.Employee(nil), + expectedErr: customerror.ErrDBServer, + queryParams: map[string]interface{}{ + "yoe": 1, + "designation": "sde", + "page": 0, + "limit": 10, + "skills": []string{}, + }, + }, + { + input: 3, + expectedOutput: []models.Employee(nil), + expectedErr: customerror.ErrRecordNotFound, + queryParams: map[string]interface{}{ + "yoe": 1, + "designation": "sde", + "page": 0, + "limit": 10, + "skills": []string{}, + }, + }, + + { + input: 4, + expectedOutput: []models.Employee(nil), + expectedErr: customerror.ErrDBServer, + queryParams: map[string]interface{}{ + "yoe": 1, + "designation": "sde", + "page": 0, + "limit": 10, + "skills": []string{}, + }, + }, + } + + for i := range testCases { + var output, err interface{} + + if i == 3 { + table := []string{"id", "name", "email", "phone", "designation", "yoe"} + query := "select * from employees where companyid=? and designation=? and yoe>=? order by id desc limit ?,?" + rows := sqlmock.NewRows(table) + for j := range testCases[i].expectedOutput { + rows.AddRow(testCases[i].expectedOutput[j].ID, testCases[i].expectedOutput[j].Name, + testCases[i].expectedOutput[j].Email, testCases[i].expectedOutput[j].Phone, + testCases[i].expectedOutput[j].Designation, testCases[i].expectedOutput[j].YOE, + testCases[i].expectedOutput[j].CompanyID) + } + + mock.ExpectQuery(regexp.QuoteMeta(query)).WithArgs(testCases[i].input, testCases[i].queryParams["designation"], testCases[i].queryParams["yoe"], testCases[i].queryParams["page"], testCases[i].queryParams["limit"]).WillReturnRows(rows) + output, err = dataStore.GetAllEmployeeWithDesignation(c, testCases[i].input, testCases[i].queryParams) + } else if i == 1 { + table := []string{"id", "name", "email", "phone", "designation", "company_id"} + query := "select * from employees where company_id=? and designation=? and yoe>=? order by id desc limit ?,?" + rows := sqlmock.NewRows(table) + + rows.AddRow(2, "Bittu Ray", "bitturay@gmail.com", 7250073080, "sde2", 2) + + mock.ExpectQuery(regexp.QuoteMeta(query)).WithArgs(testCases[i].input, testCases[i].queryParams["designation"], testCases[i].queryParams["yoe"], testCases[i].queryParams["page"], testCases[i].queryParams["limit"]).WillReturnRows(rows) + output, err = dataStore.GetAllEmployeeWithDesignation(c, testCases[i].input, testCases[i].queryParams) + } else { + table := []string{"id", "name", "email", "phone", "designation", "yoe", "company_id"} + query := "select * from employees where company_id=? and designation=? and yoe>=? order by id desc limit ?,?" + rows := sqlmock.NewRows(table) + for j := range testCases[i].expectedOutput { + rows.AddRow(testCases[i].expectedOutput[j].ID, testCases[i].expectedOutput[j].Name, + testCases[i].expectedOutput[j].Email, testCases[i].expectedOutput[j].Phone, + testCases[i].expectedOutput[j].Designation, testCases[i].expectedOutput[j].YOE, + testCases[i].expectedOutput[j].CompanyID) + } + + mock.ExpectQuery(regexp.QuoteMeta(query)).WithArgs(testCases[i].input, testCases[i].queryParams["designation"], testCases[i].queryParams["yoe"], testCases[i].queryParams["page"], testCases[i].queryParams["limit"]).WillReturnRows(rows) + output, err = dataStore.GetAllEmployeeWithDesignation(c, testCases[i].input, testCases[i].queryParams) + + if err := mock.ExpectationsWereMet(); err != nil { + t.Errorf("there were unfulfilled expectations: %s", err) + } + } + CheckErrOutput(t, testCases[i].expectedErr, err, testCases[i].expectedOutput, output) + } +} + +func TestGetAllEmployeeWithoutDesignationMock(t *testing.T) { + db, mock, err := sqlmock.New() + if err != nil { + fmt.Println(err) + } + c := &gofr.Context{Container: &gofr.Container{ + Logger: logging.NewLogger(logging.DEBUG), + DB: &gofr.DB{db}, + }} + + dataStore := New() + testCases := []struct { + input int + expectedOutput []models.Employee + expectedErr error + queryParams map[string]interface{} + }{ + { + input: 1, + expectedOutput: []models.Employee{ + {1, "Bittu", "bittu@gmail.com", 7250073079, "sde1", 2, 1}, + {2, "Bittu Ray", "bitturay@gmail.com", 7250073080, "sde2", 2, 1}, + }, + expectedErr: nil, + queryParams: map[string]interface{}{ + "yoe": 1, + "designation": "sde", + "page": 0, + "limit": 10, + "skills": []string{}, + }, }, { input: 2, expectedOutput: []models.Employee(nil), - expectedErr: customError.ErrDBServer, + expectedErr: customerror.ErrDBServer, + queryParams: map[string]interface{}{ + "yoe": 1, + "designation": "sde", + "page": 0, + "limit": 10, + "skills": []string{}, + }, }, { input: 3, expectedOutput: []models.Employee(nil), - expectedErr: customError.ErrRecordNotFound, + expectedErr: customerror.ErrRecordNotFound, + queryParams: map[string]interface{}{ + "yoe": 1, + "designation": "sde", + "page": 0, + "limit": 10, + "skills": []string{}, + }, }, { input: 4, expectedOutput: []models.Employee(nil), - expectedErr: customError.ErrDBServer, + + expectedErr: customerror.ErrDBServer, + queryParams: map[string]interface{}{ + "yoe": 1, + "designation": "sde", + "page": 0, + "limit": 10, + "skills": []string{}, + }, }, } @@ -74,7 +223,7 @@ func TestGetAllEmployeeMock(t *testing.T) { if i == 3 { table := []string{"id", "name", "email", "phone", "designation", "yoe"} - query := "select * from employee where companyd=? order by id, company_id asc" + query := "select * from employees where companyid=? and yoe>=? order by id desc limit ?,?" rows := sqlmock.NewRows(table) for j := range testCases[i].expectedOutput { rows.AddRow(testCases[i].expectedOutput[j].ID, testCases[i].expectedOutput[j].Name, @@ -83,20 +232,20 @@ func TestGetAllEmployeeMock(t *testing.T) { testCases[i].expectedOutput[j].CompanyID) } - mock.ExpectQuery(regexp.QuoteMeta(query)).WithArgs(testCases[i].input).WillReturnRows(rows) - output, err = dataStore.GetAllEmployee(c, testCases[i].input) + mock.ExpectQuery(regexp.QuoteMeta(query)).WithArgs(testCases[i].input, testCases[i].queryParams["yoe"], testCases[i].queryParams["page"], testCases[i].queryParams["limit"]).WillReturnRows(rows) + output, err = dataStore.GetAllEmployeeWithoutDesignation(c, testCases[i].input, testCases[i].queryParams) } else if i == 1 { table := []string{"id", "name", "email", "phone", "designation", "company_id"} - query := "select * from employee where company_id=? order by id, company_id asc" + query := "select * from employees where company_id=? and yoe>=? order by id desc limit ?,?" rows := sqlmock.NewRows(table) rows.AddRow(2, "Bittu Ray", "bitturay@gmail.com", 7250073080, "sde2", 2) - mock.ExpectQuery(regexp.QuoteMeta(query)).WithArgs(testCases[i].input).WillReturnRows(rows) - output, err = dataStore.GetAllEmployee(c, testCases[i].input) + mock.ExpectQuery(regexp.QuoteMeta(query)).WithArgs(testCases[i].input, testCases[i].queryParams["yoe"], testCases[i].queryParams["page"], testCases[i].queryParams["limit"]).WillReturnRows(rows) + output, err = dataStore.GetAllEmployeeWithoutDesignation(c, testCases[i].input, testCases[i].queryParams) } else { table := []string{"id", "name", "email", "phone", "designation", "yoe", "company_id"} - query := "select * from employee where company_id=? order by id, company_id asc" + query := "select * from employees where company_id=? and yoe>=? order by id desc limit ?,?" rows := sqlmock.NewRows(table) for j := range testCases[i].expectedOutput { rows.AddRow(testCases[i].expectedOutput[j].ID, testCases[i].expectedOutput[j].Name, @@ -105,8 +254,8 @@ func TestGetAllEmployeeMock(t *testing.T) { testCases[i].expectedOutput[j].CompanyID) } - mock.ExpectQuery(regexp.QuoteMeta(query)).WithArgs(testCases[i].input).WillReturnRows(rows) - output, err = dataStore.GetAllEmployee(c, testCases[i].input) + mock.ExpectQuery(regexp.QuoteMeta(query)).WithArgs(testCases[i].input, testCases[i].queryParams["yoe"], testCases[i].queryParams["page"], testCases[i].queryParams["limit"]).WillReturnRows(rows) + output, err = dataStore.GetAllEmployeeWithoutDesignation(c, testCases[i].input, testCases[i].queryParams) if err := mock.ExpectationsWereMet(); err != nil { t.Errorf("there were unfulfilled expectations: %s", err) @@ -146,18 +295,18 @@ func TestGetEmployeeByIDMock(t *testing.T) { { input: inputData{1, 1}, expectedOutput: models.Employee{}, - expectedErr: customError.ErrDBServer, + expectedErr: customerror.ErrDBServer, }, { input: inputData{2, 2}, expectedOutput: models.Employee{}, - expectedErr: customError.ErrRecordNotFound, + expectedErr: customerror.ErrRecordNotFound, }, { input: inputData{4, 3}, expectedOutput: models.Employee{}, - expectedErr: customError.ErrDBServer, + expectedErr: customerror.ErrDBServer, }, } @@ -165,7 +314,7 @@ func TestGetEmployeeByIDMock(t *testing.T) { var output, err interface{} if i == 1 { table := []string{"id", "name", "email", "phone", "designation", "company_id"} - query := "select * from employee where company_id=? and id=?" + query := "select * from employees where company_id=? and id=?" rows := sqlmock.NewRows(table) rows.AddRow(1, "Bittu Ray", "bitturay@gmail.com", 7250073080, "sde2", 1) mock.ExpectQuery(regexp.QuoteMeta(query)).WithArgs(testCases[i].input.companyID, testCases[i].input.empID). @@ -173,7 +322,7 @@ func TestGetEmployeeByIDMock(t *testing.T) { output, err = dataStore.GetEmployeeByID(c, testCases[i].input.companyID, testCases[i].input.empID) } else if i == 3 { table := []string{"id", "name", "email", "phone", "designation", "yoe", "company_id"} - query := "select * from employee where companyd=? and id=?" + query := "select * from employees where companyd=? and id=?" rows := sqlmock.NewRows(table). AddRow(testCases[i].expectedOutput.ID, testCases[i].expectedOutput.Name, testCases[i].expectedOutput.Email, testCases[i].expectedOutput.Phone, @@ -186,7 +335,7 @@ func TestGetEmployeeByIDMock(t *testing.T) { output, err = dataStore.GetEmployeeByID(c, testCases[i].input.companyID, testCases[i].input.empID) } else { table := []string{"id", "name", "email", "phone", "designation", "yoe", "company_id"} - query := "select * from employee where company_id=? and id=?" + query := "select * from employees where company_id=? and id=?" rows := sqlmock.NewRows(table). AddRow(testCases[i].expectedOutput.ID, testCases[i].expectedOutput.Name, testCases[i].expectedOutput.Email, testCases[i].expectedOutput.Phone, @@ -243,14 +392,14 @@ func TestCreateEmployeeMock(t *testing.T) { { input: inputData{5, models.Employee{3, "Bittu", "bittu@gmail.com", 7250073079, "sde1", 2, 4}}, expectedOutput: -1, - expectedErr: customError.ErrRecordNotFound, + expectedErr: customerror.ErrRecordNotFound, rowsAffected: 0, }, { input: inputData{10, models.Employee{3, "Bittu", "bittu@gmail.com", 7250073079, "sde1", 2, 4}}, expectedOutput: -1, - expectedErr: customError.ErrRecordNotFound, + expectedErr: customerror.ErrRecordNotFound, rowsAffected: 0, }, } @@ -258,14 +407,14 @@ func TestCreateEmployeeMock(t *testing.T) { for i := range testCases { var output, err interface{} if i == 3 { - query := "insert into employee(name, email, phone, designation, yoe, company_id) values(?,?,?,?,?)" + query := "insert into employees(name, email, phone, designation, yoe, company_id) values(?,?,?,?,?)" mock.ExpectExec(regexp.QuoteMeta(query)). WithArgs(testCases[i].input.body.Name, testCases[i].input.body.Email, testCases[i].input.body.Phone, testCases[i].input.body.Designation, testCases[i].input.body.YOE). WillReturnResult(sqlmock.NewResult(int64(testCases[i].expectedOutput), int64(testCases[i].rowsAffected))) output, err = dataStore.CreateEmployee(c, testCases[i].input.companyID, &testCases[i].input.body) } else { - query := "insert into employee(name, email, phone, designation, yoe, company_id) values(?,?,?,?,?,?)" + query := "insert into employees(name, email, phone, designation, yoe, company_id) values(?,?,?,?,?,?)" mock.ExpectExec(regexp.QuoteMeta(query)). WithArgs(testCases[i].input.body.Name, testCases[i].input.body.Email, testCases[i].input.body.Phone, testCases[i].input.body.Designation, @@ -321,13 +470,13 @@ func TestEditEmployeeMock(t *testing.T) { { input: inputData{10, 2, models.Employee{3, "Bittu", "bittu@gmail.com", 7250073079, "sde1", 2, 4}}, expectedOutput: -1, - expectedErr: customError.ErrRecordNotFound, + expectedErr: customerror.ErrRecordNotFound, rowsAffected: 0, }, { input: inputData{5, 1, models.Employee{}}, expectedOutput: -1, - expectedErr: customError.ErrDBServer, + expectedErr: customerror.ErrDBServer, rowsAffected: 0, }, } @@ -335,7 +484,7 @@ func TestEditEmployeeMock(t *testing.T) { for i := range testCases { var output, err interface{} if i == 3 { - query := "update employee set designtion = ?, yoe = ?, phone = ? where company_id = ? and id = ?" + query := "update employees set designtion = ?, yoe = ?, phone = ? where company_id = ? and id = ?" mock.ExpectExec(regexp.QuoteMeta(query)). WithArgs(testCases[i].input.body.Designation, testCases[i].input.body.YOE, testCases[i].input.body.Phone, @@ -344,7 +493,7 @@ func TestEditEmployeeMock(t *testing.T) { output, err = dataStore.EditEmployee(c, testCases[i].input.companyID, testCases[i].input.empID, &testCases[i].input.body) } else { - query := "update employee set designation = ?, yoe = ?, phone = ? where company_id = ? and id = ?" + query := "update employees set designation = ?, yoe = ?, phone = ? where company_id = ? and id = ?" mock.ExpectExec(regexp.QuoteMeta(query)). WithArgs(testCases[i].input.body.Designation, testCases[i].input.body.YOE, testCases[i].input.body.Phone, @@ -394,19 +543,19 @@ func TestDeleteEmployeeMock(t *testing.T) { { input: inputType{2, 3}, rowsAffected: 0, - expectedErr: customError.ErrRecordNotFound, + expectedErr: customerror.ErrRecordNotFound, }, // DBQuery cover fail: i = 2 { input: inputType{1, 1}, rowsAffected: 0, - expectedErr: customError.ErrDBServer, + expectedErr: customerror.ErrDBServer, }, } for i, val := range testCases { if i == 2 { - mock.ExpectExec(regexp.QuoteMeta("DELETE FROM employee WHERE id=? AND companyd=?")). + mock.ExpectExec(regexp.QuoteMeta("DELETE FROM employees WHERE id=? AND companyd=?")). WithArgs(val.input.id, val.input.companyId). WillReturnResult(sqlmock.NewResult(0, val.rowsAffected)) actualError := dataStore.DeleteEmployee(c, val.input.id, val.input.companyId) @@ -415,7 +564,7 @@ func TestDeleteEmployeeMock(t *testing.T) { t.Errorf("FAILED!! Expected value: %v Actual Output: %v\n", val.expectedErr, actualError) } } else { - mock.ExpectExec(regexp.QuoteMeta("DELETE FROM employee WHERE id=? AND company_id=?")). + mock.ExpectExec(regexp.QuoteMeta("DELETE FROM employees WHERE id=? AND company_id=?")). WithArgs(val.input.id, val.input.companyId). WillReturnResult(sqlmock.NewResult(0, val.rowsAffected)) actualError := dataStore.DeleteEmployee(c, val.input.companyId, val.input.id) diff --git a/swagger/.DS_Store b/swagger/.DS_Store deleted file mode 100644 index 5008ddfc..00000000 Binary files a/swagger/.DS_Store and /dev/null differ diff --git a/swagger/EmployeePanel.yaml b/swagger/EmployeePanel.yaml deleted file mode 100644 index 7d09a695..00000000 --- a/swagger/EmployeePanel.yaml +++ /dev/null @@ -1,211 +0,0 @@ -swagger: "2.0" -info: - description: "This is a sample `quizzing-HR` api specifications doc. These docs will be used during the interview and panel selection process." - version: "0.0.0" - title: "Hiring Portal API - #3EmployeePanel" - termsOfService: "http://zopsmart.com/terms/" - contact: - email: "ishan.pandey@zopsmart.com" - license: - name: "Apache 2.0" - url: "http://www.apache.org/licenses/LICENSE-2.0.html" -host: "quiz-hr.swagger.io" -basePath: "/v0" -tags: -- name: "panel-employee" - description: "Every operation about an employee belonging to a company" -schemes: -- "https" -- "http" - -paths: -#----------------------------------------------------------------------------------------------- - /employee/{companyID}: - get: - tags: - - "panel-employee" - summary: "Lists everything about an employee" - description: "..." - operationId: "allEmployeeInACompany" - produces: - - "application/json" - parameters: - - name: companyID - in: path - description: ID of company whose all employees need to be fetched. - required: true - type: integer - format: int64 - responses: - "200": - description: "sucessful operation" - schema: - type: "array" - items: - $ref: "#/definitions/Employee" - "500": - description: "Internal server error" - post: - tags: - - "panel-employee" - summary: "Creates a new employee in a company, and returns it's id." - operationId: "createNewEmployeeInACompany" - consumes: - - "application/json" - produces: - - "application/json" - parameters: - - name: companyID - in: path - description: ID of company inside which employee is to be created. - required: true - type: integer - format: int64 - - in: "body" - name: "data" - description: "Input employee data" - required: true - # Isme confirm for the schema, whether id will be input. - schema: - $ref: "#/definitions/Employee" - responses: - "200": - description: "sucessful operation" - # Confirm return schema. - schema: - $ref: "#/definitions/Employee" - "500": - description: "Internal server error" - - /employee/{companyID}/{employeeID}: - get: - tags: - - "panel-employee" - summary: "Lists everything about an employee" - description: "..." - operationId: "employeeInACompany" - produces: - - "application/json" - parameters: - - name: companyID - in: path - description: ID of company whose all employees need to be fetched. - required: true - type: integer - format: int64 - - name: employeeID - in: path - description: ID of employee whose details need to be fetched. - required: true - type: integer - format: int64 - responses: - "200": - description: "sucessful operation" - schema: - $ref: "#/definitions/Employee" - "500": - description: "Internal server error" - put: - tags: - - "panel-employee" - summary: "Edit details of an employee belonging to a company" - description: "" - operationId: "editEmployeeInACompany" - consumes: - - "application/json" - produces: - - "application/json" - parameters: - - name: companyID - in: path - description: ID of company whose employee details need to be edited. - required: true - type: integer - format: int64 - - name: employeeID - in: path - description: ID of employee whose details need to be edited/updated. - required: true - type: integer - format: int64 - - in: "body" - name: "body" - description: "Pet object that needs to be added to the store" - required: true - schema: - $ref: "#/definitions/Employee" - responses: - "200": - description: "sucessful operation" - schema: - $ref: "#/definitions/Employee" - "500": - description: "Internal server error" - - delete: - tags: - - "panel-employee" - summary: "Deletes an employee of a company" - description: "..." - operationId: "deleteEmployeeInACompany" - produces: - - "application/json" - parameters: - - name: companyID - in: path - description: ID of company whose employee needs to be deleted. - required: true - type: integer - format: int64 - - name: employeeID - in: path - description: ID of employee which is deleted. - required: true - type: integer - format: int64 - responses: - "200": - description: "sucessful operation" - "500": - description: "Internal server error" - -#----------------------------------------------------------------------------------------------- -definitions: - Employee: - type: "object" - properties: - id: - type: "integer" - format: "int64" - example: 1 - name: - type: "string" - example: "Itachi Uchiha" - email: - type: "string" - example: "xyz@zopsmart.com" - phone: - type: "integer" - format: "int64" - example: 9454323321 - designation: - type: "string" - example: "SDE-1" - # skills: - # type: "array" - # items: - # type: "string" - # example: "JAVA" - YOE: - type: "integer" - format: "int32" - example: 2 - companyID: - type: "integer" - format: "int64" - example: 1 - -externalDocs: - description: "Find out more about Quizzer-HR" - url: "https://docs.google.com/document/d/10Em-YRUfzJunVT37WyjJCYFuzpQ_cbI-ToScVQNcGiM/edit?ts=601b8c8a" \ No newline at end of file