Skip to content

Commit

Permalink
Merge pull request #96 from FBoucher/dev
Browse files Browse the repository at this point in the history
Update to version 0.5
  • Loading branch information
FBoucher authored May 29, 2020
2 parents 341d8e0 + c88d5cf commit 0629cc9
Show file tree
Hide file tree
Showing 16 changed files with 223 additions and 44 deletions.
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": []
}
28 changes: 14 additions & 14 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"workbench.colorCustomizations": {
"activityBar.background": "#1f6fd0",
"activityBar.activeBackground": "#1f6fd0",
"activityBar.activeBorder": "#ee90bb",
"activityBar.foreground": "#e7e7e7",
"activityBar.inactiveForeground": "#e7e7e799",
"activityBarBadge.background": "#ee90bb",
"activityBarBadge.foreground": "#15202b",
"titleBar.activeBackground": "#1857a4",
"titleBar.inactiveBackground": "#1857a499",
"activityBar.background": "#3399ff",
"activityBar.activeBackground": "#3399ff",
"activityBar.activeBorder": "#bf0060",
"activityBar.foreground": "#15202b",
"activityBar.inactiveForeground": "#15202b99",
"activityBarBadge.background": "#bf0060",
"activityBarBadge.foreground": "#e7e7e7",
"titleBar.activeBackground": "#007fff",
"titleBar.inactiveBackground": "#007fff99",
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveForeground": "#e7e7e799",
"statusBar.background": "#1857a4",
"statusBarItem.hoverBackground": "#1f6fd0",
"statusBar.background": "#007fff",
"statusBarItem.hoverBackground": "#3399ff",
"statusBar.foreground": "#e7e7e7",
"statusBar.border": "#1857a4",
"titleBar.border": "#1857a4"
"statusBar.border": "#007fff",
"titleBar.border": "#007fff"
},
"peacock.color": "#1857a4"
"peacock.color": "#272727"
}
49 changes: 49 additions & 0 deletions AzUrlShortener.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30122.103
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "shortenerTools", "src\shortenerTools\shortenerTools.csproj", "{F2DDB6A9-0522-44D0-A34D-8DBB63B9BCA7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "adminBlazorWebsite", "src\adminTools\adminBlazorWebsite\src\adminBlazorWebsite.csproj", "{C0F1FBEA-E94D-4D65-9DD4-FA3089547354}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Deployment", "Deployment", "{91EC9638-F1E4-4939-837B-206A6E94B7BD}"
ProjectSection(SolutionItems) = preProject
deployment\azureDeploy.json = deployment\azureDeploy.json
deployment\azureDeploy.params.json = deployment\azureDeploy.params.json
deployment\debug.azcli = deployment\debug.azcli
deployment\debugARM.json = deployment\debugARM.json
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{029E1EDF-80F2-40D5-9C76-4C5371D6AB94}"
ProjectSection(SolutionItems) = preProject
azFunctions-deployment.md = azFunctions-deployment.md
CODE_OF_CONDUCT.md = CODE_OF_CONDUCT.md
CONTRIBUTING.md = CONTRIBUTING.md
how-it-works.md = how-it-works.md
post-deployment-configuration.md = post-deployment-configuration.md
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F2DDB6A9-0522-44D0-A34D-8DBB63B9BCA7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F2DDB6A9-0522-44D0-A34D-8DBB63B9BCA7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F2DDB6A9-0522-44D0-A34D-8DBB63B9BCA7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F2DDB6A9-0522-44D0-A34D-8DBB63B9BCA7}.Release|Any CPU.Build.0 = Release|Any CPU
{C0F1FBEA-E94D-4D65-9DD4-FA3089547354}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C0F1FBEA-E94D-4D65-9DD4-FA3089547354}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C0F1FBEA-E94D-4D65-9DD4-FA3089547354}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C0F1FBEA-E94D-4D65-9DD4-FA3089547354}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {08EEDDBA-DEEE-4573-8A3E-CCB57D35BDCD}
EndGlobalSection
EndGlobal
7 changes: 5 additions & 2 deletions src/adminTools/adminBlazorWebsite/src/Data/ShortUrlEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,21 @@ namespace adminBlazorWebsite.Data
public class ShortUrlEntity
{
public string PartitionKey { get; set; }

public string RowKey { get; set; }

public string Title { get; set; }

public string Url { get; set; }

public string ShortUrl { get; set; }

public int Clicks { get; set; }

public ShortUrlEntity(){}

public static ShortUrlEntity GetEntity(string longUrl, string endUrl){
public static ShortUrlEntity GetEntity(string longUrl, string endUrl)
{
return new ShortUrlEntity
{
PartitionKey = endUrl.First().ToString(),
Expand All @@ -29,7 +32,7 @@ public string GetDisplayableUrl(){

var lenght = Url.ToString().Length;
if (lenght >= 50){
return Url.Substring(1,50);
return string.Concat(Url.Substring(1,50), "...");
}
return Url;
}
Expand Down
22 changes: 22 additions & 0 deletions src/adminTools/adminBlazorWebsite/src/Data/UrlShortenerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,28 @@ public async Task<ShortUrlEntity> UpdateShortUrl(ShortUrlEntity editedUrl)
}
}

public async Task<ShortUrlEntity> ArchiveShortUrl(ShortUrlEntity archivedUrl)
{
var url = GetFunctionUrl("UrlArchive");

CancellationToken cancellationToken;

using (var client = new HttpClient())
using (var request = new HttpRequestMessage(HttpMethod.Delete, url))
using (var httpContent = CreateHttpContent(archivedUrl))
{
request.Content = httpContent;

using (var response = await client
.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken)
.ConfigureAwait(false))
{
var resultList = response.Content.ReadAsStringAsync().Result;
return JsonConvert.DeserializeObject<ShortUrlEntity>(resultList);
}
}
}


private static StringContent CreateHttpContent(object content)
{
Expand Down
18 changes: 13 additions & 5 deletions src/adminTools/adminBlazorWebsite/src/Pages/Urls.razor
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ else
</td>
<td>@url.Clicks</td>
<td><button type="button" class="btn btn-outline-primary btn-sm" @onclick="@(() => EditShortUrl(url))">Edit</button></td>
<td><button type="button" class="btn btn-outline-primary btn-sm" @onclick="@(() => ArchiveShortUrl(url))">Archive</button></td>
</tr>
}
</tbody>
Expand Down Expand Up @@ -109,13 +110,13 @@ else
<div class="modal-body">
<label>Title</label>
<input class="form-control" type="text"
placeholder="Title or description for this URL"
@bind="editedUrl.Title" />
placeholder="Title or description for this URL"
@bind="editedUrl.Title" />
<br />
<label>The Url to redirect</label>
<input class="form-control" type="text"
placeholder="https://..."
@bind="editedUrl.Url" />
placeholder="https://..."
@bind="editedUrl.Url" />
<br />
<button class="btn btn-primary"
@onclick="SaveUpdatedShortUrl">
Expand Down Expand Up @@ -148,7 +149,7 @@ else
await UrlService.CreateShortUrl(shortUrlRequest);
UrlList = await UrlService.GetUrlList();
}

private async Task SaveUpdatedShortUrl()
{
ShowEditPopup = false;
Expand All @@ -175,6 +176,13 @@ else
ShowEditPopup = true;
}

[Authorize(Roles = "admin")]
public async Task ArchiveShortUrl(ShortUrlEntity urlEntity)
{
await UrlService.ArchiveShortUrl(urlEntity);
UrlList = await UrlService.GetUrlList();
}


[Inject] public IJSRuntime JsRuntime { get; set; }
public async Task CopyToClipboardAsync(string url)
Expand Down
10 changes: 5 additions & 5 deletions src/adminTools/adminBlazorWebsite/src/adminBlazorWebsite.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.1.4" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.3" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/adminTools/adminBlazorWebsite/src/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
}
},
"AllowedHosts": "*",
"azFunctionUrl" :"http://....../api/UrlList",
"code":"http://..../api/UrlShortener",
"azFunctionUrl": "http://....../api/UrlList",
"code": "http://....../api/UrlShortener",
"defaultAdminEMail": "[email protected]",
"defaultAdminPW": "_STRONG_PASSWORD_"
}
2 changes: 1 addition & 1 deletion src/shortenerTools/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"type": "func",
"dependsOn": "build",
"options": {
"cwd": "${workspaceFolder}/bin/Debug/netcoreapp2.2"
"cwd": "${workspaceFolder}/bin/Debug/netcoreapp3.1"
},
"command": "host start",
"isBackground": true,
Expand Down
3 changes: 2 additions & 1 deletion src/shortenerTools/Domain/ShortResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ public class ShortResponse
{
public string ShortUrl { get; set; }
public string LongUrl { get; set; }
public string Title { get; set; }
public string Title { get; set; }

public ShortResponse(){}
public ShortResponse (string host, string longUrl, string endUrl, string title)
{
LongUrl = longUrl;
ShortUrl = string.Concat(host, "/", endUrl);
Title = title;

}
}
}
21 changes: 14 additions & 7 deletions src/shortenerTools/Domain/ShortUrlEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,37 @@ public class ShortUrlEntity : TableEntity

public int Clicks { get; set; }

public bool? IsArchived { get; set; }

public ShortUrlEntity(){}

public ShortUrlEntity(string longUrl, string endUrl){
initialize(longUrl, endUrl, string.Empty);
public ShortUrlEntity(string longUrl, string endUrl)
{
Initialize(longUrl, endUrl, string.Empty);
}

public ShortUrlEntity(string longUrl, string endUrl, string title){
initialize(longUrl, endUrl, title);
public ShortUrlEntity(string longUrl, string endUrl, string title)
{
Initialize(longUrl, endUrl, title);
}

private void initialize(string longUrl, string endUrl, string title){
private void Initialize(string longUrl, string endUrl, string title)
{
PartitionKey = endUrl.First().ToString();
RowKey = endUrl;
Url = longUrl;
Title = title;
Clicks = 0;
IsArchived = false;
}

public static ShortUrlEntity GetEntity(string longUrl, string endUrl){
public static ShortUrlEntity GetEntity(string longUrl, string endUrl, string title){
return new ShortUrlEntity
{
PartitionKey = endUrl.First().ToString(),
RowKey = endUrl,
Url = longUrl
Url = longUrl,
Title = title
};
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/shortenerTools/Domain/StorageTableHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,19 @@ public async Task<ShortUrlEntity> UpdateShortUrlEntity(ShortUrlEntity urlEntity)
{
ShortUrlEntity originalUrl = await GetShortUrlEntity(urlEntity);
originalUrl.Url = urlEntity.Url;
originalUrl.Title = urlEntity.Title;
originalUrl.Title = urlEntity.Title;

return await SaveShortUrlEntity(originalUrl);
}

public async Task<ShortUrlEntity> ArchiveShortUrlEntity(ShortUrlEntity urlEntity)
{
ShortUrlEntity originalUrl = await GetShortUrlEntity(urlEntity);
originalUrl.IsArchived = true;

return await SaveShortUrlEntity(originalUrl);
}


public async Task<ShortUrlEntity> SaveShortUrlEntity(ShortUrlEntity newShortUrl)
{
Expand Down
Loading

0 comments on commit 0629cc9

Please sign in to comment.