diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000..bfc6e7f Binary files /dev/null and b/bun.lockb differ diff --git a/service/config/config.go b/service/config/config.go index b399851..07e7033 100644 --- a/service/config/config.go +++ b/service/config/config.go @@ -17,3 +17,12 @@ func getEnvWithFallback(key string, fallback string) string { } return v } + +var EmailSettings = map[string]struct { + FromDomain string + Subject string + To string +}{ + "duck": {FromDomain: "mail.helptheducks.com", Subject: "Prosecute Reichardt Duck Farm for Animal Abuse", To: "carla.rodriguez@sonoma-county.org"}, + "sonoma": {FromDomain: "mail.righttorescue.com", Subject: "Prosecute animal cruelty, not animal rescuers", To: "carla.rodriguez@sonoma-county.org"}, +} diff --git a/service/handlers.go b/service/handlers.go index 44dc22f..133e60b 100644 --- a/service/handlers.go +++ b/service/handlers.go @@ -19,6 +19,7 @@ type CreateMessageInput struct { City string `json:"city,omitempty"` Message string `json:"message"` Token string `json:"token"` + Campaign string `json:"campaign,omitempty"` } func createMessageHandler(w http.ResponseWriter, r *http.Request) { @@ -77,6 +78,10 @@ func createMessageHandler(w http.ResponseWriter, r *http.Request) { String: r.RemoteAddr, Valid: r.RemoteAddr != "", }, + Campaign: sql.NullString{ + String: body.Campaign, + Valid: body.Campaign != "", + }, } err = model.InsertMessage(db, message) diff --git a/service/main.go b/service/main.go index 8c2a73e..114274a 100644 --- a/service/main.go +++ b/service/main.go @@ -30,7 +30,7 @@ func main() { r.Use(middleware.Recoverer) r.Use(middleware.Timeout(30 * time.Second)) r.Use(cors.Handler(cors.Options{ - AllowedOrigins: []string{"http://localhost:5173", "https://helptheducks.com"}, + AllowedOrigins: []string{"http://localhost:5173", "https://helptheducks.com", "https://righttorescue.com"}, AllowedMethods: []string{"GET", "POST", "OPTIONS"}, AllowedHeaders: []string{"Accept", "Authorization", "Content-Type"}, AllowCredentials: false, @@ -78,12 +78,18 @@ func processNewMessages() { for _, message := range messages { fmt.Printf("Processing message id: %v\n", message.ID) - fromEmail := strings.Join(strings.Split(strings.ToLower(message.Name), " "), ".") + "@mail.helptheducks.com" + + settings, ok := config.EmailSettings[message.Campaign.String] + if !ok { + settings = config.EmailSettings["duck"] + } + + fromEmail := strings.Join(strings.Split(strings.ToLower(message.Name), " "), ".") + "@" + settings.FromDomain err := mailer.Send(mailClient, mailer.SendOptions{ From: fmt.Sprintf("%s <%s>", message.Name, fromEmail), ReplyTo: message.Email, - To: "carla.rodriguez@sonoma-county.org", - Subject: "Prosecute Reichardt Duck Farm for Animal Abuse", + To: settings.To, + Subject: settings.Subject, Body: message.Message, }) if err != nil { diff --git a/service/model/message.go b/service/model/message.go index e3727f3..17b86ad 100644 --- a/service/model/message.go +++ b/service/model/message.go @@ -19,6 +19,7 @@ type Message struct { Zip sql.NullString `db:"zip"` City sql.NullString `db:"city"` Message string `db:"message"` + Campaign sql.NullString `db:"campaign"` Status string `db:"status"` } @@ -33,7 +34,8 @@ func InsertMessage(db *sqlx.DB, message Message) error { zip, city, message, - status + campaign, + status, ) VALUES ( :ip_address, :name, @@ -43,6 +45,7 @@ func InsertMessage(db *sqlx.DB, message Message) error { :zip, :city, :message, + :campaign, 'PENDING' )`, message, @@ -58,7 +61,7 @@ func GetMessagesToProcess(db *sqlx.DB) ([]Message, error) { var messages []Message err = tx.Select( &messages, - `SELECT id, name, email, message FROM messages WHERE status = 'PENDING' LIMIT 50 FOR UPDATE`, + `SELECT id, name, email, message, campaign FROM messages WHERE status = 'PENDING' LIMIT 50 FOR UPDATE`, ) if err != nil { tx.Rollback() diff --git a/src/routeTree.gen.ts b/src/routeTree.gen.ts index 470e2eb..7326bbb 100644 --- a/src/routeTree.gen.ts +++ b/src/routeTree.gen.ts @@ -1,9 +1,17 @@ +// This file is auto-generated by TanStack Router + import { FileRoute, lazyRouteComponent } from '@tanstack/react-router' +// Import Routes + import { Route as rootRoute } from './routes/__root' +// Create Virtual Routes + const IndexComponentImport = new FileRoute('/').createRoute() +// Create/Update Routes + const IndexComponentRoute = IndexComponentImport.update({ path: '/', getParentRoute: () => rootRoute, @@ -13,6 +21,9 @@ const IndexComponentRoute = IndexComponentImport.update({ 'component', ), }) + +// Populate the FileRoutesByPath interface + declare module '@tanstack/react-router' { interface FileRoutesByPath { '/': { @@ -21,4 +32,7 @@ declare module '@tanstack/react-router' { } } } + +// Create and export the route tree + export const routeTree = rootRoute.addChildren([IndexComponentRoute])