Files
noteplace-server/internal/store/place.go
T
haopengzhan f1909da1ad
Go CI / build (push) Failing after 2m42s
Initial commit
feat: create basic server to manage google oauth, account, sessions, places, attributes and ratings.
2025-09-19 02:43:04 -07:00

50 lines
1.3 KiB
Go

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
}