Cleaning up the reservation summary page and improbing validation
This commit is contained in:
parent
95cddfc950
commit
e0a29d21c3
@ -83,6 +83,7 @@ func (m *Repository) MakeReservation(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
res.Room.RoomName = room.RoomName
|
res.Room.RoomName = room.RoomName
|
||||||
|
m.App.Session.Put(r.Context(), "reservation", res)
|
||||||
|
|
||||||
sd := res.StartDate.Format("2006-01-02")
|
sd := res.StartDate.Format("2006-01-02")
|
||||||
ed := res.EndDate.Format("2006-01-02")
|
ed := res.EndDate.Format("2006-01-02")
|
||||||
@ -102,43 +103,21 @@ func (m *Repository) MakeReservation(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// PostMakeReservation is the make reservation page post handler
|
// PostMakeReservation is the make reservation page post handler
|
||||||
func (m *Repository) PostMakeReservation(w http.ResponseWriter, r *http.Request) {
|
func (m *Repository) PostMakeReservation(w http.ResponseWriter, r *http.Request) {
|
||||||
|
reservation, ok := m.App.Session.Get(r.Context(), "reservation").(models.Reservation)
|
||||||
|
if !ok {
|
||||||
|
helpers.ServerError(w, errors.New("connot get item from session"))
|
||||||
|
return
|
||||||
|
}
|
||||||
err := r.ParseForm()
|
err := r.ParseForm()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
helpers.ServerError(w, err)
|
helpers.ServerError(w, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
sd := r.Form.Get("start_date")
|
reservation.FirstName = r.Form.Get("first_name")
|
||||||
ed := r.Form.Get("end_date")
|
reservation.LastName = r.Form.Get("last_name")
|
||||||
|
reservation.Email = r.Form.Get("email")
|
||||||
// 2024-07-08 -- 01/02 03:04:05PM '06 -0700
|
reservation.Phone = r.Form.Get("phone")
|
||||||
layout := "2006-01-02"
|
|
||||||
startDate, err := time.Parse(layout, sd)
|
|
||||||
if err != nil {
|
|
||||||
helpers.ServerError(w, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
endDate, err := time.Parse(layout, ed)
|
|
||||||
if err != nil {
|
|
||||||
helpers.ServerError(w, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
roomId, err := strconv.Atoi(r.Form.Get("room_id"))
|
|
||||||
if err != nil {
|
|
||||||
helpers.ServerError(w, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
reservation := models.Reservation{
|
|
||||||
FirstName: r.Form.Get("first_name"),
|
|
||||||
LastName: r.Form.Get("last_name"),
|
|
||||||
Email: r.Form.Get("email"),
|
|
||||||
Phone: r.Form.Get("phone"),
|
|
||||||
StartDate: startDate,
|
|
||||||
EndDate: endDate,
|
|
||||||
RoomID: roomId,
|
|
||||||
}
|
|
||||||
|
|
||||||
form := forms.New(r.PostForm)
|
form := forms.New(r.PostForm)
|
||||||
|
|
||||||
@ -163,11 +142,13 @@ func (m *Repository) PostMakeReservation(w http.ResponseWriter, r *http.Request)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.App.Session.Put(r.Context(), "reservation", reservation)
|
||||||
|
|
||||||
restriction := models.RoomRestriction{
|
restriction := models.RoomRestriction{
|
||||||
StartDate: startDate,
|
StartDate: reservation.StartDate,
|
||||||
EndDate: endDate,
|
EndDate: reservation.EndDate,
|
||||||
ID: 0,
|
ID: reservation.ID,
|
||||||
RoomID: roomId,
|
RoomID: reservation.RoomID,
|
||||||
ReservationID: newReservationID,
|
ReservationID: newReservationID,
|
||||||
RestrictionID: 1,
|
RestrictionID: 1,
|
||||||
}
|
}
|
||||||
@ -197,8 +178,16 @@ func (m *Repository) ReservationSummary(w http.ResponseWriter, r *http.Request)
|
|||||||
data := make(map[string]interface{})
|
data := make(map[string]interface{})
|
||||||
data["reservation"] = reservation
|
data["reservation"] = reservation
|
||||||
|
|
||||||
|
sd := reservation.StartDate.Format("2006-01-02")
|
||||||
|
ed := reservation.EndDate.Format("2006-01-02")
|
||||||
|
stringMap := map[string]string{
|
||||||
|
"start_date": sd,
|
||||||
|
"end_date": ed,
|
||||||
|
}
|
||||||
|
|
||||||
render.Template(w, r, "reservation-summary.page.tmpl", &models.TemplateData{
|
render.Template(w, r, "reservation-summary.page.tmpl", &models.TemplateData{
|
||||||
Data: data,
|
Data: data,
|
||||||
|
StringMap: stringMap,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
const elem = document.getElementById('reservation-dates');
|
const elem = document.getElementById('reservation-dates');
|
||||||
const rangepicker = new DateRangePicker(elem, {
|
const rangepicker = new DateRangePicker(elem, {
|
||||||
"format": "yyyy-mm-dd",
|
"format": "yyyy-mm-dd",
|
||||||
|
"minDate": new Date(),
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@ -15,13 +15,17 @@
|
|||||||
<td>Name: </td>
|
<td>Name: </td>
|
||||||
<td>{{$res.LastName}} {{$res.FirstName}}</td>
|
<td>{{$res.LastName}} {{$res.FirstName}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Room: </td>
|
||||||
|
<td>{{$res.Room.RoomName}}</td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Arrival: </td>
|
<td>Arrival: </td>
|
||||||
<td></td>
|
<td>{{index .StringMap "start_date"}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Departure: </td>
|
<td>Departure: </td>
|
||||||
<td></td>
|
<td>{{index .StringMap "end_date"}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Email: </td>
|
<td>Email: </td>
|
||||||
|
Loading…
Reference in New Issue
Block a user