Added functionality to create contact queue
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user