udemy-go-web-1/internal/repository/dbrepo/test-repo.go

56 lines
1.4 KiB
Go
Raw Normal View History

2024-07-12 20:43:16 +00:00
package dbrepo
import (
"errors"
2024-07-12 20:43:16 +00:00
"go-udemy-web-1/internal/models"
"time"
)
func (m *testDBRepo) AllUsers() bool {
return true
}
// InsertReservation inserts a reservation into the database
func (m *testDBRepo) InsertReservation(res models.Reservation) (int, error) {
// if the room id is 2, then fail; otherwise, pass
if res.RoomID == 2 {
return 0, errors.New("deliberate error")
}
2024-07-12 20:43:16 +00:00
return 1, nil
}
// InsertRoomRestriction inserts a room restriction into the database
func (m *testDBRepo) InsertRoomRestriction(r models.RoomRestriction) error {
if r.RoomID == 100 {
return errors.New("deliberate error")
}
2024-07-12 20:43:16 +00:00
return nil
}
// SearchAvailabilityByDatesByRoomID returns true if availability exists for roomID, and false if no availability
func (m *testDBRepo) SearchAvailabilityByDatesByRoomID(start, end time.Time, roomID int) (bool, error) {
2024-07-14 12:51:12 +00:00
if roomID == 2 {
2024-07-14 12:57:13 +00:00
return false, nil
}
if roomID == 100 {
2024-07-14 12:51:12 +00:00
return false, errors.New("deliberate error")
}
return true, nil
2024-07-12 20:43:16 +00:00
}
// SearchAvailabilityForAllRooms returns a slice of rooms, if any, for given date range
func (m *testDBRepo) SearchAvailabilityForAllRooms(start, end time.Time) ([]models.Room, error) {
var rooms []models.Room
return rooms, nil
}
// GetRoomById gets a room by id
func (m *testDBRepo) GetRoomById(id int) (models.Room, error) {
var room models.Room
if id > 2 {
return room, errors.New("deliberate error")
}
2024-07-12 20:43:16 +00:00
return room, nil
}