account page stubbed: link to etsy sign up

This commit is contained in:
2025-12-29 06:06:13 -07:00
parent 61f9afb39c
commit c9100383e4
35 changed files with 1326 additions and 158 deletions
+32 -8
View File
@@ -1,5 +1,9 @@
package main
//go:generate planter postgres://planter:planter@localhost:5432/inventory_2?sslmode=disable -o diagrams/database_schema.uml
//go:generate plantuml diagrams/*.uml -tsvg
//go:generate plantuml diagrams/etsy/*.uml -tsvg
import (
"context"
"errors"
@@ -10,9 +14,14 @@ import (
"syscall"
"time"
"github.com/jackc/pgx/v5/pgxpool"
"ruben/inventory2/internal/domains/accounts"
etsy_platform "ruben/inventory2/internal/domains/platforms/etsy"
"ruben/inventory2/internal/domains/raw_events"
"ruben/inventory2/internal/site"
"ruben/inventory2/internal/webhooks"
etsy_webhooks "ruben/inventory2/internal/webhooks/etsy"
)
const (
@@ -33,14 +42,14 @@ func runApp(ctx context.Context) error {
// connect to the database
db, err := raw_events.NewStore(ctx)
connPool, err := newPool(ctx)
if err != nil {
return fmt.Errorf("failed to initialize the raw event store: %w", err)
return fmt.Errorf("failed to initialize database connection pool: %w", err)
}
// start http server
srvErrCh := runServer(ctx, db)
srvErrCh := runServer(ctx, connPool)
// wait for interrupt signal or unrecoverable failure, then shutdown
@@ -76,10 +85,10 @@ func runApp(ctx context.Context) error {
return errors.Join(errs...)
}
func runServer(ctx context.Context, db *raw_events.Store) <-chan error {
func runServer(ctx context.Context, connPool *pgxpool.Pool) <-chan error {
srv := &http.Server{
Addr: ":8082", // local
Handler: buildHTTPHandler(db),
Handler: buildHTTPHandler(connPool),
}
ctx, cancel := context.WithCancel(ctx)
@@ -130,11 +139,26 @@ func runServer(ctx context.Context, db *raw_events.Store) <-chan error {
return errCh
}
func buildHTTPHandler(db *raw_events.Store) http.Handler {
func buildHTTPHandler(connPool *pgxpool.Pool) http.Handler {
eventsDB := raw_events.NewStore(connPool)
etsy := etsy_platform.NewPlatform(
func(acctID int64) string {
return fmt.Sprintf("/oauth/account/%d/auth_code", acctID)
},
etsyAPIKeystring,
etsyAPISharedSecret,
connPool,
)
accts := accounts.NewStore(connPool)
mux := http.NewServeMux()
mux.Handle("/webhooks/", http.StripPrefix("/webhooks", webhooks.New(db)))
mux.Handle("/site/", http.StripPrefix("/site", site.NewSiteHandler("./internal/site", db)))
mux.Handle("/webhooks/", http.StripPrefix("/webhooks", webhooks.New(eventsDB, etsy, webhooks.Config{
Etsy: etsy_webhooks.Config{
OAuthRedirectURIWithAcctIDParam: "/oauth/account/{acctID}/auth_code",
},
})))
mux.Handle("/site/", http.StripPrefix("/site", site.NewSiteHandler("./internal/site", eventsDB, accts, etsy)))
mux.Handle("/", http.RedirectHandler("/site", http.StatusPermanentRedirect))
return mux