2024-07-06 20:55:25 +00:00
|
|
|
package repository
|
|
|
|
|
2024-07-09 21:08:31 +00:00
|
|
|
import (
|
2024-08-01 08:04:50 +00:00
|
|
|
"database/sql"
|
2024-07-09 21:08:31 +00:00
|
|
|
"go-udemy-web-1/internal/models"
|
|
|
|
"time"
|
2024-08-01 08:04:50 +00:00
|
|
|
|
|
|
|
"github.com/jackc/pgx/v5"
|
2024-07-09 21:08:31 +00:00
|
|
|
)
|
2024-07-08 21:04:17 +00:00
|
|
|
|
2024-07-06 20:55:25 +00:00
|
|
|
type DatabaseRepo interface {
|
|
|
|
AllUsers() bool
|
2024-07-08 21:04:17 +00:00
|
|
|
|
2024-07-09 20:57:07 +00:00
|
|
|
InsertReservation(res models.Reservation) (int, error)
|
|
|
|
InsertRoomRestriction(res models.RoomRestriction) error
|
2024-07-09 21:50:54 +00:00
|
|
|
SearchAvailabilityByDatesByRoomID(start, end time.Time, roomID int) (bool, error)
|
|
|
|
SearchAvailabilityForAllRooms(start, end time.Time) ([]models.Room, error)
|
2024-07-10 20:34:27 +00:00
|
|
|
GetRoomById(id int) (models.Room, error)
|
2024-07-19 07:44:27 +00:00
|
|
|
GetUserByID(id int) (models.User, error)
|
|
|
|
UpdateUser(u models.User) error
|
|
|
|
Authenticate(email, testPassword string) (int, string, error)
|
2024-07-22 20:14:48 +00:00
|
|
|
AllReservations() ([]models.Reservation, error)
|
2024-07-24 12:20:30 +00:00
|
|
|
AllNewReservations() ([]models.Reservation, error)
|
2024-07-24 20:23:31 +00:00
|
|
|
GetReservationByID(id int) (models.Reservation, error)
|
2024-07-25 11:13:16 +00:00
|
|
|
UpdateReservation(r models.Reservation) error
|
|
|
|
DeleteReservation(id int) error
|
|
|
|
UpdateProcessedForReservation(id, processed int) error
|
2024-07-26 11:40:56 +00:00
|
|
|
AllRooms() ([]models.Room, error)
|
2024-07-27 20:39:23 +00:00
|
|
|
GetRestrictionsForRoomByDate(roomId int, start, end time.Time) ([]models.RoomRestriction, error)
|
2024-07-28 12:43:39 +00:00
|
|
|
InsertBlockForRoom(id int, startDate time.Time) error
|
|
|
|
DeleteBlockByID(id int) error
|
2024-07-06 20:55:25 +00:00
|
|
|
}
|
2024-08-01 08:04:50 +00:00
|
|
|
|
|
|
|
// DB holds the database connection pool
|
|
|
|
type DB struct {
|
|
|
|
SQL *sql.DB
|
|
|
|
PG *pgx.Conn
|
|
|
|
}
|
|
|
|
|
|
|
|
type DatabaseDriverRepo interface {
|
|
|
|
ConnectSQL(dsn string) (*DB, error)
|
|
|
|
}
|