refactor: clean code

This commit is contained in:
Fu Diwei
2025-01-17 18:01:47 +08:00
parent dab6ad917c
commit 0869eaafdd
12 changed files with 50 additions and 57 deletions

View File

@@ -9,25 +9,24 @@ import (
"github.com/labstack/echo/v5"
)
type NotifyService interface {
type notifyService interface {
Test(ctx context.Context, req *domain.NotifyTestPushReq) error
}
type notifyHandler struct {
service NotifyService
type NotifyHandler struct {
service notifyService
}
func NewNotifyHandler(route *echo.Group, service NotifyService) {
handler := &notifyHandler{
func NewNotifyHandler(route *echo.Group, service notifyService) {
handler := &NotifyHandler{
service: service,
}
group := route.Group("/notify")
group.POST("/test", handler.test)
}
func (handler *notifyHandler) test(c echo.Context) error {
func (handler *NotifyHandler) test(c echo.Context) error {
req := &domain.NotifyTestPushReq{}
if err := c.Bind(req); err != nil {
return resp.Err(c, err)

View File

@@ -8,25 +8,24 @@ import (
"github.com/usual2970/certimate/internal/rest/resp"
)
type StatisticsService interface {
type statisticsService interface {
Get(ctx context.Context) (*domain.Statistics, error)
}
type statisticsHandler struct {
service StatisticsService
type StatisticsHandler struct {
service statisticsService
}
func NewStatisticsHandler(route *echo.Group, service StatisticsService) {
handler := &statisticsHandler{
func NewStatisticsHandler(route *echo.Group, service statisticsService) {
handler := &StatisticsHandler{
service: service,
}
group := route.Group("/statistics")
group.GET("/get", handler.get)
}
func (handler *statisticsHandler) get(c echo.Context) error {
func (handler *StatisticsHandler) get(c echo.Context) error {
if statistics, err := handler.service.Get(c.Request().Context()); err != nil {
return resp.Err(c, err)
} else {

View File

@@ -8,26 +8,25 @@ import (
"github.com/usual2970/certimate/internal/rest/resp"
)
type WorkflowService interface {
type workflowService interface {
Run(ctx context.Context, req *domain.WorkflowRunReq) error
Stop()
Stop(ctx context.Context)
}
type workflowHandler struct {
service WorkflowService
type WorkflowHandler struct {
service workflowService
}
func NewWorkflowHandler(route *echo.Group, service WorkflowService) {
handler := &workflowHandler{
func NewWorkflowHandler(route *echo.Group, service workflowService) {
handler := &WorkflowHandler{
service: service,
}
group := route.Group("/workflow")
group.POST("/run", handler.run)
}
func (handler *workflowHandler) run(c echo.Context) error {
func (handler *WorkflowHandler) run(c echo.Context) error {
req := &domain.WorkflowRunReq{}
if err := c.Bind(req); err != nil {
return resp.Err(c, err)
@@ -36,5 +35,6 @@ func (handler *workflowHandler) run(c echo.Context) error {
if err := handler.service.Run(c.Request().Context(), req); err != nil {
return resp.Err(c, err)
}
return resp.Ok(c, nil)
}