Skip to content

Commit

Permalink
zopsmart#3 | Resolved merge conflicts for linter update
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishan Pandey committed Feb 16, 2021
2 parents b58aeff + d0437fd commit 7a0c3c2
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 62 deletions.
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@
*.so
*.dylib

.DS_Store

# 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

./panel/coverage.txt
./panel/service/coverage.txt
./panel/store/coverage.txt
./panel/http/coverage.txt

# Dependency directories (remove the comment below to include it)
# vendor/

Expand Down
12 changes: 6 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ func main() {

dataStore := store.New()
dataService := service.New(dataStore)
dataHttp := http.New(dataService)
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.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()
}
2 changes: 0 additions & 2 deletions panel/http/http.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package http

import (
"fmt"
"strconv"

"github.com/zopsmart/hiring-portal-api/panel/models"
Expand Down Expand Up @@ -97,7 +96,6 @@ func (p PanelHTTP) EditEmployee(c *gofr.Context) (interface{}, error) {
}
var data models.Employee
err = c.Request.Bind(&data)
fmt.Println(data)
if err != nil {
return nil, customerror.ErrJSONFormat
}
Expand Down
11 changes: 3 additions & 8 deletions panel/http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package http

import (
"bytes"
"fmt"
"net/http"
"net/http/httptest"
"reflect"
Expand Down Expand Up @@ -137,7 +136,6 @@ func testGetEmployeeByIDHTTP(t *testing.T, c *gofr.Context) {
}

for i := range testcases {
//req := httptest.NewRequest(http.MethodGet, fmt.Sprintf("/{%s}/employees", testcases[i].input.companyID), bytes.NewBuffer(testcases[i].input.Emp))
req := httptest.NewRequest(http.MethodGet, "/someURL/", nil)
req = mux.SetURLVars(req, map[string]string{"companyID": testcases[i].input.companyID, "employeeID": testcases[i].input.employeeID})
gofrReq := gofrHTTP.NewRequest(req)
Expand All @@ -150,7 +148,6 @@ func testGetEmployeeByIDHTTP(t *testing.T, c *gofr.Context) {
}

func testEditEmployeeHTTP(t *testing.T, c *gofr.Context) {
fmt.Println("start")
type InputData struct {
companyID string
employeeID string
Expand Down Expand Up @@ -207,11 +204,9 @@ func testEditEmployeeHTTP(t *testing.T, c *gofr.Context) {
c.Request = gofrReq
dataHTTP := New(mockService{})
var actualOutput interface{}
fmt.Println(" i is ", i)
actualOutput, actualErr := dataHTTP.EditEmployee(c)
CheckErrOutput(t, i, testcases[i].expectedErr, actualErr, testcases[i].expectedOutput, actualOutput)
}
fmt.Println("end")
}

func testGetAllEmployee(t *testing.T, c *gofr.Context) {
Expand Down Expand Up @@ -313,7 +308,7 @@ func (m mockService) CreateEmployee(c *gofr.Context, companyID int, emp *models.
return models.Employee{}, customerror.ErrDBServer
}

func (m mockService) GetEmployeeByID(c *gofr.Context, companyID int, employeeID int) (models.Employee, error) {
func (m mockService) GetEmployeeByID(c *gofr.Context, companyID, employeeID int) (models.Employee, error) {
if companyID == 1 && employeeID == 1 {
return models.Employee{
ID: 1, Name: "Ishan Pandey", Email: "[email protected]", Phone: 7250073079, Designation: "SDE1", YOE: 2, CompanyID: 1},
Expand All @@ -334,7 +329,7 @@ func (m mockService) GetAllEmployee(c *gofr.Context, companyID int, queryParams
return nil, customerror.ErrDBServer
}

func (m mockService) EditEmployee(c *gofr.Context, companyID int, employeeID int, emp *models.Employee) (models.Employee, error) {
func (m mockService) EditEmployee(c *gofr.Context, companyID, employeeID int, emp *models.Employee) (models.Employee, error) {
if companyID == 1 && employeeID == 3 {
return models.Employee{
ID: 3, Name: "Ishanx Pandey", Email: "[email protected]", Phone: 7250073079, Designation: "SDE1", YOE: 2, CompanyID: 1},
Expand All @@ -344,6 +339,6 @@ func (m mockService) EditEmployee(c *gofr.Context, companyID int, employeeID int
return models.Employee{}, customerror.ErrDBServer
}

func (m mockService) DeleteEmployee(c *gofr.Context, companyID int, employeeID int) error {
func (m mockService) DeleteEmployee(c *gofr.Context, companyID, employeeID int) error {
return nil
}
4 changes: 2 additions & 2 deletions panel/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ type panelEmployeeService struct {
store store.Panel
}

func New(store store.Panel) PanelEmployee {
return panelEmployeeService{store: store}
func New(storeInterface store.Panel) PanelEmployee {
return panelEmployeeService{store: storeInterface}
}

func (p panelEmployeeService) GetAllEmployee(c *gofr.Context, companyID int, queryParam map[string]interface{}) ([]models.Employee, error) {
Expand Down
7 changes: 1 addition & 6 deletions panel/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestServiceLayer(t *testing.T) {
}

func testAllEmployeeService(t *testing.T, c *gofr.Context) {
testCases := []struct {
var testCases = []struct {
input int
expectedOutput []models.Employee
expectedErr error
Expand Down Expand Up @@ -92,7 +92,6 @@ func testAllEmployeeService(t *testing.T, c *gofr.Context) {
},
},
}

for i := range testCases {
dataService := New(mockStore{})
output, err := dataService.GetAllEmployee(c, testCases[i].input, testCases[i].queryParams)
Expand Down Expand Up @@ -241,7 +240,6 @@ func testEditEmployeeService(t *testing.T, c *gofr.Context) {
CheckErrOutput(t, testCases[i].expectedErr, err, testCases[i].expectedOutput, output)
}
}

func testDeleteEmployeeService(t *testing.T, c *gofr.Context) {
type InputData struct {
companyID int
Expand Down Expand Up @@ -299,11 +297,9 @@ func (m mockStore) GetAllEmployeeWithoutDesignation(c *gofr.Context, companyID i
if companyID == 2 {
return nil, customerror.ErrDBServer
}

res := []models.Employee{{1, "Bittu", "[email protected]", 7250073079, "sde1", 2, 1},
{2, "Bittu Ray", "[email protected]", 7250073080, "sde2", 2, 1},
}

return res, nil
}

Expand All @@ -314,7 +310,6 @@ func (m mockStore) GetEmployeeByID(c *gofr.Context, companyID, employeeID int) (
if companyID != employeeID {
return models.Employee{}, customerror.ErrRecordNotFound
}

return models.Employee{}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion panel/store/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ type Panel interface {
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)
DeleteEmployee(c *gofr.Context, id, companyId int) error
DeleteEmployee(*gofr.Context, int, int) error
}
6 changes: 5 additions & 1 deletion panel/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (p panelStore) GetAllEmployeeWithDesignation(c *gofr.Context, companyID int
if len(res) == 0 {
return res, customerror.ErrRecordNotFound
}

return res, nil
}

Expand All @@ -55,6 +56,7 @@ func (p panelStore) GetAllEmployeeWithoutDesignation(c *gofr.Context, companyID
if len(res) == 0 {
return res, customerror.ErrRecordNotFound
}

return res, nil
}

Expand All @@ -74,7 +76,6 @@ func (p panelStore) GetEmployeeByID(c *gofr.Context, companyID, employeeID int)
}
}
if res.ID == 0 {
//fmt.Println("res is ", res)
return res, customerror.ErrRecordNotFound
}
return res, nil
Expand All @@ -93,6 +94,7 @@ func (p panelStore) CreateEmployee(c *gofr.Context, companyID int, emp *models.E
if id == -1 {
return -1, customerror.ErrRecordNotFound
}

return int(id), nil
}

Expand All @@ -109,6 +111,7 @@ func (p panelStore) EditEmployee(c *gofr.Context, companyID, employeeID int, emp
if r == 0 {
return -1, customerror.ErrRecordNotFound
}

return int(r), nil
}

Expand All @@ -125,5 +128,6 @@ func (p panelStore) DeleteEmployee(c *gofr.Context, companyID, employeeID int) e
// Some issue while deleting record.
return customerror.ErrRecordNotFound
}

return err
}
Loading

0 comments on commit 7a0c3c2

Please sign in to comment.