1111
1212 using Repositories ;
1313
14+ /// <summary>
15+ /// Controller of <see cref="IFoodRepository"/>.
16+ /// </summary>
1417 [ Route ( "api/[controller]" ) ]
1518 public class FoodController : Controller {
1619 private readonly IFoodRepository foodRepository ;
1720
21+ /// <summary>
22+ /// Constructor
23+ /// </summary>
24+ /// <param name="foodRepository">Repository of <see cref="FoodItem"/>.</param>
1825 public FoodController ( IFoodRepository foodRepository ) {
1926 this . foodRepository = foodRepository ;
2027 }
2128
29+ /// <summary>
30+ /// Get all items of food.
31+ /// </summary>
32+ /// <returns>All items of food.</returns>
33+ /// <response code="200">Returns all items of food.</response>
2234 [ HttpGet ]
35+ [ ProducesResponseType ( typeof ( IEnumerable < FoodDto > ) , 200 ) ]
2336 public IActionResult GetAllFoodItems ( ) {
2437 ICollection < FoodItem > foodItems = this . foodRepository . GetAll ( ) ;
2538 IEnumerable < FoodDto > mappedItems = foodItems . Select ( AutoMapper . Mapper . Map < FoodDto > ) ;
2639
2740 return this . Ok ( mappedItems ) ;
2841 }
2942
43+ /// <summary>
44+ /// Get a single food item of given <paramref name="id"/>.
45+ /// </summary>
46+ /// <param name="id">Id of the <see cref="FoodItem"/> to get.</param>
47+ /// <returns><see cref="FoodItem"/> of given <paramref name="id"/>.</returns>
48+ /// <response code="404">If the item cannot be found.</response>
49+ /// <response code="200">Returns the single food item.</response>
3050 [ HttpGet ( "{id:int}" , Name = "GetSingleFoodItem" ) ]
51+ [ ProducesResponseType ( typeof ( FoodDto ) , 404 ) ]
52+ [ ProducesResponseType ( typeof ( FoodDto ) , 200 ) ]
3153 public IActionResult GetSingleFoodItem ( int id ) {
3254 FoodItem foodItem = this . foodRepository . GetSingle ( id ) ;
3355
3456 if ( foodItem == null ) {
3557 return this . NotFound ( ) ;
3658 }
3759
38- return this . Ok ( AutoMapper . Mapper . Map < FoodItem > ( foodItem ) ) ;
60+ return this . Ok ( AutoMapper . Mapper . Map < FoodDto > ( foodItem ) ) ;
3961 }
4062
63+ /// <summary>
64+ /// Add a new food item.
65+ /// </summary>
66+ /// <param name="foodDto">Mapped <see cref="FoodItem"/> to add.</param>
67+ /// <returns>Link to get the food item, which was added and also the added <see cref="FoodDto"/> object.</returns>
68+ /// <response code="400">If the given food item is null or invalid.</response>
69+ /// <response code="201">Returns the created food item.</response>
4170 [ HttpPost ]
71+ [ ProducesResponseType ( typeof ( FoodDto ) , 400 ) ]
72+ [ ProducesResponseType ( typeof ( FoodDto ) , 201 ) ]
4273 public IActionResult AddNewFoodItem ( [ FromBody ] FoodDto foodDto ) {
4374 if ( foodDto == null ) {
4475 return this . BadRequest ( ) ;
@@ -58,7 +89,19 @@ public IActionResult AddNewFoodItem([FromBody] FoodDto foodDto) {
5889 AutoMapper . Mapper . Map < FoodDto > ( foodItem ) ) ;
5990 }
6091
92+ /// <summary>
93+ /// Update the given food item with the food item of the given <paramref name="id"/>.
94+ /// </summary>
95+ /// <param name="id">Id of the <see cref="FoodItem"/> to update.</param>
96+ /// <param name="foodDto">New values of the <see cref="FoodItem"/> to update.</param>
97+ /// <returns>Updated <see cref="FoodDto"/> object.</returns>
98+ /// <response code="404">If the given food item cannot be found.</response>
99+ /// <response code="400">If the given id doesn't match the id of the given food item or the given food item is invalid.</response>
100+ /// <response code="200">Returns the updated food item.</response>
61101 [ HttpPut ( "{id:int}" ) ]
102+ [ ProducesResponseType ( typeof ( FoodDto ) , 404 ) ]
103+ [ ProducesResponseType ( typeof ( FoodDto ) , 400 ) ]
104+ [ ProducesResponseType ( typeof ( FoodDto ) , 200 ) ]
62105 public IActionResult UpdateFoodItem ( int id , [ FromBody ] FoodDto foodDto ) {
63106 var foodItemToCheck = this . foodRepository . GetSingle ( id ) ;
64107 if ( foodItemToCheck == null ) {
@@ -77,7 +120,19 @@ public IActionResult UpdateFoodItem(int id, [FromBody] FoodDto foodDto) {
77120 return this . Ok ( AutoMapper . Mapper . Map < FoodDto > ( foodItem ) ) ;
78121 }
79122
123+ /// <summary>
124+ /// Partial update the given food data with the food item of the given <paramref name="id"/>.
125+ /// </summary>
126+ /// <param name="id">Id of the <see cref="FoodItem"/> to partial update.</param>
127+ /// <param name="foodDtoPatchDoc">New values of the <see cref="FoodItem"/> to partial update.</param>
128+ /// <returns>Updated <see cref="FoodDto"/> object.</returns>
129+ /// <response code="400">If the given food data is null or invalid.</response>
130+ /// <response code="404">If the food item with the given id cannot be found.</response>
131+ /// <response code="200">Returns the partial updated food item.</response>
80132 [ HttpPatch ( "{id:int}" ) ]
133+ [ ProducesResponseType ( typeof ( FoodDto ) , 400 ) ]
134+ [ ProducesResponseType ( typeof ( FoodDto ) , 404 ) ]
135+ [ ProducesResponseType ( typeof ( FoodDto ) , 200 ) ]
81136 public IActionResult PartialUpdate ( int id , [ FromBody ] JsonPatchDocument < FoodDto > foodDtoPatchDoc ) {
82137 if ( foodDtoPatchDoc == null ) {
83138 return this . BadRequest ( ) ;
@@ -99,7 +154,16 @@ public IActionResult PartialUpdate(int id, [FromBody] JsonPatchDocument<FoodDto>
99154 return this . Ok ( AutoMapper . Mapper . Map < FoodDto > ( foodItem ) ) ;
100155 }
101156
157+ /// <summary>
158+ /// Remove the food item with the given <paramref name="id"/>.
159+ /// </summary>
160+ /// <param name="id">Id of the <see cref="FoodItem"/> to remove.</param>
161+ /// <returns>Nothing.</returns>
162+ /// <response code="404">If the food item with the given id cannot be found.</response>
163+ /// <response code="204">If the food item of the given id was successfully deleted.</response>
102164 [ HttpDelete ( "{id:int}" ) ]
165+ [ ProducesResponseType ( typeof ( FoodDto ) , 404 ) ]
166+ [ ProducesResponseType ( typeof ( FoodDto ) , 204 ) ]
103167 public IActionResult Remove ( int id ) {
104168 var foodItem = this . foodRepository . GetSingle ( id ) ;
105169 if ( foodItem == null ) {
0 commit comments