Changeset 0.37.14 (#226)
Co-authored-by: gobha <jasafpro@gmail.com> Co-committed-by: gobha <jasafpro@gmail.com>
This commit is contained in:
@@ -41,9 +41,9 @@ func (s *FolderStore) List(ctx context.Context, userID string) ([]models.Folder,
|
||||
func (s *FolderStore) Create(ctx context.Context, f *models.Folder) error {
|
||||
f.ID = store.NewID()
|
||||
_, err := DB.ExecContext(ctx, `
|
||||
INSERT INTO folders (id, user_id, name, sort_order)
|
||||
VALUES (?, ?, ?, ?)
|
||||
`, f.ID, f.UserID, f.Name, f.SortOrder)
|
||||
INSERT INTO folders (id, user_id, name, parent_id, sort_order)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
`, f.ID, f.UserID, f.Name, f.ParentID, f.SortOrder)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -53,7 +53,20 @@ func (s *FolderStore) Create(ctx context.Context, f *models.Folder) error {
|
||||
`, f.ID).Scan(&f.Name, &f.ParentID, &f.SortOrder, st(&f.CreatedAt), st(&f.UpdatedAt))
|
||||
}
|
||||
|
||||
func (s *FolderStore) Update(ctx context.Context, folderID, userID string, name string, sortOrder *int) (int64, error) {
|
||||
func (s *FolderStore) Update(ctx context.Context, folderID, userID string, name string, sortOrder *int, parentID **string) (int64, error) {
|
||||
if parentID != nil {
|
||||
res, err := DB.ExecContext(ctx, `
|
||||
UPDATE folders
|
||||
SET name = COALESCE(NULLIF(?, ''), name),
|
||||
sort_order = COALESCE(?, sort_order),
|
||||
parent_id = ?
|
||||
WHERE id = ? AND user_id = ?
|
||||
`, name, sortOrder, *parentID, folderID, userID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return res.RowsAffected()
|
||||
}
|
||||
res, err := DB.ExecContext(ctx, `
|
||||
UPDATE folders
|
||||
SET name = COALESCE(NULLIF(?, ''), name),
|
||||
|
||||
Reference in New Issue
Block a user