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

Function InsertAddressBook

clientapi/routing/profile.go:94–121  ·  view source on GitHub ↗

InsertAddressBook implements POST /local/insert/addressBook

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

Source from the content-addressed store, hash-verified

92
93// InsertAddressBook implements POST /local/insert/addressBook
94func InsertAddressBook(
95 req *http.Request, profileAPI userapi.ClientUserAPI,
96) util.JSONResponse {
97 r := struct {
98 Localpart string `json:"localpart"`
99 FriendLocalpart []string `json:"friend_localpart"`
100 }{}
101 if resErr := httputil.UnmarshalJSONRequest(req, &r); resErr != nil {
102 return *resErr
103 }
104 if r.Localpart == "" || len(r.FriendLocalpart) == 0 {
105 return util.JSONResponse{
106 Code: http.StatusBadRequest,
107 JSON: jsonerror.BadJSON("'localpart' and 'friend_localpart' must be supplied."),
108 }
109 }
110 err := profileAPI.InsertAddressBook(req.Context(), r.Localpart, r.FriendLocalpart)
111 if err != nil {
112 return util.JSONResponse{
113 Code: http.StatusBadRequest,
114 JSON: jsonerror.BadJSON("InsertAddressBook err."),
115 }
116 }
117 return util.JSONResponse{
118 Code: http.StatusOK,
119 JSON: struct{}{},
120 }
121}
122
123// AddTelNumbers implements POST /local/add/telNumbers
124func AddTelNumbers(

Callers 1

SetupFunction · 0.85

Calls 2

ContextMethod · 0.80
InsertAddressBookMethod · 0.65

Tested by

no test coverage detected