Skip to content

Commit

Permalink
breaking: remove serious-cases property from country-statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
alsami committed Oct 21, 2020
1 parent 2220638 commit 84598d7
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 28 deletions.
14 changes: 0 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ stages:
- test
- publish
- deploy
- database

jobs:
include:
Expand Down Expand Up @@ -56,16 +55,3 @@ jobs:
- curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
script:
- ./deploy-app.sh

- stage: database
name: database migrations and updates
if: tag IS present
env:
global:
- DOTNET_ENVIRONMENT="Azure"
before_script:
- sudo snap alias dotnet-sdk.dotnet dotnet
script:
- ./execute-database-updates.sh
- rm -rf publish
- ./execute-database-migrations
3 changes: 1 addition & 2 deletions src/Covid19Api.AutoMapper/CountryStatsProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public CountryStatsProfile()
{
this.CreateMap<CountryStatistics, CountryStatisticsDto>()
.ConvertUsing(src => new CountryStatisticsDto(src.Country, src.CountryCode, src.TotalCases,
src.NewCases, src.TotalDeaths,
src.NewDeaths, src.RecoveredCases, src.ActiveCases, src.SeriousCases, src.FetchedAt));
src.NewCases, src.TotalDeaths, src.NewDeaths, src.RecoveredCases, src.ActiveCases, src.FetchedAt));
}
}
}
8 changes: 2 additions & 6 deletions src/Covid19Api.Domain/CountryStatistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,11 @@ public class CountryStatistics

public int ActiveCases { get; private set; }

public int SeriousCases { get; private set; }

public DateTime FetchedAt { get; private set; }

public CountryStatistics(string country, string? countryCode, int totalCases, int newCases, int totalDeaths,
int newDeaths,
int recoveredCases, int activeCases, int seriousCases, DateTime fetchedAt)
int recoveredCases, int activeCases, DateTime fetchedAt)
{
this.Country = country;
this.CountryCode = countryCode;
Expand All @@ -44,7 +42,6 @@ public CountryStatistics(string country, string? countryCode, int totalCases, in
this.NewDeaths = newDeaths;
this.RecoveredCases = recoveredCases;
this.ActiveCases = activeCases;
this.SeriousCases = seriousCases;
this.FetchedAt = fetchedAt;
this.Id = this.Generate();
}
Expand All @@ -53,8 +50,7 @@ public bool Empty()
{
return this.TotalCases == 0 && this.NewCases == 0 &&
this.TotalDeaths == 0 && this.NewDeaths == 0 &&
this.RecoveredCases == 0 && this.ActiveCases == 0 &&
this.SeriousCases == 0;
this.RecoveredCases == 0 && this.ActiveCases == 0;
}

private Guid Generate()
Expand Down
61 changes: 61 additions & 0 deletions src/Covid19Api.Domain/CountryStatisticsAggregate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Security.Cryptography;
using System.Text;

namespace Covid19Api.Domain
{
// ReSharper disable UnusedAutoPropertyAccessor.Local
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Local
// ReSharper disable UnusedAutoPropertyAccessor.Global
public class CountryStatisticsAggregate
{
public Guid Id { get; private set; }

public string Country { get; private set; }

public string? CountryCode { get; private set; }

public int Total { get; private set; }

public int New { get; private set; }

public int Deaths { get; private set; }

public int NewDeaths { get; private set; }

public int Recovered { get; private set; }

public int Active { get; private set; }
public int Month { get; private set; }
public int Year { get; private set; }


public CountryStatisticsAggregate(string country, string? countryCode, int total, int @new, int deaths,
int newDeaths,
int recovered, int active, int month, int year)
{
this.Country = country;
this.CountryCode = countryCode;
this.Total = total;
this.New = @new;
this.Deaths = deaths;
this.NewDeaths = newDeaths;
this.Recovered = recovered;
this.Active = active;
this.Month = month;
this.Year = year;
this.Id = this.Generate();
}

private Guid Generate()
{
using var hasher = MD5.Create();

var valueToHash = $"{nameof(CountryStatisticsAggregate)}_{this.Country}_{this.Month}_{this.Year}";

var hashed = hasher.ComputeHash(Encoding.UTF8.GetBytes(valueToHash));

return new Guid(hashed);
}
}
}
5 changes: 1 addition & 4 deletions src/Covid19Api.Presentation/Response/CountryStatisticsDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ public class CountryStatisticsDto

public int ActiveCases { get; }

public int SeriousCases { get; }

public DateTime FetchedAt { get; }

public CountryStatisticsDto(string country, string? countryCode, int totalCases, int newCases, int totalDeaths,
int newDeaths,
int recoveredCases, int activeCases, int seriousCases, DateTime fetchedAt)
int recoveredCases, int activeCases, DateTime fetchedAt)
{
this.Country = country;
this.CountryCode = countryCode;
Expand All @@ -36,7 +34,6 @@ public CountryStatisticsDto(string country, string? countryCode, int totalCases,
this.NewDeaths = newDeaths;
this.RecoveredCases = recoveredCases;
this.ActiveCases = activeCases;
this.SeriousCases = seriousCases;
this.FetchedAt = fetchedAt;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Covid19Api.Services/Loader/CountryStatisticsLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ public CountryStatisticsLoader(ICountryMetaDataLoader countryMetaDataLoader,
var newDeaths = ParseIntegerValue(tableDataNodes[5]);
var recovered = ParseIntegerValue(tableDataNodes[6]);
var active = ParseIntegerValue(tableDataNodes[8]);
var serious = ParseIntegerValue(tableDataNodes[9]);
// This would be serious: var serious = ParseIntegerValue(tableDataNodes[9])

if (string.IsNullOrWhiteSpace(country)) return null;

var countryCode = GetCountryCode(countryMetaData, country);

return new CountryStatistics(country, countryCode, totalCases, newCases, totalDeaths, newDeaths, recovered,
active, serious, fetchedAt);
active, fetchedAt);
}

private static string? GetCountryCode(IEnumerable<CountryMetaData> countryMetaData, string country)
Expand Down

0 comments on commit 84598d7

Please sign in to comment.