mirror of
https://github.com/christianselig/apollo-backend
synced 2024-12-25 15:55:28 +00:00
remove lingering bad code
This commit is contained in:
parent
713e56d375
commit
9df9999a0a
1 changed files with 0 additions and 65 deletions
|
@ -108,68 +108,3 @@ func (a *api) deleteDeviceHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func (a *api) testDeviceHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
ctx := context.Background()
|
||||
tok := ps.ByName("apns")
|
||||
|
||||
d, err := a.models.Devices.GetByAPNSToken(tok)
|
||||
if err != nil {
|
||||
a.logger.WithFields(logrus.Fields{
|
||||
"err": err,
|
||||
}).Info("failed fetching device from database")
|
||||
a.errorResponse(w, r, 500, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
stmt := `
|
||||
SELECT username
|
||||
FROM accounts
|
||||
INNER JOIN devices_accounts ON devices_accounts.account_id = accounts.id
|
||||
WHERE devices_accounts.device_id = $1`
|
||||
rows, err := a.db.Query(ctx, stmt, d.ID)
|
||||
if err != nil {
|
||||
a.logger.WithFields(logrus.Fields{
|
||||
"apns": tok,
|
||||
"err": err,
|
||||
}).Error("failed to fetch device accounts")
|
||||
return
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var users []string
|
||||
for rows.Next() {
|
||||
var user string
|
||||
rows.Scan(&user)
|
||||
users = append(users, user)
|
||||
}
|
||||
|
||||
body := fmt.Sprintf("Active usernames are: %s. Tap me for more info!", english.OxfordWordSeries(users, "and"))
|
||||
notification := &apns2.Notification{}
|
||||
notification.Topic = "com.christianselig.Apollo"
|
||||
notification.DeviceToken = d.APNSToken
|
||||
notification.Payload = payload.
|
||||
NewPayload().
|
||||
Category("test-notification").
|
||||
Custom("test_accounts", strings.Join(users, ",")).
|
||||
AlertTitle(notificationTitle).
|
||||
AlertBody(body)
|
||||
|
||||
client := apns2.NewTokenClient(a.apns)
|
||||
if !d.Sandbox {
|
||||
client = client.Production()
|
||||
}
|
||||
|
||||
if _, err := client.Push(notification); err != nil {
|
||||
a.logger.WithFields(logrus.Fields{
|
||||
"err": err,
|
||||
}).Info("failed to send test notification")
|
||||
a.errorResponse(w, r, 500, err.Error())
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func (a *api) deleteDeviceHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue