lots of stuff, don't truly remember

This commit is contained in:
Blake Ridgway
2026-05-17 20:39:47 -05:00
parent 178ffb3425
commit dc4fe558b7
35 changed files with 3501 additions and 112 deletions

View File

@@ -0,0 +1,49 @@
package goal
import (
"rideaware/pkg/database"
)
type Repository struct{}
func NewRepository() *Repository {
return &Repository{}
}
func (r *Repository) Create(goal *Goal) error {
return database.DB.Create(goal).Error
}
func (r *Repository) GetByID(id, userID uint) (*Goal, error) {
var g Goal
err := database.DB.Where("id = ? AND user_id = ?", id, userID).First(&g).Error
if err != nil {
return nil, err
}
return &g, nil
}
func (r *Repository) List(userID uint) ([]Goal, error) {
var goals []Goal
err := database.DB.Where("user_id = ?", userID).
Order("created_at desc").
Find(&goals).Error
return goals, err
}
func (r *Repository) ListByStatus(userID uint, status GoalStatus) ([]Goal, error) {
var goals []Goal
err := database.DB.Where("user_id = ? AND status = ?", userID, status).
Order("created_at desc").
Find(&goals).Error
return goals, err
}
func (r *Repository) Update(goal *Goal) error {
return database.DB.Save(goal).Error
}
func (r *Repository) Delete(id, userID uint) error {
return database.DB.Where("id = ? AND user_id = ?", id, userID).Delete(&Goal{}).Error
}