Finish adding sqlc and fix some bugs
This commit is contained in:
@ -28,11 +28,12 @@ func (m *pgcDBRepo) InsertReservation(res models.Reservation) (int, error) {
|
||||
Phone: res.Phone,
|
||||
StartDate: pgtype.Date{Time: res.StartDate, Valid: true},
|
||||
EndDate: pgtype.Date{Time: res.EndDate, Valid: true},
|
||||
RoomID: int32(res.Room.ID),
|
||||
CreatedAt: pgtype.Timestamp{Time: res.CreatedAt, Valid: true},
|
||||
UpdatedAt: pgtype.Timestamp{Time: res.UpdatedAt, Valid: true},
|
||||
RoomID: int32(res.RoomID),
|
||||
CreatedAt: pgtype.Timestamp{Time: time.Now(), Valid: true},
|
||||
UpdatedAt: pgtype.Timestamp{Time: time.Now(), Valid: true},
|
||||
})
|
||||
if err != nil {
|
||||
m.App.ErrorLog.Println(err)
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@ -47,13 +48,14 @@ func (m *pgcDBRepo) InsertRoomRestriction(r models.RoomRestriction) error {
|
||||
err := m.Q.InsertRoomRestriction(ctx, sqlc.InsertRoomRestrictionParams{
|
||||
StartDate: pgtype.Date{Time: r.StartDate, Valid: true},
|
||||
EndDate: pgtype.Date{Time: r.EndDate, Valid: true},
|
||||
RoomID: int32(r.Room.ID),
|
||||
ReservationID: pgtype.Int4{Int32: int32(r.ID), Valid: true},
|
||||
RoomID: int32(r.RoomID),
|
||||
ReservationID: pgtype.Int4{Int32: int32(r.ReservationID), Valid: true},
|
||||
RestrictionID: int32(r.RestrictionID),
|
||||
CreatedAt: pgtype.Timestamp{Time: r.CreatedAt, Valid: true},
|
||||
UpdatedAt: pgtype.Timestamp{Time: r.UpdatedAt, Valid: true},
|
||||
CreatedAt: pgtype.Timestamp{Time: time.Now(), Valid: true},
|
||||
UpdatedAt: pgtype.Timestamp{Time: time.Now(), Valid: true},
|
||||
})
|
||||
if err != nil {
|
||||
m.App.ErrorLog.Println(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@ -74,10 +76,10 @@ func (m *pgcDBRepo) SearchAvailabilityByDatesByRoomID(start, end time.Time, room
|
||||
}
|
||||
|
||||
if numRows == 0 {
|
||||
return true, nil
|
||||
return false, nil
|
||||
}
|
||||
|
||||
return false, nil
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// SearchAvailabilityForAllRooms returns a slice of rooms, if any, for given date range
|
||||
@ -158,7 +160,7 @@ func (m *pgcDBRepo) UpdateUser(u models.User) error {
|
||||
LastName: u.LastName,
|
||||
Email: u.Email,
|
||||
AccessLevel: int32(u.AccessLevel),
|
||||
UpdatedAt: pgtype.Timestamp{Time: u.UpdatedAt, Valid: true},
|
||||
UpdatedAt: pgtype.Timestamp{Time: time.Now(), Valid: true},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
@ -294,7 +296,7 @@ func (m *pgcDBRepo) UpdateReservation(r models.Reservation) error {
|
||||
LastName: r.LastName,
|
||||
Email: r.Email,
|
||||
Phone: r.Phone,
|
||||
UpdatedAt: pgtype.Timestamp{Time: r.UpdatedAt, Valid: true},
|
||||
UpdatedAt: pgtype.Timestamp{Time: time.Now(), Valid: true},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user