Listing new reservations
This commit is contained in:
		@ -223,7 +223,7 @@ func (m *postgresDBRepo) AllReservations() ([]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, rm.id, rm.room_name
 | 
			
		||||
                     r.updated_at, r.processed, rm.id, rm.room_name
 | 
			
		||||
              from reservations r
 | 
			
		||||
              left join rooms rm on (r.room_id = rm.id)
 | 
			
		||||
              order by r.start_date asc`
 | 
			
		||||
@ -247,6 +247,54 @@ func (m *postgresDBRepo) AllReservations() ([]models.Reservation, error) {
 | 
			
		||||
			&i.RoomID,
 | 
			
		||||
			&i.CreatedAt,
 | 
			
		||||
			&i.UpdatedAt,
 | 
			
		||||
			&i.Processed,
 | 
			
		||||
			&i.Room.ID,
 | 
			
		||||
			&i.Room.RoomName,
 | 
			
		||||
		)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return reservations, err
 | 
			
		||||
		}
 | 
			
		||||
		reservations = append(reservations, i)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return reservations, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// AllNewReservations returns a slice of all new reservations
 | 
			
		||||
func (m *postgresDBRepo) AllNewReservations() ([]models.Reservation, error) {
 | 
			
		||||
	ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
 | 
			
		||||
	defer cancel()
 | 
			
		||||
 | 
			
		||||
	var reservations []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.processed = 0
 | 
			
		||||
              order by r.start_date asc`
 | 
			
		||||
 | 
			
		||||
	rows, err := m.DB.QueryContext(ctx, query)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return reservations, err
 | 
			
		||||
	}
 | 
			
		||||
	defer rows.Close() // To avoid memory leak
 | 
			
		||||
 | 
			
		||||
	for rows.Next() {
 | 
			
		||||
		var i models.Reservation
 | 
			
		||||
		err := rows.Scan(
 | 
			
		||||
			&i.ID,
 | 
			
		||||
			&i.FirstName,
 | 
			
		||||
			&i.LastName,
 | 
			
		||||
			&i.Email,
 | 
			
		||||
			&i.Phone,
 | 
			
		||||
			&i.StartDate,
 | 
			
		||||
			&i.EndDate,
 | 
			
		||||
			&i.RoomID,
 | 
			
		||||
			&i.CreatedAt,
 | 
			
		||||
			&i.UpdatedAt,
 | 
			
		||||
			&i.Processed,
 | 
			
		||||
			&i.Room.ID,
 | 
			
		||||
			&i.Room.RoomName,
 | 
			
		||||
		)
 | 
			
		||||
 | 
			
		||||
@ -88,3 +88,10 @@ func (m *testDBRepo) AllReservations() ([]models.Reservation, error) {
 | 
			
		||||
 | 
			
		||||
	return reservations, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// AllNewReservations returns a slice of all new reservations
 | 
			
		||||
func (m *testDBRepo) AllNewReservations() ([]models.Reservation, error) {
 | 
			
		||||
	var reservations []models.Reservation
 | 
			
		||||
 | 
			
		||||
	return reservations, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user