Attendance Log Handler Documentation
This code defines an AttendanceLogHandler
struct that handles various attendance log-related HTTP requests. It uses the Echo framework for routing and handling HTTP requests and responses.
AttendanceLogHandler
struct
type AttendanceLogHandler struct {
medahandler.MedaHandler
cfg config.Config
devices map[machinescanner.MachineBrand]attendancemachine.AttendanceMachine
}
medahandler.MedaHandler
: Embeds theMedaHandler
struct from themedahandler
package.cfg config.Config
: Configuration settings.devices map[machinescanner.MachineBrand]attendancemachine.AttendanceMachine
: A map of attendance machines by their brand.
Functions
NewAttendanceLogHandler
func NewAttendanceLogHandler(
cfg config.Config,
deviceRevo attendancemachine.AttendanceMachine,
deviceHik attendancemachine.AttendanceMachine,
deviceDahua attendancemachine.AttendanceMachine,
) medahandler.MedaHandlerContract
Creates a new AttendanceLogHandler
instance.
cfg
: Configuration settings.deviceRevo
: Attendance machine for Revo brand.deviceHik
: Attendance machine for Hik brand.deviceDahua
: Attendance machine for Dahua brand.
BindRouter
func (h *AttendanceLogHandler) BindRouter(pbx *core.ServeEvent) error
Binds the handler's routes to the Echo router.
GetSummaryThreshlod
func (h *AttendanceLogHandler) GetSummaryThreshlod(c echo.Context) error
Gets the company threshold and returns it as a JSON response.
GetAttendanceLogs
func (h *AttendanceLogHandler) GetAttendanceLogs(c echo.Context) error
Gets attendance logs from a specified device and returns them as a JSON response.
SyncAttendanceLog
func (h *AttendanceLogHandler) SyncAttendanceLog(c echo.Context) error
Synchronizes attendance logs from specified devices within a date range and returns the result as a JSON response.
ComputeAttendanceLog
func (h *AttendanceLogHandler) ComputeAttendanceLog(c echo.Context) error
Computes attendance logs for a company within a date range and returns the result as a JSON response.
ComputeUserAttendanceLog
func (h *AttendanceLogHandler) ComputeUserAttendanceLog(c echo.Context) error
Computes attendance logs for specific users within a date range and returns the result as a JSON response.
GetAttendanceDetails
func (h *AttendanceLogHandler) GetAttendanceDetails(c echo.Context) error
Gets detailed attendance logs for a user within a date range and returns them as a JSON response.
GetAttendanceDetailsSummary
func (h *AttendanceLogHandler) GetAttendanceDetailsSummary(c echo.Context) error
Gets a summary of attendance details for a user within a date range and returns it as a JSON response.
GetUserAttendanceSummaryByDepartmentID
func (h *AttendanceLogHandler) GetUserAttendanceSummaryByDepartmentID(c echo.Context) error
Gets attendance summaries for users in a specific department within a date range and returns them as a JSON response.
GetAttendancePeriodSummary
func (h *AttendanceLogHandler) GetAttendancePeriodSummary(c echo.Context) error
Gets attendance summaries for users in a company, office, or department within a date range and returns them as a JSON response.
GetRecap
func (h *AttendanceLogHandler) GetRecap(c echo.Context) error
Gets a recap of attendance data for a company within a date range and returns it as a JSON response.
GetReportDetail
func (h *AttendanceLogHandler) GetReportDetail(c echo.Context) error
Gets detailed attendance report data for a company within a date range and returns it as a JSON response.
Example Usage
Initializing the Handler
package main
import (
"fio-backend/config"
"fio-backend/handler"
"fio-backend/utils/attendance_machine"
"github.com/labstack/echo/v5"
"github.com/pocketbase/pocketbase"
)
func main() {
// Initialize Echo
e := echo.New()
// Initialize PocketBase
pb := pocketbase.New()
// Load configuration
cfg := config.LoadConfig()
// Initialize attendance machines
deviceRevo := attendance_machine.NewRevoMachine(cfg)
deviceHik := attendance_machine.NewHikMachine(cfg)
deviceDahua := attendance_machine.NewDahuaMachine(cfg)
// Initialize the handler
attendanceHandler := handler.NewAttendanceLogHandler(cfg, deviceRevo, deviceHik, deviceDahua)
// Bind routes
pb.OnBeforeServe().Add(func(e *core.ServeEvent) error {
return attendanceHandler.BindRouter(e)
})
// Start the server
e.Logger.Fatal(e.Start(":8080"))
}
Making Requests
Get Summary Threshold
curl -X GET http://localhost:8080/api/v1/attendance/summaries/threshold
Get Attendance Logs
curl -X GET http://localhost:8080/api/v1/device/attendance-logs -d '{"device_id": "device123"}'
Sync Attendance Logs
curl -X POST http://localhost:8080/api/v1/device/attendance-logs/sync -d '{
"device_ids": ["device123", "device456"],
"start_date": "2023-01-01",
"end_date": "2023-01-31"
}'
Compute Attendance Logs
curl -X POST http://localhost:8080/api/v1/attendance-logs/compute -d '{
"company_id": "company123",
"start_date": "2023-01-01",
"end_date": "2023-01-31"
}'
Get Attendance Details
curl -X GET http://localhost:8080/api/v1/attendance/details -d '{
"user_profile_id": "user123",
"start_date": "2023-01-01",
"end_date": "2023-01-31"
}'
This documentation provides an overview of the AttendanceLogHandler
struct, its functions, and example usage. By following the example, you can initialize the handler, bind routes, and make requests to the various endpoints.