Skip to content

Commit

Permalink
feat: update group
Browse files Browse the repository at this point in the history
  • Loading branch information
zijiren233 committed Feb 27, 2025
1 parent a269af5 commit f12c152
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
25 changes: 25 additions & 0 deletions service/aiproxy/controller/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,28 @@ func CreateGroup(c *gin.Context) {
}
middleware.SuccessResponse(c, nil)
}

func UpdateGroup(c *gin.Context) {
group := c.Param("group")
if group == "" {
middleware.ErrorResponse(c, http.StatusOK, "invalid parameter")
return
}
req := CreateGroupRequest{}
err := json.NewDecoder(c.Request.Body).Decode(&req)
if err != nil {
middleware.ErrorResponse(c, http.StatusOK, "invalid parameter")
return
}
err = model.UpdateGroup(group, &model.Group{
RPMRatio: req.RPMRatio,
RPM: req.RPM,
TPMRatio: req.TPMRatio,
TPM: req.TPM,
})
if err != nil {
middleware.ErrorResponse(c, http.StatusOK, err.Error())
return
}
middleware.SuccessResponse(c, nil)
}
19 changes: 19 additions & 0 deletions service/aiproxy/model/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,25 @@ func DeleteGroupsByIDs(ids []string) (err error) {
})
}

func UpdateGroup(id string, group *Group) (err error) {
if id == "" {
return errors.New("group id is empty")
}
defer func() {
if err == nil {
if err := CacheDeleteGroup(id); err != nil {
log.Error("cache delete group failed: " + err.Error())
}
}
}()
result := DB.
Clauses(clause.Returning{}).
Where("id = ?", id).
Select("rpm_ratio", "rpm", "tpm_ratio", "tpm").
Updates(group)
return HandleUpdateResult(result, ErrGroupNotFound)
}

func UpdateGroupUsedAmountAndRequestCount(id string, amount float64, count int) (err error) {
group := &Group{ID: id}
defer func() {
Expand Down
1 change: 1 addition & 0 deletions service/aiproxy/router/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func SetAPIRouter(router *gin.Engine) {
groupRoute := apiRouter.Group("/group")
{
groupRoute.POST("/:group", controller.CreateGroup)
groupRoute.PUT("/:group", controller.UpdateGroup)
groupRoute.GET("/:group", controller.GetGroup)
groupRoute.DELETE("/:group", controller.DeleteGroup)
groupRoute.POST("/:group/status", controller.UpdateGroupStatus)
Expand Down

0 comments on commit f12c152

Please sign in to comment.