MCPcopy Create free account
hub / github.com/daodst/chat / SetChatFee

Function SetChatFee

clientapi/routing/profile.go:211–254  ·  view source on GitHub ↗

SetChatFee implements POST /local/set/chatFee

(
	req *http.Request, profileAPI userapi.ClientUserAPI,
)

Source from the content-addressed store, hash-verified

209
210// SetChatFee implements POST /local/set/chatFee
211func 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}
257func GetProfile(

Callers 1

SetupFunction · 0.85

Calls 3

ContextMethod · 0.80
SelectChainDataMethod · 0.65
SetChatFeeMethod · 0.65

Tested by

no test coverage detected