Handling Calendar changes
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"go-udemy-web-1/internal/models"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
@ -459,3 +460,35 @@ func (m *postgresDBRepo) GetRestrictionsForRoomByDate(roomId int, start, end tim
|
||||
}
|
||||
return restrictions, nil
|
||||
}
|
||||
|
||||
// InsertBlockForRoom inserts a room restriction
|
||||
func (m *postgresDBRepo) InsertBlockForRoom(id int, startDate time.Time) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
|
||||
query := `insert into room_restrictions (start_date, end_date, room_id, restriction_id,
|
||||
created_at, updated_at)
|
||||
values ($1, $2, $3, $4, $5, $6)`
|
||||
|
||||
_, err := m.DB.ExecContext(ctx, query, startDate, startDate.AddDate(0, 0, 1), id, 2, time.Now(), time.Now())
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteBlockByID deletes a block by ID
|
||||
func (m *postgresDBRepo) DeleteBlockByID(id int) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
|
||||
defer cancel()
|
||||
|
||||
query := `delete from room_restrictions where id = $1`
|
||||
|
||||
_, err := m.DB.ExecContext(ctx, query, id)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -128,3 +128,13 @@ func (m *testDBRepo) GetRestrictionsForRoomByDate(roomId int, start, end time.Ti
|
||||
var restrictions []models.RoomRestriction
|
||||
return restrictions, nil
|
||||
}
|
||||
|
||||
// InsertBlockForRoom inserts a room restriction
|
||||
func (m *testDBRepo) InsertBlockForRoom(id int, startDate time.Time) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteBlockByID deletes a block by ID
|
||||
func (m *testDBRepo) DeleteBlockByID(id int) error {
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user