10
10
using SampleWebApiAspNetCore . Models ;
11
11
using SampleWebApiAspNetCore . Helpers ;
12
12
13
- namespace SampleWebApiAspNetCore . Controllers
13
+ namespace SampleWebApiAspNetCore . v1 . Controllers
14
14
{
15
15
[ ApiVersion ( "1.0" ) ]
16
16
[ Route ( "api/v{version:apiVersion}/[controller]" ) ]
@@ -28,7 +28,7 @@ public FoodsController(IUrlHelper urlHelper, IFoodRepository foodRepository)
28
28
}
29
29
30
30
[ HttpGet ( Name = nameof ( GetAllFoods ) ) ]
31
- public IActionResult GetAllFoods ( [ FromQuery ] QueryParameters queryParameters )
31
+ public ActionResult < object > GetAllFoods ( [ FromQuery ] QueryParameters queryParameters )
32
32
{
33
33
List < FoodItem > foodItems = _foodRepository . GetAll ( queryParameters ) . ToList ( ) ;
34
34
@@ -58,7 +58,7 @@ public IActionResult GetAllFoods([FromQuery] QueryParameters queryParameters)
58
58
59
59
[ HttpGet ]
60
60
[ Route ( "{id:int}" , Name = nameof ( GetSingleFood ) ) ]
61
- public IActionResult GetSingleFood ( int id )
61
+ public ActionResult < OkObjectResult > GetSingleFood ( int id )
62
62
{
63
63
FoodItem foodItem = _foodRepository . GetSingle ( id ) ;
64
64
@@ -71,7 +71,7 @@ public IActionResult GetSingleFood(int id)
71
71
}
72
72
73
73
[ HttpPost ( Name = nameof ( AddFood ) ) ]
74
- public IActionResult AddFood ( [ FromBody ] FoodCreateDto foodCreateDto )
74
+ public ActionResult < CreatedAtRouteResult > AddFood ( [ FromBody ] FoodCreateDto foodCreateDto )
75
75
{
76
76
if ( foodCreateDto == null )
77
77
{
@@ -99,7 +99,7 @@ public IActionResult AddFood([FromBody] FoodCreateDto foodCreateDto)
99
99
}
100
100
101
101
[ HttpPatch ( "{id:int}" , Name = nameof ( PartiallyUpdateFood ) ) ]
102
- public IActionResult PartiallyUpdateFood ( int id , [ FromBody ] JsonPatchDocument < FoodUpdateDto > patchDoc )
102
+ public ActionResult < OkObjectResult > PartiallyUpdateFood ( int id , [ FromBody ] JsonPatchDocument < FoodUpdateDto > patchDoc )
103
103
{
104
104
if ( patchDoc == null )
105
105
{
@@ -136,7 +136,7 @@ public IActionResult PartiallyUpdateFood(int id, [FromBody] JsonPatchDocument<Fo
136
136
137
137
[ HttpDelete ]
138
138
[ Route ( "{id:int}" , Name = nameof ( RemoveFood ) ) ]
139
- public IActionResult RemoveFood ( int id )
139
+ public ActionResult < NoContentResult > RemoveFood ( int id )
140
140
{
141
141
FoodItem foodItem = _foodRepository . GetSingle ( id ) ;
142
142
@@ -157,7 +157,7 @@ public IActionResult RemoveFood(int id)
157
157
158
158
[ HttpPut ]
159
159
[ Route ( "{id:int}" , Name = nameof ( UpdateFood ) ) ]
160
- public IActionResult UpdateFood ( int id , [ FromBody ] FoodUpdateDto foodUpdateDto )
160
+ public ActionResult < OkObjectResult > UpdateFood ( int id , [ FromBody ] FoodUpdateDto foodUpdateDto )
161
161
{
162
162
if ( foodUpdateDto == null )
163
163
{
@@ -189,7 +189,7 @@ public IActionResult UpdateFood(int id, [FromBody]FoodUpdateDto foodUpdateDto)
189
189
}
190
190
191
191
[ HttpGet ( "GetRandomMeal" , Name = nameof ( GetRandomMeal ) ) ]
192
- public IActionResult GetRandomMeal ( )
192
+ public ActionResult < object > GetRandomMeal ( )
193
193
{
194
194
ICollection < FoodItem > foodItems = _foodRepository . GetRandomMeal ( ) ;
195
195
@@ -296,15 +296,4 @@ private IEnumerable<LinkDto> GetLinks(int id)
296
296
return links ;
297
297
}
298
298
}
299
-
300
- [ ApiVersion ( "2.0" ) ]
301
- [ Route ( "api/v{version:apiVersion}/foods" ) ]
302
- public class Foods2Controller : ControllerBase
303
- {
304
- [ HttpGet ]
305
- public IActionResult Get ( )
306
- {
307
- return Ok ( "2.0" ) ;
308
- }
309
- }
310
299
}
0 commit comments