Skip to content

Commit 13cfe43

Browse files
committed
Created UserLocationModel
Map Position to Locations APi Update current user location
1 parent 83166cd commit 13cfe43

27 files changed

Lines changed: 627 additions & 128 deletions

src/Services/Identity/Identity.API/Configuration/Config.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public static IEnumerable<Client> GetClients(Dictionary<string,string> clientsUr
7272
IdentityServerConstants.StandardScopes.Profile,
7373
IdentityServerConstants.StandardScopes.OfflineAccess,
7474
"orders",
75-
"basket"
75+
"basket",
76+
"locations"
7677
},
7778
//Allow requesting refresh tokens for long lived API access
7879
AllowOfflineAccess = true
@@ -103,7 +104,8 @@ public static IEnumerable<Client> GetClients(Dictionary<string,string> clientsUr
103104
IdentityServerConstants.StandardScopes.Profile,
104105
IdentityServerConstants.StandardScopes.OfflineAccess,
105106
"orders",
106-
"basket"
107+
"basket",
108+
"locations"
107109
},
108110
}
109111
};
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Services;
4+
using Microsoft.eShopOnContainers.Services.Locations.API.ViewModel;
5+
using System;
6+
using System.Threading.Tasks;
7+
8+
namespace Locations.API.Controllers
9+
{
10+
[Route("api/v1/[controller]")]
11+
[Authorize]
12+
public class LocationsController : ControllerBase
13+
{
14+
private readonly ILocationsService _locationsService;
15+
private readonly IIdentityService _identityService;
16+
17+
public LocationsController(ILocationsService locationsService, IIdentityService identityService)
18+
{
19+
_locationsService = locationsService ?? throw new ArgumentNullException(nameof(locationsService));
20+
_identityService = identityService ?? throw new ArgumentNullException(nameof(identityService));
21+
}
22+
23+
//POST api/v1/[controller]/
24+
[Route("")]
25+
[HttpPost]
26+
public async Task<IActionResult> UpdateUserLocation([FromBody]LocationRequest newLocReq)
27+
{
28+
var userId = _identityService.GetUserIdentity();
29+
var result = await _locationsService.AddOrUpdateUserLocation(userId, newLocReq);
30+
return result ?
31+
(IActionResult)Ok() :
32+
(IActionResult)BadRequest();
33+
}
34+
}
35+
}

src/Services/Location/Locations.API/Controllers/ValuesController.cs

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/Services/Location/Locations.API/Infrastructure/LocationsContext.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,26 @@
22
{
33
using Microsoft.EntityFrameworkCore;
44
using Microsoft.EntityFrameworkCore.Metadata.Builders;
5+
using Microsoft.eShopOnContainers.Services.Locations.API.Infrastructure.Repositories;
56
using Microsoft.eShopOnContainers.Services.Locations.API.Model;
7+
using System.Threading;
8+
using System.Threading.Tasks;
69

7-
public class LocationsContext : DbContext
10+
public class LocationsContext : DbContext, IUnitOfWork
811
{
912
public LocationsContext(DbContextOptions options) : base(options)
1013
{
1114
}
1215

1316
public DbSet<Locations> Locations { get; set; }
17+
public DbSet<FrontierPoints> FrontierPoints { get; set; }
18+
public DbSet<UserLocation> UserLocation { get; set; }
1419

1520
protected override void OnModelCreating(ModelBuilder builder)
1621
{
1722
builder.Entity<Locations>(ConfigureLocations);
1823
builder.Entity<FrontierPoints>(ConfigureFrontierPoints);
24+
builder.Entity<UserLocation>(ConfigureUserLocation);
1925
}
2026

2127
void ConfigureLocations(EntityTypeBuilder<Locations> builder)
@@ -25,7 +31,7 @@ void ConfigureLocations(EntityTypeBuilder<Locations> builder)
2531
builder.HasKey(cl => cl.Id);
2632

2733
builder.Property(cl => cl.Id)
28-
.ForSqlServerUseSequenceHiLo("locations_hilo")
34+
.ForSqlServerUseSequenceHiLo("locations_seq")
2935
.IsRequired();
3036

3137
builder.Property(cb => cb.Code)
@@ -48,8 +54,19 @@ void ConfigureFrontierPoints(EntityTypeBuilder<FrontierPoints> builder)
4854
builder.HasKey(fp => fp.Id);
4955

5056
builder.Property(fp => fp.Id)
51-
.ForSqlServerUseSequenceHiLo("frontier_hilo")
57+
.ForSqlServerUseSequenceHiLo("frontier_seq")
5258
.IsRequired();
59+
}
60+
61+
void ConfigureUserLocation(EntityTypeBuilder<UserLocation> builder)
62+
{
63+
builder.ToTable("UserLocation");
64+
65+
builder.Property(ul => ul.Id)
66+
.ForSqlServerUseSequenceHiLo("UserLocation_seq")
67+
.IsRequired();
68+
69+
builder.HasIndex(ul => ul.UserId).IsUnique();
5370
}
5471
}
5572
}

src/Services/Location/Locations.API/Infrastructure/LocationsContextSeed.cs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,102 +29,102 @@ public static async Task SeedAsync(IApplicationBuilder applicationBuilder, ILogg
2929

3030
static Locations GetPreconfiguredLocations()
3131
{
32-
var ww = new Locations() { Code = "WW", Description = "WorldWide", Latitude = -1, Longitude = -1 };
32+
var ww = new Locations("WW", "WorldWide", -1, -1);
3333
ww.ChildLocations.Add(GetUSLocations());
3434
return ww;
3535
}
3636

3737
static Locations GetUSLocations()
3838
{
39-
var us = new Locations() { Code = "US", Description = "United States", Latitude = 41.650455, Longitude = -101.357386, Polygon = GetUSPoligon() };
39+
var us = new Locations("US", "United States", 41.650455, -101.357386, GetUSPoligon());
4040
us.ChildLocations.Add(GetWashingtonLocations());
4141
return us;
4242
}
4343

4444
static Locations GetWashingtonLocations()
4545
{
46-
var wht = new Locations() { Code = "WHT", Description = "Washington", Latitude = 47.223652, Longitude = -119.542781, Polygon = GetWashingtonPoligon() };
46+
var wht = new Locations("WHT", "Washington", 47.223652, -119.542781, GetWashingtonPoligon());
4747
wht.ChildLocations.Add(GetSeattleLocations());
4848
wht.ChildLocations.Add(GetRedmondLocations());
4949
return wht;
5050
}
5151

5252
static Locations GetSeattleLocations()
5353
{
54-
var bcn = new Locations() { Code = "SEAT", Description = "Seattle", Latitude = 47.603111, Longitude = -122.330747, Polygon = GetSeattlePoligon() };
55-
bcn.ChildLocations.Add(new Locations() { Code = "SEAT-PioneerSqr", Description = "Seattle Pioneer Square Shop" , Latitude = 47.602053, Longitude= -122.333884, Polygon = GetSeattlePioneerSqrPoligon() });
54+
var bcn = new Locations("SEAT", "Seattle", 47.603111, -122.330747, GetSeattlePoligon());
55+
bcn.ChildLocations.Add(new Locations("SEAT-PioneerSqr", "Seattle Pioneer Square Shop", 47.602053, -122.333884, GetSeattlePioneerSqrPoligon()));
5656
return bcn;
5757
}
5858

5959
static Locations GetRedmondLocations()
6060
{
61-
var bcn = new Locations() { Code = "REDM", Description = "Redmond", Latitude = 47.674961, Longitude = -122.122887, Polygon = GetRedmondPoligon() };
62-
bcn.ChildLocations.Add(new Locations() { Code = "REDM-DWNTWP", Description = "Redmond Downtown Central Park Shop", Latitude = 47.674433, Longitude = -122.125006, Polygon = GetRedmondDowntownParkPoligon() });
61+
var bcn = new Locations("REDM", "Redmond", 47.674961, -122.122887, GetRedmondPoligon());
62+
bcn.ChildLocations.Add(new Locations("REDM-DWNTWP", "Redmond Downtown Central Park Shop", 47.674433, -122.125006, GetRedmondDowntownParkPoligon()));
6363
return bcn;
6464
}
6565

6666
static List<FrontierPoints> GetUSPoligon()
6767
{
6868
var poligon = new List<FrontierPoints>();
69-
poligon.Add(new FrontierPoints() { Latitude = 48.7985, Longitude = -62.88205 });
70-
poligon.Add(new FrontierPoints() { Latitude = 48.76513, Longitude = -129.31329 });
71-
poligon.Add(new FrontierPoints() { Latitude = 30.12256, Longitude = -120.9496 });
72-
poligon.Add(new FrontierPoints() { Latitude = 30.87114, Longitude = -111.39442 });
73-
poligon.Add(new FrontierPoints() { Latitude = 24.24979, Longitude = -78.11975 });
69+
poligon.Add(new FrontierPoints(48.7985, -62.88205));
70+
poligon.Add(new FrontierPoints(48.76513, -129.3132));
71+
poligon.Add(new FrontierPoints(30.12256, -120.9496));
72+
poligon.Add(new FrontierPoints(30.87114, -111.3944));
73+
poligon.Add(new FrontierPoints(24.24979, -78.11975));
7474
return poligon;
7575
}
7676

7777
static List<FrontierPoints> GetWashingtonPoligon()
7878
{
7979
var poligon = new List<FrontierPoints>();
80-
poligon.Add(new FrontierPoints() { Latitude = 48.8943, Longitude = -124.68633 });
81-
poligon.Add(new FrontierPoints() { Latitude = 45.66613, Longitude = -124.32962 });
82-
poligon.Add(new FrontierPoints() { Latitude = 45.93384, Longitude = -116.73824 });
83-
poligon.Add(new FrontierPoints() { Latitude = 49.04282, Longitude = -116.96912 });
80+
poligon.Add(new FrontierPoints(48.8943, -124.68633));
81+
poligon.Add(new FrontierPoints(45.66613, -124.32962));
82+
poligon.Add(new FrontierPoints(45.93384, -116.73824));
83+
poligon.Add(new FrontierPoints(49.04282, -116.96912));
8484
return poligon;
8585
}
8686

8787
static List<FrontierPoints> GetSeattlePoligon()
8888
{
8989
var poligon = new List<FrontierPoints>();
90-
poligon.Add(new FrontierPoints() { Latitude = 47.82929, Longitude = -122.36238 });
91-
poligon.Add(new FrontierPoints() { Latitude = 47.6337, Longitude = -122.42091 });
92-
poligon.Add(new FrontierPoints() { Latitude = 47.45224, Longitude = -122.37371 });
93-
poligon.Add(new FrontierPoints() { Latitude = 47.50259, Longitude = -122.20788 });
94-
poligon.Add(new FrontierPoints() { Latitude = 47.73644, Longitude = -122.26934 });
90+
poligon.Add(new FrontierPoints(47.82929, -122.36238));
91+
poligon.Add(new FrontierPoints(47.6337, -122.42091));
92+
poligon.Add(new FrontierPoints(47.45224, -122.37371));
93+
poligon.Add(new FrontierPoints(47.50259, -122.20788));
94+
poligon.Add(new FrontierPoints(47.73644, -122.26934));
9595
return poligon;
9696
}
9797

9898
static List<FrontierPoints> GetRedmondPoligon()
9999
{
100100
var poligon = new List<FrontierPoints>();
101-
poligon.Add(new FrontierPoints() { Latitude = 47.73148, Longitude = -122.15432 });
102-
poligon.Add(new FrontierPoints() { Latitude = 47.72559, Longitude = -122.17673 });
103-
poligon.Add(new FrontierPoints() { Latitude = 47.67851, Longitude = -122.16904 });
104-
poligon.Add(new FrontierPoints() { Latitude = 47.65036, Longitude = -122.16136 });
105-
poligon.Add(new FrontierPoints() { Latitude = 47.62746, Longitude = -122.15604 });
106-
poligon.Add(new FrontierPoints() { Latitude = 47.63463, Longitude = -122.01562 });
107-
poligon.Add(new FrontierPoints() { Latitude = 47.74244, Longitude = -122.04961 });
101+
poligon.Add(new FrontierPoints(47.73148, -122.15432));
102+
poligon.Add(new FrontierPoints(47.72559, -122.17673));
103+
poligon.Add(new FrontierPoints(47.67851, -122.16904));
104+
poligon.Add(new FrontierPoints(47.65036, -122.16136));
105+
poligon.Add(new FrontierPoints(47.62746, -122.15604));
106+
poligon.Add(new FrontierPoints(47.63463, -122.01562));
107+
poligon.Add(new FrontierPoints(47.74244, -122.04961));
108108
return poligon;
109109
}
110110

111111
static List<FrontierPoints> GetSeattlePioneerSqrPoligon()
112112
{
113113
var poligon = new List<FrontierPoints>();
114-
poligon.Add(new FrontierPoints() { Latitude = 47.60338, Longitude = -122.3327 });
115-
poligon.Add(new FrontierPoints() { Latitude = 47.60192, Longitude = -122.33665 });
116-
poligon.Add(new FrontierPoints() { Latitude = 47.60096, Longitude = -122.33456 });
117-
poligon.Add(new FrontierPoints() { Latitude = 47.60136, Longitude = -122.33186 });
114+
poligon.Add(new FrontierPoints(47.60338, -122.3327));
115+
poligon.Add(new FrontierPoints(47.60192, -122.33665));
116+
poligon.Add(new FrontierPoints(47.60096, -122.33456));
117+
poligon.Add(new FrontierPoints(47.60136, -122.33186));
118118
return poligon;
119119
}
120120

121121
static List<FrontierPoints> GetRedmondDowntownParkPoligon()
122122
{
123123
var poligon = new List<FrontierPoints>();
124-
poligon.Add(new FrontierPoints() { Latitude = 47.67595, Longitude = -122.12467 });
125-
poligon.Add(new FrontierPoints() { Latitude = 47.67449, Longitude = -122.12862 });
126-
poligon.Add(new FrontierPoints() { Latitude = 47.67353, Longitude = -122.12653 });
127-
poligon.Add(new FrontierPoints() { Latitude = 47.67368, Longitude = -122.12197 });
124+
poligon.Add(new FrontierPoints(47.67595, -122.12467));
125+
poligon.Add(new FrontierPoints(47.67449, -122.12862));
126+
poligon.Add(new FrontierPoints(47.67353, -122.12653));
127+
poligon.Add(new FrontierPoints(47.67368, -122.12197));
128128
return poligon;
129129
}
130130
}

src/Services/Location/Locations.API/Infrastructure/Migrations/20170529174524_Initial.Designer.cs renamed to src/Services/Location/Locations.API/Infrastructure/Migrations/20170601140634_Initial.Designer.cs

Lines changed: 35 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)