40 lines
1.0 KiB
Go
40 lines
1.0 KiB
Go
package handler
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"gitea.urkob.com/urko/ess-etl-go/internal/services"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
type EmployeeWorkInformationHandler struct {
|
|
employeeWISrv services.EmployeeWIService
|
|
}
|
|
|
|
func NewEmployeeWorkInformation(employeeWISrv services.EmployeeWIService) *EmployeeWorkInformationHandler {
|
|
return &EmployeeWorkInformationHandler{
|
|
employeeWISrv: employeeWISrv,
|
|
}
|
|
}
|
|
|
|
func (hdl *EmployeeWorkInformationHandler) 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)
|
|
}
|