Skip to content

Commit

Permalink
#66 Change Meal FileName
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusMeyer13 committed Mar 3, 2020
1 parent 2dcdfbe commit 647ce03
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Net.Mime;
using System.Reflection;
using System.Threading.Tasks;
using System.Web;

using AzureFunctions.Extensions.Swashbuckle.Attribute;
using Microsoft.AspNetCore.Http;
Expand Down Expand Up @@ -82,14 +83,16 @@ public static async Task<IActionResult> CreateMeal(

if (isValid)
{
var date = mealModel.Date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
var fileName = CreateFileName(mealModel);
trace.Add($"fileName", fileName);
mealModel.Id = fileName;

var filename = $"{date}-{mealModel.Restaurant}.json";
trace.Add($"filename", 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 @@ -544,5 +547,18 @@ internal static bool Validate(MealModel mealModel, Guid correlationId, out Error

return isValid;
}

/// <summary>
/// Creates the name of the file.
/// </summary>
/// <param name="model">The model.</param>
/// <returns>FileName without extension.</returns>
internal static string CreateFileName(MealModel model)
{
var date = model.Date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
string fileName = $"{date}-{model.Restaurant}";
fileName = HttpUtility.UrlEncode(fileName);
return fileName;
}
}
}
12 changes: 2 additions & 10 deletions PlanB.Butler.Services/PlanB.Butler.Services/Models/MealModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,13 @@ namespace PlanB.Butler.Services.Models
public class MealModel
{
/// <summary>
/// Gets the identifier.
/// Gets or sets the identifier.
/// </summary>
/// <value>
/// The identifier.
/// </value>
[JsonProperty("id")]
public string Id
{
get
{
var date = this.Date.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
var id = $"{date}-{this.Restaurant}";
return id;
}
}
public string Id { get; set; }

/// <summary>
/// Gets or sets the correlation identifier.
Expand Down

0 comments on commit 647ce03

Please sign in to comment.