SetChatFee implements POST /local/set/chatFee
( req *http.Request, profileAPI userapi.ClientUserAPI, )
| 209 | |
| 210 | // SetChatFee implements POST /local/set/chatFee |
| 211 | func SetChatFee( |
| 212 | req *http.Request, profileAPI userapi.ClientUserAPI, |
| 213 | ) util.JSONResponse { |
| 214 | r := struct { |
| 215 | Localpart string `json:"localpart"` |
| 216 | ChatFee string `json:"chat_fee"` |
| 217 | }{} |
| 218 | if resErr := httputil.UnmarshalJSONRequest(req, &r); resErr != nil { |
| 219 | return *resErr |
| 220 | } |
| 221 | if r.Localpart == "" { |
| 222 | return util.JSONResponse{ |
| 223 | Code: http.StatusBadRequest, |
| 224 | JSON: jsonerror.BadJSON("invalid params."), |
| 225 | } |
| 226 | } |
| 227 | // chain data,! |
| 228 | chainData, err := profileAPI.SelectChainData(req.Context(), r.Localpart) |
| 229 | if err != nil || chainData == nil || chainData.Localpart == "" { |
| 230 | return util.JSONResponse{ |
| 231 | Code: http.StatusBadRequest, |
| 232 | JSON: jsonerror.BadJSON("bad request."), |
| 233 | } |
| 234 | } |
| 235 | _, ok := types2.NewIntFromString(r.ChatFee) |
| 236 | if !ok { |
| 237 | return util.JSONResponse{ |
| 238 | Code: http.StatusBadRequest, |
| 239 | JSON: jsonerror.BadJSON(""), |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | err = profileAPI.SetChatFee(req.Context(), r.Localpart, r.ChatFee) |
| 244 | if err != nil { |
| 245 | return util.JSONResponse{ |
| 246 | Code: http.StatusBadRequest, |
| 247 | JSON: jsonerror.BadJSON("!"), |
| 248 | } |
| 249 | } |
| 250 | return util.JSONResponse{ |
| 251 | Code: http.StatusOK, |
| 252 | JSON: struct{}{}, |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | // GetProfile implements GET /profile/{userID} |
| 257 | func GetProfile( |
no test coverage detected