Added functionality to create contact queue

This commit is contained in:
kdeng00
2023-10-04 06:59:12 -04:00
parent 2a9abbb760
commit 4accff050c
4 changed files with 145 additions and 7 deletions
+40 -2
View File
@@ -1,5 +1,9 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using TextSender_API.Models;
using TextSender_API.Repositories;
namespace TextSender_API.Controllers;
@@ -30,21 +34,55 @@ public class ContactQueueCreationController : ControllerBase
{
// TODO: Save the file on the filesystem to be processed by a separate
// system
var response = new CreateQueueResponse();
var connString = this._config.GetConnectionString("MongoDBURI");
var userRepo = new UsersRepository(connString!);
var queueRepo = new ContactCreationQueueepository(connString!);
try
{
var ctMgr = new ContactManagement(this._config);
var user = userRepo.Exists(userID);
if (!user.Item1)
{
return NotFound(response);
}
foreach (var file in contactFile)
{
ctMgr.QueueContact(file);
var queue = ctMgr.QueueContact(file);
queue.UserId = user.Item2.Id;
queue.DateCreated = DateTime.Now;
queueRepo.Create(queue);
response.Data.Add(queue);
}
}
catch (Exception ex)
{
this._logger.LogError($"An error occurred: {ex.Message}");
}
return Ok();
return Ok(response);
}
#endregion
#region Responses
public class CreateQueueResponse
{
#region Properties
[JsonProperty("data")]
public List<ContactCreationQueue> Data { get; set; }
#endregion
#region Constructors
public CreateQueueResponse()
{
this.Data = new List<ContactCreationQueue>();
}
#endregion
}
#endregion
}