Showing one reservation
This commit is contained in:
parent
dafd6f21c0
commit
845f3a5836
@ -44,6 +44,8 @@ func routes(app *config.AppConfig) http.Handler {
|
||||
mux.Get("/reservations-new", handlers.Repo.AdminNewReservations)
|
||||
mux.Get("/reservations-all", handlers.Repo.AdminAllReservations)
|
||||
mux.Get("/reservations-calendar", handlers.Repo.AdminReservationsCalendar)
|
||||
|
||||
mux.Get("/reservations/{src}/{id}", handlers.Repo.AdminShowReservation)
|
||||
})
|
||||
|
||||
return mux
|
||||
|
@ -539,6 +539,36 @@ func (m *Repository) AdminAllReservations(w http.ResponseWriter, r *http.Request
|
||||
})
|
||||
}
|
||||
|
||||
// AdminShowReservation shows the detail of a reservation
|
||||
func (m *Repository) AdminShowReservation(w http.ResponseWriter, r *http.Request) {
|
||||
exploded := strings.Split(r.RequestURI, "/")
|
||||
id, err := strconv.Atoi(exploded[4])
|
||||
if err != nil {
|
||||
helpers.ServerError(w, err)
|
||||
}
|
||||
src := exploded[3]
|
||||
|
||||
stringMap := make(map[string]string)
|
||||
stringMap["src"] = src
|
||||
|
||||
// get reservation from the database
|
||||
res, err := m.DB.GetReservationByID(id)
|
||||
if err != nil {
|
||||
helpers.ServerError(w, err)
|
||||
}
|
||||
|
||||
data := make(map[string]interface{})
|
||||
|
||||
data["reservation"] = res
|
||||
|
||||
render.Template(w, r, "admin-reservations-show.page.tmpl", &models.TemplateData{
|
||||
StringMap: stringMap,
|
||||
Data: data,
|
||||
Form: forms.New(nil),
|
||||
})
|
||||
}
|
||||
|
||||
// AdminReservationsCalendar displays the reservation calendar
|
||||
func (m *Repository) AdminReservationsCalendar(w http.ResponseWriter, r *http.Request) {
|
||||
render.Template(w, r, "admin-reservations-calendar.page.tmpl", &models.TemplateData{})
|
||||
}
|
||||
|
@ -306,3 +306,39 @@ func (m *postgresDBRepo) AllNewReservations() ([]models.Reservation, error) {
|
||||
|
||||
return reservations, nil
|
||||
}
|
||||
|
||||
// GetReservationByID returns one reservation by ID
|
||||
func (m *postgresDBRepo) GetReservationByID(id int) (models.Reservation, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
|
||||
var res models.Reservation
|
||||
|
||||
query := `select r.id, r.first_name, r.last_name, r.email, r.phone,
|
||||
r.start_date, r.end_date, r.room_id, r.created_at,
|
||||
r.updated_at, r.processed, rm.id, rm.room_name
|
||||
from reservations r
|
||||
left join rooms rm on (r.room_id = rm.id)
|
||||
where r.id = $1`
|
||||
|
||||
row := m.DB.QueryRowContext(ctx, query, id)
|
||||
err := row.Scan(
|
||||
&res.ID,
|
||||
&res.FirstName,
|
||||
&res.LastName,
|
||||
&res.Email,
|
||||
&res.Phone,
|
||||
&res.StartDate,
|
||||
&res.EndDate,
|
||||
&res.RoomID,
|
||||
&res.CreatedAt,
|
||||
&res.UpdatedAt,
|
||||
&res.Processed,
|
||||
&res.Room.ID,
|
||||
&res.Room.RoomName,
|
||||
)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
@ -95,3 +95,10 @@ func (m *testDBRepo) AllNewReservations() ([]models.Reservation, error) {
|
||||
|
||||
return reservations, nil
|
||||
}
|
||||
|
||||
// GetReservationByID returns one reservation by ID
|
||||
func (m *testDBRepo) GetReservationByID(id int) (models.Reservation, error) {
|
||||
var res models.Reservation
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
@ -18,4 +18,5 @@ type DatabaseRepo interface {
|
||||
Authenticate(email, testPassword string) (int, string, error)
|
||||
AllReservations() ([]models.Reservation, error)
|
||||
AllNewReservations() ([]models.Reservation, error)
|
||||
GetReservationByID(id int) (models.Reservation, error)
|
||||
}
|
||||
|
56
templates/admin-reservations-show.page.tmpl
Normal file
56
templates/admin-reservations-show.page.tmpl
Normal file
@ -0,0 +1,56 @@
|
||||
{{template "admin" .}}
|
||||
|
||||
{{define "page-title"}}
|
||||
Reservation
|
||||
{{end}}
|
||||
|
||||
{{define "content"}}
|
||||
{{$res := index .Data "reservation"}}
|
||||
{{$src := index .StringMap "src"}}
|
||||
<div class="col-md-12">
|
||||
<p>
|
||||
<strong>Arrival:</strong> {{humanDate $res.StartDate}} <br>
|
||||
<strong>Departure:</strong> {{humanDate $res.EndDate}} <br>
|
||||
<strong>Room:</strong> {{$res.Room.RoomName}} <br>
|
||||
</p>
|
||||
<form method="post" action="/admin/reservations/{{$src}}/{{$res.ID}}" class="" novalidate>
|
||||
<input type="hidden" name="csrf_token" value="{{.CSRFToken}}">
|
||||
|
||||
<div class="form-group mt-5">
|
||||
<label for="first_name">First name:</label>
|
||||
{{with .Form.Errors.Get "first_name"}}
|
||||
<label class="text-danger">{{.}}</label>
|
||||
{{end}}
|
||||
<input type="text" name="first_name" id="first_name" class="form-control {{with .Form.Errors.Get "first_name"}} is-invalid {{end}}"
|
||||
value="{{$res.FirstName}}" required autocomplete="off">
|
||||
</div>
|
||||
<div class="form-group mt-5">
|
||||
<label for="last_name">Last name:</label>
|
||||
{{with .Form.Errors.Get "last_name"}}
|
||||
<label class="text-danger">{{.}}</label>
|
||||
{{end}}
|
||||
<input type="text" name="last_name" id="last_name" class="form-control {{with .Form.Errors.Get "last_name"}} is-invalid {{end}}"
|
||||
value="{{$res.LastName}}" required autocomplete="off">
|
||||
</div>
|
||||
|
||||
<div class="form-group mt-5">
|
||||
<label for="email">Email:</label>
|
||||
{{with .Form.Errors.Get "email"}}
|
||||
<label class="text-danger">{{.}}</label>
|
||||
{{end}}
|
||||
<input type="email" name="email" id="email" class="form-control {{with .Form.Errors.Get "email"}} is-invalid {{end}}"
|
||||
value="{{$res.Email}}" required autocomplete="off">
|
||||
</div>
|
||||
<div class="form-group mt-5">
|
||||
<label for="phone">Phone number:</label>
|
||||
<input type="text" name="phone" id="phone" class="form-control" value="{{$res.Phone}}" autocomplete="off">
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<input type="submit" class="btn btn-primary" value="Save">
|
||||
<a href="/admin/reservations-{{$src}}" class="btn btn-warning">Cancel</a>
|
||||
</form>
|
||||
</div>
|
||||
{{end}}
|
||||
|
@ -22,6 +22,9 @@
|
||||
.content-wrapper {
|
||||
background-color: white;
|
||||
}
|
||||
label {
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
{{block "css" .}}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user