mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-12 13:46:51 +00:00
can create a booking
This commit is contained in:
parent
3b56f73a66
commit
24362b95eb
4 changed files with 72 additions and 260 deletions
|
|
@ -2,8 +2,10 @@ package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
"github.com/labstack/gommon/log"
|
||||||
|
|
||||||
"github.com/rjNemo/rentease/constants"
|
"github.com/rjNemo/rentease/constants"
|
||||||
"github.com/rjNemo/rentease/internal/views"
|
"github.com/rjNemo/rentease/internal/views"
|
||||||
|
|
@ -23,257 +25,65 @@ func (s Server) handleNewBookingPage() echo.HandlerFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//func (s Server) handleLoginPage() echo.HandlerFunc {
|
func (s Server) handleCreateBooking() echo.HandlerFunc {
|
||||||
// return func(c echo.Context) error {
|
return func(c echo.Context) error {
|
||||||
// qs := c.QueryParams()
|
type NewBooking struct {
|
||||||
// errs := qs["err"]
|
Name string `form:"name"`
|
||||||
//
|
PhoneNumber string `form:"phone_number"`
|
||||||
// component := views.LoginPage(errs)
|
CustomerNumber string `form:"customer_number"`
|
||||||
// return s.renderTempl(c, http.StatusOK, component)
|
Email string `form:"email"`
|
||||||
// }
|
From time.Time `json:"from"`
|
||||||
//}
|
To time.Time `from:"to"`
|
||||||
//
|
Platform string `form:"platform"`
|
||||||
//func (s Server) handleLogin() echo.HandlerFunc {
|
PlatformFees string `form:"platform_fees"`
|
||||||
// return func(c echo.Context) error {
|
}
|
||||||
// email := c.FormValue("email")
|
|
||||||
// pwd := c.FormValue("password")
|
nb := new(NewBooking)
|
||||||
//
|
err := c.Bind(nb)
|
||||||
// user, err := s.us.SignIn(email, pwd)
|
if err != nil {
|
||||||
// if err != nil {
|
log.Warn(err)
|
||||||
// return c.Redirect(http.StatusSeeOther, fmt.Sprintf("%s?err=invalid+credentials", constants.RouteLogin))
|
return err
|
||||||
// }
|
}
|
||||||
// if err = writeCookie(c, user.Id, email, user.PaymentValid); err != nil {
|
|
||||||
// return c.Redirect(http.StatusSeeOther, fmt.Sprintf("%s?err=invalid+credentials", constants.RouteLogin))
|
ts, err := parseTime(c.FormValue("from"))
|
||||||
// }
|
nb.From = ts
|
||||||
// return c.Redirect(http.StatusFound, constants.RouteHome)
|
ts, err = parseTime(c.FormValue("to"))
|
||||||
// }
|
nb.To = ts
|
||||||
//}
|
|
||||||
//
|
type Booking struct {
|
||||||
//func (s Server) handleLogout() echo.HandlerFunc {
|
Id int
|
||||||
// return func(c echo.Context) error {
|
Name string `gorm:"column:customer_name"`
|
||||||
// cookie := new(http.Cookie)
|
PhoneNumber string
|
||||||
// cookie.Name = cookieName
|
CustomerNumber string `gorm:"column:customers"`
|
||||||
// cookie.Value = ""
|
Email string
|
||||||
// cookie.MaxAge = 0
|
From time.Time
|
||||||
// c.SetCookie(cookie)
|
To time.Time
|
||||||
// return c.Redirect(http.StatusFound, constants.RouteLogin)
|
Platform string
|
||||||
// }
|
PlatformFees string
|
||||||
//}
|
}
|
||||||
//
|
// create a booking object
|
||||||
//func (s Server) handleHomePage() echo.HandlerFunc {
|
result := s.db.Create(&Booking{
|
||||||
// return func(c echo.Context) error {
|
Name: nb.Name,
|
||||||
// user := c.Get("user").(services.User)
|
PhoneNumber: nb.PhoneNumber,
|
||||||
//
|
CustomerNumber: nb.CustomerNumber,
|
||||||
// component := views.Home(&user, s.ms.List(user.Id))
|
Email: nb.Email,
|
||||||
// return s.renderTempl(c, http.StatusOK, component)
|
From: nb.From,
|
||||||
// }
|
To: nb.To,
|
||||||
//}
|
Platform: nb.Platform,
|
||||||
//
|
PlatformFees: nb.PlatformFees,
|
||||||
//func (s Server) handleCreateMeetingNote() echo.HandlerFunc {
|
})
|
||||||
// return func(c echo.Context) error {
|
log.Info(result.Error)
|
||||||
// memberId, err := strconv.Atoi(c.FormValue("member_id"))
|
log.Info(result.RowsAffected)
|
||||||
// if err != nil {
|
// store it
|
||||||
// return err
|
// redirect to the booking page
|
||||||
// }
|
return nil
|
||||||
//
|
}
|
||||||
// audioFile, err := c.FormFile("audio_file")
|
}
|
||||||
// if err != nil {
|
|
||||||
// return err
|
func parseTime(src string) (time.Time, error) {
|
||||||
// }
|
ts, err := time.Parse("2006-01-02", src)
|
||||||
//
|
if err != nil {
|
||||||
// err = s.ms.CreateNote(audioFile, memberId)
|
return time.Time{}, err
|
||||||
// if err != nil {
|
}
|
||||||
// return err
|
return ts, nil
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// return c.Redirect(http.StatusFound, fmt.Sprintf("%s/%d", constants.RouteTeam, memberId))
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func (s Server) handleTeamPage() echo.HandlerFunc {
|
|
||||||
// return func(c echo.Context) error {
|
|
||||||
// user := c.Get("user").(services.User)
|
|
||||||
//
|
|
||||||
// component := views.Team(&user, s.ms.List(user.Id))
|
|
||||||
// return s.renderTempl(c, http.StatusOK, component)
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func (s Server) handleCreateTeamMember() echo.HandlerFunc {
|
|
||||||
// return func(c echo.Context) error {
|
|
||||||
// name := c.FormValue("name")
|
|
||||||
// user := c.Get("user").(services.User)
|
|
||||||
// if _, err := s.ms.Create(name, user.Id); err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// return c.Redirect(http.StatusFound, constants.RouteTeam)
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func (s Server) handleUpdateTeamMember() echo.HandlerFunc {
|
|
||||||
// return func(c echo.Context) error {
|
|
||||||
// name := c.FormValue("name")
|
|
||||||
// description := c.FormValue("description")
|
|
||||||
// memberId, _ := strconv.Atoi(c.Param("id"))
|
|
||||||
//
|
|
||||||
// if _, err := s.ms.Update(name, description, memberId); err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
// return c.Redirect(http.StatusFound, fmt.Sprintf("%s/%d", constants.RouteTeam, memberId))
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func (s Server) handleTeamMemberPage() echo.HandlerFunc {
|
|
||||||
// return func(c echo.Context) error {
|
|
||||||
// id, err := strconv.Atoi(c.Param("id"))
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// user := c.Get("user").(services.User)
|
|
||||||
//
|
|
||||||
// component := views.TeamMember(&user, s.ms.One(id))
|
|
||||||
// return s.renderTempl(c, http.StatusOK, component)
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func (s Server) handleCheckoutPage() echo.HandlerFunc {
|
|
||||||
// return func(c echo.Context) error {
|
|
||||||
// component := views.Checkout(os.Getenv("STRIPE_LOOKUP_KEY"))
|
|
||||||
// return s.renderTempl(c, http.StatusOK, component)
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func (s Server) handleSuccessPage() echo.HandlerFunc {
|
|
||||||
// return func(c echo.Context) error {
|
|
||||||
// stripe.Key = os.Getenv("STRIPE_API_KEY")
|
|
||||||
//
|
|
||||||
// ss, _ := session.Get(c.QueryParam("session_id"), nil)
|
|
||||||
// log.Infof("%+v", ss.Customer)
|
|
||||||
//
|
|
||||||
// uid := c.QueryParam("u")
|
|
||||||
// userId, _ := strconv.Atoi(uid)
|
|
||||||
// err := s.us.SetPaymentStatus(userId, ss.Customer.ID)
|
|
||||||
// if err != nil {
|
|
||||||
// return c.Redirect(302, constants.RouteCancel)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// component := views.Success()
|
|
||||||
// return s.renderTempl(c, http.StatusOK, component)
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func (s Server) handleCancelPage() echo.HandlerFunc {
|
|
||||||
// return func(c echo.Context) error {
|
|
||||||
// component := views.Cancel()
|
|
||||||
// return s.renderTempl(c, http.StatusOK, component)
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func (s Server) handleCreateCheckoutSession() echo.HandlerFunc {
|
|
||||||
// return func(c echo.Context) error {
|
|
||||||
// stripe.Key = os.Getenv("STRIPE_API_KEY")
|
|
||||||
// lookupKey := c.FormValue("lookup_key")
|
|
||||||
//
|
|
||||||
// params := &stripe.PriceListParams{
|
|
||||||
// LookupKeys: stripe.StringSlice([]string{lookupKey}),
|
|
||||||
// }
|
|
||||||
// i := price.List(params)
|
|
||||||
// sp := new(stripe.Price)
|
|
||||||
// for i.Next() {
|
|
||||||
// p := i.Price()
|
|
||||||
// sp = p
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// domain := os.Getenv("STRIPE_DOMAIN")
|
|
||||||
// user := c.Get("user").(services.User)
|
|
||||||
// checkoutParams := &stripe.CheckoutSessionParams{
|
|
||||||
// Mode: stripe.String(string(stripe.CheckoutSessionModeSubscription)),
|
|
||||||
// LineItems: []*stripe.CheckoutSessionLineItemParams{
|
|
||||||
// {Price: stripe.String(sp.ID), Quantity: stripe.Int64(1)},
|
|
||||||
// },
|
|
||||||
// SuccessURL: stripe.String(fmt.Sprintf("%s%s?u=%d&session_id={CHECKOUT_SESSION_ID}", domain, constants.RouteSuccess, user.Id)),
|
|
||||||
// CancelURL: stripe.String(fmt.Sprintf("%s/cancel", domain)),
|
|
||||||
// }
|
|
||||||
// s, err := session.New(checkoutParams)
|
|
||||||
// if err != nil {
|
|
||||||
// log.Warnf("session.New %v", err)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return c.Redirect(http.StatusSeeOther, s.URL)
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func (s Server) handleCreatePortalSession() echo.HandlerFunc {
|
|
||||||
// return func(c echo.Context) error {
|
|
||||||
// stripe.Key = os.Getenv("STRIPE_API_KEY")
|
|
||||||
// u := c.Get("user").(services.User)
|
|
||||||
// user := s.us.One(u.Id)
|
|
||||||
//
|
|
||||||
// params := &stripe.BillingPortalSessionParams{
|
|
||||||
// Customer: stripe.String(user.PaymentId),
|
|
||||||
// ReturnURL: stripe.String(os.Getenv("STRIPE_DOMAIN")),
|
|
||||||
// }
|
|
||||||
// ps, _ := portalsession.New(params)
|
|
||||||
//
|
|
||||||
// return c.Redirect(http.StatusSeeOther, ps.URL)
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func (s Server) handleWebhook() echo.HandlerFunc {
|
|
||||||
// return func(c echo.Context) error {
|
|
||||||
// payload, err := io.ReadAll(c.Request().Body)
|
|
||||||
// if err != nil {
|
|
||||||
// return c.String(http.StatusBadRequest, "Error reading request body: %v\n")
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// endpointSecret := os.Getenv("STRIPE_WEBHOOK_SECRET")
|
|
||||||
// signatureHeader := c.Request().Header.Get("Stripe-Signature")
|
|
||||||
// event, err := webhook.ConstructEvent(payload, signatureHeader, endpointSecret)
|
|
||||||
// if err != nil {
|
|
||||||
// return c.String(http.StatusBadRequest, fmt.Sprintf("⚠️ Webhook signature verification failed. %v\n", err))
|
|
||||||
// }
|
|
||||||
// // Unmarshal the event data into an appropriate struct depending on its Type
|
|
||||||
// switch event.Type {
|
|
||||||
// case "customer.subscription.deleted":
|
|
||||||
// var subscription stripe.Subscription
|
|
||||||
// err := json.Unmarshal(event.Data.Raw, &subscription)
|
|
||||||
// if err != nil {
|
|
||||||
// return c.String(http.StatusBadRequest, "Error parsing webhook JSON: %v\n")
|
|
||||||
// }
|
|
||||||
// log.Printf("Subscription deleted for %s.", subscription.ID)
|
|
||||||
// // Then define and call a func to handle the deleted subscription.
|
|
||||||
// // handleSubscriptionCanceled(subscription)
|
|
||||||
// case "customer.subscription.updated":
|
|
||||||
// var subscription stripe.Subscription
|
|
||||||
// err := json.Unmarshal(event.Data.Raw, &subscription)
|
|
||||||
// if err != nil {
|
|
||||||
// return c.String(http.StatusBadRequest, "Error parsing webhook JSON: %v\n")
|
|
||||||
// }
|
|
||||||
// log.Printf("Subscription updated for %s.", subscription.ID)
|
|
||||||
// // Then define and call a func to handle the successful attachment of a PaymentMethod.
|
|
||||||
// // handleSubscriptionUpdated(subscription)
|
|
||||||
// case "customer.subscription.created":
|
|
||||||
// var subscription stripe.Subscription
|
|
||||||
// err := json.Unmarshal(event.Data.Raw, &subscription)
|
|
||||||
// if err != nil {
|
|
||||||
// return c.String(http.StatusBadRequest, "Error parsing webhook JSON: %v\n")
|
|
||||||
// }
|
|
||||||
// log.Printf("Subscription created for %s.", subscription.ID)
|
|
||||||
// // Then define and call a func to handle the successful attachment of a PaymentMethod.
|
|
||||||
// // handleSubscriptionCreated(subscription)
|
|
||||||
// case "customer.subscription.trial_will_end":
|
|
||||||
// var subscription stripe.Subscription
|
|
||||||
// err := json.Unmarshal(event.Data.Raw, &subscription)
|
|
||||||
// if err != nil {
|
|
||||||
// return c.String(http.StatusBadRequest, "Error parsing webhook JSON: %v\n")
|
|
||||||
// }
|
|
||||||
// log.Printf("Subscription trial will end for %s.", subscription.ID)
|
|
||||||
// // Then define and call a func to handle the successful attachment of a PaymentMethod.
|
|
||||||
// // handleSubscriptionTrialWillEnd(subscription)
|
|
||||||
// default:
|
|
||||||
// return c.String(http.StatusBadRequest, "Unhandled event type: %s\n")
|
|
||||||
// }
|
|
||||||
// return c.NoContent(http.StatusOK)
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import (
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
Router *echo.Echo
|
Router *echo.Echo
|
||||||
|
db *gorm.DB
|
||||||
//ms *services.MemberService
|
//ms *services.MemberService
|
||||||
//us *services.UserService
|
//us *services.UserService
|
||||||
addr string
|
addr string
|
||||||
|
|
@ -28,6 +29,7 @@ type Server struct {
|
||||||
func New(db *gorm.DB) *Server {
|
func New(db *gorm.DB) *Server {
|
||||||
return &Server{
|
return &Server{
|
||||||
Router: echo.New(),
|
Router: echo.New(),
|
||||||
|
db: db,
|
||||||
//ms: services.NewMemberService(db),
|
//ms: services.NewMemberService(db),
|
||||||
//us: services.NewUserService(db),
|
//us: services.NewUserService(db),
|
||||||
addr: fmt.Sprintf("0.0.0.0:%s", os.Getenv("PORT")),
|
addr: fmt.Sprintf("0.0.0.0:%s", os.Getenv("PORT")),
|
||||||
|
|
@ -50,6 +52,7 @@ func (s Server) MountHandlers() {
|
||||||
// landing page
|
// landing page
|
||||||
s.Router.GET("/", s.handleHomePage())
|
s.Router.GET("/", s.handleHomePage())
|
||||||
s.Router.GET(constants.RouteNewBooking, s.handleNewBookingPage())
|
s.Router.GET(constants.RouteNewBooking, s.handleNewBookingPage())
|
||||||
|
s.Router.POST(constants.RouteNewBooking, s.handleCreateBooking())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Server) Start() {
|
func (s Server) Start() {
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
package views
|
package views
|
||||||
|
|
||||||
|
|
||||||
templ NewBooking(platforms []string) {
|
templ NewBooking(platforms []string) {
|
||||||
@BaseLayout() {
|
@BaseLayout() {
|
||||||
<hgroup>
|
<hgroup>
|
||||||
<h1>New Booking </h1>
|
<h1>New Booking </h1>
|
||||||
<h2>Create a new booking </h2>
|
<h2>Create a new booking </h2>
|
||||||
</hgroup>
|
</hgroup>
|
||||||
<form>
|
<form method="POST">
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<label for="name">
|
<label for="name">
|
||||||
Customer full name
|
Customer full name
|
||||||
|
|
@ -42,9 +41,9 @@ templ NewBooking(platforms []string) {
|
||||||
<label for="platform">
|
<label for="platform">
|
||||||
Platform
|
Platform
|
||||||
<select id="platform" name="platform">
|
<select id="platform" name="platform">
|
||||||
for _, platform := range platforms {
|
for _, platform := range platforms {
|
||||||
<option value={platform} > {platform} </option>
|
<option value={ platform }>{ platform } </option>
|
||||||
}
|
}
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
<label for="platform_fees">
|
<label for="platform_fees">
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ func NewBooking(platforms []string) templ.Component {
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</h2></hgroup><form><div class=\"grid\"><label for=\"name\">")
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</h2></hgroup><form method=\"POST\"><div class=\"grid\"><label for=\"name\">")
|
||||||
if templ_7745c5c3_Err != nil {
|
if templ_7745c5c3_Err != nil {
|
||||||
return templ_7745c5c3_Err
|
return templ_7745c5c3_Err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue