30 lines
570 B
Go
30 lines
570 B
Go
package storage
|
|
|
|
// ToDo: Should be logging fmt to my loggign wrapper
|
|
import (
|
|
"database/sql"
|
|
"fmt"
|
|
)
|
|
|
|
func MarkNotificationAsRead(db *sql.DB, userID int, notificationID int) error {
|
|
result, err := db.Exec(`
|
|
UPDATE users_notification
|
|
SET is_read = TRUE
|
|
WHERE id = ? AND user_id = ?
|
|
`, notificationID, userID)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
rowsAffected, err := result.RowsAffected()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if rowsAffected == 0 {
|
|
return fmt.Errorf("no matching notification for user_id=%d and id=%d", userID, notificationID)
|
|
}
|
|
|
|
return nil
|
|
}
|