Initial commit
Go CI / build (push) Failing after 2m42s

feat: create basic server to manage google oauth, account, sessions, places, attributes and ratings.
This commit is contained in:
2025-09-19 02:43:04 -07:00
commit f1909da1ad
26 changed files with 2619 additions and 0 deletions
+66
View File
@@ -0,0 +1,66 @@
package store
import "git.pengzhan.dev/noteplace-server/internal/models"
// CreateRating adds a new rating to the store.
func (s *Store) CreateRating(rating models.Rating) error {
s.Mu.Lock()
defer s.Mu.Unlock()
s.Data.Ratings[rating.ID] = rating
return s.save()
}
// GetRatingByID finds a rating by its ID.
func (s *Store) GetRatingByID(id string) (models.Rating, bool) {
s.Mu.RLock()
defer s.Mu.RUnlock()
r, ok := s.Data.Ratings[id]
return r, ok
}
// UpdateRating finds a rating by ID and updates its score and comment.
func (s *Store) UpdateRating(id string, score int, comment string) (models.Rating, bool) {
s.Mu.Lock()
defer s.Mu.Unlock()
or, ok := s.Data.Ratings[id]
if !ok {
return models.Rating{}, false
}
s.Data.Ratings[id] = models.Rating{
ID: id,
PlaceID: or.PlaceID,
AttributeID: or.AttributeID,
UserID: or.UserID,
Score: score,
Comment: comment,
CreatedAt: or.CreatedAt,
}
if err := s.save(); err != nil {
return models.Rating{}, false
}
return s.Data.Ratings[id], true
}
// DeleteRating removes a rating from the store by its ID.
func (s *Store) DeleteRating(id string) bool {
s.Mu.Lock()
defer s.Mu.Unlock()
delete(s.Data.Ratings, id)
if err := s.save(); err != nil {
return false
}
return true
}
// GetRatingsByUserID finds all ratings for a given user ID.
func (s *Store) GetRatingsByUserID(userID string) []models.Rating {
s.Mu.RLock()
defer s.Mu.RUnlock()
var results []models.Rating
for _, r := range s.Data.Ratings {
if r.UserID == userID {
results = append(results, r)
}
}
return results
}