-
-
Save NickJosevski/05fb9c634569a8376002e4bf97171575 to your computer and use it in GitHub Desktop.
Used Guid - No lookup Azure Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Net; | |
public class UserInput | |
{ | |
public string Guid {get;set;} | |
public string UsedBy { get;set;} | |
} | |
public class UsedGuidDocument | |
{ | |
public string id { get; set; } // DocumentDB default id convention | |
public string UsedBy { get;set;} | |
} | |
public static bool UserInputIsValid(UserInput userData) | |
{ | |
return !(userData == null || userData.Guid == null || userData.UsedBy == null); | |
} | |
public static HttpResponseMessage Run(HttpRequestMessage req, TraceWriter log, | |
out object doc, out string guidQueue) | |
{ | |
// prep error case initially | |
var responseMsg = "Please pass a Guid and UsedBy in the request body"; | |
var statusCode = HttpStatusCode.BadRequest; | |
var userData = req.Content.ReadAsAsync<UserInput>().Result; | |
if (UserInputIsValid(userData)) | |
{ | |
doc = new UsedGuidDocument { id = userData.Guid, UsedBy = userData.UsedBy }; | |
statusCode = HttpStatusCode.OK; | |
responseMsg = $"Success {userData.Guid} - {userData.UsedBy}"; | |
guidQueue = responseMsg; | |
} | |
else | |
{ | |
doc = null; // because doc is `out` we need to set it to something | |
guidQueue = null; //same | |
} | |
return req.CreateResponse(statusCode, responseMsg); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment