Bladeren bron

fixes; TODO

tags/v0.1.0
Robin Thoni 8 jaren geleden
bovenliggende
commit
58ff722b7b

+ 0
- 2
Luticate2.Auth/Controllers/LuAuthExtensions.cs Bestand weergeven

@@ -33,8 +33,6 @@ namespace Luticate2.Auth.Controllers
33 33
             builder.AddLuticatUtils();
34 34
 //            builder.AddApplicationPart(typeof(LuController).GetTypeInfo().Assembly)
35 35
 //                .AddControllersAsServices();
36
-            builder.Services.Configure<MvcOptions>(
37
-                options => options.ModelBinderProviders.Insert(0, new LuOrderByBinderProvider()));
38 36
             return builder;
39 37
         }
40 38
 

+ 0
- 90
Luticate2.Utils/Business/LuCrudBusiness.cs Bestand weergeven

@@ -1,6 +1,5 @@
1 1
 using System;
2 2
 using System.Collections.Generic;
3
-using Luticate2.Utils.Dbo;
4 3
 using Luticate2.Utils.Dbo.Basic;
5 4
 using Luticate2.Utils.Dbo.OrderBy;
6 5
 using Luticate2.Utils.Dbo.Result;
@@ -46,16 +45,6 @@ namespace Luticate2.Utils.Business
46 45
             return LuResult<TDboUpdate>.Ok(update);
47 46
         }
48 47
 
49
-        protected virtual LuResult<TDboRead> CheckGet(TDboRead obj)
50
-        {
51
-            return LuResult<TDboRead>.Ok(obj);
52
-        }
53
-
54
-        protected virtual LuResult<TDboRead> CheckDelete(TDboRead obj)
55
-        {
56
-            return LuResult<TDboRead>.Ok(obj);
57
-        }
58
-
59 48
         protected LuResult<TDboUpdate> GetAndCheckEdit(string id, TDboUpdate update)
60 49
         {
61 50
             var res = GetSingleById(id);
@@ -76,45 +65,6 @@ namespace Luticate2.Utils.Business
76 65
             return CheckEdit(res.Data, update);
77 66
         }
78 67
 
79
-        protected LuResult<TDboRead> GetAndCheckGet(string id)
80
-        {
81
-            var res = GetSingleById(id);
82
-            if (!res)
83
-            {
84
-                return res.To<TDboRead>();
85
-            }
86
-            return CheckGet(res.Data);
87
-        }
88
-
89
-        protected LuResult<TDboRead> GetAndCheckGet(long id)
90
-        {
91
-            var res = GetSingleById(id);
92
-            if (!res)
93
-            {
94
-                return res.To<TDboRead>();
95
-            }
96
-            return CheckGet(res.Data);
97
-        }
98
-
99
-        protected LuResult<TDboRead> GetAndCheckDelete(string id)
100
-        {
101
-            var res = GetSingleById(id);
102
-            if (!res)
103
-            {
104
-                return res.To<TDboRead>();
105
-            }
106
-            return CheckDelete(res.Data);
107
-        }
108
-
109
-        protected LuResult<TDboRead> GetAndCheckDelete(long id)
110
-        {
111
-            var res = GetSingleById(id);
112
-            if (!res)
113
-            {
114
-                return res.To<TDboRead>();
115
-            }
116
-            return CheckDelete(res.Data);
117
-        }
118 68
 
119 69
 
120 70
 
@@ -203,21 +153,11 @@ namespace Luticate2.Utils.Business
203 153
 
204 154
         public LuResult<TDboRead> GetSingleById(string id)
205 155
         {
206
-            var res = GetAndCheckGet(id);
207
-            if (!res)
208
-            {
209
-                return res.To<TDboRead>();
210
-            }
211 156
             return DataAccess.GetSingleById(id);
212 157
         }
213 158
 
214 159
         public LuResult<TDboRead> GetSingleById(long id)
215 160
         {
216
-            var res = GetAndCheckGet(id);
217
-            if (!res)
218
-            {
219
-                return res.To<TDboRead>();
220
-            }
221 161
             return DataAccess.GetSingleById(id);
222 162
         }
223 163
 
@@ -295,61 +235,31 @@ namespace Luticate2.Utils.Business
295 235
 
296 236
         public LuResult<T> DeleteSingleById<T>(string id, Func<TDboRead, T> returnFunc)
297 237
         {
298
-            var res = GetAndCheckDelete(id);
299
-            if (!res)
300
-            {
301
-                return res.To<T>();
302
-            }
303 238
             return DataAccess.DeleteSingleById(id, returnFunc);
304 239
         }
305 240
 
306 241
         public LuResult<string> DeleteSingleByIdGuid(string id)
307 242
         {
308
-            var res = GetAndCheckDelete(id);
309
-            if (!res)
310
-            {
311
-                return res.To<string>();
312
-            }
313 243
             return DataAccess.DeleteSingleByIdGuid(id);
314 244
         }
315 245
 
316 246
         public LuResult<TDboRead> DeleteSingleByIdDbo(string id)
317 247
         {
318
-            var res = GetAndCheckDelete(id);
319
-            if (!res)
320
-            {
321
-                return res.To<TDboRead>();
322
-            }
323 248
             return DataAccess.DeleteSingleByIdDbo(id);
324 249
         }
325 250
 
326 251
         public LuResult<T> DeleteSingleById<T>(long id, Func<TDboRead, T> returnFunc)
327 252
         {
328
-            var res = GetAndCheckDelete(id);
329
-            if (!res)
330
-            {
331
-                return res.To<T>();
332
-            }
333 253
             return DataAccess.DeleteSingleById(id, returnFunc);
334 254
         }
335 255
 
336 256
         public LuResult<long> DeleteSingleByIdId(long id)
337 257
         {
338
-            var res = GetAndCheckDelete(id);
339
-            if (!res)
340
-            {
341
-                return res.To<long>();
342
-            }
343 258
             return DataAccess.DeleteSingleByIdId(id);
344 259
         }
345 260
 
346 261
         public LuResult<TDboRead> DeleteSingleByIdDbo(long id)
347 262
         {
348
-            var res = GetAndCheckDelete(id);
349
-            if (!res)
350
-            {
351
-                return res.To<TDboRead>();
352
-            }
353 263
             return DataAccess.DeleteSingleByIdDbo(id);
354 264
         }
355 265
     }

+ 3
- 3
Luticate2.Utils/Controllers/LuController.cs Bestand weergeven

@@ -19,9 +19,9 @@ namespace Luticate2.Utils.Controllers
19 19
             {
20 20
                 return new LuApiWrapperDbo<T>
21 21
                 {
22
-                    Code = 200,
23
-                    Data = result.Data,
24
-                    Message = null
22
+                    code = 200,
23
+                    data = result.Data,
24
+                    message = null
25 25
                 };
26 26
             }
27 27
             throw new LuResultException(result.To<object>());

+ 5
- 3
Luticate2.Utils/Controllers/LuCrudController.cs Bestand weergeven

@@ -1,4 +1,6 @@
1
-using Luticate2.Utils.Dbo;
1
+using System;
2
+using System.Linq;
3
+using Luticate2.Utils.Dbo;
2 4
 using Luticate2.Utils.Dbo.Basic;
3 5
 using Luticate2.Utils.Dbo.OrderBy;
4 6
 using Luticate2.Utils.Interfaces;
@@ -35,14 +37,14 @@ namespace Luticate2.Utils.Controllers
35 37
 
36 38
         [HttpPost]
37 39
         [Route("[controller]")]
38
-        public LuApiWrapperDbo<TDboRead> Add([FromBody]TDboCreate data)
40
+        public LuApiWrapperDbo<TDboRead> AddDbo([FromBody]TDboCreate data)
39 41
         {
40 42
             return Handle(Busines.AddDbo(data));
41 43
         }
42 44
 
43 45
         [HttpPost]
44 46
         [Route("[controller]/{id}")]
45
-        public LuApiWrapperDbo<TDboRead> Edit(string id, [FromBody]TDboUpdate data)
47
+        public LuApiWrapperDbo<TDboRead> EditSingleByIdDbo(string id, [FromBody]TDboUpdate data)
46 48
         {
47 49
             return Handle(Busines.EditSingleByIdDbo(id, data));
48 50
         }

+ 4
- 1
Luticate2.Utils/Controllers/LuUtilsExtensions.cs Bestand weergeven

@@ -1,9 +1,11 @@
1 1
 using System.Collections.Generic;
2 2
 using Luticate2.Utils.Dbo;
3
+using Luticate2.Utils.Dbo.OrderBy;
3 4
 using Luticate2.Utils.Dbo.Result;
4 5
 using Luticate2.Utils.Middlewares;
5 6
 using Microsoft.AspNetCore.Builder;
6 7
 using Microsoft.AspNetCore.Http;
8
+using Microsoft.AspNetCore.Mvc;
7 9
 using Microsoft.Extensions.DependencyInjection;
8 10
 
9 11
 namespace Luticate2.Utils.Controllers
@@ -18,12 +20,13 @@ namespace Luticate2.Utils.Controllers
18 20
 
19 21
         public static IMvcBuilder AddLuticatUtils(this IMvcBuilder builder)
20 22
         {
23
+            builder.Services.Configure<MvcOptions>(
24
+                options => options.ModelBinderProviders.Insert(0, new LuOrderByBinderProvider()));
21 25
             return builder;
22 26
         }
23 27
 
24 28
         public static IApplicationBuilder UseLuticateUtils(this IApplicationBuilder app)
25 29
         {
26
-//            app.UseMiddleware<LuAuthMiddleware>();
27 30
             app.UseMiddleware<LuExceptionMiddleware>();
28 31
             return app;
29 32
         }

+ 34
- 9
Luticate2.Utils/DataAccess/LuEfCrudDataAccess.cs Bestand weergeven

@@ -60,14 +60,19 @@ namespace Luticate2.Utils.DataAccess
60 60
             return model;
61 61
         }
62 62
 
63
-        protected Guid GetGuid(string id)
63
+        protected Guid? GetGuid(string id)
64 64
         {
65 65
             Guid guid;
66 66
             if (Guid.TryParse(id, out guid))
67 67
             {
68 68
                 return guid;
69 69
             }
70
-            return new Guid();
70
+            return null;
71
+        }
72
+
73
+        protected LuResult<T> GetNotFoundResult<T>()
74
+        {
75
+            return LuResult<T>.Error(LuStatus.NotFound, typeof(TModel).Name + ": Value not found", "");
71 76
         }
72 77
 
73 78
 
@@ -134,9 +139,9 @@ namespace Luticate2.Utils.DataAccess
134 139
             return Execute(() =>
135 140
             {
136 141
                 var model = Table.FirstOrDefault(predicate);
137
-                if (model == null)
142
+                if (model == default(TModel))
138 143
                 {
139
-                    return LuResult<TDboRead>.Error(LuStatus.NotFound, typeof(TModel).Name + ": Value not found", "");
144
+                    return GetNotFoundResult<TDboRead>();
140 145
                 }
141 146
                 var dbo = GetDboFromModel(model);
142 147
                 return LuResult<TDboRead>.Ok(dbo);
@@ -150,7 +155,12 @@ namespace Luticate2.Utils.DataAccess
150 155
 
151 156
         public LuResult<TDboRead> GetSingleById(string id)
152 157
         {
153
-            return GetSingleByKeys(new KeyValuePair<string, object>("id", GetGuid(id)));
158
+            var guid = GetGuid(id);
159
+            if (guid == null)
160
+            {
161
+                return GetNotFoundResult<TDboRead>();
162
+            }
163
+            return GetSingleByKeys(new KeyValuePair<string, object>("id", guid));
154 164
         }
155 165
 
156 166
         public LuResult<TDboRead> GetSingleById(long id)
@@ -295,7 +305,12 @@ namespace Luticate2.Utils.DataAccess
295 305
 
296 306
         public LuResult<T> EditSingleById<T>(string id, Action<TModel> update, Func<TDboRead, T> returnFunc)
297 307
         {
298
-            return Edit(GetExpression(new KeyValuePair<string, object>("id", GetGuid(id))), update,
308
+            var guid = GetGuid(id);
309
+            if (guid == null)
310
+            {
311
+                return GetNotFoundResult<T>();
312
+            }
313
+            return Edit(GetExpression(new KeyValuePair<string, object>("id", guid)), update,
299 314
                 list => returnFunc(list.FirstOrDefault()));
300 315
         }
301 316
 
@@ -329,7 +344,12 @@ namespace Luticate2.Utils.DataAccess
329 344
 
330 345
         public LuResult<T> EditSingleById<T>(string id, TDboUpdate update, Func<TDboRead, T> returnFunc)
331 346
         {
332
-            return Edit(GetExpression(new KeyValuePair<string, object>("id", GetGuid(id))),
347
+            var guid = GetGuid(id);
348
+            if (guid == null)
349
+            {
350
+                return GetNotFoundResult<T>();
351
+            }
352
+            return Edit(GetExpression(new KeyValuePair<string, object>("id", guid)),
333 353
                 model => EditModelFromTUpdate(update, model), list => returnFunc(list.FirstOrDefault()));
334 354
         }
335 355
 
@@ -379,8 +399,13 @@ namespace Luticate2.Utils.DataAccess
379 399
 
380 400
         public LuResult<T> DeleteSingleById<T>(string id, Func<TDboRead, T> returnFunc)
381 401
         {
382
-            return Delete(GetExpression(new KeyValuePair<string, object>("id", GetGuid(id))),
383
-                reads => returnFunc(reads.First()));
402
+            var guid = GetGuid(id);
403
+            if (guid == null)
404
+            {
405
+                return GetNotFoundResult<T>();
406
+            }
407
+            return Delete(GetExpression(new KeyValuePair<string, object>("id", guid)),
408
+                reads => returnFunc(reads.FirstOrDefault()));
384 409
         }
385 410
 
386 411
         public LuResult<string> DeleteSingleByIdGuid(string id)

+ 3
- 3
Luticate2.Utils/Dbo/Basic/LuApiWrapperDbo.cs Bestand weergeven

@@ -2,10 +2,10 @@
2 2
 {
3 3
     public class LuApiWrapperDbo<T>
4 4
     {
5
-        public int Code { get; set; }
5
+        public int code { get; set; }
6 6
 
7
-        public string Message { get; set; }
7
+        public string message { get; set; }
8 8
 
9
-        public T Data { get; set; }
9
+        public T data { get; set; }
10 10
     }
11 11
 }

+ 9
- 8
Luticate2.Utils/Middlewares/LuExceptionMiddleware.cs Bestand weergeven

@@ -1,8 +1,10 @@
1 1
 using System;
2
+using System.Buffers;
2 3
 using System.Threading.Tasks;
3 4
 using Luticate2.Utils.Controllers;
4 5
 using Luticate2.Utils.Dbo.Basic;
5 6
 using Microsoft.AspNetCore.Http;
7
+using Microsoft.AspNetCore.Mvc.Formatters;
6 8
 using Microsoft.AspNetCore.Mvc.Infrastructure;
7 9
 using Newtonsoft.Json;
8 10
 
@@ -12,8 +14,7 @@ namespace Luticate2.Utils.Middlewares
12 14
     {
13 15
         private readonly RequestDelegate _next;
14 16
 
15
-        public LuExceptionMiddleware(RequestDelegate next,
16
-            IActionDescriptorCollectionProvider actionDescriptorCollectionProvider)
17
+        public LuExceptionMiddleware(RequestDelegate next)
17 18
         {
18 19
             _next = next;
19 20
         }
@@ -31,9 +32,9 @@ namespace Luticate2.Utils.Middlewares
31 32
                 response.StatusCode = e.Result.GetHttpCode();
32 33
                 await response.WriteAsync(JsonConvert.SerializeObject(new LuApiWrapperDbo<object>
33 34
                 {
34
-                    Code = e.Result.GetHttpCode(),
35
-                    Data = null,
36
-                    Message = e.Result.PublicDetails
35
+                    code = e.Result.GetHttpCode(),
36
+                    data = null,
37
+                    message = e.Result.PublicDetails
37 38
                 })).ConfigureAwait(false);
38 39
             }
39 40
             catch (Exception e)//TODO
@@ -43,9 +44,9 @@ namespace Luticate2.Utils.Middlewares
43 44
                 response.StatusCode = 500;
44 45
                 await response.WriteAsync(JsonConvert.SerializeObject(new LuApiWrapperDbo<object>
45 46
                 {
46
-                    Code = 500,
47
-                    Data = null,
48
-                    Message = "Internal Error"
47
+                    code = 500,
48
+                    data = null,
49
+                    message = "Internal Error"
49 50
                 })).ConfigureAwait(false);
50 51
             }
51 52
         }

+ 1
- 0
TODO Bestand weergeven

@@ -1,3 +1,4 @@
1
+fix crud business checks
1 2
 websockets
2 3
 authentication filter
3 4
 filter dbo

Laden…
Annuleren
Opslaan