Skip to content

Commit 133288f

Browse files
authored
Version 4.1 (#569)
* update packages * Import data From UI (#554) * Add URL and Click Stats import functionality with CSV support * Checks if URL is archived before redirecting. (#561) Co-authored-by: Frank Boucher * Feature/562 url filter (#565) * Adds vanity URL filtering to the URL manager * Adds title filtering to URL manager * Adds CreatedDate to ShortUrlEntity (#567) --------- Co-authored-by: Frank * Fix SLN file removing extra line. Update build workflow and improve Help page content - Added a step to clean up previous builds in the GitHub Actions workflow. - Revised Help page content to clarify tool functionality and provide links to GitHub issues and discussions. - Simplified Home page welcome message for clarity. ---------
1 parent 080ca0e commit 133288f

29 files changed

Lines changed: 1205 additions & 250 deletions

.github/copilot-instructions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- @azure Rule - Use Azure Best Practices: When generating code for Azure, running terminal commands for Azure, or performing operations related to Azure, invoke your `azure_development-get_best_practices` tool if available.

doc/how-to-migrate-data.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# How to migrate your data
22

3-
The easiest way to migrate your data between account or from an ealier version of AzUrlShortener is to use the **Azure Storage Explorer** to export the data as a CSV files and then import it into the new account or version.
3+
4+
The easiest way to migrate your data between account or from an ealier version of AzUrlShortener is to use the **Azure Storage Explorer** to export the data as a CSV files and use the TinyBlazorAdmin to import the files .
5+
46

57
Azure Storage Explorer is a free tool to manage your Azure cloud storage resources (aka your short URLs) from your desktop. It’s a cross-platform and can be downloaded [here](https://azure.microsoft.com/en-us/products/storage/storage-explorer/).
68

@@ -9,3 +11,6 @@ In the resources deployed to Azure there will be 2 storage accounts. One for the
911
You need to expot to CSV the following tables:
1012
- UrlsDetails: This table contains the details of the short URLs, including the original URL, the short URL, schedules, etc.
1113
- ClickStats: This table contains the clicks informations.
14+
15+
16+
To import the data use the Import button in the Settings page.

src/Api/ShortenerEnpoints.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ public static void MapShortenerEnpoints(this IEndpointRouteBuilder app)
4141
.WithDescription("Provide Click Statistics by Day")
4242
.WithDisplayName("Url Click Statistics By Day");
4343

44+
endpoints.MapPost("/UrlDataImport", UrlDataImport)
45+
.WithDescription("Import Urls from a CSV file")
46+
.WithDisplayName("Url Data Import");
47+
48+
endpoints.MapPost("/UrlClickStatsImport", UrlClickStatsImport)
49+
.WithDescription("Import Click Statistics from a CSV file")
50+
.WithDisplayName("Url Click Statistics Import");
51+
4452
}
4553

4654
static private string GetWelcomeMessage()
@@ -182,5 +190,46 @@ private static string GetHost(HttpContext context)
182190
return host ?? string.Empty;
183191
}
184192

193+
194+
static private async Task<Results<
195+
Ok,
196+
InternalServerError<DetailedBadRequest>>>
197+
UrlDataImport(UrlDetails data,
198+
TableServiceClient tblClient,
199+
ILogger logger)
200+
{
201+
try
202+
{
203+
var urlServices = new UrlServices(logger, new AzStrorageTablesService(tblClient));
204+
await urlServices.ImportUrlDataAsync(data);
205+
return TypedResults.Ok();
206+
}
207+
catch (Exception ex)
208+
{
209+
logger.LogError(ex.Message);
210+
return TypedResults.InternalServerError<DetailedBadRequest>(new DetailedBadRequest { Message = ex.Message });
211+
}
212+
}
213+
214+
static private async Task<Results<
215+
Ok,
216+
InternalServerError<DetailedBadRequest>>>
217+
UrlClickStatsImport(List<ClickStatsEntity> lstClickStats,
218+
TableServiceClient tblClient,
219+
ILogger logger)
220+
{
221+
try
222+
{
223+
var urlServices = new UrlServices(logger, new AzStrorageTablesService(tblClient));
224+
await urlServices.ImportClickStatsAsync(lstClickStats);
225+
return TypedResults.Ok();
226+
}
227+
catch (Exception ex)
228+
{
229+
logger.LogError(ex.Message);
230+
return TypedResults.InternalServerError<DetailedBadRequest>(new DetailedBadRequest { Message = ex.Message });
231+
}
232+
}
233+
185234
}
186235

src/AppHost/appsettings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,10 @@
55
"Microsoft.AspNetCore": "Warning",
66
"Aspire.Hosting.Dcp": "Warning"
77
}
8+
},
9+
"Parameters":{
10+
"CustomDomain": "https://c5m.ca",
11+
"DefaultRedirectUrl": "https://azure.com"
12+
813
}
914
}

src/AzUrlShortener.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio Version 17
44
VisualStudioVersion = 17.0.31903.59

src/Core/Cloud5mins.ShortenerTools.Core.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@
88
<PackageReference Include="Aspire.Azure.Data.Tables" Version="9.1.0" />
99
<PackageReference Include="cronos" Version="0.9.0" />
1010
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.3" />
11+
12+
<PackageReference Include="CsvHelper" Version="33.0.1" />
13+
1114
</ItemGroup>
1215
</Project>

src/Core/Domain/ImportUrlData.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace Cloud5mins.ShortenerTools.Core.Domain
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
public class UrlDetails
10+
{
11+
public required NextId NextId { get; set; }
12+
public required List<ShortUrlEntity> LstShortUrlEntity { get; set; }
13+
}
14+
}

src/Core/Domain/ShortUrlEntity.cs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
using Azure.Data.Tables;
33
using System.Runtime.Serialization;
44
using System.Text.Json;
5+
using Azure;
6+
using Azure.Data.Tables;
7+
58

69
namespace Cloud5mins.ShortenerTools.Core.Domain
710
{
@@ -62,6 +65,9 @@ public List<Schedule> Schedules
6265
public DateTimeOffset? Timestamp { get; set; }
6366
public ETag ETag { get; set; }
6467

68+
public string CreatedDate { get; set; }
69+
70+
6571

6672
public ShortUrlEntity() { }
6773

@@ -88,6 +94,7 @@ private void Initialize(string longUrl, string endUrl, string title, Schedule[]
8894
Title = title;
8995
Clicks = 0;
9096
IsArchived = false;
97+
CreatedDate = DateTime.UtcNow.ToString("yyyy-MM-dd");
9198

9299
if (schedules?.Length > 0)
93100
{
@@ -96,17 +103,19 @@ private void Initialize(string longUrl, string endUrl, string title, Schedule[]
96103
}
97104
}
98105

99-
public static ShortUrlEntity GetEntity(string longUrl, string endUrl, string title, Schedule[] schedules)
100-
{
101-
return new ShortUrlEntity
102-
{
103-
PartitionKey = endUrl.First().ToString(),
104-
RowKey = endUrl,
105-
Url = longUrl,
106-
Title = title,
107-
Schedules = schedules.ToList<Schedule>()
108-
};
109-
}
106+
107+
// public static ShortUrlEntity GetEntity(string longUrl, string endUrl, string title, Schedule[] schedules)
108+
// {
109+
// return new ShortUrlEntity
110+
// {
111+
// PartitionKey = endUrl.First().ToString(),
112+
// RowKey = endUrl,
113+
// Url = longUrl,
114+
// Title = title,
115+
// Schedules = schedules.ToList<Schedule>()
116+
// };
117+
// }
118+
110119

111120
private string GetActiveUrl()
112121
{

src/Core/Messages/ShortUrlRequest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using Cloud5mins.ShortenerTools.Core.Domain;
2+
using System.ComponentModel;
3+
24
using System.ComponentModel.DataAnnotations;
35

46
namespace Cloud5mins.ShortenerTools.Core.Messages

src/Core/Messages/UrlClickStatsRequest.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ namespace Cloud5mins.ShortenerTools.Core.Messages
33
public class UrlClickStatsRequest
44
{
55
public string Vanity { get; set; }
6+
public string StartDate { get; set; }
7+
public string EndDate { get; set; }
68

7-
public UrlClickStatsRequest(string vanity)
9+
public UrlClickStatsRequest(string vanity, string startDate, string endDate)
810
{
911
Vanity = vanity;
12+
StartDate = startDate;
13+
EndDate = endDate;
1014
}
1115
}
1216
}

0 commit comments

Comments
 (0)