(c *gin.Context)
| 58 | } |
| 59 | |
| 60 | func getProjects(c *gin.Context) { |
| 61 | developer := getDeveloperID(c) |
| 62 | p, err := model.GetMainAccount(model.GetDB(c), developer) |
| 63 | if err != nil { |
| 64 | _ = c.Error(err) |
| 65 | abortWithError(c, http.StatusForbidden, ErrNoMainAccount) |
| 66 | return |
| 67 | } |
| 68 | |
| 69 | projectList, err := model.GetProjects(model.GetDB(c), developer, p.ID) |
| 70 | if err != nil { |
| 71 | _ = c.Error(err) |
| 72 | abortWithError(c, http.StatusForbidden, ErrGetProjectsFailed) |
| 73 | return |
| 74 | } |
| 75 | |
| 76 | accountAddr, err := p.Account.Get() |
| 77 | if err != nil { |
| 78 | _ = c.Error(err) |
| 79 | abortWithError(c, http.StatusBadRequest, ErrParseAccountFailed) |
| 80 | return |
| 81 | } |
| 82 | |
| 83 | var apiResp []gin.H |
| 84 | |
| 85 | for _, p := range projectList { |
| 86 | var ( |
| 87 | profile *types.SQLChainProfile |
| 88 | balance gin.H |
| 89 | ) |
| 90 | |
| 91 | if profile, err = getDatabaseProfile(p.DB); err != nil { |
| 92 | _ = c.Error(err) |
| 93 | abortWithError(c, http.StatusInternalServerError, ErrSendETLSRPCFailed) |
| 94 | return |
| 95 | } |
| 96 | |
| 97 | for _, user := range profile.Users { |
| 98 | if user.Address == accountAddr { |
| 99 | balance = gin.H{ |
| 100 | "deposit": user.Deposit, |
| 101 | "arrears": user.Arrears, |
| 102 | "advance_payment": user.AdvancePayment, |
| 103 | } |
| 104 | break |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | apiResp = append(apiResp, gin.H{ |
| 109 | "id": p.ID, |
| 110 | "project": p.DB, |
| 111 | "alias": p.Alias, |
| 112 | "balance": balance, |
| 113 | }) |
| 114 | } |
| 115 | |
| 116 | responseWithData(c, http.StatusOK, gin.H{ |
| 117 | "projects": apiResp, |
nothing calls this directly
no test coverage detected