Skip to content

Commit

Permalink
feat: allow fetching of country-flags
Browse files Browse the repository at this point in the history
  • Loading branch information
alsami committed Jan 9, 2021
1 parent f1de210 commit dff871b
Show file tree
Hide file tree
Showing 261 changed files with 7,471 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Covid19Api.Endpoints.Rest/V1/CountryStatisticsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Covid19Api.Presentation.Response;
using Covid19Api.UseCases.Abstractions.Queries.Countries;
using Covid19Api.UseCases.Abstractions.Queries.CountryStatistics;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Microsoft.Net.Http.Headers;

namespace Covid19Api.Endpoints.Rest.V1
{
Expand Down Expand Up @@ -34,5 +37,18 @@ public Task<CountryStatisticDto> LoadLatestForCountryAsync(string country) =>
[HttpGet("{country}/history")]
public Task<IEnumerable<CountryStatisticDto>> LoadHistoryForCountryAsync(string country) =>
this.mediator.Send(new LoadHistoricalCountryStatisticsForCountryQuery(country));

[HttpGet("{countryCode}/flag")]
public async Task<IActionResult> LoadFlagAsync(string countryCode)
{
var (image, mimeType) = await this.mediator.Send(new LoadCountryFlagQuery(countryCode));

return new FileContentResult(image, mimeType)
{
EnableRangeProcessing = true,
FileDownloadName = $"{countryCode.ToLowerInvariant()}_flag",
LastModified = DateTimeOffset.MinValue,
};
}
}
}
6 changes: 6 additions & 0 deletions src/Covid19Api.Presentation/Response/ImageDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using System.Collections;

namespace Covid19Api.Presentation.Response
{
public record ImageDto(byte[] Image, string MimeType);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using Covid19Api.Presentation.Response;
using Covid19Api.UseCases.Abstractions.Base;
using Covid19Api.UseCases.Abstractions.Models;
using MediatR;

namespace Covid19Api.UseCases.Abstractions.Queries.Countries
{
public record LoadCountryFlagQuery(string CountryCode) : IRequest<ImageDto>, ICacheableRequest
{
public CacheConfiguration GetCacheConfiguration()
{
return new CacheConfiguration($"country_flag{CountryCode.ToLowerInvariant()}", TimeSpan.FromDays(1));
}
}
}
154 changes: 154 additions & 0 deletions src/Covid19Api.UseCases/CountryFlags/ad.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions src/Covid19Api.UseCases/CountryFlags/ae.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/Covid19Api.UseCases/CountryFlags/af.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/Covid19Api.UseCases/CountryFlags/ag.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/Covid19Api.UseCases/CountryFlags/ai.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/Covid19Api.UseCases/CountryFlags/al.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/Covid19Api.UseCases/CountryFlags/am.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions src/Covid19Api.UseCases/CountryFlags/an.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/Covid19Api.UseCases/CountryFlags/ao.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit dff871b

Please sign in to comment.