add optional UserId field to resource specifications; enhance user tracking in resource updates

Signed-off-by: jagger <cossjie@foxmail.com>
This commit is contained in:
jagger 2025-07-25 20:25:02 +08:00
parent d672a1e0b8
commit a7f90f139a
4 changed files with 18 additions and 4 deletions

View File

@ -1480,9 +1480,10 @@ type EditResourceReq {
CpuUnit string `json:"cpuUnit,optional"`
MemoryValue string `json:"memoryValue,optional"`
MemoryUnit string `json:"memoryUnit,optional"`
UserId int64 `json:"userId,optional"`
}
type SyncResourceReq {
Id string `json:"id"`
UserId int64 `json:"userId"`
UserId int64 `json:"userId,optional"`
}

View File

@ -6,6 +6,7 @@ import (
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/repository/result"
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
"net/http"
)
@ -17,6 +18,15 @@ func EditResourceSpecHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return
}
token := r.Header.Get("Authorization")
// 获取用户信息
jccUserInfo, err := utils.ParseTokenWithoutVerify(token)
if err != nil {
result.ParamErrorResult(r, w, err)
return
}
req.UserId = jccUserInfo.Id
l := core.NewEditResourceSpecLogic(r.Context(), svcCtx)
resp, err := l.EditResourceSpec(&req)
result.HttpResult(r, w, resp, err)

View File

@ -58,7 +58,7 @@ func (l *EditResourceSpecLogic) EditResourceSpec(req *types.EditResourceReq) (re
costPerUnit := utils.StringToFloat64(req.CostPerUnit)
// 4. 更新主资源规格
if err = updateMainResourceSpec(tx, req.Id, statusInt, req.CostType, costPerUnit); err != nil {
if err = updateMainResourceSpec(tx, req.Id, statusInt, req.CostType, costPerUnit, req.UserId); err != nil {
return nil, err
}
@ -98,13 +98,14 @@ func validateRequestParams(req *types.EditResourceReq) error {
}
// updateMainResourceSpec 更新主资源规格
func updateMainResourceSpec(tx *gorm.DB, id int64, status int64, costType string, costPerUnit float64) error {
func updateMainResourceSpec(tx *gorm.DB, id int64, status int64, costType string, costPerUnit float64, userId int64) error {
return tx.Model(&models.TResourceSpec{}).
Where("id = ?", id).
Updates(map[string]interface{}{
"status": status,
"cost_type": costType,
"cost_per_unit": costPerUnit,
"user_id": userId,
}).
Error
}

View File

@ -2145,6 +2145,8 @@ type EditResourceReq struct {
CpuUnit string `json:"cpuUnit,optional"`
MemoryValue string `json:"memoryValue,optional"`
MemoryUnit string `json:"memoryUnit,optional"`
UserId int64 `json:"userId,optional"`
}
type EndpointsReq struct {
@ -5568,7 +5570,7 @@ type SyncClusterAlertReq struct {
type SyncResourceReq struct {
Id string `json:"id"`
UserId int64 `json:"userId"`
UserId int64 `json:"userId,optional"`
}
type Tags struct {