AddMortgage implements POST /local/add/mortgage
( req *http.Request, profileAPI userapi.ClientUserAPI, )
| 153 | |
| 154 | // AddMortgage implements POST /local/add/mortgage |
| 155 | func AddMortgage( |
| 156 | req *http.Request, profileAPI userapi.ClientUserAPI, |
| 157 | ) util.JSONResponse { |
| 158 | r := struct { |
| 159 | Localpart string `json:"localpart"` |
| 160 | MortgageFee string `json:"mortgage_fee"` |
| 161 | }{} |
| 162 | if resErr := httputil.UnmarshalJSONRequest(req, &r); resErr != nil { |
| 163 | return *resErr |
| 164 | } |
| 165 | if r.Localpart == "" { |
| 166 | return util.JSONResponse{ |
| 167 | Code: http.StatusBadRequest, |
| 168 | JSON: jsonerror.BadJSON("invalid params."), |
| 169 | } |
| 170 | } |
| 171 | // chain data,! |
| 172 | chainData, err := profileAPI.SelectChainData(req.Context(), r.Localpart) |
| 173 | if err != nil || chainData == nil || chainData.Localpart == "" { |
| 174 | return util.JSONResponse{ |
| 175 | Code: http.StatusBadRequest, |
| 176 | JSON: jsonerror.BadJSON("bad request."), |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | var currentFee, addFee types2.Int |
| 181 | currentFee, ok := types2.NewIntFromString(chainData.MortgageFee) |
| 182 | if !ok { |
| 183 | return util.JSONResponse{ |
| 184 | Code: http.StatusBadRequest, |
| 185 | JSON: jsonerror.BadJSON(""), |
| 186 | } |
| 187 | } |
| 188 | addFee, ok2 := types2.NewIntFromString(r.MortgageFee) |
| 189 | if !ok2 { |
| 190 | return util.JSONResponse{ |
| 191 | Code: http.StatusBadRequest, |
| 192 | JSON: jsonerror.BadJSON(""), |
| 193 | } |
| 194 | } |
| 195 | finalFee := currentFee.Add(addFee).String() |
| 196 | |
| 197 | err = profileAPI.SetMortgageFee(req.Context(), r.Localpart, finalFee) |
| 198 | if err != nil { |
| 199 | return util.JSONResponse{ |
| 200 | Code: http.StatusBadRequest, |
| 201 | JSON: jsonerror.BadJSON("!"), |
| 202 | } |
| 203 | } |
| 204 | return util.JSONResponse{ |
| 205 | Code: http.StatusOK, |
| 206 | JSON: struct{}{}, |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | // SetChatFee implements POST /local/set/chatFee |
| 211 | func SetChatFee( |
no test coverage detected