feat: implement entity and wiki management services, repositories, and routes with associated controllers
Build and Release / release (push) Successful in 1m34s
Build and Release / release (push) Successful in 1m34s
This commit is contained in:
@@ -19,6 +19,7 @@ type EntityService interface {
|
||||
GetEntityBySlug(ctx context.Context, slug string) (*response.EntityResponse, *fiber.Error)
|
||||
IsExistEntitySlug(ctx context.Context, slug string) (bool, *fiber.Error)
|
||||
SearchEntities(ctx context.Context, req *request.SearchEntityDto) ([]*response.EntityResponse, *fiber.Error)
|
||||
GetEntitiesByGeometryIDs(ctx context.Context, req *request.GetEntitiesByGeometryIDsDto) (map[string][]*response.EntityResponse, *fiber.Error)
|
||||
}
|
||||
|
||||
type entityService struct {
|
||||
@@ -101,3 +102,45 @@ func (s *entityService) SearchEntities(ctx context.Context, req *request.SearchE
|
||||
|
||||
return models.EntitiesEntityToResponse(entities), nil
|
||||
}
|
||||
|
||||
func (s *entityService) GetEntitiesByGeometryIDs(ctx context.Context, req *request.GetEntitiesByGeometryIDsDto) (map[string][]*response.EntityResponse, *fiber.Error) {
|
||||
mapping, err := s.entityRepo.GetEntityIDsByGeometryIDs(ctx, req.GeometryIDs)
|
||||
if err != nil {
|
||||
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to fetch entity IDs by geometry IDs")
|
||||
}
|
||||
|
||||
entityIDMap := make(map[string]struct{})
|
||||
var allEntityIDs []string
|
||||
for _, eIDs := range mapping {
|
||||
for _, eID := range eIDs {
|
||||
if _, ok := entityIDMap[eID]; !ok {
|
||||
entityIDMap[eID] = struct{}{}
|
||||
allEntityIDs = append(allEntityIDs, eID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
entities, err := s.entityRepo.GetByIDs(ctx, allEntityIDs)
|
||||
if err != nil {
|
||||
return nil, fiber.NewError(fiber.StatusInternalServerError, "Failed to fetch entities")
|
||||
}
|
||||
|
||||
entitiesByID := make(map[string]*models.EntityEntity)
|
||||
for _, e := range entities {
|
||||
entitiesByID[e.ID] = e
|
||||
}
|
||||
|
||||
result := make(map[string][]*response.EntityResponse)
|
||||
for _, idStr := range req.GeometryIDs {
|
||||
result[idStr] = make([]*response.EntityResponse, 0)
|
||||
if eIDs, exists := mapping[idStr]; exists {
|
||||
for _, eID := range eIDs {
|
||||
if e, found := entitiesByID[eID]; found {
|
||||
result[idStr] = append(result[idStr], e.ToResponse())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user