Schedule Handler Documentation
This code defines a ScheduleHandler struct that handles various schedule-related HTTP requests. It uses the Echo framework for routing and handling HTTP requests and responses.
ScheduleHandler struct
type ScheduleHandler struct {
medahandler.MedaHandler
}
medahandler.MedaHandler: Embeds theMedaHandlerstruct from themedahandlerpackage.
Functions
NewScheduleHandler
func NewScheduleHandler() medahandler.MedaHandlerContract
Creates a new ScheduleHandler instance.
BindRouter
func (h *ScheduleHandler) BindRouter(pbx *core.ServeEvent) error
Binds the handler's routes to the Echo router.
CreateSchedule
func (h *ScheduleHandler) CreateSchedule(c echo.Context) error
Creates a new schedule and returns the result as a JSON response.
UpdateSchedule
func (h *ScheduleHandler) UpdateSchedule(c echo.Context) error
Updates an existing schedule and returns the result as a JSON response.
AssignSchedule
func (h *ScheduleHandler) AssignSchedule(c echo.Context) error
Assigns a schedule to a user or department and returns the result as a JSON response.
ReorderSchedule
func (h *ScheduleHandler) ReorderSchedule(c echo.Context) error
Reorders schedules and returns the result as a JSON response.
GetScheduleDetails
func (h *ScheduleHandler) GetScheduleDetails(c echo.Context) error
Gets the details of a schedule by its ID and returns the result as a JSON response.
GetDepartmentSchedules
func (h *ScheduleHandler) GetDepartmentSchedules(c echo.Context) error
Gets the schedules for all departments in a company and returns the result as a JSON response.
GetEmployeeSchedules
func (h *ScheduleHandler) GetEmployeeSchedules(c echo.Context) error
Gets the schedules for all employees in a company and returns the result as a JSON response.
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
scheduleHandler := handler.NewScheduleHandler()
// Bind routes
pb.OnBeforeServe().Add(func(e *core.ServeEvent) error {
return scheduleHandler.BindRouter(e)
})
// Start the server
e.Logger.Fatal(e.Start(":8080"))
}
Making Requests
Create Schedule
curl -X POST http://localhost:8080/api/v1/schedule -d '{
"name": "Morning Shift",
"company_id": "company123",
"shift_schedules": [
{
"shift_id": "shift123",
"start_time": "08:00",
"end_time": "16:00"
}
]
}'
Update Schedule
curl -X PUT http://localhost:8080/api/v1/schedule/schedule123 -d '{
"name": "Morning Shift Updated",
"company_id": "company123",
"shift_schedules": [
{
"shift_id": "shift123",
"start_time": "08:00",
"end_time": "16:00"
}
]
}'
Assign Schedule
curl -X POST http://localhost:8080/api/v1/schedule/assign -d '{
"user_profile_id": "user123",
"schedule_id": "schedule123",
"start_date": "2023-01-01",
"end_date": "2023-01-31"
}'
Reorder Schedule
curl -X PUT http://localhost:8080/api/v1/schedule/assign/reorder -d '{
"user_profile_id": "user123",
"schedule_id": "schedule123",
"order": 1
}'
Get Schedule Details
curl -X GET http://localhost:8080/api/v1/schedule/schedule123
Get Department Schedules
curl -X GET http://localhost:8080/api/v1/schedule/department?company_id=company123&month=1&year=2023
Get Employee Schedules
curl -X GET http://localhost:8080/api/v1/schedule/employee?company_id=company123&month=1&year=2023
This documentation provides an overview of the ScheduleHandler struct, its functions, and example usage. By following the example, you can initialize the handler, bind routes, and make requests to the various endpoints.