1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-01 17:38:37 +00:00

Check for category uniqueness before saving

This commit is contained in:
Frédéric Guillot 2017-11-21 14:57:27 -08:00
parent 5983db1a77
commit 238b9e4c85
10 changed files with 47 additions and 12 deletions

View file

@ -8,11 +8,21 @@ import (
"database/sql"
"errors"
"fmt"
"time"
"github.com/miniflux/miniflux2/helper"
"github.com/miniflux/miniflux2/model"
"time"
)
func (s *Storage) AnotherCategoryExists(userID, categoryID int64, title string) bool {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:AnotherCategoryExists] userID=%d, categoryID=%d, title=%s", userID, categoryID, title))
var result int
query := `SELECT count(*) as c FROM categories WHERE user_id=$1 AND id != $2 AND title=$3`
s.db.QueryRow(query, userID, categoryID, title).Scan(&result)
return result >= 1
}
func (s *Storage) CategoryExists(userID, categoryID int64) bool {
defer helper.ExecutionTime(time.Now(), fmt.Sprintf("[Storage:CategoryExists] userID=%d, categoryID=%d", userID, categoryID))