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 8 years ago
parent
commit
bd9cd532bf

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

13
     public class LuFsFilesCrudController<TBusiness> : LuController
13
     public class LuFsFilesCrudController<TBusiness> : LuController
14
         where TBusiness : ILuCrudInterface<LuFsFilesAddDbo, LuFsFilesDbo, LuFsFilesAddDbo, string>
14
         where TBusiness : ILuCrudInterface<LuFsFilesAddDbo, LuFsFilesDbo, LuFsFilesAddDbo, string>
15
     {
15
     {
16
-        private readonly TBusiness _business;
16
+        protected readonly TBusiness Business;
17
 
17
 
18
         public LuFsFilesCrudController(IOptions<LuUtilsOptionsDbo> luUtilsOptionsDbo, TBusiness business) : base(luUtilsOptionsDbo)
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
         [HttpPost]
30
         [HttpPost]
24
         [Route("[controller]")]
31
         [Route("[controller]")]
25
         public LuApiWrapperDbo<LuFsFilesDbo> AddDbo([Required]IFormFile file, string path)
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
                 File = file.OpenReadStream(),
36
                 File = file.OpenReadStream(),
30
                 Path = string.IsNullOrEmpty(path) ? file.FileName : path
37
                 Path = string.IsNullOrEmpty(path) ? file.FileName : path
35
         [Route("[controller]")]
42
         [Route("[controller]")]
36
         public virtual LuApiWrapperDbo<LuPaginatedDbo<LuFsFilesDbo>> GetMultiple([Required]LuPaginatedRequestDbo request)
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
         [HttpPost]
48
         [HttpPost]
42
         [Route("[controller]/{id}")]
49
         [Route("[controller]/{id}")]
43
         public virtual LuApiWrapperDbo<LuFsFilesDbo> EditSingleByIdDbo([Required]string id, IFormFile file, string path)
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
                 File = file?.OpenReadStream(),
54
                 File = file?.OpenReadStream(),
48
                 Path = path
55
                 Path = path
53
         [Route("[controller]/{id}")]
60
         [Route("[controller]/{id}")]
54
         public virtual LuApiWrapperDbo<LuFsFilesDbo> Delete([Required]string id)
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
                 return x => x.Name.ToLower();
43
                 return x => x.Name.ToLower();
44
             }
44
             }
45
             if (fieldName == "createdAt")
45
             if (fieldName == "createdAt")
46
+            {
47
+                return x => x.CreationTime;
48
+            }
49
+            if (fieldName == "updatedAt")
46
             {
50
             {
47
                 return x => x.LastWriteTime;
51
                 return x => x.LastWriteTime;
48
             }
52
             }
139
                     return get.To<T>();
143
                     return get.To<T>();
140
                 }
144
                 }
141
                 var fullpath = GetFullPath(get.Data.Path);
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
                     File.Move(fullpath, GetFullPath(update.Path));
157
                     File.Move(fullpath, GetFullPath(update.Path));
145
                     fullpath = GetFullPath(update.Path);
158
                     fullpath = GetFullPath(update.Path);
146
                 }
159
                 }

+ 1
- 1
WebApiUtils/Startup.cs View File

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

Loading…
Cancel
Save