|
@@ -6,7 +6,6 @@ import (
|
|
|
"errors"
|
|
"errors"
|
|
|
"fmt"
|
|
"fmt"
|
|
|
"math"
|
|
"math"
|
|
|
- "time"
|
|
|
|
|
|
|
|
|
|
"github.com/jackc/pgx/v5"
|
|
"github.com/jackc/pgx/v5"
|
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
"github.com/jackc/pgx/v5/pgxpool"
|
|
@@ -63,19 +62,6 @@ func (r *BookingRepo) Create(ctx context.Context, b *models.Booking) error {
|
|
|
return tx.Commit(ctx)
|
|
return tx.Commit(ctx)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (r *BookingRepo) IsTimeSlotAvailable(ctx context.Context, placeID string, start, end time.Time) (bool, error) {
|
|
|
|
|
- var count int
|
|
|
|
|
- err := r.pool.QueryRow(ctx,
|
|
|
|
|
- `SELECT COUNT(*) FROM bookings
|
|
|
|
|
- WHERE place_id = $1 AND status != 'cancelled'
|
|
|
|
|
- AND tsrange(start_time, end_time) && tsrange($2, $3)`,
|
|
|
|
|
- placeID, start, end).Scan(&count)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- return false, err
|
|
|
|
|
- }
|
|
|
|
|
- return count == 0, nil
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
func (r *BookingRepo) GetByID(ctx context.Context, id string) (*models.Booking, error) {
|
|
func (r *BookingRepo) GetByID(ctx context.Context, id string) (*models.Booking, error) {
|
|
|
row := r.pool.QueryRow(ctx,
|
|
row := r.pool.QueryRow(ctx,
|
|
|
`SELECT id, place_id, user_id, start_time, end_time, status, total_price, currency, comment,
|
|
`SELECT id, place_id, user_id, start_time, end_time, status, total_price, currency, comment,
|
|
@@ -120,12 +106,6 @@ func (r *BookingRepo) ListByPlace(ctx context.Context, placeID string) ([]*model
|
|
|
return scanBookings(rows)
|
|
return scanBookings(rows)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func (r *BookingRepo) UpdateStatus(ctx context.Context, id, status string) error {
|
|
|
|
|
- _, err := r.pool.Exec(ctx,
|
|
|
|
|
- `UPDATE bookings SET status=$1, updated_at=now() WHERE id=$2`, status, id)
|
|
|
|
|
- return err
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
func (r *BookingRepo) UpdateStatusIfPending(ctx context.Context, id, status string) (bool, error) {
|
|
func (r *BookingRepo) UpdateStatusIfPending(ctx context.Context, id, status string) (bool, error) {
|
|
|
tag, err := r.pool.Exec(ctx,
|
|
tag, err := r.pool.Exec(ctx,
|
|
|
`UPDATE bookings SET status=$1, updated_at=now() WHERE id=$2 AND status='pending'`, status, id)
|
|
`UPDATE bookings SET status=$1, updated_at=now() WHERE id=$2 AND status='pending'`, status, id)
|