repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
c9aa505
parent
a4f4855
author
Eric Bower
date
2024-12-03 21:07:25 +0000 UTC
chore(plus): record purchasing email address
6 files changed,  +8, -8
M auth/api.go
+1, -1
1@@ -555,7 +555,7 @@ func paymentWebhookHandler(apiConfig *shared.ApiConfig) http.HandlerFunc {
2 			return
3 		}
4 
5-		err = dbpool.AddPicoPlusUser(username, "lemonsqueezy", txID)
6+		err = dbpool.AddPicoPlusUser(username, email, "lemonsqueezy", txID)
7 		if err != nil {
8 			log.Error("failed to add pico+ user", "err", err)
9 			w.WriteHeader(http.StatusOK)
M auth/api_test.go
+1, -1
1@@ -197,7 +197,7 @@ type AuthDb struct {
2 	*stub.StubDB
3 }
4 
5-func (a *AuthDb) AddPicoPlusUser(username, from, txid string) error {
6+func (a *AuthDb) AddPicoPlusUser(username, email, from, txid string) error {
7 	return nil
8 }
9 
M cmd/scripts/pico-plus/main.go
+1, -1
1@@ -30,7 +30,7 @@ func main() {
2 		"txId", txId,
3 	)
4 
5-	err := dbpool.AddPicoPlusUser(username, paymentType, txId)
6+	err := dbpool.AddPicoPlusUser(username, "test@pico.sh", paymentType, txId)
7 	if err != nil {
8 		logger.Error("Failed to add pico+ user", "err", err)
9 		os.Exit(1)
M db/db.go
+1, -1
1@@ -381,7 +381,7 @@ type DB interface {
2 	VisitSummary(opts *SummaryOpts) (*SummaryVisits, error)
3 	FindVisitSiteList(opts *SummaryOpts) ([]*VisitUrl, error)
4 
5-	AddPicoPlusUser(username string, paymentType, txId string) error
6+	AddPicoPlusUser(username, email, paymentType, txId string) error
7 	FindFeatureForUser(userID string, feature string) (*FeatureFlag, error)
8 	FindFeaturesForUser(userID string) ([]*FeatureFlag, error)
9 	HasFeatureForUser(userID string, feature string) bool
M db/postgres/storage.go
+3, -3
 1@@ -1919,7 +1919,7 @@ func (me *PsqlDB) createFeatureExpiresAt(userID, name string) time.Time {
 2 	return ff.ExpiresAt.AddDate(1, 0, 0)
 3 }
 4 
 5-func (me *PsqlDB) AddPicoPlusUser(username, paymentType, txId string) error {
 6+func (me *PsqlDB) AddPicoPlusUser(username, email, paymentType, txId string) error {
 7 	user, err := me.FindUserForName(username)
 8 	if err != nil {
 9 		return err
10@@ -1953,8 +1953,8 @@ func (me *PsqlDB) AddPicoPlusUser(username, paymentType, txId string) error {
11 	}
12 
13 	plus := me.createFeatureExpiresAt(user.ID, "plus")
14-	plusQuery := `INSERT INTO feature_flags (user_id, name, data, expires_at, payment_history_id)
15-		VALUES ($1, 'plus', '{"storage_max":10000000000, "file_max":50000000}'::jsonb, $2, $3);`
16+	plusQuery := fmt.Sprintf(`INSERT INTO feature_flags (user_id, name, data, expires_at, payment_history_id)
17+	VALUES ($1, 'plus', '{"storage_max":10000000000, "file_max":50000000, "email": "%s"}'::jsonb, $2, $3);`, email)
18 	_, err = tx.Exec(plusQuery, user.ID, plus, paymentHistoryId)
19 	if err != nil {
20 		return err
M db/stub/stub.go
+1, -1
1@@ -281,6 +281,6 @@ func (me *StubDB) RemoveFeature(userID string, name string) error {
2 	return notImpl
3 }
4 
5-func (me *StubDB) AddPicoPlusUser(username, paymentType, txId string) error {
6+func (me *StubDB) AddPicoPlusUser(username, email, paymentType, txId string) error {
7 	return notImpl
8 }