2024-07-12 20:43:16 +00:00
|
|
|
package dbrepo
|
|
|
|
|
|
|
|
import (
|
2024-07-13 14:47:23 +00:00
|
|
|
"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) {
|
2024-07-14 09:49:42 +00:00
|
|
|
// 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 {
|
2024-07-14 09:49:42 +00:00
|
|
|
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
|
2024-07-15 20:38:29 +00:00
|
|
|
if start.Format("2006-01-02") == "2050-01-01" && end.Format("2006-01-02") == "2050-01-02" {
|
|
|
|
room := models.Room{
|
|
|
|
RoomName: "room",
|
|
|
|
ID: 1,
|
|
|
|
}
|
|
|
|
rooms = append(rooms, room)
|
|
|
|
return rooms, nil
|
|
|
|
}
|
|
|
|
if start.Format("2006-01-02") == "2050-01-03" && end.Format("2006-01-02") == "2050-01-04" {
|
|
|
|
return rooms, errors.New("deliberate error")
|
|
|
|
}
|
2024-07-12 20:43:16 +00:00
|
|
|
return rooms, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetRoomById gets a room by id
|
|
|
|
func (m *testDBRepo) GetRoomById(id int) (models.Room, error) {
|
|
|
|
var room models.Room
|
2024-07-13 14:47:23 +00:00
|
|
|
|
2024-07-16 11:22:46 +00:00
|
|
|
if id > 2 || id <= 0 {
|
2024-07-14 09:49:42 +00:00
|
|
|
return room, errors.New("deliberate error")
|
2024-07-13 14:47:23 +00:00
|
|
|
}
|
2024-07-12 20:43:16 +00:00
|
|
|
return room, nil
|
|
|
|
}
|
2024-07-19 07:44:27 +00:00
|
|
|
|
|
|
|
// GetUserByID gets a user by id
|
|
|
|
func (m *testDBRepo) GetUserByID(id int) (models.User, error) {
|
|
|
|
var u models.User
|
|
|
|
|
|
|
|
return u, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateUser updates a user in the database
|
|
|
|
func (m *testDBRepo) UpdateUser(u models.User) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Authenticate authenticates a user
|
|
|
|
func (m *testDBRepo) Authenticate(email, testPassword string) (int, string, error) {
|
|
|
|
return 1, "", nil
|
|
|
|
}
|
2024-07-22 20:14:48 +00:00
|
|
|
|
|
|
|
// AllReservations returns a slice of all reservations
|
|
|
|
func (m *testDBRepo) AllReservations() ([]models.Reservation, error) {
|
|
|
|
var reservations []models.Reservation
|
|
|
|
|
|
|
|
return reservations, nil
|
|
|
|
}
|
2024-07-24 12:20:30 +00:00
|
|
|
|
|
|
|
// AllNewReservations returns a slice of all new reservations
|
|
|
|
func (m *testDBRepo) AllNewReservations() ([]models.Reservation, error) {
|
|
|
|
var reservations []models.Reservation
|
|
|
|
|
|
|
|
return reservations, nil
|
|
|
|
}
|
2024-07-24 20:23:31 +00:00
|
|
|
|
|
|
|
// GetReservationByID returns one reservation by ID
|
|
|
|
func (m *testDBRepo) GetReservationByID(id int) (models.Reservation, error) {
|
|
|
|
var res models.Reservation
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|