Browse Source

#1249

add batch config api
tags/v1.22.9.2^2
chenyifan01 3 years ago
parent
commit
5a9d544003
4 changed files with 34 additions and 7 deletions
  1. +3
    -0
      models/task_config.go
  2. +11
    -7
      routers/routes/routes.go
  3. +16
    -0
      routers/task/config.go
  4. +4
    -0
      services/task/task_config.go

+ 3
- 0
models/task_config.go View File

@@ -62,6 +62,9 @@ type TaskConfigWithLimit struct {
CreatedUnix timeutil.TimeStamp
Limiters []*LimitConfigVO
}
type BatchLimitConfigVO struct {
ConfigList []TaskConfigWithLimit
}

func getTaskConfig(t *TaskConfig) (*TaskConfig, error) {
has, err := x.Get(t)


+ 11
- 7
routers/routes/routes.go View File

@@ -589,6 +589,17 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Post("/delete", admin.DeleteNotices)
m.Post("/empty", admin.EmptyNotices)
})

m.Group("/reward/point", func() {
m.Get("/limiter/list", point.GetPointLimitConfigList)
m.Post("/limiter/add", bindIgnErr(models.LimitConfigVO{}), point.AddPointLimitConfig)
})

m.Group("/task/config", func() {
m.Get("/list", task.GetTaskConfigList)
m.Post("/add", bindIgnErr(models.TaskConfigWithLimit{}), task.AddTaskConfig)
m.Post("/add/batch", bindIgnErr(models.BatchLimitConfigVO{}), task.BatchAddTaskConfig)
})
}, adminReq)
// ***** END: Admin *****

@@ -1318,13 +1329,6 @@ func RegisterRoutes(m *macaron.Macaron) {

m.Group("/reward/point", func() {
m.Get("/account", point.GetPointAccount)
m.Get("/limiter/list", point.GetPointLimitConfigList)
m.Post("/limiter/add", bindIgnErr(models.LimitConfigVO{}), point.AddPointLimitConfig)
}, reqSignIn)

m.Group("/task/config", func() {
m.Get("/list", task.GetTaskConfigList)
m.Post("/add", bindIgnErr(models.TaskConfigWithLimit{}), task.AddTaskConfig)
}, reqSignIn)

if setting.API.EnableSwagger {


+ 16
- 0
routers/task/config.go View File

@@ -25,3 +25,19 @@ func AddTaskConfig(ctx *context.Context, config models.TaskConfigWithLimit) {
}
ctx.JSON(http.StatusOK, response.Success())
}
func BatchAddTaskConfig(ctx *context.Context, list models.BatchLimitConfigVO) {
successCount := 0
failCount := 0
for _, config := range list.ConfigList {
err := task.AddTaskConfig(config, ctx.User)
if err != nil {
failCount++
} else {
successCount++
}
}
r := make(map[string]int, 2)
r["successCount"] = successCount
r["failCount"] = failCount
ctx.JSON(http.StatusOK, response.SuccessWithData(r))
}

+ 4
- 0
services/task/task_config.go View File

@@ -7,6 +7,7 @@ import (
"code.gitea.io/gitea/modules/redis/redis_key"
"code.gitea.io/gitea/services/reward/limiter"
"encoding/json"
"errors"
"time"
)

@@ -86,6 +87,9 @@ func GetTaskConfigWithLimitList() ([]*models.TaskConfigWithLimit, error) {
}

func AddTaskConfig(config models.TaskConfigWithLimit, doer *models.User) error {
if config.TaskCode == "" || config.AwardType == "" {
return errors.New("param error")
}
err := models.AddTaskConfig(config, doer)
if err != nil {
log.Error("add task config error,config:%v err:%v", config, err)


Loading…
Cancel
Save