Skip to main content

Dashboard Handler Documentation

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

DashboardHandler struct

type DashboardHandler struct {
medahandler.MedaHandler
}
  • medahandler.MedaHandler: Embeds the MedaHandler struct from the medahandler package.

Functions

NewDashboardHandler

func NewDashboardHandler() medahandler.MedaHandlerContract

Creates a new DashboardHandler instance.

BindRouter

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

Binds the handler's routes to the Echo router.

UserAttended

func (h *DashboardHandler) UserAttended(c echo.Context) error

Gets the number of attended and unattended users within a date range and returns the result as a JSON response.

DepartmentOnTimePercentage

func (h *DashboardHandler) DepartmentOnTimePercentage(c echo.Context) error

Gets the on-time percentage for each department within a date range and returns the result as a JSON response.

UserLateDuration

func (h *DashboardHandler) UserLateDuration(c echo.Context) error

Gets the late duration for each user within a date range and returns the result as a JSON response.

UserAttendedStatus

func (h *DashboardHandler) UserAttendedStatus(c echo.Context) error

Gets the attendance status (on-time, late, check-in overtime, check-out overtime) for users within a date range and returns the result as a JSON response.

VacuumHandler

func (h *DashboardHandler) VacuumHandler(c echo.Context) error

Performs a database vacuum operation 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
dashboardHandler := handler.NewDashboardHandler()

// Bind routes
pb.OnBeforeServe().Add(func(e *core.ServeEvent) error {
return dashboardHandler.BindRouter(e)
})

// Start the server
e.Logger.Fatal(e.Start(":8080"))
}

Making Requests

User Attended

curl -X GET http://localhost:8080/api/v1/dashboard/user-attended -d '{
"company_id": "company123",
"start_date": "2023-01-01",
"end_date": "2023-01-31"
}'

Department On-Time Percentage

curl -X GET http://localhost:8080/api/v1/dashboard/department-on-time-percentage -d '{
"company_id": "company123",
"start_date": "2023-01-01",
"end_date": "2023-01-31"
}'

User Late Duration

curl -X GET http://localhost:8080/api/v1/dashboard/user-late-duration -d '{
"company_id": "company123",
"start_date": "2023-01-01",
"end_date": "2023-01-31"
}'

User Attended Status

curl -X GET http://localhost:8080/api/v1/dashboard/user-attendance-status -d '{
"company_id": "company123",
"start_date": "2023-01-01",
"end_date": "2023-01-31"
}'

Vacuum Handler

curl -X POST http://localhost:8080/api/v1/dashboard/vacuum

This documentation provides an overview of the DashboardHandler struct, its functions, and example usage. By following the example, you can initialize the handler, bind routes, and make requests to the various endpoints.