Skip to content

Commit

Permalink
fix(misc): delete many
Browse files Browse the repository at this point in the history
  • Loading branch information
bouassaba committed Sep 19, 2024
1 parent edb7688 commit 5e8e755
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
4 changes: 2 additions & 2 deletions api/docs/index.html

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions api/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,17 @@ definitions:
required:
- ids
type: object
service.FileDeleteManyResult:
properties:
failed:
items:
type: string
type: array
succeeded:
items:
type: string
type: array
type: object
service.FileList:
properties:
data:
Expand Down Expand Up @@ -909,9 +920,7 @@ paths:
"200":
description: OK
schema:
items:
type: string
type: array
$ref: '#/definitions/service.FileDeleteManyResult'
"500":
description: Internal Server Error
schema:
Expand Down
2 changes: 1 addition & 1 deletion api/router/file_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ func (r *FileRouter) DeleteOne(c *fiber.Ctx) error {
// @Id files_delete_many
// @Produce json
// @Param body body service.FileDeleteManyOptions true "Body"
// @Success 200 {array} string
// @Success 200 {object} service.FileDeleteManyResult
// @Failure 500 {object} errorpkg.ErrorResponse
// @Router /files [delete]
func (r *FileRouter) DeleteMany(c *fiber.Ctx) error {
Expand Down
5 changes: 4 additions & 1 deletion api/service/file_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1390,7 +1390,10 @@ type FileDeleteManyResult struct {
}

func (svc *FileService) DeleteMany(opts FileDeleteManyOptions, userID string) (*FileDeleteManyResult, error) {
res := &FileDeleteManyResult{}
res := &FileDeleteManyResult{
Failed: make([]string, 0),
Succeeded: make([]string, 0),
}
for _, id := range opts.IDs {
if err := svc.DeleteOne(id, userID); err != nil {
res.Failed = append(res.Failed, id)
Expand Down
7 changes: 6 additions & 1 deletion ui/src/client/api/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ export type DeleteManyOptions = {
ids: string
}

export type DeleteManyResult = {
succeeded: string[]
failed: string[]
}

export type PatchNameOptions = {
name: string
}
Expand Down Expand Up @@ -325,7 +330,7 @@ export default class FileAPI {
url: `/files`,
method: 'DELETE',
body: JSON.stringify(options),
})
}) as Promise<DeleteManyResult>
}

static async moveOne(id: string, targetId: string) {
Expand Down

0 comments on commit 5e8e755

Please sign in to comment.