package Friends import ( "encoding/json" "io/ioutil" "net/http" "git.tovijaeschke.xyz/tovi/Envelope/Backend/Database" "git.tovijaeschke.xyz/tovi/Envelope/Backend/Models" "git.tovijaeschke.xyz/tovi/Envelope/Backend/Util" ) func FriendRequest(w http.ResponseWriter, r *http.Request) { var ( user Models.User requestBody []byte requestJson map[string]interface{} friendID string friendRequest Models.Friend ok bool err error ) user, err = Util.GetUserById(w, r) if err != nil { http.Error(w, "Not Found", http.StatusNotFound) return } requestBody, err = ioutil.ReadAll(r.Body) if err != nil { http.Error(w, "Not Found", http.StatusNotFound) return } json.Unmarshal(requestBody, &requestJson) if requestJson["id"] == nil { http.Error(w, "Invalid Data", http.StatusBadRequest) return } friendID, ok = requestJson["id"].(string) if !ok { http.Error(w, "Error", http.StatusInternalServerError) return } friendRequest = Models.Friend{ UserID: user.ID, FriendID: friendID, } err = Database.CreateFriendRequest(&friendRequest) if requestJson["id"] == nil { http.Error(w, "Error", http.StatusInternalServerError) return } w.WriteHeader(http.StatusNoContent) }