package Friends import ( "encoding/json" "io/ioutil" "net/http" "git.tovijaeschke.xyz/tovi/Envelope/Backend/Database" "git.tovijaeschke.xyz/tovi/Envelope/Backend/Models" ) // CreateFriendRequest creates a FriendRequest from post data func CreateFriendRequest(w http.ResponseWriter, r *http.Request) { var ( friendRequest Models.FriendRequest requestBody []byte returnJSON []byte err error ) requestBody, err = ioutil.ReadAll(r.Body) if err != nil { panic(err) } err = json.Unmarshal(requestBody, &friendRequest) if err != nil { panic(err) } friendRequest.AcceptedAt.Scan(nil) err = Database.CreateFriendRequest(&friendRequest) if err != nil { panic(err) } returnJSON, err = json.MarshalIndent(friendRequest, "", " ") if err != nil { http.Error(w, "Error", http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError) return } // Return updated json w.WriteHeader(http.StatusOK) w.Write(returnJSON) }