package store import "git.pengzhan.dev/noteplace-server/internal/models" // CreatePlace adds a new place to the store and saves it. func (s *Store) CreatePlace(place models.Place) error { s.Mu.Lock() defer s.Mu.Unlock() s.Data.Places[place.ID] = place return s.save() // Use an unexported save for internal consistency } // GetPlaceByID finds a place by its ID. func (s *Store) GetPlaceByID(id string) (models.Place, bool) { s.Mu.RLock() defer s.Mu.RUnlock() p, ok := s.Data.Places[id] return p, ok } // GetRatingsByPlaceID finds all ratings for a given place ID. func (s *Store) GetRatingsByPlaceID(placeID string) []models.Rating { s.Mu.RLock() defer s.Mu.RUnlock() var results []models.Rating for _, r := range s.Data.Ratings { if r.PlaceID == placeID { results = append(results, r) } } return results } // GetAttributesByPlace finds all relevant attributes for a given place. func (s *Store) GetAttributesByPlace(place models.Place) []models.Attribute { s.Mu.RLock() defer s.Mu.RUnlock() var results []models.Attribute for _, val := range s.Data.Attributes { if val.Scope == models.CATEGORY && place.Category == val.OwnerID { results = append(results, val) } if val.Scope == models.PLACE && place.ID == val.OwnerID { results = append(results, val) } } return results }