remove contact us
This commit is contained in:
@@ -131,10 +131,6 @@ func (db *InMemoryDb) GetSvgStringInterface(idxs SvgIdInterface) ([]string, erro
|
||||
return make([]string, len(idxs)), nil
|
||||
}
|
||||
|
||||
func (db *InMemoryDb) WriteNewContactUsForm(userId UserId, form ContactFormPost) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func userIdKey(customerId CustomerId, username UserEmail) string {
|
||||
key := fmt.Sprintf("%s:%s", customerId, username)
|
||||
return key
|
||||
|
||||
@@ -263,15 +263,3 @@ func (n *NKodeAPI) ResetNKode(userEmail UserEmail, customerId CustomerId) error
|
||||
n.EmailQueue.AddEmail(email)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *NKodeAPI) ContactUs(userEmail UserEmail, customerId CustomerId, form ContactFormPost) error {
|
||||
user, err := n.Db.GetUser(userEmail, customerId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if user == nil {
|
||||
return ErrUserForCustomerDNE
|
||||
}
|
||||
return n.Db.WriteNewContactUsForm(user.Id, form)
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ const (
|
||||
RandomSvgInterface = "/random-svg-interface"
|
||||
RefreshToken = "/refresh-token"
|
||||
ResetNKode = "/reset-nkode"
|
||||
ContactUs = "/contact-us"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -57,8 +56,6 @@ func (h *NKodeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
case ResetNKode:
|
||||
h.ResetNKode(w, r)
|
||||
|
||||
case ContactUs:
|
||||
h.ContactUs(w, r)
|
||||
default:
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
_, err := w.Write([]byte("404 not found"))
|
||||
@@ -344,41 +341,6 @@ func (h *NKodeHandler) ResetNKode(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func (h *NKodeHandler) ContactUs(w http.ResponseWriter, r *http.Request) {
|
||||
println("contact us")
|
||||
if r.Method != http.MethodPost {
|
||||
methodNotAllowed(w)
|
||||
}
|
||||
accessToken, err := getBearerToken(r)
|
||||
if err != nil {
|
||||
forbidden(w)
|
||||
return
|
||||
}
|
||||
refreshClaims, err := ParseRegisteredClaimToken(accessToken)
|
||||
customerId, err := uuid.Parse(refreshClaims.Issuer)
|
||||
if err != nil {
|
||||
badRequest(w, malformedCustomerId)
|
||||
return
|
||||
}
|
||||
userEmail, err := ParseEmail(refreshClaims.Subject)
|
||||
if err != nil {
|
||||
badRequest(w, malformedUserEmail)
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
var contactFormPost ContactFormPost
|
||||
if err := decodeJson(w, r, &contactFormPost); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err := h.Api.ContactUs(userEmail, CustomerId(customerId), contactFormPost); err != nil {
|
||||
handleError(w, err)
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func decodeJson(w http.ResponseWriter, r *http.Request, post any) error {
|
||||
if r.Body == nil {
|
||||
badRequest(w, "unable to parse body")
|
||||
|
||||
@@ -250,16 +250,6 @@ CREATE TABLE IF NOT EXISTS svg_icon (
|
||||
,svg TEXT NOT NULL
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS contact_us (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT
|
||||
,name TEXT NOT NULL
|
||||
,message TEXT NOT NULL
|
||||
,company_name TEXT NOT NULL
|
||||
,alternate_email TEXT NOT NULL
|
||||
,user_id TEXT NOT NULL
|
||||
,created_at TEXT NOT NULL
|
||||
,FOREIGN KEY (user_id) REFERENCES user(id)
|
||||
)
|
||||
`
|
||||
_, err = db.Exec(createTable)
|
||||
if err != nil {
|
||||
|
||||
@@ -452,26 +452,6 @@ func (d *SqliteDB) GetSvgStringInterface(idxs SvgIdInterface) ([]string, error)
|
||||
return d.getSvgsById(idxs)
|
||||
}
|
||||
|
||||
func (d *SqliteDB) WriteNewContactUsForm(userId UserId, form ContactFormPost) error {
|
||||
query := `
|
||||
INSERT INTO contact_us (
|
||||
name
|
||||
,message
|
||||
,company_name
|
||||
,alternate_email
|
||||
,user_id
|
||||
,created_at
|
||||
)
|
||||
VALUES (?,?,?,?,?,?)
|
||||
`
|
||||
args := []any{
|
||||
form.Name, form.Message, form.CompanyName, form.AlternateEmail, uuid.UUID(userId), timeStamp(),
|
||||
}
|
||||
|
||||
return d.addWriteTx(query, args)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *SqliteDB) getSvgsById(ids []int) ([]string, error) {
|
||||
tx, err := d.db.Begin()
|
||||
if err != nil {
|
||||
|
||||
@@ -68,13 +68,6 @@ type ResetNKodePost struct {
|
||||
CustomerId string `json:"customer_id"`
|
||||
}
|
||||
|
||||
type ContactFormPost struct {
|
||||
Name string `json:"name"`
|
||||
AlternateEmail string `json:"alternate_email"`
|
||||
CompanyName string `json:"company_name"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type CreateNewCustomerResp struct {
|
||||
CustomerId string `json:"customer_id"`
|
||||
}
|
||||
@@ -158,5 +151,4 @@ type DbAccessor interface {
|
||||
RandomSvgInterface(KeypadDimension) ([]string, error)
|
||||
RandomSvgIdxInterface(KeypadDimension) (SvgIdInterface, error)
|
||||
GetSvgStringInterface(SvgIdInterface) ([]string, error)
|
||||
WriteNewContactUsForm(userId UserId, form ContactFormPost) error
|
||||
}
|
||||
|
||||
1
main.go
1
main.go
@@ -39,7 +39,6 @@ func main() {
|
||||
mux.Handle(core.RandomSvgInterface, &handler)
|
||||
mux.Handle(core.RefreshToken, &handler)
|
||||
mux.Handle(core.ResetNKode, &handler)
|
||||
mux.Handle(core.ContactUs, &handler)
|
||||
fmt.Println("Running on localhost:8080...")
|
||||
log.Fatal(http.ListenAndServe("localhost:8080", corsMiddleware(mux)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user