Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overlay landing page water rights tab callchain #394

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public interface ISiteAccessor : IServiceContractBase
Task<IEnumerable<VariableInfoListItem>> GetVariableInfoListByUuid(string siteUuid);

Task<IEnumerable<MethodInfoListItem>> GetMethodInfoListByUuid(string siteUuid);
Task<List<WaterRightInfoListItem>> GetWaterRightInfoListByReportingUnitUuid(string reportingUnitUuid);

IEnumerable<GeoConnex> GetJSONLDData();
}
Expand Down
12 changes: 12 additions & 0 deletions src/API/WesternStatesWater.WestDaat.Accessors/SiteAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ public async Task<List<WaterRightInfoListItem>> GetWaterRightInfoListByUuid(stri
.ToListAsync();
}

public async Task<List<WaterRightInfoListItem>> GetWaterRightInfoListByReportingUnitUuid(string reportingUnitUuid)
{
await using var db = _databaseContextFactory.Create();
return await db.AllocationAmountsFact
.Where(aaf => aaf.AllocationBridgeSitesFact.Any(absf =>
absf.Site.RegulatoryOverlayBridgeSitesFact.Any(robsf =>
robsf.RegulatoryOverlay.RegulatoryReportingUnitsFact.Any(rruf =>
rruf.ReportingUnit.ReportingUnitUuid == reportingUnitUuid))))
.ProjectTo<WaterRightInfoListItem>(DtoMapper.Configuration)
.ToListAsync();
}

public async Task<IEnumerable<SiteUsagePoint>> GetSiteUsageBySiteUuid(string siteUuid)
{
await using var db = _databaseContextFactory.Create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,15 @@
return await CreateOkResponse(request, result);
}

[Function(nameof(GetWaterRightsListByReportingUnitUuid))]
public async Task<HttpResponseData> GetWaterRightsListByReportingUnitUuid(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Overlays/{reportingUnitUuid}/Rights")] HttpRequestData request,
string reportingUnitUuid)
{
var result = await _waterAllocationManager.GetWaterRightsInfoListByReportingUnitUuid(reportingUnitUuid);
return await CreateOkResponse(request, result);
}

[Function(nameof(GetSiteUsageByByUuid))]
public async Task<HttpResponseData> GetSiteUsageByByUuid([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "Sites/{siteUuid}/SiteUsage")] HttpRequestData request, string siteUuid)
{
Expand Down Expand Up @@ -230,11 +239,11 @@
{
await _waterAllocationManager.WaterRightsAsZip(ms, searchRequest);
}
catch (WestDaatException wex)

Check warning on line 242 in src/API/WesternStatesWater.WestDaat.Client.Functions/WaterAllocation.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'wex' is declared but never used
{
request.HttpContext.Response.StatusCode = (int)HttpStatusCode.RequestEntityTooLarge;
}
catch (Exception ex)

Check warning on line 246 in src/API/WesternStatesWater.WestDaat.Client.Functions/WaterAllocation.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'ex' is declared but never used
{
request.HttpContext.Response.StatusCode = (int)HttpStatusCode.InternalServerError;
throw;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ public interface IWaterAllocationManager : IServiceContractBase
Task<List<OverlayTableEntry>> GetOverlayInfoById(string reportingUnitUuid);

Task<List<MethodInfoListItem>> GetSiteMethodInfoListByUuid(string siteUuid);
Task<List<WaterRightInfoListItem>> GetWaterRightsInfoListByReportingUnitUuid(string reportingUnitUuid);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ public async Task<Feature> GetWaterSiteLocation(string siteUuid)
return (await _siteAccessor.GetWaterRightInfoListByUuid(siteUuid)).Map<List<ClientContracts.WaterRightInfoListItem>>();
}

async Task<List<ClientContracts.WaterRightInfoListItem>> ClientContracts.IWaterAllocationManager.GetWaterRightsInfoListByReportingUnitUuid(string reportingUnitUuid)
{
return (await _siteAccessor.GetWaterRightInfoListByReportingUnitUuid(reportingUnitUuid))
.Map<List<ClientContracts.WaterRightInfoListItem>>();
}

async Task<ClientContracts.SiteUsage> ClientContracts.IWaterAllocationManager.GetSiteUsageBySiteUuid(string siteUuid)
{
var siteUsagePoints = await _siteAccessor.GetSiteUsageBySiteUuid(siteUuid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -908,8 +908,120 @@ public async Task GetOverlayInfoById_ReturnsOverlayEntries()
result.Select(x => x.WaDEOverlayUuid).Should().BeEquivalentTo(new[] { "overlay_1", "overlay_2" });
_waterAllocationAccessorMock.Verify();
}

[TestMethod]
public async Task GetWaterRightsInfoListByReportingUnitUuid_Results_Returned()
{
// Arrange
var reportingUnitUuid = "test_uuid";
_siteAccessorMock.Setup(x => x.GetWaterRightInfoListByReportingUnitUuid(reportingUnitUuid))
.ReturnsAsync(new List<CommonContracts.WaterRightInfoListItem>
{
new CommonContracts.WaterRightInfoListItem { WaterRightNativeId = "test_water_right_uuid" }
})
.Verifiable();

var manager = CreateWaterAllocationManager();

// Act
var result = await manager.GetWaterRightsInfoListByReportingUnitUuid(reportingUnitUuid);

// Assert
result.Should().NotBeNull();
result.Count.Should().Be(1);
result[0].WaterRightNativeId.Should().Be("test_water_right_uuid");
_siteAccessorMock.Verify();
}

[TestMethod]
public async Task GetWaterRightsInfoListByReportingUnitUuid_MultipleResults_Returned()
{
// Arrange
var reportingUnitUuid = "test_uuid";
_siteAccessorMock.Setup(x => x.GetWaterRightInfoListByReportingUnitUuid(reportingUnitUuid))
.ReturnsAsync(new List<CommonContracts.WaterRightInfoListItem>
{
new CommonContracts.WaterRightInfoListItem
{
WaterRightNativeId = "water_right_1",
AllocationUuid = "alloc_1",
Owner = "Owner1",
PriorityDate = DateTime.Parse("2000-01-01"),
ExpirationDate = DateTime.Parse("2025-01-01"),
LegalStatus = "Valid",
Flow = 10.5,
Volume = 20.0,
BeneficialUses = new List<string> { "Irrigation", "Recreation" }
},
new CommonContracts.WaterRightInfoListItem
{
WaterRightNativeId = "water_right_2",
AllocationUuid = "alloc_2",
Owner = "Owner2",
PriorityDate = DateTime.Parse("2010-05-15"),
ExpirationDate = null,
LegalStatus = "Pending",
Flow = 5.0,
Volume = 10.0,
BeneficialUses = new List<string> { "Municipal" }
}
})
.Verifiable();

var manager = CreateWaterAllocationManager();

// Act
var result = await manager.GetWaterRightsInfoListByReportingUnitUuid(reportingUnitUuid);

// Assert
result.Should().NotBeNull();
result.Count.Should().Be(2);

// Validate the first item
result[0].WaterRightNativeId.Should().Be("water_right_1");
result[0].AllocationUuid.Should().Be("alloc_1");
result[0].Owner.Should().Be("Owner1");
result[0].PriorityDate.Should().Be(DateTime.Parse("2000-01-01"));
result[0].ExpirationDate.Should().Be(DateTime.Parse("2025-01-01"));
result[0].LegalStatus.Should().Be("Valid");
result[0].Flow.Should().Be(10.5);
result[0].Volume.Should().Be(20.0);
result[0].BeneficialUses.Should().BeEquivalentTo(new List<string> { "Irrigation", "Recreation" });

// Validate the second item
result[1].WaterRightNativeId.Should().Be("water_right_2");
result[1].AllocationUuid.Should().Be("alloc_2");
result[1].Owner.Should().Be("Owner2");
result[1].PriorityDate.Should().Be(DateTime.Parse("2010-05-15"));
result[1].ExpirationDate.Should().BeNull();
result[1].LegalStatus.Should().Be("Pending");
result[1].Flow.Should().Be(5.0);
result[1].Volume.Should().Be(10.0);
result[1].BeneficialUses.Should().BeEquivalentTo(new List<string> { "Municipal" });

_siteAccessorMock.Verify();
}

[TestMethod]
public async Task GetWaterRightsInfoListByReportingUnitUuid_ThrowsException_WhenUuidIsNullOrEmpty()
{
// Arrange
_siteAccessorMock.Setup(x => x.GetWaterRightInfoListByReportingUnitUuid(null))
.ThrowsAsync(new ArgumentException("ReportingUnitUuid cannot be null or empty."));
_siteAccessorMock.Setup(x => x.GetWaterRightInfoListByReportingUnitUuid(""))
.ThrowsAsync(new ArgumentException("ReportingUnitUuid cannot be null or empty."));

var manager = CreateWaterAllocationManager();

// Act & Assert
await Assert.ThrowsExceptionAsync<ArgumentException>(
() => manager.GetWaterRightsInfoListByReportingUnitUuid(null),
"ReportingUnitUuid cannot be null or empty.");

await Assert.ThrowsExceptionAsync<ArgumentException>(
() => manager.GetWaterRightsInfoListByReportingUnitUuid(""),
"ReportingUnitUuid cannot be null or empty.");
}

private async Task CheckRecords<T>(Stream entryStream, string fileEnd, List<T> list)
{
Expand Down
Loading