logic to update vehicles
This commit is contained in:
parent
d48c1ccf8e
commit
41bf03682c
|
@ -79,9 +79,6 @@ func (s FleetsServerImpl) GetVehicles(ctx context.Context, req *GetVehiclesReque
|
||||||
return &GetVehiclesResponse{Vehicles: vehicles}, nil
|
return &GetVehiclesResponse{Vehicles: vehicles}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s FleetsServerImpl) UpdateVehicle(context.Context, *UpdateVehicleRequest) (*UpdateVehicleResponse, error) {
|
|
||||||
return nil, status.Errorf(codes.Unimplemented, "method UpdateVehicle not implemented")
|
|
||||||
}
|
|
||||||
func (s FleetsServerImpl) CreateBooking(ctx context.Context, req *CreateBookingRequest) (*CreateBookingResponse, error) {
|
func (s FleetsServerImpl) CreateBooking(ctx context.Context, req *CreateBookingRequest) (*CreateBookingResponse, error) {
|
||||||
b := req.Booking.ToStorageType()
|
b := req.Booking.ToStorageType()
|
||||||
booking, err := s.handler.AddBooking(b)
|
booking, err := s.handler.AddBooking(b)
|
||||||
|
@ -195,3 +192,19 @@ func Run(done chan error, cfg *viper.Viper, handler handlers.FleetsHandler) {
|
||||||
done <- err
|
done <- err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/////////////////////update////////////////////////
|
||||||
|
func (s FleetsServerImpl) UpdateVehicle(ctx context.Context, req *UpdateVehicleRequest) (*UpdateVehicleResponse, error) {
|
||||||
|
b := req.Vehicle.ToStorageType()
|
||||||
|
vehicle, err := s.handler.UpdateVehicle(b)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return nil, status.Errorf(codes.AlreadyExists, "vehicle update failed : %v", err)
|
||||||
|
}
|
||||||
|
response, err := VehicleFromStorageType(vehicle)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return nil, status.Errorf(codes.Internal, "issue while retrieving vehicle : %v", err)
|
||||||
|
}
|
||||||
|
return &UpdateVehicleResponse{Vehicle: response}, nil
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ package handlers
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
// "Documents/go_projet/go/pkg/mod/git.coopgo.io/coopgo-platform/fleets@v0.0.0-20230310144446-feb935f8bf4e/storage"
|
||||||
|
|
||||||
"git.coopgo.io/coopgo-platform/fleets/storage"
|
"git.coopgo.io/coopgo-platform/fleets/storage"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
@ -56,3 +58,14 @@ func (h FleetsHandler) GetVehicles(namespaces []string, filters storage.VehicleF
|
||||||
}
|
}
|
||||||
return newvehicles, err
|
return newvehicles, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/////////////////update///////////////
|
||||||
|
func (h FleetsHandler) UpdateVehicle(vehicle storage.Vehicle) (*storage.Vehicle, error) {
|
||||||
|
|
||||||
|
// Store the account
|
||||||
|
if err := h.storage.UpdateVehicle(vehicle); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return &vehicle, nil
|
||||||
|
}
|
||||||
|
|
|
@ -236,3 +236,14 @@ func (s MongoDBStorage) DeleteBooking(bookingid string) error {
|
||||||
return err
|
return err
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/////////////////////update///////////////
|
||||||
|
func (s MongoDBStorage) UpdateVehicle(vehicle Vehicle) error {
|
||||||
|
collection := s.Client.Database(s.DbName).Collection(s.Collections["vehicles"])
|
||||||
|
if _, err := collection.ReplaceOne(context.TODO(), bson.M{"_id": vehicle.ID}, vehicle); err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@ type Storage interface {
|
||||||
CreateVehicle(Vehicle) error
|
CreateVehicle(Vehicle) error
|
||||||
GetVehicle(id string) (*Vehicle, error)
|
GetVehicle(id string) (*Vehicle, error)
|
||||||
GetVehicles(namespaces []string) ([]Vehicle, error)
|
GetVehicles(namespaces []string) ([]Vehicle, error)
|
||||||
|
UpdateVehicle(Vehicle) error
|
||||||
|
|
||||||
//Bookings management
|
//Bookings management
|
||||||
CreateBooking(Booking) error
|
CreateBooking(Booking) error
|
||||||
|
|
Loading…
Reference in New Issue