feat: update duration
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/database/models"
|
||||
)
|
||||
@@ -18,3 +21,16 @@ type TenantItem struct {
|
||||
UserCount int64
|
||||
UserBalance int64
|
||||
}
|
||||
|
||||
type TenantExpireUpdateForm struct {
|
||||
Duration int `json:"duration" validate:"required,oneof=7 30 90 180 365"`
|
||||
}
|
||||
|
||||
// Duration
|
||||
func (form *TenantExpireUpdateForm) ParseDuration() (time.Duration, error) {
|
||||
duration := time.Duration(form.Duration) * 24 * time.Hour
|
||||
if duration == 0 {
|
||||
return 0, errors.New("invalid parsed duration")
|
||||
}
|
||||
return duration, nil
|
||||
}
|
||||
|
||||
@@ -5,13 +5,12 @@
|
||||
package super
|
||||
|
||||
import (
|
||||
"quyun/v2/app/http/super/dto"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
log "github.com/sirupsen/logrus"
|
||||
_ "go.ipao.vip/atom"
|
||||
_ "go.ipao.vip/atom/contracts"
|
||||
. "go.ipao.vip/atom/fen"
|
||||
"quyun/v2/app/http/super/dto"
|
||||
)
|
||||
|
||||
// Routes implements the HttpRoute contract and provides route registration
|
||||
@@ -52,6 +51,12 @@ func (r *Routes) Register(router fiber.Router) {
|
||||
r.tenant.list,
|
||||
Query[dto.TenantFilter]("filter"),
|
||||
))
|
||||
r.log.Debugf("Registering route: Patch /super/v1/tenants/:tenantID -> tenant.updateExpire")
|
||||
router.Patch("/super/v1/tenants/:tenantID", Func2(
|
||||
r.tenant.updateExpire,
|
||||
PathParam[int64]("tenantID"),
|
||||
Body[dto.TenantExpireUpdateForm]("form"),
|
||||
))
|
||||
|
||||
r.log.Info("Successfully registered all routes")
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package super
|
||||
|
||||
import (
|
||||
"quyun/v2/app/errorx"
|
||||
"quyun/v2/app/http/super/dto"
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/app/services"
|
||||
@@ -17,3 +18,16 @@ type tenant struct{}
|
||||
func (*tenant) list(ctx fiber.Ctx, filter *dto.TenantFilter) (*requests.Pager, error) {
|
||||
return services.Tenant.Pager(ctx, filter)
|
||||
}
|
||||
|
||||
// list
|
||||
// @Router /super/v1/tenants/:tenantID [patch]
|
||||
// @Bind tenantID path
|
||||
// @Bind form body
|
||||
func (*tenant) updateExpire(ctx fiber.Ctx, tenantID int64, form *dto.TenantExpireUpdateForm) error {
|
||||
duration, err := form.ParseDuration()
|
||||
if err != nil {
|
||||
return errorx.Wrap(err).WithMsg("时间解析出错")
|
||||
}
|
||||
|
||||
return services.Tenant.AddExpireDuration(ctx, tenantID, duration)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user