Skip to content

Commit

Permalink
Merge pull request #673 from Laixer/develop
Browse files Browse the repository at this point in the history
3.6.2
  • Loading branch information
yorickdewid committed Jul 6, 2022
2 parents c4f54a8 + 0c9e488 commit 14f82fe
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 65 deletions.
86 changes: 47 additions & 39 deletions database/fundermaps_base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1430,54 +1430,51 @@ $_$;
ALTER FUNCTION data.get_foundation_category(type_indicative report.foundation_type, type_report report.foundation_type) OWNER TO fundermaps;

--
-- Name: id_resolve(text); Type: FUNCTION; Schema: data; Owner: fundermaps
-- Name: id_lookup(text); Type: FUNCTION; Schema: geocoder; Owner: fundermaps
--

CREATE FUNCTION data.id_resolve(id text) RETURNS geocoder.geocoder_id
LANGUAGE plpgsql
CREATE FUNCTION geocoder.id_lookup(input text) RETURNS geocoder.geocoder_id
LANGUAGE plpgsql PARALLEL SAFE
AS $$
declare
DECLARE
identifier geocoder.id_parser_tuple;
building_id geocoder.geocoder_id;
begin
select *
into identifier
from geocoder.id_parser(id);

case identifier.type
WHEN 'fundermaps' THEN
SELECT-- AnalysisComplete
ac.building_id
into building_id
FROM data.analysis_complete ac
WHERE ac.building_id = identifier.id
LIMIT 1;
WHEN 'nl_bag_building', 'nl_bag_berth', 'nl_bag_posting' THEN
SELECT-- AnalysisComplete
ac.building_id
into building_id
FROM data.analysis_complete ac
WHERE ac.external_building_id = identifier.id
LIMIT 1;
WHEN 'nl_bag_address' THEN
SELECT-- AnalysisComplete
ac.building_id
into building_id
FROM data.analysis_complete ac
WHERE ac.address_external_id = identifier.id
LIMIT 1;
end case;
BEGIN
SELECT parse_result.type, parse_result.id
INTO identifier
FROM geocoder.id_parser(input) AS parse_result;

if not found then
raise no_data_found;
end if;

return building_id;
end;
CASE identifier.type
WHEN 'fundermaps' THEN
SELECT ac.building_id
INTO building_id
FROM data.analysis_complete ac
WHERE ac.building_id = identifier.id
LIMIT 1;
WHEN 'nl_bag_building', 'nl_bag_berth', 'nl_bag_posting' THEN
SELECT ac.building_id
INTO building_id
FROM data.analysis_complete ac
WHERE ac.external_building_id = identifier.id
LIMIT 1;
WHEN 'nl_bag_address' THEN
SELECT ac.building_id
INTO building_id
FROM data.analysis_complete ac
WHERE ac.address_external_id = identifier.id
LIMIT 1;
END CASE;

IF NOT FOUND THEN
RAISE no_data_found;
END IF;

RETURN building_id;
END;
$$;


ALTER FUNCTION data.id_resolve(id text) OWNER TO fundermaps;
ALTER FUNCTION geocoder.id_lookup(input text) OWNER TO fundermaps;

--
-- Name: id_parser(text); Type: FUNCTION; Schema: geocoder; Owner: fundermaps
Expand Down Expand Up @@ -2950,6 +2947,17 @@ ALTER TABLE geocoder.district OWNER TO fundermaps;
COMMENT ON TABLE geocoder.district IS 'Contains all districts in our own format.';


--
-- Name: identifier; Type: TABLE; Schema: geocoder; Owner: postgres
--

CREATE TABLE geocoder.identifier (
"?column?" integer
);


ALTER TABLE geocoder.identifier OWNER TO postgres;

--
-- Name: municipality; Type: TABLE; Schema: geocoder; Owner: fundermaps
--
Expand Down
71 changes: 71 additions & 0 deletions src/FunderMaps.Admin/Pages/User.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
@page "/user"
@attribute [Authorize(Policy = "AdministratorPolicy")]

<PageTitle>Users</PageTitle>

@using FunderMaps.Core.Interfaces.Repositories
@inject IUserRepository UserRepository

<h1>Users</h1>

@if (trackers == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
@foreach (var tracker in trackers)
{
<tr>
<td>@tracker.Id</td>
<td>@tracker.Name</td>
<td>@tracker.Email</td>
</tr>
}
</tbody>
</table>
}

@code {
public class Woei
{
/// <summary>
/// Unique identifier.
/// </summary>
public Guid Id { get; set; }

/// <summary>
/// Gets or sets the name for the user.
/// </summary>
public string Name { get; set; }

/// <summary>
/// Gets or sets the email address for the user.
/// </summary>
public string Email { get; set; }
}

private List<Woei> trackers = new();

protected override async Task OnInitializedAsync()
{
await foreach (var user in UserRepository.ListAllAsync(FunderMaps.Core.Navigation.All))
{
trackers.Add(new Woei
{
Id = user.Id,
Name = user.ToString(),
Email = user.Email,
});
}
}
}
5 changes: 5 additions & 0 deletions src/FunderMaps.Admin/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
</NavLink>
</div>
<AuthorizeView Policy="AdministratorPolicy">
<div class="nav-item px-3">
<NavLink class="nav-link" href="user">
<span class="oi oi-person" aria-hidden="true"></span> Users
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="organization">
<span class="oi oi-person" aria-hidden="true"></span> Organizations
Expand Down
30 changes: 6 additions & 24 deletions src/FunderMaps.Data/Repositories/AnalysisRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task<AnalysisProduct3> Get3Async(string id)
WITH tracker AS (
INSERT INTO application.product_tracker AS pt (organization_id, product, building_id)
SELECT @tenant, 'analysis3', building_id
FROM data.id_resolve(@id) AS building_id
FROM geocoder.id_lookup(@id) AS building_id
LIMIT 1
RETURNING building_id
)
Expand Down Expand Up @@ -79,30 +79,12 @@ RETURNING building_id
public async Task<bool> GetRiskIndexAsync(string id)
{
var sql = @"
WITH identifier AS (
SELECT
type,
id
FROM geocoder.id_parser(@id)
LIMIT 1
),
tracker AS (
WITH tracker AS (
INSERT INTO application.product_tracker AS pt (organization_id, product, building_id)
SELECT
@tenant,
'riskindex',
ac.building_id
FROM data.analysis_complete ac, identifier
WHERE
CASE
WHEN identifier.type = 'fundermaps' THEN ac.building_id = identifier.id
WHEN identifier.type = 'nl_bag_address' THEN ac.address_external_id = identifier.id
WHEN identifier.type = 'nl_bag_building' THEN ac.external_building_id = identifier.id
WHEN identifier.type = 'nl_bag_berth' THEN ac.external_building_id = identifier.id
WHEN identifier.type = 'nl_bag_posting' THEN ac.external_building_id = identifier.id
END
LIMIT 1
RETURNING pt.building_id
SELECT @tenant, 'riskindex', building_id
FROM geocoder.id_lookup(@id) AS building_id
LIMIT 1
RETURNING building_id
)
SELECT -- AnalysisComplete
'a'::data.foundation_risk_indication <> ANY (ARRAY[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ namespace FunderMaps.IntegrationTests.Webservice;
/// <summary>
/// Integration test for the analysis controller.
/// </summary>
public class Analysis3Tests : IClassFixture<WebserviceFixtureFactory>
public class AnalysisTests : IClassFixture<WebserviceFixtureFactory>
{
private WebserviceFixtureFactory Factory { get; }

/// <summary>
/// Create new instance and setup the test data.
/// </summary>
public Analysis3Tests(WebserviceFixtureFactory factory)
public AnalysisTests(WebserviceFixtureFactory factory)
=> Factory = factory;

[Fact]
Expand Down Expand Up @@ -153,6 +153,21 @@ public async Task GetRiskIndexByExternalIdInvalidAddressThrows(string address)
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
}

[Theory]
[InlineData("gfm-bc31bec346744745b29f8505dff8182f")]
[InlineData("gfm-00096758461b4c8c8a8c145790126beb")]
public async Task GetRiskIndexByExternalIdAddressNotFoundThrows(string address)
{
// Arrange
using var client = Factory.CreateClient();

// Act
var response = await client.GetAsync($"api/v3/product/at_risk?id={address}");

// Assert
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
}

[Theory]
[InlineData("id=3kjhr834dhfjdeh")]
[InlineData("bagid=4928374hfdkjsfh")]
Expand All @@ -169,4 +184,19 @@ public async Task GetByIdInvalidAddressThrows(string address)
// Assert
Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode);
}

[Theory]
[InlineData("gfm-dfcdbbabf1de41c38597c049b0cce5d4")]
[InlineData("gfm-1437da5c31e944dd8d362264041d067a")]
public async Task GetByIdAddressNotFoundThrows(string address)
{
// Arrange
using var client = Factory.CreateClient();

// Act
var response = await client.GetAsync($"api/v3/product/analysis?id={address}");

// Assert
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
}
}

0 comments on commit 14f82fe

Please sign in to comment.