From 905235a8ff4739f33c84c9ac051c95f5840fe6e3 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Sat, 14 Aug 2021 11:51:27 -0400 Subject: [PATCH] Set device pinged at --- internal/api/api.go | 4 ++-- internal/api/devices.go | 3 +++ internal/repository/postgres_device.go | 1 - 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/internal/api/api.go b/internal/api/api.go index 5e104ff..7e41ed0 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -83,8 +83,8 @@ func (a *api) Routes() *mux.Router { r.HandleFunc("/v1/device/{apns}/accounts", a.upsertAccountsHandler).Methods("POST") r.HandleFunc("/v1/device/{apns}/account/{redditID}", a.disassociateAccountHandler).Methods("DELETE") - r.HandleFunc("/v1/receipt", a.checkReceiptHandler) - r.HandleFunc("/v1/receipt/{apns}", a.checkReceiptHandler) + r.HandleFunc("/v1/receipt", a.checkReceiptHandler).Methods("POST") + r.HandleFunc("/v1/receipt/{apns}", a.checkReceiptHandler).Methods("POST") r.Use(a.loggingMiddleware) diff --git a/internal/api/devices.go b/internal/api/devices.go index fee27c4..1ac6cc0 100644 --- a/internal/api/devices.go +++ b/internal/api/devices.go @@ -6,6 +6,7 @@ import ( "fmt" "net/http" "strings" + "time" "github.com/christianselig/apollo-backend/internal/domain" "github.com/dustin/go-humanize/english" @@ -26,6 +27,8 @@ func (a *api) upsertDeviceHandler(w http.ResponseWriter, r *http.Request) { return } + d.LastPingedAt = time.Now().Unix() + if err := a.deviceRepo.CreateOrUpdate(ctx, d); err != nil { a.errorResponse(w, r, 500, err.Error()) return diff --git a/internal/repository/postgres_device.go b/internal/repository/postgres_device.go index a3f68f4..5134a32 100644 --- a/internal/repository/postgres_device.go +++ b/internal/repository/postgres_device.go @@ -58,7 +58,6 @@ func (p *postgresDeviceRepository) GetByAPNSToken(ctx context.Context, token str } func (p *postgresDeviceRepository) CreateOrUpdate(ctx context.Context, dev *domain.Device) error { - fmt.Println(dev) query := ` INSERT INTO devices (apns_token, sandbox, last_pinged_at) VALUES ($1, $2, $3)