mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-11 19:04:35 +00:00
More admin data delete endpoints (#361)
This commit is contained in:
@@ -111,7 +111,6 @@ func Search(ctx context.Context, typ string, entity *Entity, radius float64, num
|
||||
|
||||
// get the index
|
||||
index := getIndex(ctx)
|
||||
|
||||
points := index.KNearest(entity, numEntities, geo.Meters(radius), func(p geo.Point) bool {
|
||||
e, ok := p.(*Entity)
|
||||
if !ok || e.Type != typ {
|
||||
@@ -132,3 +131,11 @@ func Search(ctx context.Context, typ string, entity *Entity, radius float64, num
|
||||
|
||||
return entities
|
||||
}
|
||||
|
||||
func DeleteIndex(tenantID string) error {
|
||||
mtx.Lock()
|
||||
defer mtx.Unlock()
|
||||
delete(indexes, tenantID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -6,9 +6,12 @@ import (
|
||||
|
||||
"github.com/micro/micro/v3/service"
|
||||
"github.com/micro/micro/v3/service/errors"
|
||||
"github.com/micro/micro/v3/service/logger"
|
||||
"github.com/micro/services/location/domain"
|
||||
loc "github.com/micro/services/location/proto"
|
||||
"github.com/micro/services/location/subscriber"
|
||||
pauth "github.com/micro/services/pkg/auth"
|
||||
adminpb "github.com/micro/services/pkg/service/proto"
|
||||
)
|
||||
|
||||
type Location struct{}
|
||||
@@ -70,3 +73,21 @@ func (l *Location) Search(ctx context.Context, req *loc.SearchRequest, rsp *loc.
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *Location) DeleteData(ctx context.Context, request *adminpb.DeleteDataRequest, response *adminpb.DeleteDataResponse) error {
|
||||
method := "admin.DeleteData"
|
||||
_, err := pauth.VerifyMicroAdmin(ctx, method)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(request.TenantId) == 0 {
|
||||
return errors.BadRequest(method, "Missing tenant ID")
|
||||
}
|
||||
|
||||
if err := domain.DeleteIndex(request.TenantId); err != nil {
|
||||
return err
|
||||
}
|
||||
logger.Infof("Deleted index for %s", request.TenantId)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/micro/micro/v3/service"
|
||||
"github.com/micro/services/location/handler"
|
||||
pb "github.com/micro/services/location/proto"
|
||||
admin "github.com/micro/services/pkg/service/proto"
|
||||
"github.com/micro/services/pkg/tracing"
|
||||
)
|
||||
|
||||
@@ -14,7 +15,9 @@ func main() {
|
||||
service.Name("location"),
|
||||
)
|
||||
|
||||
pb.RegisterLocationHandler(location.Server(), new(handler.Location))
|
||||
h := new(handler.Location)
|
||||
pb.RegisterLocationHandler(location.Server(), h)
|
||||
admin.RegisterAdminHandler(location.Server(), h)
|
||||
|
||||
// TODO reinstate me
|
||||
//service.Subscribe(subscriber.Topic, new(subscriber.Location))
|
||||
|
||||
Reference in New Issue
Block a user