feat(node): add PreViewNodeMultiplier endpoint and response structure
This commit is contained in:
parent
02f0d711ba
commit
453ad18303
@ -18,6 +18,10 @@ type (
|
|||||||
SetNodeMultiplierRequest {
|
SetNodeMultiplierRequest {
|
||||||
Periods []TimePeriod `json:"periods"`
|
Periods []TimePeriod `json:"periods"`
|
||||||
}
|
}
|
||||||
|
PreViewNodeMultiplierResponse {
|
||||||
|
CurrentTime string `json:"current_time"`
|
||||||
|
Ratio float32 `json:"ratio"`
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@server (
|
@server (
|
||||||
@ -117,5 +121,9 @@ service ppanel {
|
|||||||
@doc "Update Verify Code Config"
|
@doc "Update Verify Code Config"
|
||||||
@handler UpdateVerifyCodeConfig
|
@handler UpdateVerifyCodeConfig
|
||||||
put /verify_code_config (VerifyCodeConfig)
|
put /verify_code_config (VerifyCodeConfig)
|
||||||
|
|
||||||
|
@doc "PreView Node Multiplier"
|
||||||
|
@handler PreViewNodeMultiplier
|
||||||
|
get /node_multiplier/preview returns (PreViewNodeMultiplierResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -69,7 +69,6 @@ func Node(ctx *svc.ServiceContext) {
|
|||||||
|
|
||||||
nodeMultiplierData, err := ctx.SystemModel.FindNodeMultiplierConfig(context.Background())
|
nodeMultiplierData, err := ctx.SystemModel.FindNodeMultiplierConfig(context.Background())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
||||||
logger.Error("Get Node Multiplier Config Error: ", logger.Field("error", err.Error()))
|
logger.Error("Get Node Multiplier Config Error: ", logger.Field("error", err.Error()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,18 @@
|
|||||||
|
package system
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/perfect-panel/server/internal/logic/admin/system"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/pkg/result"
|
||||||
|
)
|
||||||
|
|
||||||
|
// PreView Node Multiplier
|
||||||
|
func PreViewNodeMultiplierHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
|
||||||
|
l := system.NewPreViewNodeMultiplierLogic(c.Request.Context(), svcCtx)
|
||||||
|
resp, err := l.PreViewNodeMultiplier()
|
||||||
|
result.HttpResult(c, resp, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -414,6 +414,9 @@ func RegisterHandlers(router *gin.Engine, serverCtx *svc.ServiceContext) {
|
|||||||
// Update node config
|
// Update node config
|
||||||
adminSystemGroupRouter.PUT("/node_config", adminSystem.UpdateNodeConfigHandler(serverCtx))
|
adminSystemGroupRouter.PUT("/node_config", adminSystem.UpdateNodeConfigHandler(serverCtx))
|
||||||
|
|
||||||
|
// PreView Node Multiplier
|
||||||
|
adminSystemGroupRouter.GET("/node_multiplier/preview", adminSystem.PreViewNodeMultiplierHandler(serverCtx))
|
||||||
|
|
||||||
// get Privacy Policy Config
|
// get Privacy Policy Config
|
||||||
adminSystemGroupRouter.GET("/privacy", adminSystem.GetPrivacyPolicyConfigHandler(serverCtx))
|
adminSystemGroupRouter.GET("/privacy", adminSystem.GetPrivacyPolicyConfigHandler(serverCtx))
|
||||||
|
|
||||||
|
|||||||
33
internal/logic/admin/system/preViewNodeMultiplierLogic.go
Normal file
33
internal/logic/admin/system/preViewNodeMultiplierLogic.go
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package system
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/perfect-panel/server/internal/svc"
|
||||||
|
"github.com/perfect-panel/server/internal/types"
|
||||||
|
"github.com/perfect-panel/server/pkg/logger"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type PreViewNodeMultiplierLogic struct {
|
||||||
|
logger.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
// PreView Node Multiplier
|
||||||
|
func NewPreViewNodeMultiplierLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PreViewNodeMultiplierLogic {
|
||||||
|
return &PreViewNodeMultiplierLogic{
|
||||||
|
Logger: logger.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *PreViewNodeMultiplierLogic) PreViewNodeMultiplier() (resp *types.PreViewNodeMultiplierResponse, err error) {
|
||||||
|
now := time.Now()
|
||||||
|
ratio := l.svcCtx.NodeMultiplierManager.GetMultiplier(now)
|
||||||
|
return &types.PreViewNodeMultiplierResponse{
|
||||||
|
Ratio: ratio,
|
||||||
|
CurrentTime: now.Format("2006-01-02 15:04:05"),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
@ -1429,6 +1429,11 @@ type PreUnsubscribeResponse struct {
|
|||||||
DeductionAmount int64 `json:"deduction_amount"`
|
DeductionAmount int64 `json:"deduction_amount"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type PreViewNodeMultiplierResponse struct {
|
||||||
|
CurrentTime string `json:"current_time"`
|
||||||
|
Ratio float32 `json:"ratio"`
|
||||||
|
}
|
||||||
|
|
||||||
type PreviewSubscribeTemplateRequest struct {
|
type PreviewSubscribeTemplateRequest struct {
|
||||||
Id int64 `form:"id"`
|
Id int64 `form:"id"`
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user