Calendar Schedule Handler Documentation
This code defines a CalendarEventHandler
struct that handles various calendar schedule-related HTTP requests. It uses the Echo framework for routing and handling HTTP requests and responses.
CalendarEventHandler
struct
type CalendarEventHandler struct {
medahandler.MedaHandler
}
medahandler.MedaHandler
: Embeds theMedaHandler
struct from themedahandler
package.
Functions
GenerateCalendarScheduleOneCompanyDateRange
func (h *CalendarEventHandler) GenerateCalendarScheduleOneCompanyDateRange(c echo.Context) error
Generates calendar schedules for a company within a specified date range and returns the result as a JSON response.
GenerateCalendarScheduleOnePersonDateRange
func (h *CalendarEventHandler) GenerateCalendarScheduleOnePersonDateRange(c echo.Context) error
Generates calendar schedules for a specific user within a specified date range and returns the result as a JSON response.
GenerateCalendarScheduleMultipleUsersDateRange
func (h *CalendarEventHandler) GenerateCalendarScheduleMultipleUsersDateRange(c echo.Context) error
Generates calendar schedules for multiple users within a specified date range and returns the result as a JSON response.
GenerateCalendarScheduleOnePersonOneDateHandler
func (h *CalendarEventHandler) GenerateCalendarScheduleOnePersonOneDateHandler(c echo.Context) error
Generates a calendar schedule for a specific user on a specific date 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
calendarHandler := handler.NewCalendarEventHandler()
// Bind routes
pb.OnBeforeServe().Add(func(e *core.ServeEvent) error {
return calendarHandler.BindRouter(e)
})
// Start the server
e.Logger.Fatal(e.Start(":8080"))
}
Making Requests
Generate Calendar Schedule for One Company Date Range
curl -X POST http://localhost:8080/api/v1/calendar/generate-company -d '{
"company_id": "company123",
"start_date": "2023-01-01",
"end_date": "2023-01-31",
"force": false,
"include_overwrite": false
}'
Generate Calendar Schedule for One Person Date Range
curl -X POST http://localhost:8080/api/v1/calendar/generate-person -d '{
"user_profile_id": "user123",
"start_date": "2023-01-01",
"end_date": "2023-01-31",
"force": false,
"include_overwrite": false
}'
Generate Calendar Schedule for Multiple Users Date Range
curl -X POST http://localhost:8080/api/v1/calendar/generate-multiple-users -d '{
"company_id": "company123",
"user_profile_ids": ["user123", "user456"],
"start_date": "2023-01-01",
"end_date": "2023-01-31",
"force": false,
"include_overwrite": false
}'
Generate Calendar Schedule for One Person One Date
curl -X POST http://localhost:8080/api/v1/calendar/generate-one-person-one-date -d '{
"user_profile_id": "user123",
"date": "2023-01-15",
"force": false,
"include_overwrite": false
}'
This documentation provides an overview of the CalendarEventHandler
struct, its functions, and example usage. By following the example, you can initialize the handler, bind routes, and make requests to the various endpoints.