Modify location.API change userId type from int to Guid

This commit is contained in:
Christian Arenas 2017-06-12 20:18:52 +02:00
parent c9484a0834
commit c9332396c5
6 changed files with 16 additions and 11 deletions

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);
} }

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);

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

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();

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;

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; }