mirror of
https://github.com/christianselig/apollo-backend
synced 2024-12-22 22:35:27 +00:00
check for apns token before creating it
This commit is contained in:
parent
2c04466a6b
commit
ab93194e0d
2 changed files with 12 additions and 2 deletions
|
@ -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())
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue