Database functions for editing a reservation
This commit is contained in:
		@ -342,3 +342,45 @@ func (m *postgresDBRepo) GetReservationByID(id int) (models.Reservation, error)
 | 
			
		||||
	}
 | 
			
		||||
	return res, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// UpdateReservation updates a user in the database
 | 
			
		||||
func (m *postgresDBRepo) UpdateReservation(r models.Reservation) error {
 | 
			
		||||
	ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
 | 
			
		||||
	defer cancel()
 | 
			
		||||
 | 
			
		||||
	query := `update reservations set first_name = $1, last_name = $2, email = $3, phone = $4, updated_at = $5`
 | 
			
		||||
 | 
			
		||||
	_, err := m.DB.ExecContext(ctx, query, r.FirstName, r.LastName, r.Email, r.Phone, time.Now())
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DeleteReservation deletes one reservation by ID
 | 
			
		||||
func (m *postgresDBRepo) DeleteReservation(id int) error {
 | 
			
		||||
	ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
 | 
			
		||||
	defer cancel()
 | 
			
		||||
 | 
			
		||||
	query := `delete from reservations where id = $1`
 | 
			
		||||
 | 
			
		||||
	_, err := m.DB.ExecContext(ctx, query, id)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// UpdateProcessedForReservation set processed for a reservation
 | 
			
		||||
func (m *postgresDBRepo) UpdateProcessedForReservation(id, processed int) error {
 | 
			
		||||
	ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
 | 
			
		||||
	defer cancel()
 | 
			
		||||
 | 
			
		||||
	query := `update reservations set processed = $1 where id = $2`
 | 
			
		||||
 | 
			
		||||
	_, err := m.DB.ExecContext(ctx, query, processed, id)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -102,3 +102,17 @@ func (m *testDBRepo) GetReservationByID(id int) (models.Reservation, error) {
 | 
			
		||||
 | 
			
		||||
	return res, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// UpdateReservation updates a user in the database
 | 
			
		||||
func (m *testDBRepo) UpdateReservation(r models.Reservation) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *testDBRepo) DeleteReservation(id int) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// UpdateProcessedForReservation set processed for a reservation
 | 
			
		||||
func (m *testDBRepo) UpdateProcessedForReservation(id, processed int) error {
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -19,4 +19,7 @@ type DatabaseRepo interface {
 | 
			
		||||
	AllReservations() ([]models.Reservation, error)
 | 
			
		||||
	AllNewReservations() ([]models.Reservation, error)
 | 
			
		||||
	GetReservationByID(id int) (models.Reservation, error)
 | 
			
		||||
	UpdateReservation(r models.Reservation) error
 | 
			
		||||
	DeleteReservation(id int) error
 | 
			
		||||
	UpdateProcessedForReservation(id, processed int) error
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user