40 lines
995 B
Go
40 lines
995 B
Go
package handler
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"gitea.urkob.com/urko/ess-etl-go/internal/services"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
type EmployeeWIHandler struct {
|
|
employeeWISrv services.EmployeeWIService
|
|
}
|
|
|
|
func NewEmployeeWIHandler(employeeWISrv services.EmployeeWIService) *EmployeeWIHandler {
|
|
return &EmployeeWIHandler{
|
|
employeeWISrv: employeeWISrv,
|
|
}
|
|
}
|
|
|
|
func (hdl *EmployeeWIHandler) Get(c *fiber.Ctx) error {
|
|
id := c.Params("id", "")
|
|
if id == "" {
|
|
return JSONError(c, fiber.StatusBadRequest, fmt.Errorf("id is empty"), defaultErrMessage)
|
|
}
|
|
|
|
employeeNumber, err := strconv.Atoi(id)
|
|
if err != nil {
|
|
return JSONError(c, fiber.StatusBadRequest, fmt.Errorf("strconv.Atoi: %s", err), defaultErrMessage)
|
|
}
|
|
|
|
employeeWI, err := hdl.employeeWISrv.GetByEmployeeNumber(c.Context(), employeeNumber)
|
|
if err != nil {
|
|
return JSONError(c, fiber.StatusBadRequest, fmt.Errorf("professionalSrv.GetByID: %s", err), defaultErrMessage)
|
|
}
|
|
|
|
return c.Status(fiber.StatusOK).JSON(employeeWI)
|
|
}
|