Skip to content

Commit

Permalink
Add Txt export for subscribers
Browse files Browse the repository at this point in the history
  • Loading branch information
hros18 committed Apr 26, 2021
1 parent b96818a commit cc379de
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/Blogifier.Core/Providers/BucketProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace Blogifier.Core.Providers
{
public class BucketProvider : IStorageProvider
{
private const string bucketName = "pending-bucket";
private const string bucketName = "qvanuncios-bucket";
private static readonly RegionEndpoint bucketRegion = RegionEndpoint.USWest2;
private static IAmazonS3 s3Client;

Expand Down Expand Up @@ -147,6 +147,7 @@ private async Task<string> UploadFileAsync(string filePath, string keyName)
{
var fileTransferUtility =
new TransferUtility(s3Client);
Console.WriteLine($"------------------ {0} ------------------", filePath);
await fileTransferUtility.UploadAsync(filePath, bucketName, keyName);
return "OK";
}
Expand Down
21 changes: 18 additions & 3 deletions src/Blogifier/Controllers/ExportController.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Net.Http;
using System.Data;
using System;
using Blogifier.Core.Providers;
Expand All @@ -16,6 +17,7 @@
using iTextSharp.text;
using iTextSharp.text.pdf;
using ClosedXML.Excel;
using System.Text;

namespace Blogifier.Controllers
{
Expand All @@ -25,20 +27,25 @@ public class ExportController : ControllerBase
{
private readonly INewsletterProvider _newsletterProvider;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly string fixedPath = "Downloads/";

public ExportController(INewsletterProvider newsletterProvider, IHttpContextAccessor contextAccessor)
{
_newsletterProvider = newsletterProvider;
_httpContextAccessor = contextAccessor;
}

[Authorize]
// [Authorize]
[HttpGet("emails/{fileType}")]
public async Task<IActionResult> ExportToFileType(string fileType)
{
var emails = await _newsletterProvider.GetSubscribers();

// var emails = new List<Subscriber> {
// new Subscriber() {Id = 1, Email = "subs1@gmail.com"},
// new Subscriber() {Id = 2, Email = "subs2@gmail.com"},
// new Subscriber() {Id = 3, Email = "subs3@gmail.com"},
// };

var compare = fileType.ToLower();

switch (compare) {
Expand Down Expand Up @@ -106,7 +113,15 @@ public async Task<IActionResult> ExportToFileType(string fileType)
workBook.SaveAs(stream);
return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Subscribers.xlsx");
}
}
}
case "txt":
using (MemoryStream stream = new MemoryStream())
{
foreach(var e in emails) {
stream.Write(Encoding.ASCII.GetBytes(e.Email));
}
return File(stream.ToArray(), "application/Text", "Subscribers.txt");
}
default:
break;
}
Expand Down

0 comments on commit cc379de

Please sign in to comment.