mirror of
https://github.com/christianselig/apollo-backend
synced 2024-12-22 22:35:27 +00:00
Merge pull request #70 from christianselig/feat/add-email-endpoint
add contact endpoint
This commit is contained in:
commit
ac5e110e74
4 changed files with 40 additions and 0 deletions
1
go.mod
1
go.mod
|
@ -19,6 +19,7 @@ require (
|
|||
github.com/joho/godotenv v1.4.0
|
||||
github.com/sideshow/apns2 v0.23.0
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/smtp2go-oss/smtp2go-go v1.0.1 // indirect
|
||||
github.com/spf13/cobra v1.4.0
|
||||
github.com/stretchr/testify v1.7.1
|
||||
github.com/valyala/fastjson v1.6.3
|
||||
|
|
2
go.sum
2
go.sum
|
@ -296,6 +296,8 @@ github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE
|
|||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
github.com/smtp2go-oss/smtp2go-go v1.0.1 h1:rwcoNLjOyigOzCjKp/guylKY/xJpoeypSxgtcC/g6DA=
|
||||
github.com/smtp2go-oss/smtp2go-go v1.0.1/go.mod h1:lkv36awQXRBWAvnd517FFESKvne8465KCu90lPThcEY=
|
||||
github.com/soveran/redisurl v0.0.0-20180322091936-eb325bc7a4b8/go.mod h1:FVJ8jbHu7QrNFs3bZEsv/L5JjearIAY9N0oXh2wk+6Y=
|
||||
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
github.com/spf13/cobra v0.0.2/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
|
||||
|
|
|
@ -107,6 +107,8 @@ func (a *api) Routes() *mux.Router {
|
|||
r.HandleFunc("/v1/receipt", a.checkReceiptHandler).Methods("POST")
|
||||
r.HandleFunc("/v1/receipt/{apns}", a.checkReceiptHandler).Methods("POST")
|
||||
|
||||
r.HandleFunc("/v1/contact", a.contactHandler).Methods("POST")
|
||||
|
||||
r.HandleFunc("/v1/test/bugsnag", a.testBugsnagHandler).Methods("POST")
|
||||
|
||||
r.Use(a.loggingMiddleware)
|
||||
|
|
35
internal/api/contact.go
Normal file
35
internal/api/contact.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/smtp2go-oss/smtp2go-go"
|
||||
)
|
||||
|
||||
type sendMessageRequest struct {
|
||||
Title string `json:"title"`
|
||||
Body string `json:"body"`
|
||||
}
|
||||
|
||||
func (a *api) contactHandler(w http.ResponseWriter, r *http.Request) {
|
||||
smr := &sendMessageRequest{}
|
||||
if err := json.NewDecoder(r.Body).Decode(smr); err != nil {
|
||||
a.errorResponse(w, r, 500, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
msg := &smtp2go.Email{
|
||||
From: "🤖 Apollo API <robot@apollonotifications.com>",
|
||||
To: []string{"ultrasurvey@apolloapp.io"},
|
||||
Subject: smr.Title,
|
||||
TextBody: smr.Body,
|
||||
}
|
||||
|
||||
_, err := smtp2go.Send(msg)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r, 500, err.Error())
|
||||
return
|
||||
}
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
Loading…
Reference in a new issue