feat(notifications): add admin notification acknowledgement on booking state changes
- Add AcknowledgePendingBookingNotification helper for acknowledging notifications - ConfirmBookingHandler: acknowledge pending notification when booking confirmed - Cancel handlers: acknowledge pending notification and only create cancelled_booking notification if booking was not in pending status - Add user_notification_preferences table with email, sms, push enabled flags - Update cancellation logic to check original status before creating notifications
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package notifications
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crussell/db"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
@@ -11,6 +12,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/jackc/pgx/v5/pgconn"
|
||||
)
|
||||
|
||||
// Structs returned in JSON
|
||||
@@ -173,3 +175,19 @@ func AcknowledgeNotification(w http.ResponseWriter, r *http.Request) {
|
||||
"status": "ok",
|
||||
})
|
||||
}
|
||||
|
||||
func AcknowledgePendingBookingNotification(tx interface{}, ctx context.Context, bookingID string) error {
|
||||
query := `
|
||||
UPDATE admin_notifications
|
||||
SET acknowledged_at = NOW()
|
||||
WHERE booking_id = $1 AND reason = 'pending_booking' AND acknowledged_at IS NULL
|
||||
`
|
||||
_, err := tx.(interface {
|
||||
Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error)
|
||||
}).Exec(ctx, query, bookingID)
|
||||
if err != nil {
|
||||
log.Printf("Failed to acknowledge pending booking notification for %s: %v", bookingID, err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user