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 []byte friendRequest Models.Friend 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, err = Util.ToBytes(requestJson["id"]) if requestJson["id"] == nil { 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) }