-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbulk_delete_rows.go
More file actions
32 lines (25 loc) · 878 Bytes
/
bulk_delete_rows.go
File metadata and controls
32 lines (25 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package database
import (
"fmt"
"github.com/labbs/nexo/infrastructure/helpers/apperrors"
"github.com/labbs/nexo/application/database/dto"
spaceDto "github.com/labbs/nexo/application/space/dto"
)
func (app *DatabaseApplication) BulkDeleteRows(input dto.BulkDeleteRowsInput) error {
database, err := app.DatabasePers.GetById(input.DatabaseId)
if err != nil {
return fmt.Errorf("database not found: %w", err)
}
// Verify user has access to the space
spaceResult, err := app.SpaceApplication.GetSpaceById(spaceDto.GetSpaceByIdInput{SpaceId: database.SpaceId})
if err != nil {
return fmt.Errorf("space not found: %w", err)
}
if spaceResult.Space.GetUserRole(input.UserId) == nil {
return apperrors.ErrAccessDenied
}
if err := app.DatabaseRowPers.BulkDelete(input.RowIds); err != nil {
return fmt.Errorf("failed to delete rows: %w", err)
}
return nil
}