(manager task.Manager[T], callback func(task T))
| 100 | } |
| 101 | |
| 102 | func getBatchHandler[T task.TaskExtensionInfo](manager task.Manager[T], callback func(task T)) gin.HandlerFunc { |
| 103 | return func(c *gin.Context) { |
| 104 | isAdmin, uid, ok := getUserInfo(c) |
| 105 | if !ok { |
| 106 | common.ErrorStrResp(c, "user invalid", 401) |
| 107 | return |
| 108 | } |
| 109 | var tids []string |
| 110 | if err := c.ShouldBind(&tids); err != nil { |
| 111 | common.ErrorStrResp(c, "invalid request format", 400) |
| 112 | return |
| 113 | } |
| 114 | retErrs := make(map[string]string) |
| 115 | for _, tid := range tids { |
| 116 | t, ok := manager.GetByID(tid) |
| 117 | if !ok || (!isAdmin && uid != t.GetCreator().ID) { |
| 118 | retErrs[tid] = "task not found" |
| 119 | continue |
| 120 | } |
| 121 | callback(t) |
| 122 | } |
| 123 | common.SuccessResp(c, retErrs) |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | func taskRoute[T task.TaskExtensionInfo](g *gin.RouterGroup, manager task.Manager[T]) { |
| 128 | g.GET("/undone", func(c *gin.Context) { |
no test coverage detected