From f1ccc24c85753bf49cb0c87c43bf525ea3b91448 Mon Sep 17 00:00:00 2001 From: Christian Arenas Date: Wed, 14 Jun 2017 15:17:54 +0200 Subject: [PATCH] Create a LocationId in data read model and change the affected modification --- .../Locations.API/Controllers/LocationsController.cs | 2 +- .../Infrastructure/LocationsContextSeed.cs | 12 ++++++++---- .../Repositories/ILocationsRepository.cs | 2 +- .../Repositories/LocationsRepository.cs | 4 ++-- .../Infrastructure/Services/ILocationsService.cs | 2 +- .../Infrastructure/Services/LocationsService.cs | 4 ++-- .../Locations.API/Model/UserLocationDetails.cs | 2 +- .../Marketing/Marketing.API/Model/Location.cs | 3 +-- .../Marketing.API/Model/UserLocationDetails.cs | 2 +- 9 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/Services/Location/Locations.API/Controllers/LocationsController.cs b/src/Services/Location/Locations.API/Controllers/LocationsController.cs index 1b4fd801b..a6cb8bdad 100644 --- a/src/Services/Location/Locations.API/Controllers/LocationsController.cs +++ b/src/Services/Location/Locations.API/Controllers/LocationsController.cs @@ -41,7 +41,7 @@ namespace Locations.API.Controllers //GET api/v1/[controller]/1 [Route("{locationId}")] [HttpGet] - public async Task GetLocation(string locationId) + public async Task GetLocation(int locationId) { var location = await _locationsService.GetLocation(locationId); return Ok(location); diff --git a/src/Services/Location/Locations.API/Infrastructure/LocationsContextSeed.cs b/src/Services/Location/Locations.API/Infrastructure/LocationsContextSeed.cs index 05acfe0b8..6f519f6b1 100644 --- a/src/Services/Location/Locations.API/Infrastructure/LocationsContextSeed.cs +++ b/src/Services/Location/Locations.API/Infrastructure/LocationsContextSeed.cs @@ -32,7 +32,8 @@ var us = new Locations() { Code = "US", - Description = "United States" + Description = "United States", + LocationId = 1 }; us.SetLocation(-101.357386, 41.650455); us.SetArea(GetUSPoligon()); @@ -46,7 +47,8 @@ { Parent_Id = parentId, Code = "WHT", - Description = "Washington" + Description = "Washington", + LocationId = 2 }; wht.SetLocation(-119.542781, 47.223652); wht.SetArea(GetWashingtonPoligon()); @@ -61,7 +63,8 @@ { Parent_Id = parentId, Code = "SEAT", - Description = "Seattle" + Description = "Seattle", + LocationId = 3 }; stl.SetArea(GetSeattlePoligon()); stl.SetLocation(-122.330747, 47.603111); @@ -74,7 +77,8 @@ { Parent_Id = parentId, Code = "REDM", - Description = "Redmond" + Description = "Redmond", + LocationId = 4 }; rdm.SetLocation(-122.122887, 47.674961); rdm.SetArea(GetRedmondPoligon()); diff --git a/src/Services/Location/Locations.API/Infrastructure/Repositories/ILocationsRepository.cs b/src/Services/Location/Locations.API/Infrastructure/Repositories/ILocationsRepository.cs index 03e51b0f4..e2d7f9ea2 100644 --- a/src/Services/Location/Locations.API/Infrastructure/Repositories/ILocationsRepository.cs +++ b/src/Services/Location/Locations.API/Infrastructure/Repositories/ILocationsRepository.cs @@ -7,7 +7,7 @@ public interface ILocationsRepository { - Task GetAsync(string locationId); + Task GetAsync(int locationId); Task> GetLocationListAsync(); diff --git a/src/Services/Location/Locations.API/Infrastructure/Repositories/LocationsRepository.cs b/src/Services/Location/Locations.API/Infrastructure/Repositories/LocationsRepository.cs index 764962c8a..47d443718 100644 --- a/src/Services/Location/Locations.API/Infrastructure/Repositories/LocationsRepository.cs +++ b/src/Services/Location/Locations.API/Infrastructure/Repositories/LocationsRepository.cs @@ -20,9 +20,9 @@ _context = new LocationsContext(settings); } - public async Task GetAsync(string locationId) + public async Task GetAsync(int locationId) { - var filter = Builders.Filter.Eq("Id", ObjectId.Parse(locationId)); + var filter = Builders.Filter.Eq("LocationId", locationId); return await _context.Locations .Find(filter) .FirstOrDefaultAsync(); diff --git a/src/Services/Location/Locations.API/Infrastructure/Services/ILocationsService.cs b/src/Services/Location/Locations.API/Infrastructure/Services/ILocationsService.cs index 94c566664..5d55bb25e 100644 --- a/src/Services/Location/Locations.API/Infrastructure/Services/ILocationsService.cs +++ b/src/Services/Location/Locations.API/Infrastructure/Services/ILocationsService.cs @@ -7,7 +7,7 @@ public interface ILocationsService { - Task GetLocation(string locationId); + Task GetLocation(int locationId); Task GetUserLocation(string id); diff --git a/src/Services/Location/Locations.API/Infrastructure/Services/LocationsService.cs b/src/Services/Location/Locations.API/Infrastructure/Services/LocationsService.cs index e0596b20f..f9882c10d 100644 --- a/src/Services/Location/Locations.API/Infrastructure/Services/LocationsService.cs +++ b/src/Services/Location/Locations.API/Infrastructure/Services/LocationsService.cs @@ -22,7 +22,7 @@ _eventBus = eventBus ?? throw new ArgumentNullException(nameof(eventBus)); } - public async Task GetLocation(string locationId) + public async Task GetLocation(int locationId) { return await _locationsRepository.GetAsync(locationId); } @@ -76,7 +76,7 @@ newLocations.ForEach(location => { result.Add(new UserLocationDetails() { - LocationId = location.Id, + LocationId = location.LocationId, Code = location.Code, Description = location.Description }); diff --git a/src/Services/Location/Locations.API/Model/UserLocationDetails.cs b/src/Services/Location/Locations.API/Model/UserLocationDetails.cs index 03d56b9ec..6e152fe1b 100644 --- a/src/Services/Location/Locations.API/Model/UserLocationDetails.cs +++ b/src/Services/Location/Locations.API/Model/UserLocationDetails.cs @@ -7,7 +7,7 @@ namespace Microsoft.eShopOnContainers.Services.Locations.API.Model { public class UserLocationDetails { - public string LocationId { get; set; } + public int LocationId { get; set; } public string Code { get; set; } public string Description { get; set; } } diff --git a/src/Services/Marketing/Marketing.API/Model/Location.cs b/src/Services/Marketing/Marketing.API/Model/Location.cs index 388c0156b..0e3e19c1a 100644 --- a/src/Services/Marketing/Marketing.API/Model/Location.cs +++ b/src/Services/Marketing/Marketing.API/Model/Location.cs @@ -9,8 +9,7 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Model { public class Location { - [BsonRepresentation(BsonType.ObjectId)] - public string LocationId { get; set; } + public int LocationId { get; set; } public string Code { get; set; } public string Description { get; set; } } diff --git a/src/Services/Marketing/Marketing.API/Model/UserLocationDetails.cs b/src/Services/Marketing/Marketing.API/Model/UserLocationDetails.cs index 0bbe89c44..e6d7fe305 100644 --- a/src/Services/Marketing/Marketing.API/Model/UserLocationDetails.cs +++ b/src/Services/Marketing/Marketing.API/Model/UserLocationDetails.cs @@ -2,7 +2,7 @@ { public class UserLocationDetails { - public string LocationId { get; set; } + public int LocationId { get; set; } public string Code { get; set; } public string Description { get; set; } }