Skip to content

Commit

Permalink
#66 Change Restaurant Id
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusMeyer13 committed Mar 3, 2020
1 parent e17496b commit 26feaec
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,15 @@ namespace PlanB.Butler.Services.Models
public class RestaurantModel
{
/// <summary>
/// Gets the identifier.
/// Gets or sets the identifier.
/// </summary>
/// <value>
/// The identifier.
/// </value>
[JsonProperty("id")]
public string Id
{
get
{
var id = $"{this.Name}-{this.City}";
return id;
}
get; set;
}

/// <summary>
Expand Down
24 changes: 20 additions & 4 deletions PlanB.Butler.Services/PlanB.Butler.Services/RestaurantService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

using System.Web;
using AzureFunctions.Extensions.Swashbuckle.Attribute;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -271,12 +271,16 @@ public static async Task<IActionResult> CreateRestaurant(

if (isValid)
{
var filename = $"{restaurantModel.Id}.json";
trace.Add($"filename", filename);
var fileName = CreateFileName(restaurantModel);
trace.Add($"fileName", fileName);
restaurantModel.Id = fileName;

var fullFileName = $"{fileName}.json";
trace.Add($"fullFileName", fullFileName);

req.HttpContext.Response.Headers.Add(Constants.ButlerCorrelationTraceHeader, correlationId.ToString());

CloudBlockBlob blob = cloudBlobContainer.GetBlockBlobReference($"{filename}");
CloudBlockBlob blob = cloudBlobContainer.GetBlockBlobReference($"{fullFileName}");
if (blob != null)
{
blob.Properties.ContentType = "application/json";
Expand Down Expand Up @@ -377,5 +381,17 @@ internal static bool Validate(RestaurantModel model, Guid correlationId, ILogger

return isValid;
}

/// <summary>
/// Creates the name of the file.
/// </summary>
/// <param name="model">The model.</param>
/// <returns></returns>
internal static string CreateFileName(RestaurantModel model)
{
string fileName = $"{model.Name}-{model.City}";
fileName = HttpUtility.UrlEncode(fileName);
return fileName;
}
}
}

0 comments on commit 26feaec

Please sign in to comment.