feat: migrate pocketbase to v0.23

This commit is contained in:
Fu Diwei
2025-01-18 05:22:18 +08:00
parent 1568e5a2a7
commit 32f9c95dd0
46 changed files with 632 additions and 674 deletions

View File

@@ -0,0 +1,41 @@
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 notifyService interface {
Test(ctx context.Context, req *domain.NotifyTestPushReq) error
}
type NotifyHandler struct {
service notifyService
}
func NewNotifyHandler(router *router.RouterGroup[*core.RequestEvent], service notifyService) {
handler := &NotifyHandler{
service: service,
}
group := router.Group("/notify")
group.POST("/test", handler.test)
}
func (handler *NotifyHandler) test(e *core.RequestEvent) error {
req := &domain.NotifyTestPushReq{}
if err := e.BindBody(req); err != nil {
return resp.Err(e, err)
}
if err := handler.service.Test(e.Request.Context(), req); err != nil {
return resp.Err(e, err)
}
return resp.Ok(e, nil)
}

View 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)
}
}

View File

@@ -0,0 +1,42 @@
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 workflowService interface {
Run(ctx context.Context, req *domain.WorkflowRunReq) error
Stop(ctx context.Context)
}
type WorkflowHandler struct {
service workflowService
}
func NewWorkflowHandler(router *router.RouterGroup[*core.RequestEvent], service workflowService) {
handler := &WorkflowHandler{
service: service,
}
group := router.Group("/workflow")
group.POST("/run", handler.run)
}
func (handler *WorkflowHandler) run(e *core.RequestEvent) error {
req := &domain.WorkflowRunReq{}
if err := e.BindBody(req); err != nil {
return resp.Err(e, err)
}
if err := handler.service.Run(e.Request.Context(), req); err != nil {
return resp.Err(e, err)
}
return resp.Ok(e, nil)
}