Skip to content
Snippets Groups Projects
Commit a6d48ffe authored by Hans Kristian Hoel's avatar Hans Kristian Hoel
Browse files

i have implementet delete func to firebase

parent bd5242a5
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,7 @@ func main() { ...@@ -17,6 +17,7 @@ func main() {
assignment2.FBInit() assignment2.FBInit()
//assignment2.FBSave() //assignment2.FBSave()
//assignment2.FBRead() //assignment2.FBRead()
//assignment2.FBDelete()
defer assignment2.FBClose() defer assignment2.FBClose()
port := os.Getenv("PORT") port := os.Getenv("PORT")
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"log" "log"
"github.com/pkg/errors"
"golang.org/x/net/context" "golang.org/x/net/context"
firebase "firebase.google.com/go" // Same as python's import dependency as alias. firebase "firebase.google.com/go" // Same as python's import dependency as alias.
...@@ -77,3 +78,24 @@ func FBRead() { ...@@ -77,3 +78,24 @@ func FBRead() {
} }
} }
func FBDelete(ID string) error {
docRef := fb.Client.Collection("Webhooks").Doc(ID)
_, err := docRef.Delete(fb.Ctx)
if err != nil {
fmt.Printf("ERROR deleting student (%v) from Firestore DB: %v\n", err)
return errors.Wrap(err, "Error in FirebaseDatabase.Delete()")
}
return nil
}
// Delete deletes a students from the DB.
// func (db *FirestoreDatabase) Delete(s *Student) error {
// docRef := db.Client.Collection(db.CollectionName).Doc(s.ID)
// _, err := docRef.Delete(db.Ctx)
// if err != nil {
// fmt.Printf("ERROR deleting student (%v) from Firestore DB: %v\n", s, err)
// return errors.Wrap(err, "Error in FirebaseDatabase.Delete()")
// }
// return nil
// }
...@@ -61,6 +61,18 @@ func WebhookHandeler(w http.ResponseWriter, r *http.Request) { ...@@ -61,6 +61,18 @@ func WebhookHandeler(w http.ResponseWriter, r *http.Request) {
} }
} }
case http.MethodDelete:
err := json.NewDecoder(r.Body).Decode(&webhook) //decode to webhook
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
}
err = FBDelete(webhook.ID)
if err != nil {
fmt.Println("Error: ", err)
}
default: default:
http.Error(w, "Method is invalid "+r.Method, http.StatusBadRequest) http.Error(w, "Method is invalid "+r.Method, http.StatusBadRequest)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment