Changeset 0.37.14 (#226)
Co-authored-by: gobha <jasafpro@gmail.com> Co-committed-by: gobha <jasafpro@gmail.com>
This commit is contained in:
@@ -39,14 +39,27 @@ func (s *FolderStore) List(ctx context.Context, userID string) ([]models.Folder,
|
||||
|
||||
func (s *FolderStore) Create(ctx context.Context, f *models.Folder) error {
|
||||
return DB.QueryRowContext(ctx, `
|
||||
INSERT INTO folders (user_id, name, sort_order)
|
||||
VALUES ($1, $2, $3)
|
||||
INSERT INTO folders (user_id, name, parent_id, sort_order)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
RETURNING id, name, parent_id, sort_order, created_at, updated_at
|
||||
`, f.UserID, f.Name, f.SortOrder).Scan(
|
||||
`, f.UserID, f.Name, f.ParentID, f.SortOrder).Scan(
|
||||
&f.ID, &f.Name, &f.ParentID, &f.SortOrder, &f.CreatedAt, &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($3, ''), name),
|
||||
sort_order = COALESCE($4, sort_order),
|
||||
parent_id = $5
|
||||
WHERE id = $1 AND user_id = $2
|
||||
`, folderID, userID, name, sortOrder, *parentID)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return res.RowsAffected()
|
||||
}
|
||||
res, err := DB.ExecContext(ctx, `
|
||||
UPDATE folders
|
||||
SET name = COALESCE(NULLIF($3, ''), name),
|
||||
|
||||
Reference in New Issue
Block a user