check for apns token before creating it

This commit is contained in:
Andre Medeiros 2022-10-26 22:45:05 -04:00
parent 2c04466a6b
commit ab93194e0d
2 changed files with 12 additions and 2 deletions

View file

@ -1,6 +1,11 @@
package api
import "net/http"
import (
"errors"
"net/http"
)
var ErrDuplicateAPNSToken = errors.New("duplicate apns token")
func (a *api) errorResponse(w http.ResponseWriter, _ *http.Request, status int, err error) {
w.Header().Set("X-Apollo-Error", err.Error())

View file

@ -13,7 +13,12 @@ func (a *api) createLiveActivityHandler(w http.ResponseWriter, r *http.Request)
la := &domain.LiveActivity{}
if err := json.NewDecoder(r.Body).Decode(la); err != nil {
a.errorResponse(w, r, 500, err)
a.errorResponse(w, r, 400, err)
return
}
if _, err := a.liveActivityRepo.Get(ctx, la.APNSToken); err == nil {
a.errorResponse(w, r, 400, ErrDuplicateAPNSToken)
return
}