Update Priority as standalone endpoint

This commit is contained in:
Mo Tarbin 2024-11-28 11:30:39 -05:00
parent a0265de264
commit 46a5549e53
2 changed files with 13 additions and 21 deletions

View file

@ -2,6 +2,7 @@ package chore
import (
"context"
"errors"
"fmt"
"time"
@ -22,7 +23,14 @@ func NewChoreRepository(db *gorm.DB, cfg *config.Config) *ChoreRepository {
func (r *ChoreRepository) UpsertChore(c context.Context, chore *chModel.Chore) error {
return r.db.WithContext(c).Model(&chore).Save(chore).Error
}
func (r *ChoreRepository) UpdateChorePriority(c context.Context, userID int, choreID int, priority int) error {
var affectedRows int64
r.db.WithContext(c).Model(&chModel.Chore{}).Where("id = ? and created_by = ?", choreID, userID).Update("priority", priority).Count(&affectedRows)
if affectedRows == 0 {
return errors.New("no rows affected")
}
return nil
}
func (r *ChoreRepository) UpdateChores(c context.Context, chores []*chModel.Chore) error {
return r.db.WithContext(c).Save(&chores).Error
}