Temporary repo to track my changes on LTS functions app porting
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
using System; using System.Threading.Tasks; using Azure.Messaging.ServiceBus; using Microsoft.AspNetCore.Mvc; using Microsoft.Azure.Functions.Worker; using Microsoft.Azure.Functions.Worker.Http; using Microsoft.Extensions.Logging; using Newtonsoft.Json;
namespace CDP { public class ContactFunctions { private readonly ILogger<ContactFunctions> _logger;
public ContactFunctions(ILogger<ContactFunctions> logger) { _logger = logger; }
[Function("GetContacts")] public async Task<IActionResult> GetContacts([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req) { _logger.LogInformation("Get Contacts invoked");
// Convert the JSON payload to a string
string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); GetContactsDto dto = JsonConvert.DeserializeObject<GetContactsDto>(requestBody); if (dto == null) return new BadRequestObjectResult(new { error = true, message = "Parse error." });
string userId = Helpers.HashAndShortenText(dto.Email.ToLower()); // userId = "user-" + Helpers.HashToHex(dto.Email.ToLower());
List<ContactRecord> fr = await ContactsDB.GetUserContacts(dto.AppKey, userId); if (fr == null) { return new BadRequestObjectResult(new { error = true, message = "File not found " + dto.Email }); }
return new OkObjectResult(fr); }
[Function("AddContact")] public async Task<IActionResult> AddContacts([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req) { _logger.LogInformation("Add Contacts invoked");
// Convert the JSON payload to a string
string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); AddUserContactsDto addContactdto = JsonConvert.DeserializeObject<AddUserContactsDto>(requestBody); if (addContactdto == null) return new BadRequestObjectResult(new { error = true, message = "Parse error." });
string userId = Helpers.HashAndShortenText(addContactdto.EmailId.ToLower()); ContactRecord cr = new ContactRecord(addContactdto.ContactName, addContactdto.ContactEmail, addContactdto.ContactPhone, addContactdto.ContactAddress, addContactdto.ContactCompany);
Boolean resp = await ContactsDB.AppendRecord(addContactdto.AppKey, userId, cr);
return new OkObjectResult(resp); }
[Function("DeleteContact")] public async Task<IActionResult> DeleteContact([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req) { _logger.LogInformation("Deleting Contact invoked");
// Convert the JSON payload to a string
string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); DeleteUserContactsDto deleteContactdto = JsonConvert.DeserializeObject<DeleteUserContactsDto>(requestBody); if (deleteContactdto == null) return new BadRequestObjectResult(new { error = true, message = "Parse error." });
string userId = Helpers.HashAndShortenText(deleteContactdto.UserEmail.ToLower()); Boolean resp = await ContactsDB.RemoveRecord(deleteContactdto.AppKey, userId, deleteContactdto.ContactEmail.ToLower()); await CDPDB.revokePolicies(deleteContactdto.AppKey, deleteContactdto.UserEmail.ToLower(), deleteContactdto.ContactEmail.ToLower());
return new OkObjectResult(resp); } } }
|