Skip to content
This repository has been archived by the owner on Jun 13, 2020. It is now read-only.

Commit

Permalink
Added a method to create a location from an address
Browse files Browse the repository at this point in the history
Issue #29
  • Loading branch information
Timo-Weike committed Apr 14, 2020
1 parent 1abf50b commit 01f87af
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Pirat/Services/Helper/AddressMaking/AddressMaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,33 @@
using Newtonsoft.Json.Linq;
using Pirat.Codes;
using Pirat.Exceptions;
using Pirat.Model.Api.Resource;
using Pirat.Model.Entity.Resource.Common;
using Pirat.Other;

namespace Pirat.Services.Helper.AddressMaking
{
public class AddressMaker : IAddressMaker
{
public Location? CreateLocationForAddress(Address address)
{
NullCheck.ThrowIfNull(address);

if (!string.IsNullOrEmpty(address.country)
&& !string.IsNullOrEmpty(address.postalcode))
{
var locationOfDemandedConsumable = new AddressEntity().build(address);
this.SetCoordinates(locationOfDemandedConsumable);

return new Location(
decimal.ToDouble(locationOfDemandedConsumable.latitude),
decimal.ToDouble(locationOfDemandedConsumable.longitude)
);
}

return null;
}

public void SetCoordinates(AddressEntity address)
{
NullCheck.ThrowIfNull<AddressEntity>(address);
Expand Down
9 changes: 9 additions & 0 deletions Pirat/Services/Helper/AddressMaking/IAddressMaker.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
using Pirat.Model.Api.Resource;
using Pirat.Model.Entity.Resource.Common;
using Pirat.Other;

namespace Pirat.Services.Helper.AddressMaking
{
public interface IAddressMaker {

public void SetCoordinates(AddressEntity address);

/// <summary>
/// Creates a <see cref="Location"/> with latitude and longitude for
/// the given Address.
/// </summary>
/// <param name="address">the address</param>
/// <returns>the lat/long location for the address</returns>
Location? CreateLocationForAddress(Address address);
}
}

0 comments on commit 01f87af

Please sign in to comment.