From 833f4a5a0743436c92273014cdf496a3f1c455e6 Mon Sep 17 00:00:00 2001 From: Daniel Goc Date: Thu, 2 Apr 2026 11:26:58 +0200 Subject: [PATCH] deleting and uploading files --- app/delivery/web/api/restricted/storage.go | 9 +++---- app/repos/storageRepo/storageRepo.go | 7 ++--- app/service/storageService/storageService.go | 6 +++-- bruno/b2b-daniel/add-new-cart.yml | 2 +- bruno/b2b-daniel/add-product-to-cart (1).yml | 2 +- bruno/b2b-daniel/add-product-to-cart.yml | 2 +- bruno/b2b-daniel/change-cart-name.yml | 2 +- bruno/b2b-daniel/create-folder.yml | 6 ++--- bruno/b2b-daniel/create-index.yml | 2 +- bruno/b2b-daniel/delete-file.yml | 19 ++++++++++++++ .../{delete-entry.yml => delete-folder.yml} | 10 +++---- bruno/b2b-daniel/download-file.yml | 2 +- bruno/b2b-daniel/get-breadcrumb.yml | 2 +- bruno/b2b-daniel/get-category-tree.yml | 2 +- bruno/b2b-daniel/get-description.yml | 22 ---------------- bruno/b2b-daniel/get-indexes.yml | 2 +- bruno/b2b-daniel/get-product-description.yml | 2 +- bruno/b2b-daniel/get_countries.yml | 2 +- bruno/b2b-daniel/list-content.yml | 2 +- bruno/b2b-daniel/list-products.yml | 2 +- bruno/b2b-daniel/list-users.yml | 2 +- bruno/b2b-daniel/remove-index.yml | 2 +- bruno/b2b-daniel/retrieve-cart.yml | 2 +- bruno/b2b-daniel/retrieve-carts-info.yml | 2 +- bruno/b2b-daniel/save-product-description.yml | 2 +- bruno/b2b-daniel/search.yml | 2 +- bruno/b2b-daniel/test.yml | 2 +- .../translate-product-description.yml | 2 +- bruno/b2b-daniel/update-choice.yml | 2 +- bruno/b2b-daniel/upload-file.yml | 26 +++++++++++++++++++ storage/test.txt | 1 + 31 files changed, 88 insertions(+), 62 deletions(-) create mode 100644 bruno/b2b-daniel/delete-file.yml rename bruno/b2b-daniel/{delete-entry.yml => delete-folder.yml} (52%) delete mode 100644 bruno/b2b-daniel/get-description.yml create mode 100644 bruno/b2b-daniel/upload-file.yml create mode 100644 storage/test.txt diff --git a/app/delivery/web/api/restricted/storage.go b/app/delivery/web/api/restricted/storage.go index 6722a9b..3760547 100644 --- a/app/delivery/web/api/restricted/storage.go +++ b/app/delivery/web/api/restricted/storage.go @@ -30,10 +30,10 @@ func StorageHandlerRoutes(r fiber.Router) fiber.Router { r.Get("/list-content", handler.ListContent) r.Get("/download-file", handler.DownloadFile) - r.Post("/upload-file", handler.CreateFolder) + r.Post("/upload-file", handler.UploadFile) r.Get("/create-folder", handler.CreateFolder) - r.Get("/delete-file", handler.DeleteFile) - r.Get("/delete-folder", handler.DeleteFolder) + r.Delete("/delete-file", handler.DeleteFile) + r.Delete("/delete-folder", handler.DeleteFolder) return r } @@ -88,12 +88,11 @@ func (h *StorageHandler) UploadFile(c fiber.Ctx) error { JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, responseErrors.ErrMissingFileFieldDocument))) } - err = h.storageService.UploadFile(abs_path, c.Query("name"), f) + err = h.storageService.UploadFile(c, abs_path, f) if err != nil { return c.Status(responseErrors.GetErrorStatus(err)). JSON(response.Make(nullable.GetNil(""), 0, responseErrors.GetErrorCode(c, err))) } - err = c.SaveFile(f, abs_path) return c.JSON(response.Make(nullable.GetNil(""), 0, i18n.T_(c, response.Message_OK))) } diff --git a/app/repos/storageRepo/storageRepo.go b/app/repos/storageRepo/storageRepo.go index ac838ff..e6c1461 100644 --- a/app/repos/storageRepo/storageRepo.go +++ b/app/repos/storageRepo/storageRepo.go @@ -5,13 +5,14 @@ import ( "os" "git.ma-al.com/goc_daniel/b2b/app/model" + "github.com/gofiber/fiber/v3" ) type UIStorageRepo interface { EntryInfo(abs_path string) (os.FileInfo, error) ListContent(abs_path string) (*[]model.EntryInList, error) OpenFile(abs_path string) (*os.File, error) - UploadFile(abs_path string, f *multipart.FileHeader) error + UploadFile(c fiber.Ctx, abs_path string, f *multipart.FileHeader) error CreateFolder(abs_path string) error DeleteFile(abs_path string) error DeleteFolder(abs_path string) error @@ -50,8 +51,8 @@ func (r *StorageRepo) OpenFile(abs_path string) (*os.File, error) { return os.Open(abs_path) } -func (r *StorageRepo) UploadFile(abs_path string, f *multipart.FileHeader) error { - return nil +func (r *StorageRepo) UploadFile(c fiber.Ctx, abs_path string, f *multipart.FileHeader) error { + return c.SaveFile(f, abs_path) } func (r *StorageRepo) CreateFolder(abs_path string) error { diff --git a/app/service/storageService/storageService.go b/app/service/storageService/storageService.go index f60f14b..3e01c61 100644 --- a/app/service/storageService/storageService.go +++ b/app/service/storageService/storageService.go @@ -9,6 +9,7 @@ import ( "git.ma-al.com/goc_daniel/b2b/app/model" "git.ma-al.com/goc_daniel/b2b/app/repos/storageRepo" "git.ma-al.com/goc_daniel/b2b/app/utils/responseErrors" + "github.com/gofiber/fiber/v3" ) type StorageService struct { @@ -45,12 +46,13 @@ func (s *StorageService) DownloadFilePrep(abs_path string) (*os.File, string, in return f, filepath.Base(abs_path), info.Size(), nil } -func (s *StorageService) UploadFile(abs_path string, name string, f *multipart.FileHeader) error { +func (s *StorageService) UploadFile(c fiber.Ctx, abs_path string, f *multipart.FileHeader) error { info, err := s.storageRepo.EntryInfo(abs_path) if err != nil || !info.IsDir() { return responseErrors.ErrFolderDoesNotExist } + name := f.Filename if name == "" || name == "." || name == ".." || filepath.Base(name) != name { return responseErrors.ErrBadAttribute } @@ -66,7 +68,7 @@ func (s *StorageService) UploadFile(abs_path string, name string, f *multipart.F if err == nil { return responseErrors.ErrNameTaken } else if os.IsNotExist(err) { - return s.storageRepo.UploadFile(abs_file_path, f) + return s.storageRepo.UploadFile(c, abs_file_path, f) } else { return err } diff --git a/bruno/b2b-daniel/add-new-cart.yml b/bruno/b2b-daniel/add-new-cart.yml index a6beb62..1b6cbde 100644 --- a/bruno/b2b-daniel/add-new-cart.yml +++ b/bruno/b2b-daniel/add-new-cart.yml @@ -1,7 +1,7 @@ info: name: add-new-cart type: http - seq: 11 + seq: 14 http: method: GET diff --git a/bruno/b2b-daniel/add-product-to-cart (1).yml b/bruno/b2b-daniel/add-product-to-cart (1).yml index 7441656..bf5252b 100644 --- a/bruno/b2b-daniel/add-product-to-cart (1).yml +++ b/bruno/b2b-daniel/add-product-to-cart (1).yml @@ -1,7 +1,7 @@ info: name: add-product-to-cart (1) type: http - seq: 16 + seq: 19 http: method: GET diff --git a/bruno/b2b-daniel/add-product-to-cart.yml b/bruno/b2b-daniel/add-product-to-cart.yml index 95e978b..045c7b0 100644 --- a/bruno/b2b-daniel/add-product-to-cart.yml +++ b/bruno/b2b-daniel/add-product-to-cart.yml @@ -1,7 +1,7 @@ info: name: add-product-to-cart type: http - seq: 15 + seq: 18 http: method: GET diff --git a/bruno/b2b-daniel/change-cart-name.yml b/bruno/b2b-daniel/change-cart-name.yml index 5dd32ee..ced76f1 100644 --- a/bruno/b2b-daniel/change-cart-name.yml +++ b/bruno/b2b-daniel/change-cart-name.yml @@ -1,7 +1,7 @@ info: name: change-cart-name type: http - seq: 12 + seq: 15 http: method: GET diff --git a/bruno/b2b-daniel/create-folder.yml b/bruno/b2b-daniel/create-folder.yml index fb04ec1..0f9fabb 100644 --- a/bruno/b2b-daniel/create-folder.yml +++ b/bruno/b2b-daniel/create-folder.yml @@ -1,17 +1,17 @@ info: name: create-folder type: http - seq: 22 + seq: 24 http: method: GET - url: http://localhost:3000/api/v1/restricted/storage/create-folder?path&name=../k + url: http://localhost:3000/api/v1/restricted/storage/create-folder?path=&name=folder params: - name: path value: "" type: query - name: name - value: ../k + value: folder type: query auth: inherit diff --git a/bruno/b2b-daniel/create-index.yml b/bruno/b2b-daniel/create-index.yml index 79eb62e..6f00a56 100644 --- a/bruno/b2b-daniel/create-index.yml +++ b/bruno/b2b-daniel/create-index.yml @@ -1,7 +1,7 @@ info: name: create-index type: http - seq: 7 + seq: 10 http: method: GET diff --git a/bruno/b2b-daniel/delete-file.yml b/bruno/b2b-daniel/delete-file.yml new file mode 100644 index 0000000..32f7104 --- /dev/null +++ b/bruno/b2b-daniel/delete-file.yml @@ -0,0 +1,19 @@ +info: + name: delete-file + type: http + seq: 25 + +http: + method: DELETE + url: http://localhost:3000/api/v1/restricted/storage/delete-file?path=/folder/test.txt + params: + - name: path + value: /folder/test.txt + type: query + auth: inherit + +settings: + encodeUrl: true + timeout: 0 + followRedirects: true + maxRedirects: 5 diff --git a/bruno/b2b-daniel/delete-entry.yml b/bruno/b2b-daniel/delete-folder.yml similarity index 52% rename from bruno/b2b-daniel/delete-entry.yml rename to bruno/b2b-daniel/delete-folder.yml index baf63f2..49dacb7 100644 --- a/bruno/b2b-daniel/delete-entry.yml +++ b/bruno/b2b-daniel/delete-folder.yml @@ -1,14 +1,14 @@ info: - name: delete-entry + name: delete-folder type: http - seq: 23 + seq: 26 http: - method: GET - url: http://localhost:3000/api/v1/restricted/storage/delete-entry?path=folder2 + method: DELETE + url: http://localhost:3000/api/v1/restricted/storage/delete-folder?path=/folder/ params: - name: path - value: folder2 + value: /folder/ type: query auth: inherit diff --git a/bruno/b2b-daniel/download-file.yml b/bruno/b2b-daniel/download-file.yml index 468be8d..d400ef4 100644 --- a/bruno/b2b-daniel/download-file.yml +++ b/bruno/b2b-daniel/download-file.yml @@ -1,7 +1,7 @@ info: name: download-file type: http - seq: 20 + seq: 22 http: method: GET diff --git a/bruno/b2b-daniel/get-breadcrumb.yml b/bruno/b2b-daniel/get-breadcrumb.yml index 8b10c00..9a49428 100644 --- a/bruno/b2b-daniel/get-breadcrumb.yml +++ b/bruno/b2b-daniel/get-breadcrumb.yml @@ -1,7 +1,7 @@ info: name: get-breadcrumb type: http - seq: 18 + seq: 20 http: method: GET diff --git a/bruno/b2b-daniel/get-category-tree.yml b/bruno/b2b-daniel/get-category-tree.yml index c6b436e..b81d6d1 100644 --- a/bruno/b2b-daniel/get-category-tree.yml +++ b/bruno/b2b-daniel/get-category-tree.yml @@ -1,7 +1,7 @@ info: name: get-category-tree type: http - seq: 5 + seq: 8 http: method: GET diff --git a/bruno/b2b-daniel/get-description.yml b/bruno/b2b-daniel/get-description.yml deleted file mode 100644 index bd2137d..0000000 --- a/bruno/b2b-daniel/get-description.yml +++ /dev/null @@ -1,22 +0,0 @@ -info: - name: get-description - type: http - seq: 24 - -http: - method: GET - url: http://localhost:3000/api/v1/restricted/product-translation/get-product-description?productID=51&productLangID=2 - params: - - name: productID - value: "51" - type: query - - name: productLangID - value: "2" - type: query - auth: inherit - -settings: - encodeUrl: true - timeout: 0 - followRedirects: true - maxRedirects: 5 diff --git a/bruno/b2b-daniel/get-indexes.yml b/bruno/b2b-daniel/get-indexes.yml index 850f7bc..ebca4aa 100644 --- a/bruno/b2b-daniel/get-indexes.yml +++ b/bruno/b2b-daniel/get-indexes.yml @@ -1,7 +1,7 @@ info: name: get-indexes type: http - seq: 9 + seq: 12 http: method: GET diff --git a/bruno/b2b-daniel/get-product-description.yml b/bruno/b2b-daniel/get-product-description.yml index 63a7447..4b6086d 100644 --- a/bruno/b2b-daniel/get-product-description.yml +++ b/bruno/b2b-daniel/get-product-description.yml @@ -1,7 +1,7 @@ info: name: get-product-description type: http - seq: 17 + seq: 1 http: method: GET diff --git a/bruno/b2b-daniel/get_countries.yml b/bruno/b2b-daniel/get_countries.yml index e7077fd..07fed01 100644 --- a/bruno/b2b-daniel/get_countries.yml +++ b/bruno/b2b-daniel/get_countries.yml @@ -1,7 +1,7 @@ info: name: get_countries type: http - seq: 4 + seq: 7 http: method: GET diff --git a/bruno/b2b-daniel/list-content.yml b/bruno/b2b-daniel/list-content.yml index 8a9d600..972779f 100644 --- a/bruno/b2b-daniel/list-content.yml +++ b/bruno/b2b-daniel/list-content.yml @@ -1,7 +1,7 @@ info: name: list-content type: http - seq: 19 + seq: 21 http: method: GET diff --git a/bruno/b2b-daniel/list-products.yml b/bruno/b2b-daniel/list-products.yml index adc88a7..8fed3db 100644 --- a/bruno/b2b-daniel/list-products.yml +++ b/bruno/b2b-daniel/list-products.yml @@ -1,7 +1,7 @@ info: name: list-products type: http - seq: 1 + seq: 4 http: method: GET diff --git a/bruno/b2b-daniel/list-users.yml b/bruno/b2b-daniel/list-users.yml index 288afbc..4e435aa 100644 --- a/bruno/b2b-daniel/list-users.yml +++ b/bruno/b2b-daniel/list-users.yml @@ -1,7 +1,7 @@ info: name: list-users type: http - seq: 2 + seq: 5 http: method: GET diff --git a/bruno/b2b-daniel/remove-index.yml b/bruno/b2b-daniel/remove-index.yml index aecc977..6ee9ebb 100644 --- a/bruno/b2b-daniel/remove-index.yml +++ b/bruno/b2b-daniel/remove-index.yml @@ -1,7 +1,7 @@ info: name: remove-index type: http - seq: 8 + seq: 11 http: method: DELETE diff --git a/bruno/b2b-daniel/retrieve-cart.yml b/bruno/b2b-daniel/retrieve-cart.yml index 114116c..8316965 100644 --- a/bruno/b2b-daniel/retrieve-cart.yml +++ b/bruno/b2b-daniel/retrieve-cart.yml @@ -1,7 +1,7 @@ info: name: retrieve-cart type: http - seq: 14 + seq: 17 http: method: GET diff --git a/bruno/b2b-daniel/retrieve-carts-info.yml b/bruno/b2b-daniel/retrieve-carts-info.yml index f15ce51..8d76d52 100644 --- a/bruno/b2b-daniel/retrieve-carts-info.yml +++ b/bruno/b2b-daniel/retrieve-carts-info.yml @@ -1,7 +1,7 @@ info: name: retrieve-carts-info type: http - seq: 13 + seq: 16 http: method: GET diff --git a/bruno/b2b-daniel/save-product-description.yml b/bruno/b2b-daniel/save-product-description.yml index 201f4f8..eb3fb26 100644 --- a/bruno/b2b-daniel/save-product-description.yml +++ b/bruno/b2b-daniel/save-product-description.yml @@ -1,7 +1,7 @@ info: name: save-product-description type: http - seq: 25 + seq: 3 http: method: POST diff --git a/bruno/b2b-daniel/search.yml b/bruno/b2b-daniel/search.yml index 39d3f04..16cb913 100644 --- a/bruno/b2b-daniel/search.yml +++ b/bruno/b2b-daniel/search.yml @@ -1,7 +1,7 @@ info: name: search type: http - seq: 10 + seq: 13 http: method: GET diff --git a/bruno/b2b-daniel/test.yml b/bruno/b2b-daniel/test.yml index e63fe60..0b73d2f 100644 --- a/bruno/b2b-daniel/test.yml +++ b/bruno/b2b-daniel/test.yml @@ -1,7 +1,7 @@ info: name: test type: http - seq: 6 + seq: 9 http: method: GET diff --git a/bruno/b2b-daniel/translate-product-description.yml b/bruno/b2b-daniel/translate-product-description.yml index f08dc01..2e8a7b4 100644 --- a/bruno/b2b-daniel/translate-product-description.yml +++ b/bruno/b2b-daniel/translate-product-description.yml @@ -1,7 +1,7 @@ info: name: translate-product-description type: http - seq: 19 + seq: 2 http: method: GET diff --git a/bruno/b2b-daniel/update-choice.yml b/bruno/b2b-daniel/update-choice.yml index 53a469b..3cd6ece 100644 --- a/bruno/b2b-daniel/update-choice.yml +++ b/bruno/b2b-daniel/update-choice.yml @@ -1,7 +1,7 @@ info: name: update-choice type: http - seq: 3 + seq: 6 http: method: POST diff --git a/bruno/b2b-daniel/upload-file.yml b/bruno/b2b-daniel/upload-file.yml new file mode 100644 index 0000000..41ab47a --- /dev/null +++ b/bruno/b2b-daniel/upload-file.yml @@ -0,0 +1,26 @@ +info: + name: upload-file + type: http + seq: 23 + +http: + method: POST + url: http://localhost:3000/api/v1/restricted/storage/upload-file?path=folder/ + params: + - name: path + value: folder/ + type: query + body: + type: multipart-form + data: + - name: document + type: file + value: + - /home/daniel/coding/work/b2b/storage/folder1/test.txt + auth: inherit + +settings: + encodeUrl: true + timeout: 0 + followRedirects: true + maxRedirects: 5 diff --git a/storage/test.txt b/storage/test.txt new file mode 100644 index 0000000..273c1a9 --- /dev/null +++ b/storage/test.txt @@ -0,0 +1 @@ +This is a test. \ No newline at end of file