소스 검색

fixes; TODO

tags/v0.1.0
Robin Thoni 7 년 전
부모
커밋
58ff722b7b

+ 0
- 2
Luticate2.Auth/Controllers/LuAuthExtensions.cs 파일 보기

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

+ 0
- 90
Luticate2.Utils/Business/LuCrudBusiness.cs 파일 보기

1
 using System;
1
 using System;
2
 using System.Collections.Generic;
2
 using System.Collections.Generic;
3
-using Luticate2.Utils.Dbo;
4
 using Luticate2.Utils.Dbo.Basic;
3
 using Luticate2.Utils.Dbo.Basic;
5
 using Luticate2.Utils.Dbo.OrderBy;
4
 using Luticate2.Utils.Dbo.OrderBy;
6
 using Luticate2.Utils.Dbo.Result;
5
 using Luticate2.Utils.Dbo.Result;
46
             return LuResult<TDboUpdate>.Ok(update);
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
         protected LuResult<TDboUpdate> GetAndCheckEdit(string id, TDboUpdate update)
48
         protected LuResult<TDboUpdate> GetAndCheckEdit(string id, TDboUpdate update)
60
         {
49
         {
61
             var res = GetSingleById(id);
50
             var res = GetSingleById(id);
76
             return CheckEdit(res.Data, update);
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
 
153
 
204
         public LuResult<TDboRead> GetSingleById(string id)
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
             return DataAccess.GetSingleById(id);
156
             return DataAccess.GetSingleById(id);
212
         }
157
         }
213
 
158
 
214
         public LuResult<TDboRead> GetSingleById(long id)
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
             return DataAccess.GetSingleById(id);
161
             return DataAccess.GetSingleById(id);
222
         }
162
         }
223
 
163
 
295
 
235
 
296
         public LuResult<T> DeleteSingleById<T>(string id, Func<TDboRead, T> returnFunc)
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
             return DataAccess.DeleteSingleById(id, returnFunc);
238
             return DataAccess.DeleteSingleById(id, returnFunc);
304
         }
239
         }
305
 
240
 
306
         public LuResult<string> DeleteSingleByIdGuid(string id)
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
             return DataAccess.DeleteSingleByIdGuid(id);
243
             return DataAccess.DeleteSingleByIdGuid(id);
314
         }
244
         }
315
 
245
 
316
         public LuResult<TDboRead> DeleteSingleByIdDbo(string id)
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
             return DataAccess.DeleteSingleByIdDbo(id);
248
             return DataAccess.DeleteSingleByIdDbo(id);
324
         }
249
         }
325
 
250
 
326
         public LuResult<T> DeleteSingleById<T>(long id, Func<TDboRead, T> returnFunc)
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
             return DataAccess.DeleteSingleById(id, returnFunc);
253
             return DataAccess.DeleteSingleById(id, returnFunc);
334
         }
254
         }
335
 
255
 
336
         public LuResult<long> DeleteSingleByIdId(long id)
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
             return DataAccess.DeleteSingleByIdId(id);
258
             return DataAccess.DeleteSingleByIdId(id);
344
         }
259
         }
345
 
260
 
346
         public LuResult<TDboRead> DeleteSingleByIdDbo(long id)
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
             return DataAccess.DeleteSingleByIdDbo(id);
263
             return DataAccess.DeleteSingleByIdDbo(id);
354
         }
264
         }
355
     }
265
     }

+ 3
- 3
Luticate2.Utils/Controllers/LuController.cs 파일 보기

19
             {
19
             {
20
                 return new LuApiWrapperDbo<T>
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
             throw new LuResultException(result.To<object>());
27
             throw new LuResultException(result.To<object>());

+ 5
- 3
Luticate2.Utils/Controllers/LuCrudController.cs 파일 보기

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

+ 4
- 1
Luticate2.Utils/Controllers/LuUtilsExtensions.cs 파일 보기

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

+ 34
- 9
Luticate2.Utils/DataAccess/LuEfCrudDataAccess.cs 파일 보기

60
             return model;
60
             return model;
61
         }
61
         }
62
 
62
 
63
-        protected Guid GetGuid(string id)
63
+        protected Guid? GetGuid(string id)
64
         {
64
         {
65
             Guid guid;
65
             Guid guid;
66
             if (Guid.TryParse(id, out guid))
66
             if (Guid.TryParse(id, out guid))
67
             {
67
             {
68
                 return guid;
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
             return Execute(() =>
139
             return Execute(() =>
135
             {
140
             {
136
                 var model = Table.FirstOrDefault(predicate);
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
                 var dbo = GetDboFromModel(model);
146
                 var dbo = GetDboFromModel(model);
142
                 return LuResult<TDboRead>.Ok(dbo);
147
                 return LuResult<TDboRead>.Ok(dbo);
150
 
155
 
151
         public LuResult<TDboRead> GetSingleById(string id)
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
         public LuResult<TDboRead> GetSingleById(long id)
166
         public LuResult<TDboRead> GetSingleById(long id)
295
 
305
 
296
         public LuResult<T> EditSingleById<T>(string id, Action<TModel> update, Func<TDboRead, T> returnFunc)
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
                 list => returnFunc(list.FirstOrDefault()));
314
                 list => returnFunc(list.FirstOrDefault()));
300
         }
315
         }
301
 
316
 
329
 
344
 
330
         public LuResult<T> EditSingleById<T>(string id, TDboUpdate update, Func<TDboRead, T> returnFunc)
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
                 model => EditModelFromTUpdate(update, model), list => returnFunc(list.FirstOrDefault()));
353
                 model => EditModelFromTUpdate(update, model), list => returnFunc(list.FirstOrDefault()));
334
         }
354
         }
335
 
355
 
379
 
399
 
380
         public LuResult<T> DeleteSingleById<T>(string id, Func<TDboRead, T> returnFunc)
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
         public LuResult<string> DeleteSingleByIdGuid(string id)
411
         public LuResult<string> DeleteSingleByIdGuid(string id)

+ 3
- 3
Luticate2.Utils/Dbo/Basic/LuApiWrapperDbo.cs 파일 보기

2
 {
2
 {
3
     public class LuApiWrapperDbo<T>
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 파일 보기

1
 using System;
1
 using System;
2
+using System.Buffers;
2
 using System.Threading.Tasks;
3
 using System.Threading.Tasks;
3
 using Luticate2.Utils.Controllers;
4
 using Luticate2.Utils.Controllers;
4
 using Luticate2.Utils.Dbo.Basic;
5
 using Luticate2.Utils.Dbo.Basic;
5
 using Microsoft.AspNetCore.Http;
6
 using Microsoft.AspNetCore.Http;
7
+using Microsoft.AspNetCore.Mvc.Formatters;
6
 using Microsoft.AspNetCore.Mvc.Infrastructure;
8
 using Microsoft.AspNetCore.Mvc.Infrastructure;
7
 using Newtonsoft.Json;
9
 using Newtonsoft.Json;
8
 
10
 
12
     {
14
     {
13
         private readonly RequestDelegate _next;
15
         private readonly RequestDelegate _next;
14
 
16
 
15
-        public LuExceptionMiddleware(RequestDelegate next,
16
-            IActionDescriptorCollectionProvider actionDescriptorCollectionProvider)
17
+        public LuExceptionMiddleware(RequestDelegate next)
17
         {
18
         {
18
             _next = next;
19
             _next = next;
19
         }
20
         }
31
                 response.StatusCode = e.Result.GetHttpCode();
32
                 response.StatusCode = e.Result.GetHttpCode();
32
                 await response.WriteAsync(JsonConvert.SerializeObject(new LuApiWrapperDbo<object>
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
                 })).ConfigureAwait(false);
38
                 })).ConfigureAwait(false);
38
             }
39
             }
39
             catch (Exception e)//TODO
40
             catch (Exception e)//TODO
43
                 response.StatusCode = 500;
44
                 response.StatusCode = 500;
44
                 await response.WriteAsync(JsonConvert.SerializeObject(new LuApiWrapperDbo<object>
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
                 })).ConfigureAwait(false);
50
                 })).ConfigureAwait(false);
50
             }
51
             }
51
         }
52
         }

+ 1
- 0
TODO 파일 보기

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

Loading…
취소
저장