88using Microsoft . AspNetCore . Mvc ;
99using TestWebApi . Models ;
1010
11- namespace TestWebApi . Controllers
11+ namespace TestWebApi . Controllers ;
12+
13+ [ ApiController ]
14+ [ Route ( "[controller]" ) ]
15+ public class WeatherForecastController : ControllerBase
1216{
13- [ ApiController ]
14- [ Route ( "[controller]" ) ]
15- public class WeatherForecastController : ControllerBase
17+ private static readonly string [ ] Summaries = new [ ]
1618 {
17- private static readonly string [ ] Summaries = new [ ]
18- {
19- "Freezing" , "Bracing" , "Chilly" , "Cool" , "Mild" , "Warm" , "Balmy" , "Hot" , "Sweltering" , "Scorching"
20- } ;
19+ "Freezing" , "Bracing" , "Chilly" , "Cool" , "Mild" , "Warm" , "Balmy" , "Hot" , "Sweltering" , "Scorching"
20+ } ;
2121
22- [ HttpGet ]
23- public IEnumerable < WeatherForecast > Get ( )
22+ [ HttpGet ]
23+ public IEnumerable < WeatherForecast > Get ( )
24+ {
25+ var rng = new Random ( ) ;
26+ return Enumerable . Range ( 1 , 5 ) . Select ( index => new WeatherForecast
2427 {
25- var rng = new Random ( ) ;
26- return Enumerable . Range ( 1 , 5 ) . Select ( index => new WeatherForecast
27- {
28- Date = DateTime . Now . AddDays ( index ) ,
29- TemperatureC = rng . Next ( - 20 , 55 ) ,
30- Summary = Summaries [ rng . Next ( Summaries . Length ) ]
31- } )
32- . ToArray ( ) ;
33- }
28+ Date = DateTime . Now . AddDays ( index ) ,
29+ TemperatureC = rng . Next ( - 20 , 55 ) ,
30+ Summary = Summaries [ rng . Next ( Summaries . Length ) ]
31+ } )
32+ . ToArray ( ) ;
33+ }
3434
35- /// <summary>
36- /// Get weather forecast by Id.
37- /// </summary>
38- /// <param name="id">some id.</param>
39- /// <param name="cancellationToken">cancellation Token.</param>
40- /// <returns><see cref="WeatherForecast"/> with matching id.</returns>
41- [ HttpGet ( "{id}" ) ]
42- public WeatherForecast Get ( Guid id , CancellationToken cancellationToken )
35+ /// <summary>
36+ /// Get weather forecast by Id.
37+ /// </summary>
38+ /// <param name="id">some id.</param>
39+ /// <param name="cancellationToken">cancellation Token.</param>
40+ /// <returns><see cref="WeatherForecast"/> with matching id.</returns>
41+ [ HttpGet ( "{id}" ) ]
42+ public WeatherForecast Get ( Guid id , CancellationToken cancellationToken )
43+ {
44+ var rng = new Random ( ) ;
45+ return new WeatherForecast
4346 {
44- var rng = new Random ( ) ;
45- return new WeatherForecast
46- {
47- Date = DateTime . Now . AddDays ( 6 ) ,
48- TemperatureC = rng . Next ( - 20 , 55 ) ,
49- Summary = Summaries [ rng . Next ( Summaries . Length ) ]
50- } ;
51- }
47+ Date = DateTime . Now . AddDays ( 6 ) ,
48+ TemperatureC = rng . Next ( - 20 , 55 ) ,
49+ Summary = Summaries [ rng . Next ( Summaries . Length ) ]
50+ } ;
51+ }
5252
53- [ HttpPost ( "create" ) ]
54- public Task < ActionResult < WeatherForecast > > Post ( WeatherForecast weatherForecast )
55- {
56- return null ;
57- }
53+ [ HttpPost ( "create" ) ]
54+ public Task < ActionResult < WeatherForecast > > Post ( WeatherForecast weatherForecast )
55+ {
56+ return null ;
57+ }
5858
59- [ HttpPost ( "upload" ) ]
60- public Task Upload ( IFormFile uploadedFile )
61- {
62- return null ;
63- }
59+ [ HttpPost ( "upload" ) ]
60+ public Task Upload ( IFormFile uploadedFile )
61+ {
62+ return null ;
63+ }
6464
65- [ HttpGet ( "download" ) ]
66- public Task < FileContentResult > Download ( )
67- {
68- var bb = new byte [ 1 ] ;
69- return Task . FromResult ( File ( bb , "application/pdf" , "weather.pdf" ) ) ;
70- }
65+ [ HttpGet ( "download" ) ]
66+ public Task < FileContentResult > Download ( )
67+ {
68+ var bb = new byte [ 1 ] ;
69+ return Task . FromResult ( File ( bb , "application/pdf" , "weather.pdf" ) ) ;
70+ }
7171
72- [ HttpPost ( "search" ) ]
73- public Task < WeatherForecast > Search ( string name = "test" )
74- {
75- return null ;
76- }
72+ [ HttpPost ( "search" ) ]
73+ public Task < WeatherForecast > Search ( string name = "test" )
74+ {
75+ return null ;
76+ }
7777
78- [ HttpPost ( "{id}/queryParams" ) ]
79- public Task < WeatherForecast > SomethingWithQueryParams ( int id , int par1 = 2 , [ Required ] string par2 = null , string par3 = null , string par4 = "1" )
80- {
81- return null ;
82- }
78+ [ HttpPost ( "{id}/queryParams" ) ]
79+ public Task < WeatherForecast > SomethingWithQueryParams ( int id , int par1 = 2 , [ Required ] string par2 = null , string par3 = null , string par4 = "1" )
80+ {
81+ return null ;
82+ }
8383
84- [ HttpPatch ( "headerParams" ) ]
85- public async Task < ActionResult > WithHeaderParams ( [ FromHeader ( Name = "x-header-name" ) ] string headerParam )
86- {
87- await Task . Delay ( 1 ) ;
88- return Ok ( ) ;
89- }
84+ [ HttpPatch ( "headerParams" ) ]
85+ public async Task < ActionResult > WithHeaderParams ( [ FromHeader ( Name = "x-header-name" ) ] string headerParam )
86+ {
87+ await Task . Delay ( 1 ) ;
88+ return Ok ( ) ;
89+ }
9090
91- [ HttpPost ( "form" ) ]
92- public async Task < ActionResult > WithFormParam ( [ FromForm ] SomeQueryModel formParam )
93- {
94- await Task . Delay ( 1 ) ;
95- return Ok ( ) ;
96- }
91+ [ HttpPost ( "form" ) ]
92+ public async Task < ActionResult > WithFormParam ( [ FromForm ] SomeQueryModel formParam )
93+ {
94+ await Task . Delay ( 1 ) ;
95+ return Ok ( ) ;
96+ }
9797
98- [ HttpGet ( "record" ) ]
99- public async Task < ActionResult < RecordModel > > WithRecordModels ( [ FromQuery ] RecordModel record )
100- {
101- await Task . Delay ( 1 ) ;
102- return Ok ( record ) ;
103- }
98+ [ HttpPost ( "form-with-file" ) ]
99+ public async Task < ActionResult > WithFormWithFileParam ( [ FromForm ] FormModelWithFile formParam )
100+ {
101+ await Task . Delay ( 1 ) ;
102+ return Ok ( ) ;
103+ }
104+
105+ [ HttpGet ( "record" ) ]
106+ public async Task < ActionResult < RecordModel > > WithRecordModels ( [ FromQuery ] RecordModel record )
107+ {
108+ await Task . Delay ( 1 ) ;
109+ return Ok ( record ) ;
104110 }
105111}
112+
113+
114+ public record FormModelWithFile ( IFormFile File , string Title ) ;
0 commit comments