Files
.github
.vscode
docker
internal
app
applicant
certificate
deployer
domain
notify
pkg
repository
rest
handlers
certificate.go
notify.go
statistics.go
workflow.go
resp
routes
scheduler
statistics
workflow
migrations
ui
.dockerignore
.editorconfig
.gitignore
.goreleaser.yml
CHANGELOG.md
CONTRIBUTING.md
CONTRIBUTING_EN.md
Dockerfile
LICENSE.md
Makefile
README.md
README_EN.md
go.mod
go.sum
main.go
nixpacks.toml
certimate/internal/rest/handlers/statistics.go
2025-01-18 07:09:41 +08:00

37 lines
841 B
Go

package handlers
import (
"context"
"github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/tools/router"
"github.com/usual2970/certimate/internal/domain"
"github.com/usual2970/certimate/internal/rest/resp"
)
type statisticsService interface {
Get(ctx context.Context) (*domain.Statistics, error)
}
type StatisticsHandler struct {
service statisticsService
}
func NewStatisticsHandler(router *router.RouterGroup[*core.RequestEvent], service statisticsService) {
handler := &StatisticsHandler{
service: service,
}
group := router.Group("/statistics")
group.GET("/get", handler.get)
}
func (handler *StatisticsHandler) get(e *core.RequestEvent) error {
if statistics, err := handler.service.Get(e.Request.Context()); err != nil {
return resp.Err(e, err)
} else {
return resp.Ok(e, statistics)
}
}