8
8
using SampleWebApiAspNetCore . Models ;
9
9
using SampleWebApiAspNetCore . Repositories ;
10
10
using System . Text . Json ;
11
+ using System ;
12
+ using static Microsoft . EntityFrameworkCore . DbLoggerCategory ;
11
13
12
14
namespace SampleWebApiAspNetCore . Controllers . v1
13
15
{
@@ -91,14 +93,15 @@ public ActionResult<FoodDto> AddFood(ApiVersion version, [FromBody] FoodCreateDt
91
93
}
92
94
93
95
FoodEntity newFoodItem = _foodRepository . GetSingle ( toAdd . Id ) ;
96
+ FoodDto foodDto = _mapper . Map < FoodDto > ( newFoodItem ) ;
94
97
95
98
return CreatedAtRoute ( nameof ( GetSingleFood ) ,
96
99
new { version = version . ToString ( ) , id = newFoodItem . Id } ,
97
- _mapper . Map < FoodDto > ( newFoodItem ) ) ;
100
+ _linkService . ExpandSingleFoodItem ( foodDto , foodDto . Id , version ) ) ;
98
101
}
99
102
100
103
[ HttpPatch ( "{id:int}" , Name = nameof ( PartiallyUpdateFood ) ) ]
101
- public ActionResult < FoodDto > PartiallyUpdateFood ( int id , [ FromBody ] JsonPatchDocument < FoodUpdateDto > patchDoc )
104
+ public ActionResult < FoodDto > PartiallyUpdateFood ( ApiVersion version , int id , [ FromBody ] JsonPatchDocument < FoodUpdateDto > patchDoc )
102
105
{
103
106
if ( patchDoc == null )
104
107
{
@@ -130,7 +133,9 @@ public ActionResult<FoodDto> PartiallyUpdateFood(int id, [FromBody] JsonPatchDoc
130
133
throw new Exception ( "Updating a fooditem failed on save." ) ;
131
134
}
132
135
133
- return Ok ( _mapper . Map < FoodDto > ( updated ) ) ;
136
+ FoodDto foodDto = _mapper . Map < FoodDto > ( updated ) ;
137
+
138
+ return Ok ( _linkService . ExpandSingleFoodItem ( foodDto , foodDto . Id , version ) ) ;
134
139
}
135
140
136
141
[ HttpDelete ]
@@ -156,7 +161,7 @@ public ActionResult RemoveFood(int id)
156
161
157
162
[ HttpPut ]
158
163
[ Route ( "{id:int}" , Name = nameof ( UpdateFood ) ) ]
159
- public ActionResult < FoodDto > UpdateFood ( int id , [ FromBody ] FoodUpdateDto foodUpdateDto )
164
+ public ActionResult < FoodDto > UpdateFood ( ApiVersion version , int id , [ FromBody ] FoodUpdateDto foodUpdateDto )
160
165
{
161
166
if ( foodUpdateDto == null )
162
167
{
@@ -179,7 +184,9 @@ public ActionResult<FoodDto> UpdateFood(int id, [FromBody] FoodUpdateDto foodUpd
179
184
throw new Exception ( "Updating a fooditem failed on save." ) ;
180
185
}
181
186
182
- return Ok ( _mapper . Map < FoodDto > ( existingFoodItem ) ) ;
187
+ FoodDto foodDto = _mapper . Map < FoodDto > ( existingFoodItem ) ;
188
+
189
+ return Ok ( _linkService . ExpandSingleFoodItem ( foodDto , foodDto . Id , version ) ) ;
183
190
}
184
191
185
192
[ HttpGet ( "GetRandomMeal" , Name = nameof ( GetRandomMeal ) ) ]
0 commit comments