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

Implementet firebase read func and conneceted it with webhooks get

parent b53eab04
Branches
No related tags found
No related merge requests found
......@@ -16,7 +16,7 @@ func main() {
assignment2.FBInit()
//assignment2.FBSave()
assignment2.FBRead()
//assignment2.FBRead()
defer assignment2.FBClose()
port := os.Getenv("PORT")
......
......@@ -42,18 +42,18 @@ func FBClose() {
func FBSave() {
ref := fb.Client.Collection(webhook.Event).NewDoc()
ref := fb.Client.Collection("Webhooks").NewDoc()
webhook.ID = ref.ID
_, err := ref.Set(fb.Ctx, webhook)
if err != nil {
fmt.Println("ERROR saving student to Firestore DB: ", err)
fmt.Println("ERROR saving webhook to Firestore DB: ", err)
//return errors.Wrap(err, "Error in FirebaseDatabase.Save()")
}
// return nil
}
func FBRead() {
iter := fb.Client.Collection("users").Documents(fb.Ctx)
iter := fb.Client.Collection("Webhooks").Documents(fb.Ctx)
for {
doc, err := iter.Next()
if err == iterator.Done {
......@@ -63,5 +63,7 @@ func FBRead() {
log.Fatalf("Failed to iterate: %v", err)
}
fmt.Println(doc.Data())
doc.DataTo(&webhook)
webhooks = append(webhooks, webhook)
}
}
......@@ -56,7 +56,7 @@ type Status struct {
type WebhookRegistration struct {
ID string `json:"id"`
Event string `json:"Event"`
Event string `json:"event"`
URL string `json:"url"`
Time time.Time `json:"time"`
}
......
......@@ -39,10 +39,12 @@ func WebhookHandeler(w http.ResponseWriter, r *http.Request) {
fmt.Println("Webhooks " + webhook.URL + " has been regstrerd")
case http.MethodGet:
FBRead()
err := json.NewEncoder(w).Encode(webhooks)
if err != nil {
http.Error(w, "Some thing went wrong"+err.Error(), http.StatusInternalServerError)
}
//FBRead()
default:
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