Creating a test database repository
This commit is contained in:
parent
32250d92c4
commit
1c46c5a64b
@ -35,6 +35,14 @@ func NewRepo(a *config.AppConfig, db *driver.DB) *Repository {
|
||||
}
|
||||
}
|
||||
|
||||
// NewTestRepo creates a new testing repository
|
||||
func NewTestRepo(a *config.AppConfig) *Repository {
|
||||
return &Repository{
|
||||
App: a,
|
||||
DB: dbrepo.NewTestingRepo(a),
|
||||
}
|
||||
}
|
||||
|
||||
// NewHandlers sets the repository for the handlers
|
||||
func NewHandlers(r *Repository) {
|
||||
Repo = r
|
||||
|
@ -52,7 +52,7 @@ func getRoutes() http.Handler {
|
||||
errorLog := log.New(os.Stdout, "ERROR\t", log.Ldate|log.Ltime|log.Lshortfile)
|
||||
app.ErrorLog = errorLog
|
||||
|
||||
repo := NewRepo(&app)
|
||||
repo := NewTestRepo(&app)
|
||||
NewHandlers(repo)
|
||||
|
||||
render.NewRenderer(&app)
|
||||
|
@ -11,9 +11,20 @@ type postgresDBRepo struct {
|
||||
DB *sql.DB
|
||||
}
|
||||
|
||||
type testDBRepo struct {
|
||||
App *config.AppConfig
|
||||
DB *sql.DB
|
||||
}
|
||||
|
||||
func NewPostgresRepo(conn *sql.DB, a *config.AppConfig) repository.DatabaseRepo {
|
||||
return &postgresDBRepo{
|
||||
App: a,
|
||||
DB: conn,
|
||||
}
|
||||
}
|
||||
|
||||
func NewTestingRepo(a *config.AppConfig) repository.DatabaseRepo {
|
||||
return &testDBRepo{
|
||||
App: a,
|
||||
}
|
||||
}
|
||||
|
37
internal/repository/dbrepo/test-repo.go
Normal file
37
internal/repository/dbrepo/test-repo.go
Normal file
@ -0,0 +1,37 @@
|
||||
package dbrepo
|
||||
|
||||
import (
|
||||
"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) {
|
||||
return 1, nil
|
||||
}
|
||||
|
||||
// InsertRoomRestriction inserts a room restriction into the database
|
||||
func (m *testDBRepo) InsertRoomRestriction(r models.RoomRestriction) error {
|
||||
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) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// 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
|
||||
return room, nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user