Shift Rule Handler Documentation
This code defines a ShiftRuleHandler
struct that handles various shift rule-related HTTP requests. It uses the Echo framework for routing and handling HTTP requests and responses.
ShiftRuleHandler
struct
type ShiftRuleHandler struct {
medahandler.MedaHandler
}
medahandler.MedaHandler
: Embeds theMedaHandler
struct from themedahandler
package.
Functions
NewShiftRuleHandler
func NewShiftRuleHandler() medahandler.MedaHandlerContract
Creates a new ShiftRuleHandler
instance.
BindRouter
func (h *ShiftRuleHandler) BindRouter(pbx *core.ServeEvent) error
Binds the handler's routes to the Echo router.
GetShiftRuleByID
func (h *ShiftRuleHandler) GetShiftRuleByID(c echo.Context) error
Gets a shift rule by its ID and returns it as a JSON response.
CreateShiftRule
func (h *ShiftRuleHandler) CreateShiftRule(c echo.Context) error
Creates a new shift rule and returns the result as a JSON response.
UpdateShiftRule
func (h *ShiftRuleHandler) UpdateShiftRule(c echo.Context) error
Updates an existing shift rule by its ID and returns the result as a JSON response.
syncRuleDetails
func (h *ShiftRuleHandler) syncRuleDetails(dao *daos.Dao, ruleID string, payload *entity.CreateShiftRuleRequest) error
Synchronizes the rule details for a given rule ID and payload.
Example Usage
Initializing the Handler
package main
import (
"fio-backend/handler"
"github.com/labstack/echo/v5"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/core"
)
func main() {
// Initialize Echo
e := echo.New()
// Initialize PocketBase
pb := pocketbase.New()
// Initialize the handler
shiftRuleHandler := handler.NewShiftRuleHandler()
// Bind routes
pb.OnBeforeServe().Add(func(e *core.ServeEvent) error {
return shiftRuleHandler.BindRouter(e)
})
// Start the server
e.Logger.Fatal(e.Start(":8080"))
}
Making Requests
Get Shift Rule by ID
curl -X GET http://localhost:8080/api/v1/rules/shift/{id}
Create Shift Rule
curl -X POST http://localhost:8080/api/v1/rules/shift -d '{
"company_id": "company123",
"label": "Shift Rule 1",
"overtime_type": "standard",
"scan_status_by_system": true,
"duration_rule": {
"as_half_day_on_minutes": 240,
"as_no_work_on_minutes": 120
},
"work_hour_rule": {
"in_no_scan_action": "absent",
"in_no_scan_value": 0,
"in_late_action": "deduct",
"in_late_minutes": 15,
"in_early_action": "none",
"out_no_scan_action": "absent",
"out_no_scan_value": 0,
"out_early_action": "deduct",
"out_early_minutes": 15,
"out_late_action": "none"
}
}'
Update Shift Rule
curl -X PUT http://localhost:8080/api/v1/rules/shift/{id} -d '{
"company_id": "company123",
"label": "Updated Shift Rule",
"overtime_type": "standard",
"scan_status_by_system": true,
"duration_rule": {
"as_half_day_on_minutes": 240,
"as_no_work_on_minutes": 120
},
"work_hour_rule": {
"in_no_scan_action": "absent",
"in_no_scan_value": 0,
"in_late_action": "deduct",
"in_late_minutes": 15,
"in_early_action": "none",
"out_no_scan_action": "absent",
"out_no_scan_value": 0,
"out_early_action": "deduct",
"out_early_minutes": 15,
"out_late_action": "none"
}
}'
This documentation provides an overview of the ShiftRuleHandler
struct, its functions, and example usage. By following the example, you can initialize the handler, bind routes, and make requests to the various endpoints.