forked from zopsmart/ezgo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request zopsmart#9 from zopsmart/3-EmployeePanel
3 employee panel - Create Employee Crud and tests
- Loading branch information
Showing
24 changed files
with
1,677 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
HTTP_PORT=8000 | ||
|
||
DB_HOST=localhost | ||
DB_USER=root | ||
DB_PASSWORD=password | ||
DB_NAME=hiring_portal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package errors | ||
|
||
type Error string | ||
|
||
const ErrDBServer Error = "something went wrong in server" | ||
const ErrRecordNotFound Error = "record not found in our database" | ||
const ErrJSONFormat Error = "json format not correct" | ||
|
||
func (e Error) Error() string { | ||
return string(e) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package errors | ||
|
||
import "fmt" | ||
|
||
type InvalidParam struct { | ||
Param string | ||
} | ||
|
||
func (i InvalidParam) Error() string { | ||
return fmt.Sprintf("%v is invalid", i.Param) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package errors | ||
|
||
import "fmt" | ||
|
||
type MissingParam struct { | ||
Param string | ||
} | ||
|
||
func (m MissingParam) Error() string { | ||
return fmt.Sprintf("%v is missing", m.Param) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,24 @@ | ||
package main | ||
|
||
import "github.com/vikash/gofr/pkg/gofr" | ||
import ( | ||
"github.com/vikash/gofr/pkg/gofr" | ||
"github.com/zopsmart/hiring-portal-api/panel/http" | ||
"github.com/zopsmart/hiring-portal-api/panel/service" | ||
"github.com/zopsmart/hiring-portal-api/panel/store" | ||
) | ||
|
||
func main() { | ||
app := gofr.New() | ||
|
||
dataStore := store.New() | ||
dataService := service.New(dataStore) | ||
dataHTTP := http.New(dataService) | ||
|
||
app.GET("/{companyID}/employees", dataHTTP.GetAllEmployee) | ||
app.GET("/{companyID}/employees/{employeeID}", dataHTTP.GetEmployeeByID) | ||
app.POST("/{companyID}/employees", dataHTTP.CreateEmployee) | ||
app.PUT("/{companyID}/employees/{employeeID}", dataHTTP.EditEmployee) | ||
app.DELETE("/{companyID}/employees/{employeeID}", dataHTTP.DeleteEmployee) | ||
|
||
app.Run() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
package http | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/vikash/gofr/pkg/gofr" | ||
"github.com/zopsmart/hiring-portal-api/errors" | ||
"github.com/zopsmart/hiring-portal-api/panel/models" | ||
"github.com/zopsmart/hiring-portal-api/panel/service" | ||
"github.com/zopsmart/hiring-portal-api/panel/utils" | ||
) | ||
|
||
type PanelHTTP struct { | ||
service service.PanelEmployee | ||
} | ||
|
||
func New(s service.PanelEmployee) PanelHTTP { | ||
return PanelHTTP{service: s} | ||
} | ||
|
||
func (p PanelHTTP) CreateEmployee(c *gofr.Context) (interface{}, error) { | ||
companyID, err := strconv.Atoi(c.Request.PathParam("companyID")) | ||
if err != nil { | ||
return nil, errors.InvalidParam{Param: "company id"} | ||
} | ||
|
||
var emp models.Employee | ||
|
||
err = c.Request.Bind(&emp) | ||
if err != nil { | ||
return nil, errors.ErrJSONFormat | ||
} | ||
|
||
res, err := p.service.CreateEmployee(c, companyID, &emp) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return res, nil | ||
} | ||
|
||
func (p PanelHTTP) GetAllEmployee(c *gofr.Context) (interface{}, error) { | ||
companyID, err := strconv.Atoi(c.Request.PathParam("companyID")) | ||
if err != nil { | ||
return nil, errors.InvalidParam{Param: "company id"} | ||
} | ||
|
||
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 := utils.Filter{ | ||
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 | ||
} | ||
|
||
return res, nil | ||
} | ||
|
||
func (p PanelHTTP) GetEmployeeByID(c *gofr.Context) (interface{}, error) { | ||
companyID, err := strconv.Atoi(c.Request.PathParam("companyID")) | ||
if err != nil { | ||
return nil, errors.InvalidParam{Param: "company id"} | ||
} | ||
|
||
employeeID, err := strconv.Atoi(c.Request.PathParam("employeeID")) | ||
if err != nil { | ||
return nil, errors.InvalidParam{Param: "employee id"} | ||
} | ||
|
||
res, err := p.service.GetEmployeeByID(c, companyID, employeeID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return res, nil | ||
} | ||
|
||
func (p PanelHTTP) EditEmployee(c *gofr.Context) (interface{}, error) { | ||
companyID, err := strconv.Atoi(c.Request.PathParam("companyID")) | ||
if err != nil { | ||
return nil, errors.InvalidParam{Param: "company id"} | ||
} | ||
|
||
employeeID, err := strconv.Atoi(c.Request.PathParam("employeeID")) | ||
if err != nil { | ||
return nil, errors.InvalidParam{Param: "employee id"} | ||
} | ||
|
||
var data models.Employee | ||
|
||
err = c.Request.Bind(&data) | ||
if err != nil { | ||
return nil, errors.ErrJSONFormat | ||
} | ||
|
||
res, err := p.service.EditEmployee(c, companyID, employeeID, &data) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return res, nil | ||
} | ||
|
||
func (p PanelHTTP) DeleteEmployee(c *gofr.Context) (interface{}, error) { | ||
companyID, err := strconv.Atoi(c.Request.PathParam("companyID")) | ||
if err != nil { | ||
return nil, errors.InvalidParam{Param: "company id"} | ||
} | ||
|
||
employeeID, err := strconv.Atoi(c.Request.PathParam("employeeID")) | ||
if err != nil { | ||
return nil, errors.InvalidParam{Param: "employee id"} | ||
} | ||
|
||
return nil, p.service.DeleteEmployee(c, companyID, employeeID) | ||
} |
Oops, something went wrong.