mirror of
https://github.com/christianselig/apollo-backend
synced 2024-11-13 07:27:43 +00:00
Add subreddit validation and de-register from old API
This commit is contained in:
parent
310567fde2
commit
8a8431fc0f
3 changed files with 30 additions and 9 deletions
|
@ -183,6 +183,22 @@ func (a *api) upsertAccountsHandler(w http.ResponseWriter, r *http.Request) {
|
|||
_ = a.accountRepo.Disassociate(ctx, &acc, &dev)
|
||||
}
|
||||
|
||||
go func(apns string) {
|
||||
url := fmt.Sprintf("https://apollopushserver.xyz/api/new-server-addition?apns_token=%s", apns)
|
||||
req, err := http.NewRequest("POST", url, nil)
|
||||
req.Header.Set("Authentication", "Bearer 98g5j89aurqwfcsp9khlnvgd38fa15")
|
||||
|
||||
if err != nil {
|
||||
a.logger.WithFields(logrus.Fields{
|
||||
"apns": apns,
|
||||
}).Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := a.httpClient.Do(req)
|
||||
resp.Body.Close()
|
||||
}(apns)
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
|
|
|
@ -22,10 +22,11 @@ import (
|
|||
)
|
||||
|
||||
type api struct {
|
||||
logger *logrus.Logger
|
||||
statsd *statsd.Client
|
||||
reddit *reddit.Client
|
||||
apns *token.Token
|
||||
logger *logrus.Logger
|
||||
statsd *statsd.Client
|
||||
reddit *reddit.Client
|
||||
apns *token.Token
|
||||
httpClient *http.Client
|
||||
|
||||
accountRepo domain.AccountRepository
|
||||
deviceRepo domain.DeviceRepository
|
||||
|
@ -63,11 +64,14 @@ func NewAPI(ctx context.Context, logger *logrus.Logger, statsd *statsd.Client, r
|
|||
watcherRepo := repository.NewPostgresWatcher(pool)
|
||||
userRepo := repository.NewPostgresUser(pool)
|
||||
|
||||
client := &http.Client{}
|
||||
|
||||
return &api{
|
||||
logger: logger,
|
||||
statsd: statsd,
|
||||
reddit: reddit,
|
||||
apns: apns,
|
||||
logger: logger,
|
||||
statsd: statsd,
|
||||
reddit: reddit,
|
||||
apns: apns,
|
||||
httpClient: client,
|
||||
|
||||
accountRepo: accountRepo,
|
||||
deviceRepo: deviceRepo,
|
||||
|
|
|
@ -2,6 +2,7 @@ package domain
|
|||
|
||||
import (
|
||||
"context"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
validation "github.com/go-ozzo/ozzo-validation/v4"
|
||||
|
@ -22,7 +23,7 @@ func (sr *Subreddit) NormalizedName() string {
|
|||
|
||||
func (sr *Subreddit) Validate() error {
|
||||
return validation.ValidateStruct(sr,
|
||||
validation.Field(&sr.Name, validation.Required, validation.Length(3, 32)),
|
||||
validation.Field(&sr.Name, validation.Required, validation.Length(3, 32), validation.Match(regexp.MustCompile("^(?!u_)[a-zA-Z0-9]\\w{1,19}$"))),
|
||||
validation.Field(&sr.SubredditID, validation.Required, validation.Length(4, 9)),
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue