Added functionality to create contact queue
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
using TextSender_API.Models;
|
||||
|
||||
namespace TextSender_API.Controllers;
|
||||
|
||||
public class ContactManagement
|
||||
@@ -18,14 +20,22 @@ public class ContactManagement
|
||||
#region Methods
|
||||
// TODO: Need to implement
|
||||
// Queues the contact file to be processed latter
|
||||
public void QueueContact(IFormFile file)
|
||||
public ContactCreationQueue QueueContact(IFormFile file)
|
||||
{
|
||||
var queue = new ContactCreationQueue();
|
||||
queue.Processed = false;
|
||||
var directory = this._config["Paths:ContactQueueDirectory"];
|
||||
|
||||
if (!System.IO.File.Exists(directory))
|
||||
if (directory!.ElementAt(directory!.Length - 1) != '/')
|
||||
{
|
||||
directory.Append('/');
|
||||
}
|
||||
|
||||
if (!System.IO.Directory.Exists(directory))
|
||||
{
|
||||
queue.Status = "Missing directory";
|
||||
// Directory does not exist
|
||||
return;
|
||||
return queue;
|
||||
}
|
||||
|
||||
var length = 16;
|
||||
@@ -35,18 +45,24 @@ public class ContactManagement
|
||||
s[random.Next(s.Length)]).ToArray());
|
||||
var extension = ".txt";
|
||||
|
||||
var contactPath = $"{filename}{extension}";
|
||||
var contactPath = $"{directory}/{filename}{extension}";
|
||||
queue.Filepath = contactPath;
|
||||
|
||||
if (System.IO.File.Exists(contactPath))
|
||||
{
|
||||
// Already exists
|
||||
return;
|
||||
queue.Status = "File exists";
|
||||
return queue;
|
||||
}
|
||||
|
||||
queue.Status = "Created";
|
||||
|
||||
using (var filestream = new FileStream(contactPath, FileMode.Create))
|
||||
{
|
||||
file.CopyTo(filestream);
|
||||
}
|
||||
|
||||
return queue;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user