diff --git a/internal/handlers/handlers.go b/internal/handlers/handlers.go index cccfb05..be43e37 100644 --- a/internal/handlers/handlers.go +++ b/internal/handlers/handlers.go @@ -482,7 +482,7 @@ func (m *Repository) PostShowLogin(w http.ResponseWriter, r *http.Request) { password := r.Form.Get("password") id, _, err := m.DB.Autenticate(email, password) - fmt.Println(id) + if err != nil { m.App.Session.Put(r.Context(), "error", "Invalid Login ERROR") http.Redirect(w, r, "/user-login", http.StatusSeeOther) @@ -549,9 +549,24 @@ func (m *Repository) AdminShowReservation(w http.ResponseWriter, r *http.Request helpers.ServerError(w, err) return } - log.Println(id) + src := exploded[3] + stringMap := make(map[string]string) + stringMap["src"] = src // get reservation from the DB - render.Template(w, r, "admin-reservations-show.page.tmpl", &models.TemplateData{}) + res, err := m.DB.GetReservationByID(id) + if err != nil { + helpers.ServerError(w, err) + return + } + + 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), + }) } diff --git a/internal/repository/dbrepo/postgres.go b/internal/repository/dbrepo/postgres.go index 2a13afb..8ed3dd9 100644 --- a/internal/repository/dbrepo/postgres.go +++ b/internal/repository/dbrepo/postgres.go @@ -3,7 +3,6 @@ package dbrepo import ( "context" "errors" - "fmt" "time" "udemyCourse1/internal/models" @@ -217,9 +216,6 @@ func (m *postgresDBRepo) Autenticate(email, testPassword string) (int, string, e return id, hashedPassword, err } - fmt.Println("hashedPassword : " + hashedPassword) - fmt.Println("testPassword : " + testPassword) - err = bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(testPassword)) if err == bcrypt.ErrMismatchedHashAndPassword { return 0, "", errors.New("incorrect password") @@ -351,7 +347,7 @@ func (m *postgresDBRepo) GetReservationByID(id int) (models.Reservation, error) 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 + 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 @@ -361,7 +357,6 @@ func (m *postgresDBRepo) GetReservationByID(id int) (models.Reservation, error) row := m.DB.QueryRowContext(ctx, query, id) err := row.Scan( &i.ID, - &i.Processed, &i.FirstName, &i.LastName, &i.Email, @@ -371,6 +366,7 @@ func (m *postgresDBRepo) GetReservationByID(id int) (models.Reservation, error) &i.RoomID, &i.CreatedAt, &i.UpdatedAt, + &i.Processed, &i.Room.ID, &i.Room.RoomName, ) diff --git a/templates/admin-new-reservations.page.tmpl b/templates/admin-new-reservations.page.tmpl index d5731d5..bda606c 100644 --- a/templates/admin-new-reservations.page.tmpl +++ b/templates/admin-new-reservations.page.tmpl @@ -57,7 +57,7 @@ - + {{end}} {{define "js"}} diff --git a/templates/admin-reservations-show.page.tmpl b/templates/admin-reservations-show.page.tmpl index f64af49..3e1f3fe 100644 --- a/templates/admin-reservations-show.page.tmpl +++ b/templates/admin-reservations-show.page.tmpl @@ -5,7 +5,104 @@ {{end}} {{define "content"}} + {{$reservation := index .Data "reservation"}} + {{$src := index .StringMap "src"}}
- Show Reservations +

+ Arrival: {{dateformate $reservation.StartDate}}
+ Departue: {{dateformate $reservation.EndDate}}
+

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
IDNewFirst NameLast NameEmailPhoneStart DateEnd DateRoom IDCreated AtUpdated AtRoom Name
{{$reservation.ID}}{{$reservation.Processed}}{{$reservation.FirstName}} + + {{$reservation.LastName}} + + {{$reservation.Email}}{{$reservation.Phone}}{{dateformate $reservation.StartDate}}{{dateformate $reservation.EndDate}}{{$reservation.RoomID}}{{dateformate $reservation.CreatedAt}}{{dateformate $reservation.UpdatedAt}}{{$reservation.Room.RoomName}}
+ +
+ + +
+ + {{with.Form.Errors.Get "first_name"}} + + {{end}} + +
+ +
+ + {{with.Form.Errors.Get "last_name"}} + + {{end}} + +
+ +
+ + {{with.Form.Errors.Get "email"}} + + {{end}} + +
+ +
+ + {{with.Form.Errors.Get "phone"}} + + {{end}} + +
+ +
+ + Cancel +
+
-{{end}} \ No newline at end of file +
+ + +{{end}} diff --git a/templates/admin.layout.tmpl b/templates/admin.layout.tmpl index ed319b7..9230b6b 100644 --- a/templates/admin.layout.tmpl +++ b/templates/admin.layout.tmpl @@ -20,7 +20,14 @@ {{block "css" . }} + + {{end}} +