create collections for passenger, driver, booking

This commit is contained in:
Maxime 2024-05-24 14:58:44 +02:00
parent 860e3624d7
commit 935176da52
1 changed files with 11 additions and 11 deletions

View File

@ -63,7 +63,7 @@ func NewMongoDBStorage(cfg *viper.Viper) (MongoDBStorage, error) {
}
func (s MongoDBStorage) CreatePassenger(passenger internal.Passenger) (err error) {
collection := s.Client.Database(s.DbName).Collection(s.Collections["users"])
collection := s.Client.Database(s.DbName).Collection(s.Collections["passengers"])
_, err = uuid.Parse(passenger.Passenger.ID)
if err != nil {
@ -101,7 +101,7 @@ func (s MongoDBStorage) CreatePassenger(passenger internal.Passenger) (err error
return nil
}
func (s MongoDBStorage) UpdatePassenger(passenger internal.Passenger) (err error) {
collection := s.Client.Database(s.DbName).Collection(s.Collections["users"])
collection := s.Client.Database(s.DbName).Collection(s.Collections["passengers"])
_, err = uuid.Parse(passenger.Passenger.ID)
if err != nil {
@ -132,7 +132,7 @@ func (s MongoDBStorage) UpdatePassenger(passenger internal.Passenger) (err error
}
func (s MongoDBStorage) GetPassenger(passengerID string) (passenger internal.Passenger, err error) {
collection := s.Client.Database(s.DbName).Collection(s.Collections["users"])
collection := s.Client.Database(s.DbName).Collection(s.Collections["passengers"])
var preferencesJSON []byte
_ , err = uuid.Parse(passenger.Passenger.ID)
@ -161,7 +161,7 @@ func (s MongoDBStorage) GetPassenger(passengerID string) (passenger internal.Pas
}
func (s MongoDBStorage) CreateDriver(driver internal.Driver) (err error) {
collection := s.Client.Database(s.DbName).Collection(s.Collections["users"])
collection := s.Client.Database(s.DbName).Collection(s.Collections["drivers"])
//var availabilities []byte
_, err = uuid.Parse(driver.Driver.ID)
if err != nil {
@ -235,7 +235,7 @@ func (s MongoDBStorage) CreateDriver(driver internal.Driver) (err error) {
return nil
}
func (s MongoDBStorage) UpdateDriver(driver internal.Driver) (err error) {
collection := s.Client.Database(s.DbName).Collection(s.Collections["groups"])
collection := s.Client.Database(s.DbName).Collection(s.Collections["drivers"])
//var availabilities []byte
_, err = uuid.Parse(driver.Driver.ID)
if err != nil {
@ -305,7 +305,7 @@ func (s MongoDBStorage) UpdateDriver(driver internal.Driver) (err error) {
}
func (s MongoDBStorage) GetDriver(driverID string) ( *internal.Driver, error) {
collection := s.Client.Database(s.DbName).Collection(s.Collections["users"])
collection := s.Client.Database(s.DbName).Collection(s.Collections["drivers"])
// var preferencesJSON []byte
// var departureAddress []byte
// var availabilitiesJSON []byte
@ -364,7 +364,7 @@ func (s MongoDBStorage) GetDriver(driverID string) ( *internal.Driver, error) {
}
func (s MongoDBStorage) CreateBooking(booking internal.BookingRequest) (err error) {
collection := s.Client.Database(s.DbName).Collection(s.Collections["users"])
collection := s.Client.Database(s.DbName).Collection(s.Collections["bookings"])
_, err = uuid.Parse(booking.Driver_id)
if err != nil {
log.Error().Err(err).Msg("MongoDB Storage CreateBooking invalid Driver ID")
@ -417,7 +417,7 @@ func (s MongoDBStorage) CreateBooking(booking internal.BookingRequest) (err erro
}
func (s MongoDBStorage) GetBooking(bookingID string) (*internal.Booking, error) {
collection := s.Client.Database(s.DbName).Collection(s.Collections["users"])
collection := s.Client.Database(s.DbName).Collection(s.Collections["bookings"])
//var departureAddress []byte
//var destinationAddress []byte
booking := &internal.Booking{}
@ -460,7 +460,7 @@ func (s MongoDBStorage) GetBooking(bookingID string) (*internal.Booking, error)
}
func (s MongoDBStorage) UpdateBookingStatus(bookingStatusID string, status internal.BookingStatus) (err error) {
collection := s.Client.Database(s.DbName).Collection(s.Collections["users"])
collection := s.Client.Database(s.DbName).Collection(s.Collections["bookings"])
_, err = uuid.Parse(bookingStatusID)
if err != nil {
log.Error().Err(err).Msg("MongoDB Storage UpdateBookingStatus invalid Booking ID")
@ -480,7 +480,7 @@ func (s MongoDBStorage) UpdateBookingStatus(bookingStatusID string, status inter
}
func (s MongoDBStorage) FilterUserBookingsByStatus(userType string, status internal.BookingStatus, userID string) (bookings []internal.Booking, err error) {
collection := s.Client.Database(s.DbName).Collection(s.Collections["groups"])
collection := s.Client.Database(s.DbName).Collection(s.Collections["bookings"])
if err != nil {
return nil, errors.New("invalid UUID")
}
@ -641,7 +641,7 @@ func (s MongoDBStorage) populateBookingDetails(booking internal.Booking, departu
}
func (s MongoDBStorage) GetAllDrivers( date int64) (drivers []internal.Driver, err error) {
// rows := s.Client.Database(s.DbName).Collection(s.Collections["users"])
// rows := s.Client.Database(s.DbName).Collection(s.Collections["drivers"])
if err != nil {
return nil, err
}