Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ParagRaut committed Nov 26, 2020
1 parent 573f3cc commit 8f0dfde
Show file tree
Hide file tree
Showing 28 changed files with 137 additions and 144 deletions.
1 change: 0 additions & 1 deletion src/Client/Pages/CalvinAndHobbesComicsViewer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<div class="container">
<div style="text-align: center;">
<RadzenButton Click="@GetPreviousComic" ButtonStyle="ButtonStyle.Secondary" Icon="chevron_left" Text=" " />
<RadzenButton Click="@GetCalvinAndHobbesComic" Text="Random" />
<RadzenButton Click="@GetNextComic" ButtonStyle="ButtonStyle.Secondary" Icon="chevron_right" Text=" " />
</div>
<br />
Expand Down
1 change: 0 additions & 1 deletion src/Client/Pages/DilbertComicsViewer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<div class="container">
<div style="text-align: center;">
<RadzenButton Click="@GetPreviousComic" ButtonStyle="ButtonStyle.Secondary" Icon="chevron_left" Text=" " />
<RadzenButton Click="@GetDilbertComic" Text="Random" />
<RadzenButton Click="@GetNextComic" ButtonStyle="ButtonStyle.Secondary" Icon="chevron_right" Text=" " />
</div>
<br />
Expand Down
1 change: 0 additions & 1 deletion src/Client/Pages/GarfieldComicsViewer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<div class="container">
<div style="text-align: center;">
<RadzenButton Click="@GetPreviousComic" ButtonStyle="ButtonStyle.Secondary" Icon="chevron_left" Text=" " />
<RadzenButton Click="@GetGarfieldComic" Text="Random" />
<RadzenButton Click="@GetNextComic" ButtonStyle="ButtonStyle.Secondary" Icon="chevron_right" Text=" " />
</div>
<br />
Expand Down
1 change: 0 additions & 1 deletion src/Client/Pages/RandomComicsViewer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<div class="container">
<div style="text-align: center;">
<RadzenButton Click="@GetPreviousComic" ButtonStyle="ButtonStyle.Secondary" Icon="chevron_left" Text=" " />
<RadzenButton Click="@GetRandomComic" Text="Random" />
<RadzenButton Click="@GetNextComic" ButtonStyle="ButtonStyle.Secondary" Icon="chevron_right" Text=" " />
</div>
<br />
Expand Down
1 change: 0 additions & 1 deletion src/Client/Pages/XkcdComicsViewer.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<div class="container">
<div style="text-align: center;">
<RadzenButton Click="@GetPreviousComic" ButtonStyle="ButtonStyle.Secondary" Icon="chevron_left" Text=" " />
<RadzenButton Click="@GetXkcdComic" Text="Random"/>
<RadzenButton Click="@GetNextComic" ButtonStyle="ButtonStyle.Secondary" Icon="chevron_right" Text=" " />
</div>
<br />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Threading.Tasks;

namespace ComicsApp.Server.ComicsService.ComicSources.CalvinAndHobbes
{
public class CalvinAndHobbes : ICalvinAndHobbes
{
public async Task<string> CalvinAndHobbesComicUri()
{
return await Service.GetComicUri();
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ComicsApp.Server.ComicsService.ComicSources.CalvinAndHobbes
{
public interface ICalvinAndHobbesComics
public interface ICalvinAndHobbes
{
Task<string> CalvinAndHobbesComicUri();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@
using System.Threading.Tasks;
using HtmlAgilityPack;

namespace ComicsApp.Server.ComicsService.ComicSources.CalvinAndHobbes.CalvinAndHobbesService
namespace ComicsApp.Server.ComicsService.ComicSources.CalvinAndHobbes
{
public class CalvinAndHobbesServiceApi
public class Service
{
public static async Task<string> CalvinAndHobbesComicUrl()
public static async Task<string> GetComicUri()
{
var baseUrl = new Uri($"https://www.gocomics.com/random/calvinandhobbes");

var httpClient = new HttpClient();

string source = await httpClient.GetStringAsync(baseUrl);

string imageLink = GetUri(source);
string imageLink = GetImageUri(source);

return imageLink;
}

private static string GetUri(string source)
private static string GetImageUri(string source)
{
var document = new HtmlDocument();

Expand Down
12 changes: 12 additions & 0 deletions src/Server/ComicsService/ComicSources/Dilbert/Dilbert.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Threading.Tasks;

namespace ComicsApp.Server.ComicsService.ComicSources.Dilbert
{
public class Dilbert : IDilbert
{
public async Task<string> GetDilbertComicUri()
{
return await Service.GetComicUri();
}
}
}
9 changes: 9 additions & 0 deletions src/Server/ComicsService/ComicSources/Dilbert/IDilbert.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Threading.Tasks;

namespace ComicsApp.Server.ComicsService.ComicSources.Dilbert
{
public interface IDilbert
{
Task<string> GetDilbertComicUri();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
using System.Threading.Tasks;
using HtmlAgilityPack;

namespace ComicsApp.Server.ComicsService.ComicSources.DilbertComics.DilbertService
namespace ComicsApp.Server.ComicsService.ComicSources.Dilbert
{
public class DilbertServiceApi
public class Service
{
public static async Task<string> GetDilbertComicsUrl()
public static async Task<string> GetComicUri()
{
string dateRange = GetRandomDateRange();

Expand All @@ -17,12 +17,12 @@ public static async Task<string> GetDilbertComicsUrl()

string source = await httpClient.GetStringAsync(baseUrl);

string imageLink = GetUri(source);
string imageLink = GetImageUri(source);

return imageLink;
}

private static string GetUri(string source)
private static string GetImageUri(string source)
{
var document = new HtmlDocument();

Expand Down

This file was deleted.

This file was deleted.

12 changes: 12 additions & 0 deletions src/Server/ComicsService/ComicSources/Garfield/Garfield.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Threading.Tasks;

namespace ComicsApp.Server.ComicsService.ComicSources.Garfield
{
public class Garfield : IGarfield
{
public Task<string> GetGarfieldComicUri()
{
return Service.GetComicUri();
}
}
}
9 changes: 9 additions & 0 deletions src/Server/ComicsService/ComicSources/Garfield/IGarfield.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Threading.Tasks;

namespace ComicsApp.Server.ComicsService.ComicSources.Garfield
{
public interface IGarfield
{
Task<string> GetGarfieldComicUri();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
using System.Threading.Tasks;
using HtmlAgilityPack;

namespace ComicsApp.Server.ComicsService.ComicSources.GarfieldComics.GarfieldService
namespace ComicsApp.Server.ComicsService.ComicSources.Garfield
{
public class GarfieldServiceApi
public class Service
{
public static async Task<string> GetGarfieldComicsUrl()
public static async Task<string> GetComicUri()
{
string dateRange = GetRandomDateRange();

Expand All @@ -18,7 +18,7 @@ public static async Task<string> GetGarfieldComicsUrl()

string source = await httpClient.GetStringAsync(baseUrl);

string imageLink = GetUri(source);
string imageLink = GetImageUri(source);

return imageLink;
}
Expand All @@ -31,7 +31,7 @@ private static string GetRandomDateRange()
return startDate.AddDays(random.Next(dateRange)).ToString("yyyy/MM/dd");
}

private static string GetUri(string source)
private static string GetImageUri(string source)
{
var document = new HtmlDocument();

Expand Down

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion src/Server/ComicsService/ComicSources/XKCD/IXKCD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// regenerated.
// </auto-generated>

namespace ComicsApp.Server.ComicsService.ComicSources.XKCD
namespace ComicsApp.Server.ComicsService.ComicSources.Xkcd
{
using Microsoft.Rest;
using Models;
Expand Down
2 changes: 1 addition & 1 deletion src/Server/ComicsService/ComicSources/XKCD/IXkcdComic.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Threading.Tasks;

namespace ComicsApp.Server.ComicsService.ComicSources.XKCD
namespace ComicsApp.Server.ComicsService.ComicSources.Xkcd
{
public interface IXkcdComic
{
Expand Down
2 changes: 1 addition & 1 deletion src/Server/ComicsService/ComicSources/XKCD/Models/Comic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// regenerated.
// </auto-generated>

namespace ComicsApp.Server.ComicsService.ComicSources.XKCD.Models
namespace ComicsApp.Server.ComicsService.ComicSources.Xkcd.Models
{
using Newtonsoft.Json;
using System.Linq;
Expand Down
2 changes: 1 addition & 1 deletion src/Server/ComicsService/ComicSources/XKCD/XKCD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// regenerated.
// </auto-generated>

namespace ComicsApp.Server.ComicsService.ComicSources.XKCD
namespace ComicsApp.Server.ComicsService.ComicSources.Xkcd
{
using Microsoft.Rest;
using Microsoft.Rest.Serialization;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// regenerated.
// </auto-generated>

namespace ComicsApp.Server.ComicsService.ComicSources.XKCD
namespace ComicsApp.Server.ComicsService.ComicSources.Xkcd
{
using Models;
using System.Threading;
Expand Down
16 changes: 8 additions & 8 deletions src/Server/ComicsService/ComicSources/XKCD/XkcdComic.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using ComicsApp.Server.ComicsService.ComicSources.XKCD.Models;
using ComicsApp.Server.ComicsService.ComicSources.Xkcd.Models;

namespace ComicsApp.Server.ComicsService.ComicSources.XKCD
namespace ComicsApp.Server.ComicsService.ComicSources.Xkcd
{
public class XkcdComic : IXkcdComic
{
public XkcdComic(IXKCD xKcdComics)
{
this.XkcdService = xKcdComics;
XkcdService = xKcdComics;
}

private IXKCD XkcdService { get; }

public async Task<string> GetXkcdComicUri()
{
var comicId = await this.GetRandomComicNumber();
var comicId = await GetRandomComicNumber();

string comicImageUri = await this.GetImageUri(comicId);
string comicImageUri = await GetImageUri(comicId);

return comicImageUri;
}

private async Task<int> GetLatestComicId()
{
Comic response = await this.XkcdService.GetLatestComicAsync();
Comic response = await XkcdService.GetLatestComicAsync();

Debug.Assert(response.Num != null, "response.Num != null");

Expand All @@ -34,14 +34,14 @@ private async Task<int> GetLatestComicId()

private async Task<int> GetRandomComicNumber()
{
var maxId = await this.GetLatestComicId();
var maxId = await GetLatestComicId();
var randomNumber = new Random();
return randomNumber.Next(maxId);
}

private async Task<string> GetImageUri(int comicId)
{
Comic comicImage = await this.XkcdService.GetComicByIdAsync(comicId).ConfigureAwait(false);
Comic comicImage = await XkcdService.GetComicByIdAsync(comicId).ConfigureAwait(false);

return comicImage.Img;
}
Expand Down
Loading

0 comments on commit 8f0dfde

Please sign in to comment.