-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
280 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package database | ||
|
||
import ( | ||
firebase "firebase.google.com/go" | ||
"google.golang.org/api/iterator" | ||
) | ||
|
||
func RetrieveSubscriptions(email string) (*[]map[string]interface{}, error) { | ||
app, err := firebase.NewApp(Ctx, nil, Sa) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
client, err := app.Firestore(Ctx) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
defer client.Close() | ||
|
||
subscriptionsQuery := client.Collection("subscriptions").Where("user_email", "==", email) | ||
subscriptions := subscriptionsQuery.Documents(Ctx) | ||
results := make([]map[string]interface{}, 0) | ||
for { | ||
doc, err := subscriptions.Next() | ||
if err == iterator.Done { | ||
break | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
results = append(results, doc.Data()) | ||
} | ||
return &results, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,22 @@ | ||
package database | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"gptube/config" | ||
|
||
"google.golang.org/api/option" | ||
) | ||
|
||
var Ctx context.Context | ||
var Sa option.ClientOption | ||
|
||
func init() { | ||
Ctx = context.Background() | ||
fmt.Printf("Firebase setup in %s mode.\n", config.Config("ENV_MODE")) | ||
if config.Config("ENV_MODE") == "development" { | ||
Sa = option.WithCredentialsJSON([]byte(config.Config("DB_KEYS_DEVELOPMENT"))) | ||
} else { | ||
Sa = option.WithCredentialsJSON([]byte(config.Config("DB_KEYS_PRODUCTION"))) | ||
} | ||
} |
Oops, something went wrong.
a57bb54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
gptube-subscriptions – ./subscriptions-server
gptube-subscriptions-git-main-luckly083-gmailcom.vercel.app
gptube-subscriptions.vercel.app
gptube-subscriptions-luckly083-gmailcom.vercel.app