Searching for availability by room
This commit is contained in:
@ -64,3 +64,26 @@ func (m *postgresDBRepo) InsertRoomRestriction(r models.RoomRestriction) error {
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SearchAvailabilityByDates returns true if availability exists for roomID, and false if no availability
|
||||
func (m *postgresDBRepo) SearchAvailabilityByDates(start, end time.Time, roomID int) (bool, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
|
||||
var numRows int
|
||||
stmt := `select count(id) from room_restrictions
|
||||
where room_id = $1 and
|
||||
$2 < end_date and $3> start_date`
|
||||
|
||||
row := m.DB.QueryRowContext(ctx, stmt, roomID, start, end)
|
||||
err := row.Scan(&numRows)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if numRows == 0 {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user