rabbal / DNTFrameworkCore

Lightweight and Extensible Infrastructure for Building Web Applications - Web Application Framework
Apache License 2.0
318 stars 75 forks source link

crudController Get List #2

Closed pMonfared closed 5 years ago

pMonfared commented 5 years ago

i have a problem with crudController when use getPagedList: at this line i think you should add [FromQuery] to Get method, because when i user swagger Ui to work with API when i call Role [Get] . i got this error :

TypeError: Failed to execute 'fetch' on 'Window': Request with GET/HEAD method cannot have body.

curl request :

curl -X GET "https://localhost:6001/api/Roles" -H "accept: application/json" -H "Authorization: bearer eyJhbGciOiJBMTI4S1ciLCJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwidHlwIjoiSldUIn0.WE_y7hKS8yJSBWI99rIN6udO-QLyniKXqGttEEnB6Q4gAlo7JL7Rew.aW5C5luexUJ-OrxNcDkDzQ.3mG88SI7h2CM0CtEIIFVAX2eOTvablgHY4AHktvwhuWcwKw4Ydl5vr3K2ZY-_IwJVNJ0oxjsdhox9746ysJMKYVPEaRfSj-ikjbHq3sePGk9sP7uYK6QBtvqBUOwT1T0dmz-w1mJuJYgTSMebmLZWZLgg0DsTlpYjqYVTkxAm8LnIji24E3SjHxXqrbGPthgqYIGSI4Hj08JWhePWy5XY755_VFx3NDs94eZr5p4Q-JDlYW-RAiCxJ-QHsuuJkH575tUZTwVrc66TVu1WEMjrEBjfn4mOffbINHA4K7ZfaodGyvdQWhZyCmiOL6KSpQMEj0n5eUUFct7CUyyGDXBcykI5mBI8v9h5x_84o96Q8qiZ4JmE4pyXA2tAUlDbbo28BZl5U3t00YQVFg7rdSJtr57RnTrmFswgpO8hevv60CT50sQsyIK0V_PE1mOmZOYUQbzzvmTsCg0_r92bLfjfhAQDhKjavAUA9d3U6r0F09sk7zI7yDnE3WNVTLjuGbk0GWrUX16kF-MIvZSojxQYzPtMJ4JfqVp56fXWohXqgHT2GjtyMwb5hoFs2k78lu8Eq9ANu3VDAra63Zn7gqOZnUuwR67KU8jhWUCeCn_EnXXeOSZlDjqKjGcbR_tNqWC4odNngehVPm7GyiTt2WwNZKESSRflFP8J2_L1NDFq1DEPHckKpYNo1hI3yMn6Dw6IFrLjrT6teH84ya_Se9wokRiEwk7PPTxfsOWRyr0P-HonOBTzJwJhPFyTXRZ62hRaudonpiTXARVVzPHq_EW15Np99V48BFFN5XrShtZNiLF4dwHLezekxVPV3SADsp2Oxt1EvOVdkgiNI9grKxqWUnwGgpgD9yJos8pXzubZ-C84yjSY96R5h3-7rI2_DTpJPkX64CnQVBh5gZhmWNqAvS_7IWolROdzlAsrZDsTJLMFDuuy1eC6e9gkUZ9pLbvjg5vRI8pQmzhBTv-ztBFf3DCsJeRE_6-2vBLhZiq-G8f8LScdwHRMgx3eTY4-lvSUXAunbO2OoTB6DBx_WOdNkEYDSVvoGbkKoLKRjsGhw7ti-Zu0HVmpUhfxX87uV9E3kG-N_y6gJpxMFdSkmx4EdO1U1P_gnwOGteDYovf2WmR7OGV4PC3sCfbgN0pbVUn.REviOM9Z5qvFJgsyYVOvag" -H "Content-Type: application/json-patch+json" -d "{ \"filter\": { \"field\": \"\", \"operator\": \"\", \"value\": {}, \"logic\": \"\", \"filters\": [ null ] }, \"page\": 0, \"pageSize\": 0, \"sortExpression\": \"\"}"

my solution suggest :

public async Task<IActionResult> Get([FromQuery]TFilteredPagedQueryModel query)
public async Task<IActionResult> Put([BindRequired] TKey id, [FromBody]TModel model)
public async Task<ActionResult<TModel>> Post([FromBody]TModel model)
rabbal commented 5 years ago

There is a default ModelBinder for FilteredPagedQueryModel. Register it with below piece of code:

 services.AddMvcCore(options =>
                {
                    options.UseDefaultFilteredPagedQueryModelBinder();
                })

Then, you can send GET requests like below:

{{endpoint}}/blogs?query={"page":1,"pageSize":100,"filter":{"logic":"and","filters":[{"field":"title","value":"Blog1","operator":"startswith"}]}}

You can find more info in the following post: شروع به کار با DNTFrameworkCore - قسمت 4 - پیاده‌سازی CRUD API موجودیت‌ها

pMonfared commented 5 years ago

I Register it with below piece of code:

 services.AddMvcCore(options =>
                {
                    options.UseDefaultFilteredPagedQueryModelBinder();
                })

but when use swagger Call Get request Roles got this error : image

Please test by swagger!

rabbal commented 5 years ago

This issue related to swagger.