(c *gin.Context)
| 73 | } |
| 74 | |
| 75 | func topUp(c *gin.Context) { |
| 76 | r := struct { |
| 77 | Database proto.DatabaseID `json:"db" form:"db" uri:"db" binding:"required,len=64"` |
| 78 | Amount uint64 `json:"amount" form:"amount" binding:"gt=0"` |
| 79 | }{} |
| 80 | |
| 81 | _ = c.ShouldBindUri(&r) |
| 82 | |
| 83 | if err := c.ShouldBind(&r); err != nil { |
| 84 | abortWithError(c, http.StatusBadRequest, err) |
| 85 | return |
| 86 | } |
| 87 | |
| 88 | developer := getDeveloperID(c) |
| 89 | |
| 90 | p, err := model.GetMainAccount(model.GetDB(c), developer) |
| 91 | if err != nil { |
| 92 | _ = c.Error(err) |
| 93 | abortWithError(c, http.StatusBadRequest, ErrNoMainAccount) |
| 94 | return |
| 95 | } |
| 96 | |
| 97 | // run task |
| 98 | taskID, err := getTaskManager(c).New(model.TaskTopUp, developer, p.ID, gin.H{ |
| 99 | "db": r.Database, |
| 100 | "amount": r.Amount, |
| 101 | }) |
| 102 | if err != nil { |
| 103 | _ = c.Error(err) |
| 104 | abortWithError(c, http.StatusInternalServerError, ErrCreateTaskFailed) |
| 105 | return |
| 106 | } |
| 107 | |
| 108 | responseWithData(c, http.StatusOK, gin.H{ |
| 109 | "task_id": taskID, |
| 110 | "amount": r.Amount, |
| 111 | }) |
| 112 | } |
| 113 | |
| 114 | func databaseBalance(c *gin.Context) { |
| 115 | r := struct { |
nothing calls this directly
no test coverage detected