udemy-go-web-2/cmd/api/routes-api.go

50 lines
1.6 KiB
Go
Raw Permalink Normal View History

package main
import (
"net/http"
"github.com/go-chi/chi/v5"
"github.com/go-chi/cors"
)
func (app *application) routes() http.Handler {
mux := chi.NewRouter()
mux.Use(cors.Handler(cors.Options{
AllowedOrigins: []string{"https://*", "http://*"},
AllowedMethods: []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
AllowedHeaders: []string{"Accept", "Authorization", "Content-Type", "X-CSRF-Token"},
AllowCredentials: false,
MaxAge: 300,
}))
mux.Post("/api/payment-intent", app.GetPaymentIntent)
mux.Get("/api/widget/{id}", app.GetWidgetByID)
mux.Post("/api/create-customer-and-subscribe-to-plan", app.CreateCustomerAndSubscribeToPlan)
mux.Post("/api/authenticate", app.CreateAuthToken)
2024-08-19 19:39:36 +00:00
mux.Post("/api/is-authenticated", app.CheckAuthentication)
mux.Route("/api/admin", func(mux chi.Router) {
mux.Use(app.Auth)
// mux.Get("/test", func(w http.ResponseWriter, r *http.Request) {
// w.Write([]byte("got in"))
// })
2024-08-20 12:13:35 +00:00
mux.Post("/virtual-terminal-succeeded", app.VirtualTerminalPaymentSucceeded)
2024-08-21 21:18:51 +00:00
mux.Post("/all-sales", app.AllSales)
2024-08-21 21:27:33 +00:00
mux.Post("/all-subscriptions", app.AllSubscriptions)
2024-08-21 21:43:16 +00:00
mux.Post("/get-sale/{id}", app.GetSale)
2024-08-22 11:38:51 +00:00
mux.Post("/refund", app.RefundCharge)
2024-08-22 19:34:58 +00:00
mux.Post("/cancel-subscription", app.CancelSubscription)
2024-08-23 12:13:06 +00:00
mux.Post("/all-users", app.AllUsers)
2024-08-23 19:07:13 +00:00
mux.Post("/all-users/{id}", app.OneUser)
2024-08-26 11:37:05 +00:00
mux.Post("/all-users/edit/{id}", app.EditUser)
2024-08-26 12:10:18 +00:00
mux.Post("/all-users/delete/{id}", app.DeleteUser)
})
2024-08-20 20:20:37 +00:00
mux.Post("/api/forgot-password", app.SendPasswordResetEmail)
mux.Post("/api/reset-password", app.ResetPassword)
return mux
}