initial commit
This commit is contained in:
5
servers/grpc/proto/README.md
Normal file
5
servers/grpc/proto/README.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# Protocol buffer spec of the gRPC API
|
||||
|
||||
```
|
||||
protoc --go_out=paths=source_relative:. --go-grpc_out=paths=source_relative:. ./*.proto
|
||||
```
|
||||
2704
servers/grpc/proto/carpool-service-types.pb.go
Normal file
2704
servers/grpc/proto/carpool-service-types.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
222
servers/grpc/proto/carpool-service-types.proto
Normal file
222
servers/grpc/proto/carpool-service-types.proto
Normal file
@@ -0,0 +1,222 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option go_package = "git.coopgo.io/coopgo-platform/carpool-service/grpc/proto";
|
||||
|
||||
// import "google/protobuf/struct.proto";
|
||||
import "google/protobuf/timestamp.proto";
|
||||
|
||||
message CarpoolRoutesCollection {
|
||||
repeated CarpoolFeatureCollection collection = 1;
|
||||
}
|
||||
|
||||
message CarpoolFeatureCollection {
|
||||
string serialized = 1;
|
||||
}
|
||||
|
||||
|
||||
message CarpoolServiceDriverJourney {
|
||||
string id = 1;
|
||||
string operator = 2;
|
||||
double passenger_pickup_lat = 3;
|
||||
double passenger_pickup_lng = 4;
|
||||
double passenger_drop_lat = 5;
|
||||
double passenger_drop_lng = 6;
|
||||
string passenger_pickup_address = 7;
|
||||
string passenger_drop_address = 8;
|
||||
int64 distance = 9;
|
||||
double driver_departure_lat = 10;
|
||||
double driver_departure_lng = 11;
|
||||
double driver_arrival_lat = 12;
|
||||
double driver_arrival_lng = 13;
|
||||
string driver_departure_address = 14;
|
||||
string driver_arrival_address = 15;
|
||||
int64 duration = 16;
|
||||
string journey_polyline = 17;
|
||||
string web_url = 18;
|
||||
CarpoolServiceUser driver = 19;
|
||||
int64 departure_to_pickup_walking_distance = 20;
|
||||
int64 departure_to_pickup_walking_duration = 21;
|
||||
string departure_to_pickup_walking_polyline = 22;
|
||||
int64 dropoff_to_arrival_walking_distance = 23;
|
||||
int64 dropoff_to_arrival_walking_duration = 24;
|
||||
string dropoff_to_arrival_walking_polyline = 25;
|
||||
CarpoolServiceCar car = 26;
|
||||
google.protobuf.Timestamp passenger_pickup_date = 27;
|
||||
google.protobuf.Timestamp driver_departure_date = 28;
|
||||
CarpoolServiceJourneyType type = 29;
|
||||
int64 available_seats = 30;
|
||||
CarpoolServicePrice price = 31;
|
||||
CarpoolServicePreferences preferences = 32;
|
||||
}
|
||||
|
||||
message CarpoolServicePassengerJourney {
|
||||
string id = 1;
|
||||
string operator = 2;
|
||||
double passenger_pickup_lat = 3;
|
||||
double passenger_pickup_lng = 4;
|
||||
double passenger_drop_lat = 5;
|
||||
double passenger_drop_lng = 6;
|
||||
string passenger_pickup_address = 7;
|
||||
string passenger_drop_address = 8;
|
||||
int64 distance = 9;
|
||||
double driver_departure_lat = 10;
|
||||
double driver_departure_lng = 11;
|
||||
double driver_arrival_lat = 12;
|
||||
double driver_arrival_lng = 13;
|
||||
string driver_departure_address = 14;
|
||||
string driver_arrival_address = 15;
|
||||
int64 duration = 16;
|
||||
string journey_polyline = 17;
|
||||
string web_url = 18;
|
||||
CarpoolServiceUser passenger = 19;
|
||||
google.protobuf.Timestamp passenger_pickup_date = 27;
|
||||
google.protobuf.Timestamp driver_departure_date = 28;
|
||||
CarpoolServiceJourneyType type = 29;
|
||||
int64 requested_seats = 30;
|
||||
CarpoolServicePreferences preferences = 32;
|
||||
}
|
||||
|
||||
message CarpoolServiceDriverRegularTrip {
|
||||
string id = 1;
|
||||
string operator = 2;
|
||||
double passenger_pickup_lat = 3;
|
||||
double passenger_pickup_lng = 4;
|
||||
double passenger_drop_lat = 5;
|
||||
double passenger_drop_lng = 6;
|
||||
string passenger_pickup_address = 7;
|
||||
string passenger_drop_address = 8;
|
||||
int64 distance = 9;
|
||||
double driver_departure_lat = 10;
|
||||
double driver_departure_lng = 11;
|
||||
double driver_arrival_lat = 12;
|
||||
double driver_arrival_lng = 13;
|
||||
string driver_departure_address = 14;
|
||||
string driver_arrival_address = 15;
|
||||
int64 duration = 16;
|
||||
string journey_polyline = 17;
|
||||
string web_url = 18;
|
||||
CarpoolServiceUser driver = 19;
|
||||
int64 departure_to_pickup_walking_distance = 20;
|
||||
int64 departure_to_pickup_walking_duration = 21;
|
||||
string departure_to_pickup_walking_polyline = 22;
|
||||
int64 dropoff_to_arrival_walking_distance = 23;
|
||||
int64 dropoff_to_arrival_walking_duration = 24;
|
||||
string dropoff_to_arrival_walking_polyline = 25;
|
||||
CarpoolServiceCar car = 26;
|
||||
google.protobuf.Timestamp passenger_pickup_date = 27;
|
||||
google.protobuf.Timestamp driver_departure_date = 28;
|
||||
CarpoolServiceJourneyType type = 29;
|
||||
int64 requested_seats = 30;
|
||||
CarpoolServicePreferences preferences = 32;
|
||||
repeated CarpoolServiceJourneySchedule schedules = 33;
|
||||
}
|
||||
|
||||
message CarpoolServicePassengerRegularTrip {
|
||||
string id = 1;
|
||||
string operator = 2;
|
||||
double passenger_pickup_lat = 3;
|
||||
double passenger_pickup_lng = 4;
|
||||
double passenger_drop_lat = 5;
|
||||
double passenger_drop_lng = 6;
|
||||
string passenger_pickup_address = 7;
|
||||
string passenger_drop_address = 8;
|
||||
int64 distance = 9;
|
||||
double driver_departure_lat = 10;
|
||||
double driver_departure_lng = 11;
|
||||
double driver_arrival_lat = 12;
|
||||
double driver_arrival_lng = 13;
|
||||
string driver_departure_address = 14;
|
||||
string driver_arrival_address = 15;
|
||||
int64 duration = 16;
|
||||
string journey_polyline = 17;
|
||||
string web_url = 18;
|
||||
CarpoolServiceUser passenger = 19;
|
||||
CarpoolServicePreferences preferences = 32;
|
||||
repeated CarpoolServiceJourneySchedule schedules = 33;
|
||||
}
|
||||
|
||||
message CarpoolServiceBooking {
|
||||
string id = 1;
|
||||
CarpoolServiceUser driver = 2;
|
||||
CarpoolServiceUser passenger = 3;
|
||||
google.protobuf.Timestamp passenger_pickup_date = 4;
|
||||
double passenger_pickup_lat = 5;
|
||||
double passenger_pickup_lng = 6;
|
||||
double passenger_drop_lat = 7;
|
||||
double passenger_drop_lng = 8;
|
||||
string passenger_pickup_address = 9;
|
||||
string passenger_drop_address = 10;
|
||||
CarpoolServiceBookingStatus status = 11;
|
||||
int64 duration = 12;
|
||||
string web_url = 13;
|
||||
CarpoolServicePrice price = 14;
|
||||
CarpoolServiceCar car = 15;
|
||||
string driver_journey_id = 16;
|
||||
string passenger_journey_id = 17;
|
||||
}
|
||||
|
||||
message CarpoolServicePreferences {
|
||||
bool smoking = 1;
|
||||
bool animals = 2;
|
||||
bool music = 3;
|
||||
bool is_talker = 4;
|
||||
int64 luggage_size = 5;
|
||||
}
|
||||
|
||||
message CarpoolServiceUser {
|
||||
string id = 1;
|
||||
string operator = 2;
|
||||
string alias = 3;
|
||||
optional string first_name = 4;
|
||||
optional string last_name = 5;
|
||||
optional int64 grade = 6;
|
||||
optional string picture = 7;
|
||||
optional string gender = 8;
|
||||
optional bool verified_identity = 9;
|
||||
}
|
||||
|
||||
message CarpoolServiceCar {
|
||||
string model = 1;
|
||||
string brand = 2;
|
||||
}
|
||||
|
||||
message CarpoolServicePrice {
|
||||
CarpoolServicePriceType type = 1;
|
||||
double amount = 2;
|
||||
string currency = 3;
|
||||
}
|
||||
|
||||
message CarpoolServiceSchedule {
|
||||
string passenger_pickup_day = 1;
|
||||
string passenger_pickup_time_of_day = 2;
|
||||
repeated CarpoolServiceJourneySchedule journey_schedules = 3;
|
||||
}
|
||||
|
||||
message CarpoolServiceJourneySchedule {
|
||||
string id = 1;
|
||||
google.protobuf.Timestamp passenger_pickup_date = 2;
|
||||
google.protobuf.Timestamp driver_departure_date = 3;
|
||||
string web_url = 4;
|
||||
CarpoolServiceJourneyType type = 5;
|
||||
}
|
||||
|
||||
enum CarpoolServiceJourneyType {
|
||||
PLANNED = 0;
|
||||
DYNAMIC = 1;
|
||||
LINE = 2;
|
||||
}
|
||||
|
||||
enum CarpoolServicePriceType {
|
||||
FREE = 0;
|
||||
PAYING = 1;
|
||||
UNKNOWN = 2;
|
||||
}
|
||||
|
||||
enum CarpoolServiceBookingStatus {
|
||||
INITIATED = 0;
|
||||
WAITING_CONFIRMATION = 1;
|
||||
CONFIRMED = 2;
|
||||
CANCELLED = 3;
|
||||
COMPLETED_PENDING_VALIDATION = 4;
|
||||
VALIDATED = 5;
|
||||
}
|
||||
1911
servers/grpc/proto/carpool-service.pb.go
Normal file
1911
servers/grpc/proto/carpool-service.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
145
servers/grpc/proto/carpool-service.proto
Normal file
145
servers/grpc/proto/carpool-service.proto
Normal file
@@ -0,0 +1,145 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option go_package = "git.coopgo.io/coopgo-platform/carpool-service/grpc/proto";
|
||||
|
||||
import "google/protobuf/timestamp.proto";
|
||||
import "carpool-service-types.proto";
|
||||
|
||||
service CarpoolService {
|
||||
// Internal trips and journeys management
|
||||
// rpc XXXX(Request) returns (Response) {}
|
||||
rpc CreateRegularRoutes(CreateRegularRoutesRequest) returns (CreateRegularRoutesResponse) {}
|
||||
rpc DeleteRegularRoutes(DeleteRegularRoutesRequest) returns (DeleteRegularRoutesResponse) {}
|
||||
|
||||
rpc GetUserPlanning(GetUserPlanningRequest) returns (GetUserPlanningResponse) {}
|
||||
|
||||
// OCSS-like interaction
|
||||
rpc DriverJourneys(DriverJourneysRequest) returns (DriverJourneysResponse) {}
|
||||
rpc PassengerJourneys(PassengerJourneysRequest) returns (PassengerJourneysResponse) {}
|
||||
rpc DriverRegularTrips(DriverRegularTripsRequest) returns (DriverRegularTripsResponse) {}
|
||||
rpc PassengerRegularTrips(PassengerRegularTripsRequest) returns (PassengerRegularTripsResponse) {}
|
||||
|
||||
rpc CreateBooking(CreateBookingRequest) returns (CreateBookingResponse) {}
|
||||
rpc UpdateBooking(UpdateBookingRequest) returns (UpdateBookingResponse) {}
|
||||
rpc GetBooking(GetBookingRequest) returns (GetBookingResponse) {}
|
||||
}
|
||||
|
||||
// Internal trips and journeys management messages
|
||||
message CreateRegularRoutesRequest{
|
||||
repeated CarpoolFeatureCollection routes = 1;
|
||||
}
|
||||
|
||||
message CreateRegularRoutesResponse{}
|
||||
|
||||
message DeleteRegularRoutesRequest {
|
||||
repeated string ids = 1;
|
||||
}
|
||||
|
||||
message DeleteRegularRoutesResponse {}
|
||||
|
||||
message GetUserPlanningRequest {
|
||||
string user_id = 1;
|
||||
google.protobuf.Timestamp min_departure_date = 2;
|
||||
google.protobuf.Timestamp max_departure_date = 3;
|
||||
}
|
||||
|
||||
message GetUserPlanningResponse {
|
||||
map<string, CarpoolRoutesCollection> routes_by_dates = 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// OCSS-like interaction messages
|
||||
message DriverJourneysRequest {
|
||||
double departure_lat = 1;
|
||||
double departure_lng = 2;
|
||||
double arrival_lat = 3;
|
||||
double arrival_lng = 4;
|
||||
google.protobuf.Timestamp departure_date = 5;
|
||||
int64 time_delta = 6;
|
||||
double departure_radius = 7;
|
||||
double arrival_radius = 8;
|
||||
int64 count = 9;
|
||||
}
|
||||
|
||||
message DriverJourneysResponse {
|
||||
repeated CarpoolServiceDriverJourney driver_journeys = 1;
|
||||
}
|
||||
|
||||
message PassengerJourneysRequest {
|
||||
double departure_lat = 1;
|
||||
double departure_lng = 2;
|
||||
double arrival_lat = 3;
|
||||
double arrival_lng = 4;
|
||||
google.protobuf.Timestamp departure_date = 5;
|
||||
int64 time_delta = 6;
|
||||
double departure_radius = 7;
|
||||
double arrival_radius = 8;
|
||||
int64 count = 9;
|
||||
}
|
||||
|
||||
message PassengerJourneysResponse {
|
||||
repeated CarpoolServicePassengerJourney passenger_journeys = 1;
|
||||
}
|
||||
|
||||
message DriverRegularTripsRequest {
|
||||
double departure_lat = 1;
|
||||
double departure_lng = 2;
|
||||
double arrival_lat = 3;
|
||||
double arrival_lng = 4;
|
||||
string departure_time_of_day = 5;
|
||||
repeated string departure_week_days = 6;
|
||||
int64 time_delta = 7;
|
||||
double departure_radius = 8;
|
||||
double arrival_radius = 9;
|
||||
google.protobuf.Timestamp min_departure_date = 10;
|
||||
google.protobuf.Timestamp max_departure_date = 11;
|
||||
int64 count = 12;
|
||||
}
|
||||
|
||||
message DriverRegularTripsResponse {
|
||||
repeated CarpoolServiceDriverRegularTrip driver_regular_trips = 1;
|
||||
}
|
||||
|
||||
message PassengerRegularTripsRequest {
|
||||
double departure_lat = 1;
|
||||
double departure_lng = 2;
|
||||
double arrival_lat = 3;
|
||||
double arrival_lng = 4;
|
||||
string departure_time_of_day = 5;
|
||||
repeated string departure_week_days = 6;
|
||||
int64 time_delta = 7;
|
||||
double departure_radius = 8;
|
||||
double arrival_radius = 9;
|
||||
google.protobuf.Timestamp min_departure_date = 10;
|
||||
google.protobuf.Timestamp max_departure_date = 11;
|
||||
int64 count = 12;
|
||||
}
|
||||
|
||||
message PassengerRegularTripsResponse {
|
||||
repeated CarpoolServiceDriverRegularTrip driver_regular_trips = 1;
|
||||
}
|
||||
|
||||
message CreateBookingRequest {
|
||||
CarpoolServiceBooking booking = 1;
|
||||
}
|
||||
|
||||
message CreateBookingResponse {
|
||||
CarpoolServiceBooking booking = 1;
|
||||
}
|
||||
|
||||
message UpdateBookingRequest {
|
||||
string booking_id = 1;
|
||||
CarpoolServiceBookingStatus status = 2;
|
||||
string message = 3;
|
||||
}
|
||||
|
||||
message UpdateBookingResponse {}
|
||||
|
||||
message GetBookingRequest {
|
||||
string booking_id = 1;
|
||||
}
|
||||
|
||||
message GetBookingResponse {
|
||||
CarpoolServiceBooking booking = 1;
|
||||
}
|
||||
435
servers/grpc/proto/carpool-service_grpc.pb.go
Normal file
435
servers/grpc/proto/carpool-service_grpc.pb.go
Normal file
@@ -0,0 +1,435 @@
|
||||
// Code generated by protoc-gen-go-grpc. DO NOT EDIT.
|
||||
// versions:
|
||||
// - protoc-gen-go-grpc v1.2.0
|
||||
// - protoc v3.19.4
|
||||
// source: carpool-service.proto
|
||||
|
||||
package proto
|
||||
|
||||
import (
|
||||
context "context"
|
||||
grpc "google.golang.org/grpc"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
status "google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
// This is a compile-time assertion to ensure that this generated file
|
||||
// is compatible with the grpc package it is being compiled against.
|
||||
// Requires gRPC-Go v1.32.0 or later.
|
||||
const _ = grpc.SupportPackageIsVersion7
|
||||
|
||||
// CarpoolServiceClient is the client API for CarpoolService service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
type CarpoolServiceClient interface {
|
||||
// Internal trips and journeys management
|
||||
// rpc XXXX(Request) returns (Response) {}
|
||||
CreateRegularRoutes(ctx context.Context, in *CreateRegularRoutesRequest, opts ...grpc.CallOption) (*CreateRegularRoutesResponse, error)
|
||||
DeleteRegularRoutes(ctx context.Context, in *DeleteRegularRoutesRequest, opts ...grpc.CallOption) (*DeleteRegularRoutesResponse, error)
|
||||
GetUserPlanning(ctx context.Context, in *GetUserPlanningRequest, opts ...grpc.CallOption) (*GetUserPlanningResponse, error)
|
||||
// OCSS-like interaction
|
||||
DriverJourneys(ctx context.Context, in *DriverJourneysRequest, opts ...grpc.CallOption) (*DriverJourneysResponse, error)
|
||||
PassengerJourneys(ctx context.Context, in *PassengerJourneysRequest, opts ...grpc.CallOption) (*PassengerJourneysResponse, error)
|
||||
DriverRegularTrips(ctx context.Context, in *DriverRegularTripsRequest, opts ...grpc.CallOption) (*DriverRegularTripsResponse, error)
|
||||
PassengerRegularTrips(ctx context.Context, in *PassengerRegularTripsRequest, opts ...grpc.CallOption) (*PassengerRegularTripsResponse, error)
|
||||
CreateBooking(ctx context.Context, in *CreateBookingRequest, opts ...grpc.CallOption) (*CreateBookingResponse, error)
|
||||
UpdateBooking(ctx context.Context, in *UpdateBookingRequest, opts ...grpc.CallOption) (*UpdateBookingResponse, error)
|
||||
GetBooking(ctx context.Context, in *GetBookingRequest, opts ...grpc.CallOption) (*GetBookingResponse, error)
|
||||
}
|
||||
|
||||
type carpoolServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewCarpoolServiceClient(cc grpc.ClientConnInterface) CarpoolServiceClient {
|
||||
return &carpoolServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *carpoolServiceClient) CreateRegularRoutes(ctx context.Context, in *CreateRegularRoutesRequest, opts ...grpc.CallOption) (*CreateRegularRoutesResponse, error) {
|
||||
out := new(CreateRegularRoutesResponse)
|
||||
err := c.cc.Invoke(ctx, "/CarpoolService/CreateRegularRoutes", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *carpoolServiceClient) DeleteRegularRoutes(ctx context.Context, in *DeleteRegularRoutesRequest, opts ...grpc.CallOption) (*DeleteRegularRoutesResponse, error) {
|
||||
out := new(DeleteRegularRoutesResponse)
|
||||
err := c.cc.Invoke(ctx, "/CarpoolService/DeleteRegularRoutes", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *carpoolServiceClient) GetUserPlanning(ctx context.Context, in *GetUserPlanningRequest, opts ...grpc.CallOption) (*GetUserPlanningResponse, error) {
|
||||
out := new(GetUserPlanningResponse)
|
||||
err := c.cc.Invoke(ctx, "/CarpoolService/GetUserPlanning", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *carpoolServiceClient) DriverJourneys(ctx context.Context, in *DriverJourneysRequest, opts ...grpc.CallOption) (*DriverJourneysResponse, error) {
|
||||
out := new(DriverJourneysResponse)
|
||||
err := c.cc.Invoke(ctx, "/CarpoolService/DriverJourneys", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *carpoolServiceClient) PassengerJourneys(ctx context.Context, in *PassengerJourneysRequest, opts ...grpc.CallOption) (*PassengerJourneysResponse, error) {
|
||||
out := new(PassengerJourneysResponse)
|
||||
err := c.cc.Invoke(ctx, "/CarpoolService/PassengerJourneys", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *carpoolServiceClient) DriverRegularTrips(ctx context.Context, in *DriverRegularTripsRequest, opts ...grpc.CallOption) (*DriverRegularTripsResponse, error) {
|
||||
out := new(DriverRegularTripsResponse)
|
||||
err := c.cc.Invoke(ctx, "/CarpoolService/DriverRegularTrips", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *carpoolServiceClient) PassengerRegularTrips(ctx context.Context, in *PassengerRegularTripsRequest, opts ...grpc.CallOption) (*PassengerRegularTripsResponse, error) {
|
||||
out := new(PassengerRegularTripsResponse)
|
||||
err := c.cc.Invoke(ctx, "/CarpoolService/PassengerRegularTrips", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *carpoolServiceClient) CreateBooking(ctx context.Context, in *CreateBookingRequest, opts ...grpc.CallOption) (*CreateBookingResponse, error) {
|
||||
out := new(CreateBookingResponse)
|
||||
err := c.cc.Invoke(ctx, "/CarpoolService/CreateBooking", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *carpoolServiceClient) UpdateBooking(ctx context.Context, in *UpdateBookingRequest, opts ...grpc.CallOption) (*UpdateBookingResponse, error) {
|
||||
out := new(UpdateBookingResponse)
|
||||
err := c.cc.Invoke(ctx, "/CarpoolService/UpdateBooking", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *carpoolServiceClient) GetBooking(ctx context.Context, in *GetBookingRequest, opts ...grpc.CallOption) (*GetBookingResponse, error) {
|
||||
out := new(GetBookingResponse)
|
||||
err := c.cc.Invoke(ctx, "/CarpoolService/GetBooking", in, out, opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// CarpoolServiceServer is the server API for CarpoolService service.
|
||||
// All implementations must embed UnimplementedCarpoolServiceServer
|
||||
// for forward compatibility
|
||||
type CarpoolServiceServer interface {
|
||||
// Internal trips and journeys management
|
||||
// rpc XXXX(Request) returns (Response) {}
|
||||
CreateRegularRoutes(context.Context, *CreateRegularRoutesRequest) (*CreateRegularRoutesResponse, error)
|
||||
DeleteRegularRoutes(context.Context, *DeleteRegularRoutesRequest) (*DeleteRegularRoutesResponse, error)
|
||||
GetUserPlanning(context.Context, *GetUserPlanningRequest) (*GetUserPlanningResponse, error)
|
||||
// OCSS-like interaction
|
||||
DriverJourneys(context.Context, *DriverJourneysRequest) (*DriverJourneysResponse, error)
|
||||
PassengerJourneys(context.Context, *PassengerJourneysRequest) (*PassengerJourneysResponse, error)
|
||||
DriverRegularTrips(context.Context, *DriverRegularTripsRequest) (*DriverRegularTripsResponse, error)
|
||||
PassengerRegularTrips(context.Context, *PassengerRegularTripsRequest) (*PassengerRegularTripsResponse, error)
|
||||
CreateBooking(context.Context, *CreateBookingRequest) (*CreateBookingResponse, error)
|
||||
UpdateBooking(context.Context, *UpdateBookingRequest) (*UpdateBookingResponse, error)
|
||||
GetBooking(context.Context, *GetBookingRequest) (*GetBookingResponse, error)
|
||||
mustEmbedUnimplementedCarpoolServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedCarpoolServiceServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedCarpoolServiceServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedCarpoolServiceServer) CreateRegularRoutes(context.Context, *CreateRegularRoutesRequest) (*CreateRegularRoutesResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method CreateRegularRoutes not implemented")
|
||||
}
|
||||
func (UnimplementedCarpoolServiceServer) DeleteRegularRoutes(context.Context, *DeleteRegularRoutesRequest) (*DeleteRegularRoutesResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method DeleteRegularRoutes not implemented")
|
||||
}
|
||||
func (UnimplementedCarpoolServiceServer) GetUserPlanning(context.Context, *GetUserPlanningRequest) (*GetUserPlanningResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetUserPlanning not implemented")
|
||||
}
|
||||
func (UnimplementedCarpoolServiceServer) DriverJourneys(context.Context, *DriverJourneysRequest) (*DriverJourneysResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method DriverJourneys not implemented")
|
||||
}
|
||||
func (UnimplementedCarpoolServiceServer) PassengerJourneys(context.Context, *PassengerJourneysRequest) (*PassengerJourneysResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method PassengerJourneys not implemented")
|
||||
}
|
||||
func (UnimplementedCarpoolServiceServer) DriverRegularTrips(context.Context, *DriverRegularTripsRequest) (*DriverRegularTripsResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method DriverRegularTrips not implemented")
|
||||
}
|
||||
func (UnimplementedCarpoolServiceServer) PassengerRegularTrips(context.Context, *PassengerRegularTripsRequest) (*PassengerRegularTripsResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method PassengerRegularTrips not implemented")
|
||||
}
|
||||
func (UnimplementedCarpoolServiceServer) CreateBooking(context.Context, *CreateBookingRequest) (*CreateBookingResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method CreateBooking not implemented")
|
||||
}
|
||||
func (UnimplementedCarpoolServiceServer) UpdateBooking(context.Context, *UpdateBookingRequest) (*UpdateBookingResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method UpdateBooking not implemented")
|
||||
}
|
||||
func (UnimplementedCarpoolServiceServer) GetBooking(context.Context, *GetBookingRequest) (*GetBookingResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetBooking not implemented")
|
||||
}
|
||||
func (UnimplementedCarpoolServiceServer) mustEmbedUnimplementedCarpoolServiceServer() {}
|
||||
|
||||
// UnsafeCarpoolServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to CarpoolServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeCarpoolServiceServer interface {
|
||||
mustEmbedUnimplementedCarpoolServiceServer()
|
||||
}
|
||||
|
||||
func RegisterCarpoolServiceServer(s grpc.ServiceRegistrar, srv CarpoolServiceServer) {
|
||||
s.RegisterService(&CarpoolService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _CarpoolService_CreateRegularRoutes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(CreateRegularRoutesRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(CarpoolServiceServer).CreateRegularRoutes(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/CarpoolService/CreateRegularRoutes",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(CarpoolServiceServer).CreateRegularRoutes(ctx, req.(*CreateRegularRoutesRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _CarpoolService_DeleteRegularRoutes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(DeleteRegularRoutesRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(CarpoolServiceServer).DeleteRegularRoutes(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/CarpoolService/DeleteRegularRoutes",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(CarpoolServiceServer).DeleteRegularRoutes(ctx, req.(*DeleteRegularRoutesRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _CarpoolService_GetUserPlanning_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetUserPlanningRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(CarpoolServiceServer).GetUserPlanning(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/CarpoolService/GetUserPlanning",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(CarpoolServiceServer).GetUserPlanning(ctx, req.(*GetUserPlanningRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _CarpoolService_DriverJourneys_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(DriverJourneysRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(CarpoolServiceServer).DriverJourneys(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/CarpoolService/DriverJourneys",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(CarpoolServiceServer).DriverJourneys(ctx, req.(*DriverJourneysRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _CarpoolService_PassengerJourneys_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(PassengerJourneysRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(CarpoolServiceServer).PassengerJourneys(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/CarpoolService/PassengerJourneys",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(CarpoolServiceServer).PassengerJourneys(ctx, req.(*PassengerJourneysRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _CarpoolService_DriverRegularTrips_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(DriverRegularTripsRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(CarpoolServiceServer).DriverRegularTrips(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/CarpoolService/DriverRegularTrips",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(CarpoolServiceServer).DriverRegularTrips(ctx, req.(*DriverRegularTripsRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _CarpoolService_PassengerRegularTrips_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(PassengerRegularTripsRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(CarpoolServiceServer).PassengerRegularTrips(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/CarpoolService/PassengerRegularTrips",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(CarpoolServiceServer).PassengerRegularTrips(ctx, req.(*PassengerRegularTripsRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _CarpoolService_CreateBooking_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(CreateBookingRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(CarpoolServiceServer).CreateBooking(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/CarpoolService/CreateBooking",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(CarpoolServiceServer).CreateBooking(ctx, req.(*CreateBookingRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _CarpoolService_UpdateBooking_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(UpdateBookingRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(CarpoolServiceServer).UpdateBooking(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/CarpoolService/UpdateBooking",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(CarpoolServiceServer).UpdateBooking(ctx, req.(*UpdateBookingRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _CarpoolService_GetBooking_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(GetBookingRequest)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(CarpoolServiceServer).GetBooking(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: "/CarpoolService/GetBooking",
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(CarpoolServiceServer).GetBooking(ctx, req.(*GetBookingRequest))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// CarpoolService_ServiceDesc is the grpc.ServiceDesc for CarpoolService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var CarpoolService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "CarpoolService",
|
||||
HandlerType: (*CarpoolServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "CreateRegularRoutes",
|
||||
Handler: _CarpoolService_CreateRegularRoutes_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "DeleteRegularRoutes",
|
||||
Handler: _CarpoolService_DeleteRegularRoutes_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetUserPlanning",
|
||||
Handler: _CarpoolService_GetUserPlanning_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "DriverJourneys",
|
||||
Handler: _CarpoolService_DriverJourneys_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "PassengerJourneys",
|
||||
Handler: _CarpoolService_PassengerJourneys_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "DriverRegularTrips",
|
||||
Handler: _CarpoolService_DriverRegularTrips_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "PassengerRegularTrips",
|
||||
Handler: _CarpoolService_PassengerRegularTrips_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "CreateBooking",
|
||||
Handler: _CarpoolService_CreateBooking_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "UpdateBooking",
|
||||
Handler: _CarpoolService_UpdateBooking_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "GetBooking",
|
||||
Handler: _CarpoolService_GetBooking_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "carpool-service.proto",
|
||||
}
|
||||
131
servers/grpc/server/server.go
Normal file
131
servers/grpc/server/server.go
Normal file
@@ -0,0 +1,131 @@
|
||||
package grpcserver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"git.coopgo.io/coopgo-platform/carpool-service/handler"
|
||||
"git.coopgo.io/coopgo-platform/carpool-service/servers/grpc/proto"
|
||||
"github.com/paulmach/orb/geojson"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/viper"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/reflection"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type CarpoolServiceServerImpl struct {
|
||||
Handler *handler.CarpoolServiceHandler
|
||||
|
||||
proto.UnimplementedCarpoolServiceServer
|
||||
}
|
||||
|
||||
func NewCarpoolServiceServer(handler *handler.CarpoolServiceHandler) *CarpoolServiceServerImpl {
|
||||
return &CarpoolServiceServerImpl{
|
||||
Handler: handler,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CarpoolServiceServerImpl) CreateRegularRoutes(ctx context.Context, req *proto.CreateRegularRoutesRequest) (*proto.CreateRegularRoutesResponse, error) {
|
||||
log.Debug().Msg("grpc CarpoolService - CreateTrips")
|
||||
routes := []*geojson.FeatureCollection{}
|
||||
|
||||
for _, r := range req.Routes {
|
||||
route, err := geojson.UnmarshalFeatureCollection([]byte(r.Serialized))
|
||||
if err == nil {
|
||||
routes = append(routes, route)
|
||||
}
|
||||
}
|
||||
|
||||
if len(routes) == 0 {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "no route to create")
|
||||
}
|
||||
|
||||
if err := s.Handler.CreateRegularRoutes(routes); err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "could not create routes in CreateRegularRoutes : %s", err.Error())
|
||||
}
|
||||
|
||||
return &proto.CreateRegularRoutesResponse{}, nil
|
||||
}
|
||||
|
||||
func (s *CarpoolServiceServerImpl) DeleteRegularRoutes(context.Context, *proto.DeleteRegularRoutesRequest) (*proto.DeleteRegularRoutesResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method DeleteTrips not implemented")
|
||||
}
|
||||
|
||||
func (s *CarpoolServiceServerImpl) GetUserPlanning(ctx context.Context, req *proto.GetUserPlanningRequest) (*proto.GetUserPlanningResponse, error) {
|
||||
log.Debug().Msg("grpc CarpoolService - GetRegularUserRoutes")
|
||||
|
||||
planned_schedules, err := s.Handler.GetUserPlanning(req.UserId, req.MinDepartureDate.AsTime(), req.MaxDepartureDate.AsTime())
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "could not get user planning : %s", err.Error())
|
||||
}
|
||||
|
||||
results := map[string]*proto.CarpoolRoutesCollection{}
|
||||
|
||||
for k, scheds := range planned_schedules {
|
||||
|
||||
results[k] = &proto.CarpoolRoutesCollection{
|
||||
Collection: []*proto.CarpoolFeatureCollection{},
|
||||
}
|
||||
|
||||
for _, s := range scheds {
|
||||
s.Route.ExtraMembers["departure_date"] = s.DepartureDate
|
||||
fcraw, _ := s.Route.FeatureCollection().MarshalJSON()
|
||||
results[k].Collection = append(results[k].Collection, &proto.CarpoolFeatureCollection{
|
||||
Serialized: string(fcraw),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return &proto.GetUserPlanningResponse{
|
||||
RoutesByDates: results,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *CarpoolServiceServerImpl) DriverJourneys(context.Context, *proto.DriverJourneysRequest) (*proto.DriverJourneysResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method DriverJourneys not implemented")
|
||||
}
|
||||
func (s *CarpoolServiceServerImpl) PassengerJourneys(context.Context, *proto.PassengerJourneysRequest) (*proto.PassengerJourneysResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method PassengerJourneys not implemented")
|
||||
}
|
||||
func (s *CarpoolServiceServerImpl) DriverRegularTrips(context.Context, *proto.DriverRegularTripsRequest) (*proto.DriverRegularTripsResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method DriverRegularTrips not implemented")
|
||||
}
|
||||
func (s *CarpoolServiceServerImpl) PassengerRegularTrips(context.Context, *proto.PassengerRegularTripsRequest) (*proto.PassengerRegularTripsResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method PassengerRegularTrips not implemented")
|
||||
}
|
||||
func (s *CarpoolServiceServerImpl) CreateBooking(context.Context, *proto.CreateBookingRequest) (*proto.CreateBookingResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method CreateBooking not implemented")
|
||||
}
|
||||
func (s *CarpoolServiceServerImpl) UpdateBooking(context.Context, *proto.UpdateBookingRequest) (*proto.UpdateBookingResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method UpdateBooking not implemented")
|
||||
}
|
||||
func (s *CarpoolServiceServerImpl) GetBooking(context.Context, *proto.GetBookingRequest) (*proto.GetBookingResponse, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method GetBooking not implemented")
|
||||
}
|
||||
|
||||
func Run(done chan error, cfg *viper.Viper, handler *handler.CarpoolServiceHandler) {
|
||||
var (
|
||||
dev_env = cfg.GetBool("dev_env")
|
||||
address = ":" + cfg.GetString("services.grpc.port")
|
||||
)
|
||||
|
||||
server := grpc.NewServer()
|
||||
proto.RegisterCarpoolServiceServer(server, NewCarpoolServiceServer(handler))
|
||||
l, err := net.Listen("tcp", address)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err)
|
||||
return
|
||||
}
|
||||
|
||||
if dev_env {
|
||||
reflection.Register(server)
|
||||
}
|
||||
|
||||
if err := server.Serve(l); err != nil {
|
||||
fmt.Println("gRPC service ended")
|
||||
done <- err
|
||||
}
|
||||
}
|
||||
18
servers/ocss-api/book.go
Normal file
18
servers/ocss-api/book.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package ocssapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"git.coopgo.io/coopgo-platform/carpool-service/interoperability/ocss"
|
||||
)
|
||||
|
||||
func (s *OCSSApiService) PostBookings(ctx context.Context, booking ocss.Booking) (*ocss.Booking, error) {
|
||||
return nil, errors.New("method not implmeented - PostBookings")
|
||||
}
|
||||
func (s *OCSSApiService) PatchBooking(ctx context.Context, bookingId string, status ocss.BookingStatus, message *string) error {
|
||||
return errors.New("method not implmeented - PatchBooking")
|
||||
}
|
||||
func (s *OCSSApiService) GetBooking(ctx context.Context, bookingId string) (*ocss.Booking, error) {
|
||||
return nil, errors.New("method not implmeented - GetBooking")
|
||||
}
|
||||
12
servers/ocss-api/booking-events.go
Normal file
12
servers/ocss-api/booking-events.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package ocssapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"git.coopgo.io/coopgo-platform/carpool-service/interoperability/ocss"
|
||||
)
|
||||
|
||||
func (s *OCSSApiService) PostBookingEvents(ctx context.Context, event ocss.CarpoolBookingEvent) error {
|
||||
return errors.New("method not implmeented - GetBooking")
|
||||
}
|
||||
53
servers/ocss-api/ocss-api.go
Normal file
53
servers/ocss-api/ocss-api.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package ocssapi
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"git.coopgo.io/coopgo-platform/carpool-service/handler"
|
||||
"git.coopgo.io/coopgo-platform/carpool-service/interoperability/ocss"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
type OCSSApiService struct {
|
||||
Handler *handler.CarpoolServiceHandler
|
||||
}
|
||||
|
||||
func NewOCSSApiService(handler *handler.CarpoolServiceHandler) (*OCSSApiService, error) {
|
||||
return &OCSSApiService{
|
||||
Handler: handler,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Status
|
||||
func (s *OCSSApiService) Status() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func Run(done chan error, cfg *viper.Viper, handler *handler.CarpoolServiceHandler) {
|
||||
var (
|
||||
address = ":" + cfg.GetString("services.ocss_api.port")
|
||||
)
|
||||
|
||||
service, err := NewOCSSApiService(handler)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("could not initialize OCSS api service")
|
||||
return
|
||||
}
|
||||
|
||||
err = http.ListenAndServe(address, ocss.NewServer(service))
|
||||
|
||||
srv := &http.Server{
|
||||
Handler: ocss.NewServer(service),
|
||||
Addr: address,
|
||||
WriteTimeout: 15 * time.Second,
|
||||
ReadTimeout: 15 * time.Second,
|
||||
}
|
||||
|
||||
err = srv.ListenAndServe()
|
||||
|
||||
log.Error().Err(err).Msg("OCSS api error")
|
||||
done <- err
|
||||
}
|
||||
42
servers/ocss-api/search.go
Normal file
42
servers/ocss-api/search.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package ocssapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"time"
|
||||
|
||||
"git.coopgo.io/coopgo-platform/carpool-service/interoperability/ocss"
|
||||
"github.com/paulmach/orb"
|
||||
)
|
||||
|
||||
func (s *OCSSApiService) GetDriverJourneys(ctx context.Context, departureLat float64, departureLng float64, arrivalLat float64, arrivalLng float64, departureDate time.Time, timeDelta *time.Duration, departureRadius *float64, arrivalRadius *float64, count *int64) ([]ocss.DriverJourney, error) {
|
||||
departure := orb.Point{departureLng, departureLat}
|
||||
arrival := orb.Point{arrivalLng, arrivalLat}
|
||||
|
||||
td := 900 * time.Second
|
||||
if timeDelta != nil {
|
||||
td = *timeDelta
|
||||
}
|
||||
|
||||
minDate := departureDate.Add(-td * time.Second)
|
||||
maxDate := departureDate.Add(td * time.Second)
|
||||
|
||||
result, err := s.Handler.GetDriverJourneys(departure, arrival, minDate, maxDate)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (s *OCSSApiService) GetPassengerJourneys(ctx context.Context, departureLat float64, departureLng float64, arrivalLat float64, arrivalLng float64, departureDate time.Time, timeDelta *time.Duration, departureRadius *float64, arrivalRadius *float64, count *int64) ([]ocss.PassengerJourney, error) {
|
||||
return nil, errors.New("method not implmeented - GetPassengerJourneys")
|
||||
}
|
||||
|
||||
func (s *OCSSApiService) GetDriverRegularTrips(ctx context.Context, departureLat float64, departureLng float64, arrivalLat float64, arrivalLng float64, departureTimeOfDay string, departureWeekDays *[]string, timeDelta *time.Duration, departureRadius *float64, arrivalRadius *float64, minDepartureDate *time.Time, maxDepartureDate *time.Time, count *int64) ([]ocss.DriverTrip, error) {
|
||||
return []ocss.DriverTrip{}, nil
|
||||
}
|
||||
|
||||
func (s *OCSSApiService) GetPassengerRegularTrips(ctx context.Context, departureLat float64, departureLng float64, arrivalLat float64, arrivalLng float64, departureTimeOfDay string, departureWeekDays *[]string, timeDelta *time.Duration, departureRadius *float64, arrivalRadius *float64, minDepartureDate *time.Time, maxDepartureDate *time.Time, count *int64) ([]ocss.PassengerTrip, error) {
|
||||
return []ocss.PassengerTrip{}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user