Add tiles management
This commit is contained in:
@@ -115,6 +115,92 @@ func (s MongoDBStorage) GetUserRegularRoutes(userid string) ([]*geojson.FeatureC
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (s MongoDBStorage) GetDriverRegularRoutesForTile(day string, gridId int64) ([]*geojson.FeatureCollection, error) {
|
||||
findOptions := options.Find()
|
||||
collection := s.Client.Database(s.DbName).Collection(s.Collections["regular_routes"])
|
||||
cur, err := collection.Find(context.TODO(), bson.M{
|
||||
"properties.schedule.day": day,
|
||||
"grid_ids": gridId,
|
||||
"properties.is_driver": true,
|
||||
}, findOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
results := []*geojson.FeatureCollection{}
|
||||
for cur.Next(context.TODO()) {
|
||||
var elem bson.M
|
||||
|
||||
if err := cur.Decode(&elem); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bsonBytes, _ := bson.Marshal(elem)
|
||||
fc := geojson.NewFeatureCollection()
|
||||
err := fc.UnmarshalBSON(bsonBytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fc.ExtraMembers["id"] = fc.ExtraMembers.MustString("_id")
|
||||
delete(fc.ExtraMembers, "_id")
|
||||
|
||||
for k, v := range fc.ExtraMembers {
|
||||
if val, ok := v.(primitive.D); ok {
|
||||
em := map[string]any{}
|
||||
jsonbytes, _ := bson.MarshalExtJSON(val, true, true)
|
||||
json.Unmarshal(jsonbytes, &em)
|
||||
fc.ExtraMembers[k] = em
|
||||
}
|
||||
}
|
||||
|
||||
results = append(results, fc)
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
func (s MongoDBStorage) GetPassengerRegularRoutesForTile(day string, gridId int64) ([]*geojson.FeatureCollection, error) {
|
||||
findOptions := options.Find()
|
||||
collection := s.Client.Database(s.DbName).Collection(s.Collections["regular_routes"])
|
||||
cur, err := collection.Find(context.TODO(), bson.M{
|
||||
"properties.schedule.day": day,
|
||||
"grid_ids": gridId,
|
||||
"properties.is_passenger": true,
|
||||
}, findOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
results := []*geojson.FeatureCollection{}
|
||||
for cur.Next(context.TODO()) {
|
||||
var elem bson.M
|
||||
|
||||
if err := cur.Decode(&elem); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
bsonBytes, _ := bson.Marshal(elem)
|
||||
fc := geojson.NewFeatureCollection()
|
||||
err := fc.UnmarshalBSON(bsonBytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fc.ExtraMembers["id"] = fc.ExtraMembers.MustString("_id")
|
||||
delete(fc.ExtraMembers, "_id")
|
||||
|
||||
for k, v := range fc.ExtraMembers {
|
||||
if val, ok := v.(primitive.D); ok {
|
||||
em := map[string]any{}
|
||||
jsonbytes, _ := bson.MarshalExtJSON(val, true, true)
|
||||
json.Unmarshal(jsonbytes, &em)
|
||||
fc.ExtraMembers[k] = em
|
||||
}
|
||||
}
|
||||
|
||||
results = append(results, fc)
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
// func (s MongoDBStorage) CreatePassengerRegularTrips(trips []*geojson.FeatureCollection) error {
|
||||
|
||||
// log.Debug().Msg("Storage - CreatePassengerRegularTrips")
|
||||
|
||||
@@ -10,6 +10,8 @@ import (
|
||||
type Storage interface {
|
||||
CreateRegularRoutes([]*geojson.FeatureCollection) error
|
||||
GetUserRegularRoutes(userid string) ([]*geojson.FeatureCollection, error)
|
||||
GetDriverRegularRoutesForTile(day string, gridId int64) ([]*geojson.FeatureCollection, error)
|
||||
GetPassengerRegularRoutesForTile(day string, gridId int64) ([]*geojson.FeatureCollection, error)
|
||||
}
|
||||
|
||||
func NewStorage(cfg *viper.Viper) (Storage, error) {
|
||||
|
||||
Reference in New Issue
Block a user