mirror of
https://github.com/usual2970/certimate.git
synced 2025-07-19 17:37:59 +00:00
feat: migrate pocketbase to v0.23
This commit is contained in:
36
internal/rest/handlers/statistics.go
Normal file
36
internal/rest/handlers/statistics.go
Normal file
@@ -0,0 +1,36 @@
|
||||
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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user