Skip to content

Commit

Permalink
complete getReservationsBetweenMonth
Browse files Browse the repository at this point in the history
  • Loading branch information
ErfiDev committed Dec 9, 2021
1 parent 870f665 commit 9302b95
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
39 changes: 39 additions & 0 deletions repository/dbrepo/dbrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,42 @@ func (psdb postgresDbRepo) CompleteReservation(id int) (bool, error) {

return true, nil
}

func (psdb postgresDbRepo) GetReservationsBetweemMonth(start, end time.Time) ([]models.Reservation, error) {
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()

query := `select * from reservations
where end_date > $1 and start_date < $2`

sd := start.Format("2006-01-02")
ed := end.Format("2006-01-02")

var reservations []models.Reservation

rows, err := psdb.DB.QueryContext(ctx, query, sd, ed)
if err != nil {
return reservations, err
}

for rows.Next() {
res := models.Reservation{}

rows.Scan(
&res.ID,
&res.FirstName,
&res.LastName,
&res.Email,
&res.Phone,
&res.StartDate,
&res.EndDate,
&res.RoomId,
&res.CreatedAt,
&res.UpdatedAt,
)

reservations = append(reservations, res)
}

return reservations, nil
}
4 changes: 4 additions & 0 deletions repository/dbrepo/test-db.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,7 @@ func (psdb testDbRepo) DeleteReservation(id int) (bool, error) {
func (psdb testDbRepo) CompleteReservation(id int) (bool, error) {
return true, nil
}

func (psdb testDbRepo) GetReservationsBetweemMonth(start, end time.Time) ([]models.Reservation, error) {
return []models.Reservation{}, nil
}
1 change: 1 addition & 0 deletions repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ type DatabaseRepository interface {
UpdateReservation(models.Reservation) (bool, error)
DeleteReservation(id int) (bool, error)
CompleteReservation(id int) (bool, error)
GetReservationsBetweemMonth(start, end time.Time) ([]models.Reservation, error)
}

0 comments on commit 9302b95

Please sign in to comment.