-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_row.go
More file actions
41 lines (32 loc) · 1.04 KB
/
delete_row.go
File metadata and controls
41 lines (32 loc) · 1.04 KB
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
33
34
35
36
37
38
39
40
41
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) DeleteRow(input dto.DeleteRowInput) error {
row, err := app.DatabaseRowPers.GetById(input.RowId)
if err != nil {
return fmt.Errorf("row not found: %w", err)
}
if row.DatabaseId != input.DatabaseId {
return apperrors.ErrRowNotFound
}
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.Delete(input.RowId); err != nil {
return fmt.Errorf("failed to delete row: %w", err)
}
return nil
}