Skip to main content

Calendar Event Handler Documentation

This code defines a CalendarEventHandler struct that handles various calendar event-related HTTP requests. It uses the Echo framework for routing and handling HTTP requests and responses.

CalendarEventHandler struct

type CalendarEventHandler struct {
medahandler.MedaHandler
cfg config.Config
}
  • medahandler.MedaHandler: Embeds the MedaHandler struct from the medahandler package.
  • cfg config.Config: Configuration settings.

Functions

NewCalendarEventHandler

func NewCalendarEventHandler(cfg config.Config) medahandler.MedaHandlerContract

Creates a new CalendarEventHandler instance.

BindRouter

func (h *CalendarEventHandler) BindRouter(pbx *core.ServeEvent) error

Binds the handler's routes to the Echo router.

CreateHoliday

func (h *CalendarEventHandler) CreateHoliday(c echo.Context) error

Creates a new holiday and returns the result as a JSON response.

UpdateHoliday

func (h *CalendarEventHandler) UpdateHoliday(c echo.Context) error

Updates an existing holiday and returns the result as a JSON response.

ReplaceShifts

func (h *CalendarEventHandler) ReplaceShifts(c echo.Context) error

Replaces shifts for a user or department and returns the result as a JSON response.

GetDepartmentCalendars

func (h *CalendarEventHandler) GetDepartmentCalendars(c echo.Context) error

Gets the calendar for all departments in an office and returns the result as a JSON response.

GetUserCalendar

func (h *CalendarEventHandler) GetUserCalendar(c echo.Context) error

Gets the calendar for all users in a department and returns the result as a JSON response.

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.

ImportSampleData

func (h *CalendarEventHandler) ImportSampleData(c echo.Context) error

Generates a sample CSV file for importing calendar schedules and returns it as a downloadable file.

ImportCalendarSchedule

func (h *CalendarEventHandler) ImportCalendarSchedule(c echo.Context) error

Imports calendar schedules from an uploaded Excel file and returns the result as a JSON response.

downloadSampleUserProfileIds

func (h *CalendarEventHandler) downloadSampleUserProfileIds(c echo.Context) error

Generates a sample CSV file with user profile IDs for importing calendar schedules and returns it as a downloadable file.

Example Usage

Initializing the Handler

package main

import (
"fio-backend/config"
"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()

// Load configuration
cfg := config.LoadConfig()

// Initialize the handler
calendarHandler := handler.NewCalendarEventHandler(cfg)

// 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

Create Holiday

curl -X POST http://localhost:8080/api/v1/calendar/holiday -d '{
"name": "New Year",
"date": "2023-01-01",
"company_id": "company123"
}'

Update Holiday

curl -X PUT http://localhost:8080/api/v1/calendar/holiday/holiday123 -d '{
"name": "New Year Updated",
"date": "2023-01-01",
"company_id": "company123"
}'

Replace Shifts

curl -X POST http://localhost:8080/api/v1/calendar/shift/replace -d '{
"user_profile_id": "user123",
"shift_id": "shift123",
"start_date": "2023-01-01",
"end_date": "2023-01-31"
}'

Get Department Calendars

curl -X GET http://localhost:8080/api/v1/calendar/office/office123/department -d '{
"company_id": "company123",
"year": 2023,
"month": 1
}'

Get User Calendar

curl -X GET http://localhost:8080/api/v1/calendar/department/department123/employee -d '{
"company_id": "company123",
"year": 2023,
"month": 1
}'

Generate Calendar Schedule for One Company Date Range

curl -X GET http://localhost:8080/api/v1/calendar/calendarschedule/generate/all -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 GET http://localhost:8080/api/v1/calendar/calendarschedule/generate/single -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/calendarschedule/generate/multiple -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 GET http://localhost:8080/api/v1/calendar/calendarschedule/generate/onepersononedate -d '{
"user_profile_id": "user123",
"date": "2023-01-15",
"force": false,
"include_overwrite": false
}'

Import Sample Data

curl -X POST http://localhost:8080/api/v1/calendar/calendarschedule/import/sample

Import Calendar Schedule

curl -X POST http://localhost:8080/api/v1/calendar/calendarschedule/import -F "file=@path/to/your/file.xlsx" -F "company_id=company123"

Download Sample User Profile IDs

curl -X POST http://localhost:8080/api/v1/calendar/calendarschedule/import/sample -d '{
"company_id": "company123",
"user_profile_ids": ["user123", "user456"],
"month": 1,
"year": 2023
}'

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.