75 lines
3.2 KiB
Go
75 lines
3.2 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.coopgo.io/coopgo-platform/solidarity-transport/servers/grpc/proto/gen"
|
|
"git.coopgo.io/coopgo-platform/solidarity-transport/servers/grpc/transformers"
|
|
"git.coopgo.io/coopgo-platform/solidarity-transport/types"
|
|
"github.com/rs/zerolog/log"
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
)
|
|
|
|
func (s SolidarityTransportServerImpl) AddDriverRegularAvailability(ctx context.Context, req *gen.AddDriverRegularAvailabilityRequest) (*gen.AddDriverRegularAvailabilityResponse, error) {
|
|
if err := s.Handler.AddRegularAvailability(req.DriverId, int(req.Day), req.StartTime, req.EndTime); err != nil {
|
|
return nil, status.Errorf(codes.Internal, "AddDriverRegularAvailability : %v", err)
|
|
}
|
|
return &gen.AddDriverRegularAvailabilityResponse{}, nil
|
|
}
|
|
|
|
func (s SolidarityTransportServerImpl) AddDriverRegularAvailabilities(ctx context.Context, req *gen.AddDriverRegularAvailabilitiesRequest) (*gen.AddDriverRegularAvailabilitiesResponse, error) {
|
|
log.Info().Msg("grpc call - AddDriverRegularAvailabilities")
|
|
availabilities := []*types.DriverRegularAvailability{}
|
|
|
|
for _, a := range req.Availabilities {
|
|
if a != nil {
|
|
log.Debug().Any("availability", a).Msg("New availability")
|
|
na := transformers.DriverRegularAvailabilityProtoToType(a)
|
|
availabilities = append(availabilities, na)
|
|
}
|
|
}
|
|
if err := s.Handler.AddDriverRegularAvailabilities(availabilities); err != nil {
|
|
log.Error().Err(err).Msg("AddDriverAvailabilities error")
|
|
return nil, status.Errorf(codes.Internal, "AddDriverRegularAvailabilities : %v", err)
|
|
}
|
|
return &gen.AddDriverRegularAvailabilitiesResponse{}, nil
|
|
}
|
|
|
|
func (s SolidarityTransportServerImpl) GetDriverRegularAvailabilities(ctx context.Context, req *gen.GetDriverRegularAvailabilitiesRequest) (*gen.GetDriverRegularAvailabilitiesResponse, error) {
|
|
log.Info().Str("driver", req.DriverId).Msg("grpc call - GetDriverRegularAvailabilities")
|
|
availabilities, err := s.Handler.GetDriverRegularAvailabilities(req.DriverId)
|
|
if err != nil {
|
|
log.Error().Err(err).Msg("GetDriverRegularAvailabilities error")
|
|
return nil, status.Errorf(codes.Internal, "GetDriverRegularAvailabilities : %v", err)
|
|
}
|
|
|
|
results := []*gen.DriverRegularAvailability{}
|
|
|
|
log.Debug().Any("availabilities", availabilities).Msg("retrieved availabilities")
|
|
|
|
for _, a := range availabilities {
|
|
if a != nil {
|
|
log.Debug().Any("availability", a).Msg("Availability")
|
|
protoavailability := transformers.DriverRegularAvailabilityTypeToProto(a)
|
|
results = append(results, protoavailability)
|
|
}
|
|
}
|
|
|
|
return &gen.GetDriverRegularAvailabilitiesResponse{
|
|
Results: results,
|
|
}, nil
|
|
}
|
|
|
|
func (s SolidarityTransportServerImpl) DeleteDriverRegularAvailability(ctx context.Context, req *gen.DeleteDriverRegularAvailabilityRequest) (*gen.DeleteDriverRegularAvailabilityResponse, error) {
|
|
driverid := req.DriverId
|
|
availabilityid := req.AvailabilityId
|
|
|
|
if err := s.Handler.DeleteDriverRegularAvailabilities(driverid, availabilityid); err != nil {
|
|
log.Error().Err(err).Msg("DeleteDriverRegularAvailability error")
|
|
return nil, status.Errorf(codes.Internal, "DeleteDriverRegularAvailability error : %v", err)
|
|
}
|
|
|
|
return &gen.DeleteDriverRegularAvailabilityResponse{}, nil
|
|
}
|