feat: 添加独立其他设置菜单及有效端参数保存

This commit is contained in:
Yvan
2026-11-04 21:18:31 +08:00
parent c2e8b729be
commit ca9ce99b66
27 changed files with 805 additions and 9 deletions
+2 -1
View File
@@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"sort"
"strconv"
"strings"
"testing"
@@ -136,7 +137,7 @@ func TestGinStartupLogsEveryRegisteredRoute(t *testing.T) {
if got, want := strings.Count(text, `"msg":"router registered"`), len(engine.Routes()); got != want {
t.Fatalf("registered route log count = %d, want %d", got, want)
}
if !strings.Contains(text, `"msg":"router register success"`) || !strings.Contains(text, `"route_count":252`) {
if !strings.Contains(text, `"msg":"router register success"`) || !strings.Contains(text, `"route_count":`+strconv.Itoa(len(engine.Routes()))) {
t.Fatalf("startup route summary is missing: %s", text)
}
}
+39
View File
@@ -0,0 +1,39 @@
package handler
import (
"github.com/gin-gonic/gin"
"github.com/go-kratos/kratos/v3/errors"
"kra/internal/service/business"
"kra/internal/service/dto"
)
type OtherSettings struct {
service *business.OtherSettingsService
}
func NewOtherSettings(service *business.OtherSettingsService) *OtherSettings {
return &OtherSettings{service: service}
}
func (h *OtherSettings) Get(c *gin.Context) {
value, err := h.service.Get(c.Request.Context())
if err != nil {
Fail(c, errors.FromError(err).Message)
return
}
OKWithData(c, value)
}
func (h *OtherSettings) Save(c *gin.Context) {
var req dto.OtherSettingsRequest
if err := c.ShouldBindJSON(&req); err != nil {
Fail(c, "请输入完整的整数金额和天数")
return
}
value, err := h.service.Save(c.Request.Context(), &req)
if err != nil {
Fail(c, errors.FromError(err).Message)
return
}
OKWithData(c, value)
}
+1
View File
@@ -5,6 +5,7 @@ import "github.com/google/wire"
// ProviderSet wires the system HTTP handlers. Set itself is filled field by
// field so adding a handler only means adding its constructor here.
var ProviderSet = wire.NewSet(
NewOtherSettings,
NewBusiness,
NewBusinessPassword,
NewBusinessPromote,
+1
View File
@@ -1,6 +1,7 @@
package handler
type Set struct {
OtherSettings *OtherSettings
Ranking *Ranking
Workbench *Workbench
ServerAnalysis *ServerAnalysis
+11
View File
@@ -0,0 +1,11 @@
package router
import (
"github.com/gin-gonic/gin"
"kra/internal/server/handler"
)
func RegisterOtherSettings(private *gin.RouterGroup, h *handler.OtherSettings) {
private.GET("/sw/settings/effectiveness", h.Get)
private.PUT("/sw/settings/effectiveness", h.Save)
}
+1
View File
@@ -20,6 +20,7 @@ func (r *Routes) RegisterRoutes(public, private *gin.RouterGroup, engine *gin.En
return
}
registrations := []func(){
func() { RegisterOtherSettings(private, r.handlers.OtherSettings) },
func() {
private.GET("/sw/rank/channel", r.handlers.Ranking.Channel)
private.GET("/sw/rank/business", r.handlers.Ranking.Business)