Browse Source

fixed fs files order by; added fs files get single by id; moved test static file controller to 'uploadraw'; fs files controller refactor; fixed fs files edit by id

tags/v0.5.1
Robin Thoni 7 years ago
parent
commit
bd9cd532bf

+ 13
- 6
Luticate2.Utils/Controllers/LuFsFilesCrudController.cs View File

@@ -13,18 +13,25 @@ namespace Luticate2.Utils.Controllers
13 13
     public class LuFsFilesCrudController<TBusiness> : LuController
14 14
         where TBusiness : ILuCrudInterface<LuFsFilesAddDbo, LuFsFilesDbo, LuFsFilesAddDbo, string>
15 15
     {
16
-        private readonly TBusiness _business;
16
+        protected readonly TBusiness Business;
17 17
 
18 18
         public LuFsFilesCrudController(IOptions<LuUtilsOptionsDbo> luUtilsOptionsDbo, TBusiness business) : base(luUtilsOptionsDbo)
19 19
         {
20
-            _business = business;
20
+            Business = business;
21
+        }
22
+
23
+        [HttpGet]
24
+        [Route("[controller]/{id}")]
25
+        public virtual LuApiWrapperDbo<LuFsFilesDbo> GetSingleById([Required]string id)
26
+        {
27
+            return Handle(Business.GetSingleById(id));
21 28
         }
22 29
 
23 30
         [HttpPost]
24 31
         [Route("[controller]")]
25 32
         public LuApiWrapperDbo<LuFsFilesDbo> AddDbo([Required]IFormFile file, string path)
26 33
         {
27
-            return Handle(_business.AddDbo(new LuFsFilesAddDbo
34
+            return Handle(Business.AddDbo(new LuFsFilesAddDbo
28 35
             {
29 36
                 File = file.OpenReadStream(),
30 37
                 Path = string.IsNullOrEmpty(path) ? file.FileName : path
@@ -35,14 +42,14 @@ namespace Luticate2.Utils.Controllers
35 42
         [Route("[controller]")]
36 43
         public virtual LuApiWrapperDbo<LuPaginatedDbo<LuFsFilesDbo>> GetMultiple([Required]LuPaginatedRequestDbo request)
37 44
         {
38
-            return Handle(_business.GetMultiple(request));
45
+            return Handle(Business.GetMultiple(request));
39 46
         }
40 47
 
41 48
         [HttpPost]
42 49
         [Route("[controller]/{id}")]
43 50
         public virtual LuApiWrapperDbo<LuFsFilesDbo> EditSingleByIdDbo([Required]string id, IFormFile file, string path)
44 51
         {
45
-            return Handle(_business.EditSingleByIdDbo(id, new LuFsFilesAddDbo
52
+            return Handle(Business.EditSingleByIdDbo(id, new LuFsFilesAddDbo
46 53
             {
47 54
                 File = file?.OpenReadStream(),
48 55
                 Path = path
@@ -53,7 +60,7 @@ namespace Luticate2.Utils.Controllers
53 60
         [Route("[controller]/{id}")]
54 61
         public virtual LuApiWrapperDbo<LuFsFilesDbo> Delete([Required]string id)
55 62
         {
56
-            return Handle(_business.DeleteSingleByIdDbo(id));
63
+            return Handle(Business.DeleteSingleByIdDbo(id));
57 64
         }
58 65
     }
59 66
 }

+ 14
- 1
Luticate2.Utils/DataAccess/LuFsFilesCrudDataAccess.cs View File

@@ -43,6 +43,10 @@ namespace Luticate2.Utils.DataAccess
43 43
                 return x => x.Name.ToLower();
44 44
             }
45 45
             if (fieldName == "createdAt")
46
+            {
47
+                return x => x.CreationTime;
48
+            }
49
+            if (fieldName == "updatedAt")
46 50
             {
47 51
                 return x => x.LastWriteTime;
48 52
             }
@@ -139,8 +143,17 @@ namespace Luticate2.Utils.DataAccess
139 143
                     return get.To<T>();
140 144
                 }
141 145
                 var fullpath = GetFullPath(get.Data.Path);
142
-                if (update.Path != null)
146
+                if (update.Path != null && update.Path != get.Data.Path)
143 147
                 {
148
+                    var existing = GetSingleById(update.Path);
149
+                    if (existing)
150
+                    {
151
+                        return LuResult<T>.Error(LuStatus.InputError, $"File {update.Path}", "File already exist");
152
+                    }
153
+                    if (existing.Status != LuStatus.NotFound)
154
+                    {
155
+                        return existing.To<T>();
156
+                    }
144 157
                     File.Move(fullpath, GetFullPath(update.Path));
145 158
                     fullpath = GetFullPath(update.Path);
146 159
                 }

+ 1
- 1
WebApiUtils/Startup.cs View File

@@ -73,7 +73,7 @@ namespace WebApiUtils
73 73
             {
74 74
                 ServeUnknownFileTypes = true,
75 75
                 FileProvider = new PhysicalFileProvider("/tmp/luticate2"),
76
-                RequestPath = new PathString("/upload")
76
+                RequestPath = new PathString("/uploadraw")
77 77
             });
78 78
 
79 79
             app.UseLuticateUtils();

Loading…
Cancel
Save