Browse Source

Modify location.API change userId type from int to Guid

pull/223/head
Christian Arenas 7 years ago
parent
commit
c9332396c5
6 changed files with 16 additions and 11 deletions
  1. +3
    -3
      src/Services/Location/Locations.API/Controllers/LocationsController.cs
  2. +1
    -1
      src/Services/Location/Locations.API/Infrastructure/Repositories/ILocationsRepository.cs
  3. +1
    -1
      src/Services/Location/Locations.API/Infrastructure/Repositories/LocationsRepository.cs
  4. +1
    -1
      src/Services/Location/Locations.API/Infrastructure/Services/ILocationsService.cs
  5. +9
    -4
      src/Services/Location/Locations.API/Infrastructure/Services/LocationsService.cs
  6. +1
    -1
      src/Services/Location/Locations.API/Model/UserLocation.cs

+ 3
- 3
src/Services/Location/Locations.API/Controllers/LocationsController.cs View File

@ -21,11 +21,11 @@ namespace Locations.API.Controllers
} }
//GET api/v1/[controller]/user/1 //GET api/v1/[controller]/user/1
[Route("user/{userId:int}")]
[Route("user/{userId:guid}")]
[HttpGet] [HttpGet]
public async Task<IActionResult> GetUserLocation(int userId)
public async Task<IActionResult> GetUserLocation(Guid userId)
{ {
var userLocation = await _locationsService.GetUserLocation(userId);
var userLocation = await _locationsService.GetUserLocation(userId.ToString());
return Ok(userLocation); return Ok(userLocation);
} }


+ 1
- 1
src/Services/Location/Locations.API/Infrastructure/Repositories/ILocationsRepository.cs View File

@ -11,7 +11,7 @@
Task<List<Locations>> GetLocationListAsync(); Task<List<Locations>> GetLocationListAsync();
Task<UserLocation> GetUserLocationAsync(int userId);
Task<UserLocation> GetUserLocationAsync(string userId);
Task<List<Locations>> GetCurrentUserRegionsListAsync(LocationRequest currentPosition); Task<List<Locations>> GetCurrentUserRegionsListAsync(LocationRequest currentPosition);


+ 1
- 1
src/Services/Location/Locations.API/Infrastructure/Repositories/LocationsRepository.cs View File

@ -28,7 +28,7 @@
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
} }
public async Task<UserLocation> GetUserLocationAsync(int userId)
public async Task<UserLocation> GetUserLocationAsync(string userId)
{ {
var filter = Builders<UserLocation>.Filter.Eq("UserId", userId); var filter = Builders<UserLocation>.Filter.Eq("UserId", userId);
return await _context.UserLocation return await _context.UserLocation


+ 1
- 1
src/Services/Location/Locations.API/Infrastructure/Services/ILocationsService.cs View File

@ -9,7 +9,7 @@
{ {
Task<Locations> GetLocation(string locationId); Task<Locations> GetLocation(string locationId);
Task<UserLocation> GetUserLocation(int id);
Task<UserLocation> GetUserLocation(string id);
Task<List<Locations>> GetAllLocation(); Task<List<Locations>> GetAllLocation();


+ 9
- 4
src/Services/Location/Locations.API/Infrastructure/Services/LocationsService.cs View File

@ -23,9 +23,14 @@
return await _locationsRepository.GetAsync(locationId); return await _locationsRepository.GetAsync(locationId);
} }
public async Task<UserLocation> GetUserLocation(int id)
public async Task<UserLocation> GetUserLocation(string id)
{ {
return await _locationsRepository.GetUserLocationAsync(id);
if (!Guid.TryParse(id, out Guid userId))
{
throw new ArgumentException("Not valid userId");
}
return await _locationsRepository.GetUserLocationAsync(userId.ToString());
} }
public async Task<List<Locations>> GetAllLocation() public async Task<List<Locations>> GetAllLocation()
@ -35,7 +40,7 @@
public async Task<bool> AddOrUpdateUserLocation(string id, LocationRequest currentPosition) public async Task<bool> AddOrUpdateUserLocation(string id, LocationRequest currentPosition)
{ {
if (!int.TryParse(id, out int userId))
if (!Guid.TryParse(id, out Guid userId))
{ {
throw new ArgumentException("Not valid userId"); throw new ArgumentException("Not valid userId");
} }
@ -50,7 +55,7 @@
// If current area found, then update user location // If current area found, then update user location
var locationAncestors = new List<string>(); var locationAncestors = new List<string>();
var userLocation = await _locationsRepository.GetUserLocationAsync(userId);
var userLocation = await _locationsRepository.GetUserLocationAsync(userId.ToString());
userLocation = userLocation ?? new UserLocation(); userLocation = userLocation ?? new UserLocation();
userLocation.UserId = userId; userLocation.UserId = userId;
userLocation.LocationId = currentUserAreaLocationList[0].Id; userLocation.LocationId = currentUserAreaLocationList[0].Id;


+ 1
- 1
src/Services/Location/Locations.API/Model/UserLocation.cs View File

@ -9,7 +9,7 @@
[BsonIgnoreIfDefault] [BsonIgnoreIfDefault]
[BsonRepresentation(BsonType.ObjectId)] [BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; } public string Id { get; set; }
public int UserId { get; set; } = 0;
public Guid UserId { get; set; }
[BsonRepresentation(BsonType.ObjectId)] [BsonRepresentation(BsonType.ObjectId)]
public string LocationId { get; set; } public string LocationId { get; set; }
public DateTime UpdateDate { get; set; } public DateTime UpdateDate { get; set; }


Loading…
Cancel
Save