|
@@ -24,6 +24,8 @@ type PlaceRepo interface {
|
|
|
SetFeatures(ctx context.Context, placeID string, features []models.Feature) error
|
|
SetFeatures(ctx context.Context, placeID string, features []models.Feature) error
|
|
|
GetTags(ctx context.Context, placeID string) ([]models.Tag, error)
|
|
GetTags(ctx context.Context, placeID string) ([]models.Tag, error)
|
|
|
GetFeatures(ctx context.Context, placeID string) ([]models.Feature, error)
|
|
GetFeatures(ctx context.Context, placeID string) ([]models.Feature, error)
|
|
|
|
|
+ GetTagsBatch(ctx context.Context, placeIDs []string) (map[string][]models.Tag, error)
|
|
|
|
|
+ GetFeaturesBatch(ctx context.Context, placeIDs []string) (map[string][]models.Feature, error)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type PlaceService struct {
|
|
type PlaceService struct {
|
|
@@ -104,7 +106,38 @@ func (s *PlaceService) GetByID(ctx context.Context, id string, fetchTags bool) (
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (s *PlaceService) List(ctx context.Context, filter models.PlaceFilter) ([]*models.Place, error) {
|
|
func (s *PlaceService) List(ctx context.Context, filter models.PlaceFilter) ([]*models.Place, error) {
|
|
|
- return s.placeRepo.List(ctx, filter)
|
|
|
|
|
|
|
+ places, err := s.placeRepo.List(ctx, filter)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return nil, err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if filter.IncludeTagsFeatures && len(places) > 0 {
|
|
|
|
|
+ placeIDs := make([]string, len(places))
|
|
|
|
|
+ for i, p := range places {
|
|
|
|
|
+ placeIDs[i] = p.ID
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ tagsMap, err := s.placeRepo.GetTagsBatch(ctx, placeIDs)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return nil, err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ featuresMap, err := s.placeRepo.GetFeaturesBatch(ctx, placeIDs)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ return nil, err
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ for _, p := range places {
|
|
|
|
|
+ if tags, ok := tagsMap[p.ID]; ok {
|
|
|
|
|
+ p.Tags = tags
|
|
|
|
|
+ }
|
|
|
|
|
+ if features, ok := featuresMap[p.ID]; ok {
|
|
|
|
|
+ p.Features = features
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return places, nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
type UpdatePlaceInput struct {
|
|
type UpdatePlaceInput struct {
|