Skip to content

Commit

Permalink
fix: property mapping in CentralApi contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
Artonus committed Mar 1, 2024
1 parent 4d32bc5 commit 7a49087
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/CentralApi/Mappings/ApiContractToDomainMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public static Location ToLocation(this RegisterRequest x)
{
Name = x.Name,
Organization = x.Organization,
Type = Enum.Parse<LocationType>(x.Type)
Type = Enum.Parse<LocationType>(x.Type),
Address = new (x.Address)
};
}
}
2 changes: 1 addition & 1 deletion src/CentralApi/Services/LocationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public LocationService(ILocationRepository locationRepository)
public async Task<OneOf<Location, NotFound>> RegisterLocation(Location location)
{
// when location not found in db
var (found, loc) = await _locationRepository.ExistsAsync(location.Name);
var (found, loc) = await _locationRepository.ExistsAsync(location.Name, location.Organization);


if (found == false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Task<List<Location>> OrderLocationsByUtilizationAsync(List<Location> locationsTo
Task<bool> IsBusyAsync(Guid id);
Task<ImmutableList<Location>> GetLocationsByOrganizationAsync(string organization);

Task<(bool, Location?)> ExistsAsync(string name);
Task<(bool, Location?)> ExistsAsync(string name, string organization);

Task<(bool, Location?)> ExistsAsync(Guid id);

Expand Down
4 changes: 2 additions & 2 deletions src/DataAccess/Repositories/Redis/RedisLocationRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ public async Task<ImmutableList<Location>> GetLocationsByOrganizationAsync(strin
}

/// <inheritdoc />
public async Task<(bool, Location?)> ExistsAsync(string name)
public async Task<(bool, Location?)> ExistsAsync(string name, string organization)
{
var loc = await FindSingleAsync(dto => dto.Name == name);
var loc = await FindSingleAsync(dto => dto.Name == name && dto.Organization == organization);

return (loc is not null, loc);
}
Expand Down
4 changes: 2 additions & 2 deletions test/CentralApi.Tests.Unit/Services/LocationServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public async Task RegisterLocation_ShouldMakeLocationOnlineAndUpdateAddress_When
Type = LocationType.Cloud,
IsOnline = true
};
_locationRepository.ExistsAsync(Arg.Any<string>()).Returns((true, cloud));
_locationRepository.ExistsAsync(Arg.Any<string>(), Arg.Any<string>()).Returns((true, cloud));

_locationRepository.AddAsync(Arg.Any<Location>()).ReturnsForAnyArgs(cloud);
// act
Expand All @@ -76,7 +76,7 @@ public async Task RegisterLocation_ShouldRegisterNewBareLocation_WhenLocationIsN
Organization = "MiddlewareTesting",
Type = LocationType.Cloud
};
_locationRepository.ExistsAsync(Arg.Any<string>()).Returns((false, null));
_locationRepository.ExistsAsync(Arg.Any<string>(), Arg.Any<string>()).Returns((false, null));

// act
var result = await _sut.RegisterLocation(paramLocation);
Expand Down

0 comments on commit 7a49087

Please sign in to comment.