Skip to content

Commit

Permalink
zopsmart#3 | added pagination and filter, only filter by skills remai…
Browse files Browse the repository at this point in the history
…ning
  • Loading branch information
raybittu committed Feb 15, 2021
1 parent 1b9b32b commit 52ae0ad
Show file tree
Hide file tree
Showing 11 changed files with 317 additions and 66 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file added panel.zip
Binary file not shown.
22 changes: 21 additions & 1 deletion panel/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,27 @@ func (p PanelHTTP) GetAllEmployee(c *gofr.Context) (interface{}, error) {
return "Invalid CompanyID", customeerror.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
}
Expand Down
50 changes: 26 additions & 24 deletions panel/service/coverage.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion panel/service/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions panel/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ func New(store store.Panel) PanelEmployee {
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, customeerror.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) {
Expand Down
49 changes: 47 additions & 2 deletions panel/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,61 @@ func testAllEmployeeService(t *testing.T, c *gofr.Context) {
input int
expectedOutput []models.Employee
expectedErr error
queryParams map[string]interface{}
}{
{
input: 1,
expectedOutput: []models.Employee{{1, "Bittu", "[email protected]", 7250073079, "sde1", 2, 1},
{2, "Bittu Ray", "[email protected]", 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: customeerror.ErrInvalidCompanyID,
queryParams: map[string]interface{}{
"yoe": 1,
"designation": "sde",
"page": 0,
"limit": 10,
"skills": []string{},
},
},
{
input: 2,
expectedErr: customeerror.ErrDBServer,
queryParams: map[string]interface{}{
"yoe": 1,
"designation": "sde",
"page": 0,
"limit": 10,
"skills": []string{},
},
},
{
input: 2,
expectedErr: customeerror.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)
}
}
Expand Down Expand Up @@ -235,7 +268,19 @@ 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, customeerror.ErrDBServer
}

res := []models.Employee{{1, "Bittu", "[email protected]", 7250073079, "sde1", 2, 1},
{2, "Bittu Ray", "[email protected]", 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, customeerror.ErrDBServer
}
Expand Down
53 changes: 31 additions & 22 deletions panel/store/coverage.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
3 changes: 2 additions & 1 deletion panel/store/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 26 additions & 3 deletions panel/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,33 @@ func New() Panel {
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 employee 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, customeerror.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, customeerror.ErrDBServer
}
res = append(res, e)
}
if len(res) == 0 {
return res, customeerror.ErrRecordNotFound
}
return res, nil
}

func (p PanelStore) GetAllEmployeeWithoutDesignation(c *gofr.Context, companyID int, queryParams map[string]interface{}) ([]models.Employee, error) {
const query = "select * from employee 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, customeerror.ErrDBServer
Expand Down
Loading

0 comments on commit 52ae0ad

Please sign in to comment.