Skip to content

Commit

Permalink
zopsmart#3 | Resolved renaming of customeerror to customError across …
Browse files Browse the repository at this point in the history
…layers
  • Loading branch information
Ishan Pandey committed Feb 12, 2021
2 parents 139c32f + d5634bb commit af0638b
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 71 deletions.
Binary file removed .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out
.DS_Store

# Dependency directories (remove the comment below to include it)
# vendor/
Expand Down
2 changes: 1 addition & 1 deletion configs/.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ REDIS_HOST=localhost

DB_HOST=localhost
DB_USER=root
DB_PASSWORD=Bittu@1998
DB_PASSWORD=password
DB_NAME=Hiring
Binary file modified panel/.DS_Store
Binary file not shown.
20 changes: 10 additions & 10 deletions panel/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/zopsmart/hiring-portal-api/panel/models"

"github.com/vikash/gofr/pkg/gofr"
customeerror "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"
)

Expand All @@ -21,14 +21,14 @@ 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 "Invalid CompanyID", customeerror.ErrInvalidCompanyID
return "Invalid CompanyID", customError.ErrInvalidCompanyID
}
var emp models.Employee

err = c.Request.Bind(&emp)

if err != nil {
return "Wrong json format", customeerror.ErrJSONFormat
return "Wrong json format", customError.ErrJSONFormat
}

res, err := p.service.CreateEmployee(c, companyID, &emp)
Expand All @@ -43,7 +43,7 @@ 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", customeerror.ErrInvalidCompanyID
return "Invalid CompanyID", customError.ErrInvalidCompanyID
}

res, err := p.service.GetAllEmployee(c, companyID)
Expand All @@ -57,11 +57,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 nil, customeerror.ErrInvalidCompanyID
return nil, customError.ErrInvalidCompanyID
}
employeeId, err := strconv.Atoi(c.Request.PathParam("employeeID"))
if err != nil {
return nil, customeerror.ErrInvalidEmployeeID
return nil, customError.ErrInvalidEmployeeID
}

res, err := p.service.GetEmployeeByID(c, companyId, employeeId)
Expand All @@ -75,11 +75,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 nil, customeerror.ErrInvalidCompanyID
return nil, customError.ErrInvalidCompanyID
}
employeeID, err := strconv.Atoi(c.Request.PathParam("employeeID"))
if err != nil {
return nil, customeerror.ErrInvalidEmployeeID
return nil, customError.ErrInvalidEmployeeID
}

var data models.Employee
Expand All @@ -96,11 +96,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, customeerror.ErrInvalidCompanyID
return nil, customError.ErrInvalidCompanyID
}
employeeID, err := strconv.Atoi(c.Request.PathParam("employeeID"))
if err != nil {
return nil, customeerror.ErrInvalidEmployeeID
return nil, customError.ErrInvalidEmployeeID
}
return nil, p.service.DeleteEmployee(c, companyID, employeeID)

Expand Down
1 change: 1 addition & 0 deletions panel/models/company.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ type Company struct {
Domain string `json:"domain"`
Name string `json:"name"`
Description string `json:"description"`
Email string `json:"email"`
Employee []Employee `json:"employee"`
}
18 changes: 9 additions & 9 deletions panel/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package service

import (
"github.com/vikash/gofr/pkg/gofr"
customeerror "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"
"github.com/zopsmart/hiring-portal-api/panel/store"
)
Expand All @@ -17,24 +17,24 @@ func New(store store.Panel) PanelEmployee {

func (p PanelEmployeeService) GetAllEmployee(c *gofr.Context, companyID int) ([]models.Employee, error) {
if companyID <= 0 {
return nil, customeerror.ErrInvalidCompanyID
return nil, customError.ErrInvalidCompanyID
}
return p.store.GetAllEmployee(c, companyID)
}

func (p PanelEmployeeService) GetEmployeeByID(c *gofr.Context, companyID, employeeID int) (models.Employee, error) {
if companyID <= 0 {
return models.Employee{}, customeerror.ErrInvalidCompanyID
return models.Employee{}, customError.ErrInvalidCompanyID
}
if employeeID <= 0 {
return models.Employee{}, customeerror.ErrInvalidEmployeeID
return models.Employee{}, customError.ErrInvalidEmployeeID
}
return p.store.GetEmployeeByID(c, companyID, employeeID)
}

func (p PanelEmployeeService) CreateEmployee(c *gofr.Context, companyID int, emp *models.Employee) (models.Employee, error) {
if companyID <= 0 {
return models.Employee{}, customeerror.ErrInvalidCompanyID
return models.Employee{}, customError.ErrInvalidCompanyID
}
id, err := p.store.CreateEmployee(c, companyID, emp)
if err != nil {
Expand All @@ -47,10 +47,10 @@ func (p PanelEmployeeService) CreateEmployee(c *gofr.Context, companyID int, emp

func (p PanelEmployeeService) EditEmployee(c *gofr.Context, companyID, employeeID int, emp *models.Employee) (models.Employee, error) {
if companyID <= 0 {
return models.Employee{}, customeerror.ErrInvalidCompanyID
return models.Employee{}, customError.ErrInvalidCompanyID
}
if employeeID <= 0 {
return models.Employee{}, customeerror.ErrInvalidEmployeeID
return models.Employee{}, customError.ErrInvalidEmployeeID
}
_, err := p.store.EditEmployee(c, companyID, employeeID, emp)
if err != nil {
Expand All @@ -63,10 +63,10 @@ func (p PanelEmployeeService) EditEmployee(c *gofr.Context, companyID, employeeI

func (p PanelEmployeeService) DeleteEmployee(c *gofr.Context, companyID, employeeID int) error {
if companyID <= 0 {
return customeerror.ErrInvalidCompanyID
return customError.ErrInvalidCompanyID
}
if employeeID <= 0 {
return customeerror.ErrInvalidEmployeeID
return customError.ErrInvalidEmployeeID
}
return p.store.DeleteEmployee(c, companyID, employeeID)
}
38 changes: 19 additions & 19 deletions panel/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/DATA-DOG/go-sqlmock"
"github.com/vikash/gofr/pkg/gofr"
"github.com/vikash/gofr/pkg/gofr/logging"
customeerror "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"
)

Expand Down Expand Up @@ -52,11 +52,11 @@ func testAllEmployeeService(t *testing.T, c *gofr.Context) {
{
input: -1,
expectedOutput: []models.Employee(nil),
expectedErr: customeerror.ErrInvalidCompanyID,
expectedErr: customError.ErrInvalidCompanyID,
},
{
input: 2,
expectedErr: customeerror.ErrDBServer,
expectedErr: customError.ErrDBServer,
},
}

Expand Down Expand Up @@ -85,18 +85,18 @@ func testEmployeeByIDService(t *testing.T, c *gofr.Context) {
{
input: inputData{1, -1},
expectedOutput: models.Employee{},
expectedErr: customeerror.ErrInvalidCompanyID,
expectedErr: customError.ErrInvalidCompanyID,
},
{
input: inputData{-2, 2},
expectedOutput: models.Employee{},
expectedErr: customeerror.ErrInvalidEmployeeID,
expectedErr: customError.ErrInvalidEmployeeID,
},

{
input: inputData{4, 3},
expectedOutput: models.Employee{},
expectedErr: customeerror.ErrRecordNotFound,
expectedErr: customError.ErrRecordNotFound,
},
}

Expand Down Expand Up @@ -129,13 +129,13 @@ func testCreateEmployeeService(t *testing.T, c *gofr.Context) {
{
input: InputData{-1, models.Employee{1, "Bittu", "[email protected]", 7250073079, "sde1", 2, 1}},
expectedOutput: models.Employee{},
expectedErr: customeerror.ErrInvalidCompanyID,
expectedErr: customError.ErrInvalidCompanyID,
},

{
input: InputData{1, models.Employee{1, "Bittu", "[email protected]", 7250073079, "sde1", 2, 2}},
expectedOutput: models.Employee{},
expectedErr: customeerror.ErrDBServer,
expectedErr: customError.ErrDBServer,
},
}

Expand Down Expand Up @@ -168,18 +168,18 @@ func testEditEmployeeService(t *testing.T, c *gofr.Context) {
{
input: InputData{-1, 2, models.Employee{1, "Bittu", "[email protected]", 7250073079, "sde1", 2, 1}},
expectedOutput: models.Employee{},
expectedErr: customeerror.ErrInvalidCompanyID,
expectedErr: customError.ErrInvalidCompanyID,
},
{
input: InputData{1, -1, models.Employee{1, "Bittu", "[email protected]", 7250073079, "sde1", 2, 2}},
expectedOutput: models.Employee{},
expectedErr: customeerror.ErrInvalidEmployeeID,
expectedErr: customError.ErrInvalidEmployeeID,
},

{
input: InputData{1, 2, models.Employee{1, "Bittu", "[email protected]", 7250073079, "sde1", 2, 2}},
expectedOutput: models.Employee{},
expectedErr: customeerror.ErrDBServer,
expectedErr: customError.ErrDBServer,
},
}

Expand Down Expand Up @@ -210,16 +210,16 @@ func testDeleteEmployeeService(t *testing.T, c *gofr.Context) {

{
input: InputData{-1, 2},
expectedErr: customeerror.ErrInvalidCompanyID,
expectedErr: customError.ErrInvalidCompanyID,
},
{
input: InputData{1, -1},
expectedErr: customeerror.ErrInvalidEmployeeID,
expectedErr: customError.ErrInvalidEmployeeID,
},

{
input: InputData{1, 2},
expectedErr: customeerror.ErrDBServer,
expectedErr: customError.ErrDBServer,
},
}

Expand All @@ -237,7 +237,7 @@ type mockStore struct {

func (m mockStore) GetAllEmployee(c *gofr.Context, companyID int) ([]models.Employee, error) {
if companyID == 2 {
return nil, customeerror.ErrDBServer
return nil, customError.ErrDBServer
}

res := []models.Employee{{1, "Bittu", "[email protected]", 7250073079, "sde1", 2, 1},
Expand All @@ -252,7 +252,7 @@ func (m mockStore) GetEmployeeByID(c *gofr.Context, companyID, employeeID int) (
return models.Employee{1, "Bittu", "[email protected]", 7250073079, "sde1", 2, 1}, nil
}
if companyID != employeeID {
return models.Employee{}, customeerror.ErrRecordNotFound
return models.Employee{}, customError.ErrRecordNotFound
}

return models.Employee{}, nil
Expand All @@ -261,21 +261,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, customeerror.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, customeerror.ErrDBServer
return -1, customError.ErrDBServer
}
return companyID, nil
}

func (m mockStore) DeleteEmployee(c *gofr.Context, companyID, employeeID int) error {
if companyID != employeeID {
return customeerror.ErrDBServer
return customError.ErrDBServer
}
return nil
}
Loading

0 comments on commit af0638b

Please sign in to comment.