Compare commits
4 Commits
8a271fdcf8
...
6e6b559356
Author | SHA1 | Date |
---|---|---|
Arnaud Delcasse | 6e6b559356 | |
Arnaud Delcasse | 0c8cf6be60 | |
Nicolas CARON | 8147a7a6b9 | |
soukainna | 41bf03682c |
1
go.sum
1
go.sum
|
@ -127,7 +127,6 @@ github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLe
|
|||
github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
||||
github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||
github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
|
|
|
@ -80,9 +80,6 @@ func (s FleetsServerImpl) GetVehicles(ctx context.Context, req *GetVehiclesReque
|
|||
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) {
|
||||
b := req.Booking.ToStorageType()
|
||||
booking, err := s.handler.AddBooking(b)
|
||||
|
@ -196,3 +193,19 @@ func Run(done chan error, cfg *viper.Viper, handler handlers.FleetsHandler) {
|
|||
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
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package handlers
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.coopgo.io/coopgo-platform/fleets/storage"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
@ -26,9 +24,9 @@ func (h FleetsHandler) GetBooking(id string) (booking *storage.Booking, err erro
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if booking.Deleted {
|
||||
return nil, errors.New("booking was deleted")
|
||||
}
|
||||
// if booking.Deleted {
|
||||
// return nil, errors.New("booking was deleted")
|
||||
// }
|
||||
|
||||
vehicle, err := h.storage.GetVehicle(booking.Vehicleid)
|
||||
if err != nil {
|
||||
|
|
|
@ -3,6 +3,8 @@ package handlers
|
|||
import (
|
||||
"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"
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
@ -56,3 +58,14 @@ func (h FleetsHandler) GetVehicles(namespaces []string, filters storage.VehicleF
|
|||
}
|
||||
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
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ type Booking struct {
|
|||
Unavailableto time.Time `json:"unavailableto"`
|
||||
Data map[string]any `json:"data"`
|
||||
|
||||
Deleted bool
|
||||
Deleted bool `json:"deleted"`
|
||||
Vehicle Vehicle `json:"vehicle" bson:"-"`
|
||||
}
|
||||
|
||||
|
|
|
@ -225,6 +225,8 @@ func (s MongoDBStorage) GetBookingsForDriver(driver string) (bookings []Booking,
|
|||
func (s MongoDBStorage) DeleteBooking(bookingid string) error {
|
||||
collection := s.Client.Database(s.DbName).Collection(s.Collections["bookings"])
|
||||
|
||||
fmt.Println(bookingid)
|
||||
|
||||
_, err := collection.UpdateOne(
|
||||
context.TODO(),
|
||||
bson.M{"_id": bookingid},
|
||||
|
@ -236,3 +238,14 @@ func (s MongoDBStorage) DeleteBooking(bookingid string) error {
|
|||
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
|
||||
GetVehicle(id string) (*Vehicle, error)
|
||||
GetVehicles(namespaces []string) ([]Vehicle, error)
|
||||
UpdateVehicle(Vehicle) error
|
||||
|
||||
//Bookings management
|
||||
CreateBooking(Booking) error
|
||||
|
|
Loading…
Reference in New Issue