Skip to content

Commit 3a9093a

Browse files
committed
Modify location.API change userId type from int to Guid
1 parent 06f978b commit 3a9093a

6 files changed

Lines changed: 16 additions & 11 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ public LocationsController(ILocationsService locationsService, IIdentityService
2121
}
2222

2323
//GET api/v1/[controller]/user/1
24-
[Route("user/{userId:int}")]
24+
[Route("user/{userId:guid}")]
2525
[HttpGet]
26-
public async Task<IActionResult> GetUserLocation(int userId)
26+
public async Task<IActionResult> GetUserLocation(Guid userId)
2727
{
28-
var userLocation = await _locationsService.GetUserLocation(userId);
28+
var userLocation = await _locationsService.GetUserLocation(userId.ToString());
2929
return Ok(userLocation);
3030
}
3131

src/Services/Location/Locations.API/Infrastructure/Repositories/ILocationsRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public interface ILocationsRepository
1111

1212
Task<List<Locations>> GetLocationListAsync();
1313

14-
Task<UserLocation> GetUserLocationAsync(int userId);
14+
Task<UserLocation> GetUserLocationAsync(string userId);
1515

1616
Task<List<Locations>> GetCurrentUserRegionsListAsync(LocationRequest currentPosition);
1717

src/Services/Location/Locations.API/Infrastructure/Repositories/LocationsRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public async Task<Locations> GetAsync(string locationId)
2828
.FirstOrDefaultAsync();
2929
}
3030

31-
public async Task<UserLocation> GetUserLocationAsync(int userId)
31+
public async Task<UserLocation> GetUserLocationAsync(string userId)
3232
{
3333
var filter = Builders<UserLocation>.Filter.Eq("UserId", userId);
3434
return await _context.UserLocation

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public interface ILocationsService
99
{
1010
Task<Locations> GetLocation(string locationId);
1111

12-
Task<UserLocation> GetUserLocation(int id);
12+
Task<UserLocation> GetUserLocation(string id);
1313

1414
Task<List<Locations>> GetAllLocation();
1515

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ public async Task<Locations> GetLocation(string locationId)
2323
return await _locationsRepository.GetAsync(locationId);
2424
}
2525

26-
public async Task<UserLocation> GetUserLocation(int id)
26+
public async Task<UserLocation> GetUserLocation(string id)
2727
{
28-
return await _locationsRepository.GetUserLocationAsync(id);
28+
if (!Guid.TryParse(id, out Guid userId))
29+
{
30+
throw new ArgumentException("Not valid userId");
31+
}
32+
33+
return await _locationsRepository.GetUserLocationAsync(userId.ToString());
2934
}
3035

3136
public async Task<List<Locations>> GetAllLocation()
@@ -35,7 +40,7 @@ public async Task<List<Locations>> GetAllLocation()
3540

3641
public async Task<bool> AddOrUpdateUserLocation(string id, LocationRequest currentPosition)
3742
{
38-
if (!int.TryParse(id, out int userId))
43+
if (!Guid.TryParse(id, out Guid userId))
3944
{
4045
throw new ArgumentException("Not valid userId");
4146
}
@@ -50,7 +55,7 @@ public async Task<bool> AddOrUpdateUserLocation(string id, LocationRequest curre
5055

5156
// If current area found, then update user location
5257
var locationAncestors = new List<string>();
53-
var userLocation = await _locationsRepository.GetUserLocationAsync(userId);
58+
var userLocation = await _locationsRepository.GetUserLocationAsync(userId.ToString());
5459
userLocation = userLocation ?? new UserLocation();
5560
userLocation.UserId = userId;
5661
userLocation.LocationId = currentUserAreaLocationList[0].Id;

src/Services/Location/Locations.API/Model/UserLocation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class UserLocation
99
[BsonIgnoreIfDefault]
1010
[BsonRepresentation(BsonType.ObjectId)]
1111
public string Id { get; set; }
12-
public int UserId { get; set; } = 0;
12+
public Guid UserId { get; set; }
1313
[BsonRepresentation(BsonType.ObjectId)]
1414
public string LocationId { get; set; }
1515
public DateTime UpdateDate { get; set; }

0 commit comments

Comments
 (0)