-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(countrylist): Add new endpoint getAllCountries (#347)
* countrylist endpoint returning internationalized names of all countries --------- Co-authored-by: Norbert Truchsess <[email protected]> Reviewed-by: Norbert Truchsess <[email protected]>
- Loading branch information
1 parent
4e1c4ba
commit 1989515
Showing
12 changed files
with
317 additions
and
7 deletions.
There are no files selected for viewing
1 change: 0 additions & 1 deletion
1
src/administration/Administration.Service/Controllers/StaticDataController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
src/portalbackend/PortalBackend.DBAccess/Models/CountryLongNameData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
namespace Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models; | ||
|
||
/// <summary> | ||
/// Model for CountryLongNameData | ||
/// </summary>] | ||
/// <param name="Alpha2Code">Language Short Name</param> | ||
/// <param name="CountryName">Language Long Name</param> | ||
/// <returns></returns> | ||
public record CountryLongNameData(string Alpha2Code, IEnumerable<CountryName> CountryName); | ||
|
||
/// <summary> | ||
/// Model for CountryName | ||
/// </summary> | ||
/// <param name="Language">language</param> | ||
/// <param name="value">long Description</param> | ||
/// <returns></returns> | ||
public record CountryName(string Language, string Value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
src/portalbackend/PortalBackend.PortalEntities/Entities/Country.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/registration/Registration.Service/BusinessLogic/IStaticDataBusinessLogic.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models; | ||
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Entities; | ||
using Org.Eclipse.TractusX.Portal.Backend.Registration.Service.Model; | ||
|
||
namespace Org.Eclipse.TractusX.Portal.Backend.Registration.Service.BusinessLogic; | ||
|
||
public interface IStaticDataBusinessLogic | ||
{ | ||
/// <summary> | ||
/// Get all Countries. | ||
/// </summary> | ||
/// <returns>AsyncEnumerable of the result Counties with long names</returns> | ||
IAsyncEnumerable<CountryLongNameData> GetAllCountries(); | ||
} |
42 changes: 42 additions & 0 deletions
42
src/registration/Registration.Service/BusinessLogic/StaticDataBusinessLogic.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess; | ||
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models; | ||
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories; | ||
|
||
namespace Org.Eclipse.TractusX.Portal.Backend.Registration.Service.BusinessLogic; | ||
|
||
public class StaticDataBusinessLogic : IStaticDataBusinessLogic | ||
{ | ||
private readonly IPortalRepositories _portalRepositories; | ||
|
||
/// <summary> | ||
/// Constructor | ||
/// </summary> | ||
/// <param name="portalRepositories"></param> | ||
public StaticDataBusinessLogic(IPortalRepositories portalRepositories) | ||
{ | ||
_portalRepositories = portalRepositories; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public IAsyncEnumerable<CountryLongNameData> GetAllCountries() => | ||
_portalRepositories.GetInstance<IStaticDataRepository>().GetAllCountries(); | ||
} |
57 changes: 57 additions & 0 deletions
57
src/registration/Registration.Service/Controllers/StaticDataController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
using Microsoft.AspNetCore.Mvc; | ||
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models; | ||
using Org.Eclipse.TractusX.Portal.Backend.Registration.Service.BusinessLogic; | ||
|
||
namespace Org.Eclipse.TractusX.Portal.Backend.Registration.Service.Controllers | ||
{ | ||
|
||
[ApiController] | ||
[Route("api/registration/[controller]")] | ||
[Produces("application/json")] | ||
[Consumes("application/json")] | ||
public class StaticDataController : ControllerBase | ||
{ | ||
private readonly IStaticDataBusinessLogic _staticDataBusinessLogic; | ||
|
||
/// <summary> | ||
/// Creates a new instance of <see cref="StaticDataController"/> | ||
/// </summary> | ||
/// <param name="staticDataBusinessLogic">Access to the business logic</param> | ||
public StaticDataController(IStaticDataBusinessLogic staticDataBusinessLogic) | ||
{ | ||
_staticDataBusinessLogic = staticDataBusinessLogic; | ||
} | ||
|
||
/// <summary> | ||
/// Retrieve all app countries - short name (2digit) and countries long name | ||
/// </summary> | ||
/// <returns>AsyncEnumerable of Countries Long name Data</returns> | ||
/// <remarks> | ||
/// Example: GET: /api/registration/staticdata/countrylist | ||
/// <response code="200">Returns a list of all countries long name with language code i.e german and english</response> | ||
[HttpGet] | ||
[Route("countrylist")] | ||
[ProducesResponseType(typeof(IAsyncEnumerable<CountryLongNameData>), StatusCodes.Status200OK)] | ||
public IAsyncEnumerable<CountryLongNameData> GetCountries() => | ||
_staticDataBusinessLogic.GetAllCountries(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
tests/registration/Registration.Service.Tests/BusinessLogic/StaticDataBusinessLogicTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
using AutoFixture; | ||
using AutoFixture.AutoFakeItEasy; | ||
using FakeItEasy; | ||
using FluentAssertions; | ||
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess; | ||
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models; | ||
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories; | ||
using Org.Eclipse.TractusX.Portal.Backend.Registration.Service.BusinessLogic; | ||
using System.Collections.Immutable; | ||
using Xunit; | ||
|
||
namespace Org.Eclipse.TractusX.Portal.Backend.Registration.Service.Tests; | ||
|
||
public class StaticDataBusinessLogicTest | ||
{ | ||
private readonly IFixture _fixture; | ||
private readonly IPortalRepositories _portalRepositories; | ||
private readonly ICompanyRepository _companyRepository; | ||
private readonly IStaticDataRepository _staticDataRepository; | ||
|
||
public StaticDataBusinessLogicTest() | ||
{ | ||
_fixture = new Fixture().Customize(new AutoFakeItEasyCustomization { ConfigureMembers = true }); | ||
_fixture.Behaviors.OfType<ThrowingRecursionBehavior>().ToList() | ||
.ForEach(b => _fixture.Behaviors.Remove(b)); | ||
_fixture.Behaviors.Add(new OmitOnRecursionBehavior()); | ||
|
||
_companyRepository = A.Fake<ICompanyRepository>(); | ||
_staticDataRepository = A.Fake<IStaticDataRepository>(); | ||
_portalRepositories = A.Fake<IPortalRepositories>(); | ||
|
||
A.CallTo(() => _portalRepositories.GetInstance<ICompanyRepository>()).Returns(_companyRepository); | ||
A.CallTo(() => _portalRepositories.GetInstance<IStaticDataRepository>()).Returns(_staticDataRepository); | ||
} | ||
|
||
[Fact] | ||
public async Task GetAllCountries_ReturnsExpectedResult() | ||
{ | ||
// Arrange | ||
var data = _fixture.CreateMany<CountryLongNameData>(3).ToImmutableArray(); | ||
|
||
A.CallTo(() => _staticDataRepository.GetAllCountries()) | ||
.Returns(data.ToAsyncEnumerable()); | ||
|
||
var sut = new StaticDataBusinessLogic(_portalRepositories); | ||
|
||
// Act | ||
var result = await sut.GetAllCountries().ToListAsync().ConfigureAwait(false); | ||
|
||
// Assert | ||
A.CallTo(() => _staticDataRepository.GetAllCountries()) | ||
.MustHaveHappenedOnceExactly(); | ||
result.Should().HaveCount(3).And.ContainInOrder(data); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
tests/registration/Registration.Service.Tests/Controller/StaticDataControllerTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/******************************************************************************** | ||
* Copyright (c) 2021, 2023 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
********************************************************************************/ | ||
|
||
using AutoFixture; | ||
using FakeItEasy; | ||
using FluentAssertions; | ||
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models; | ||
using Org.Eclipse.TractusX.Portal.Backend.Registration.Service.BusinessLogic; | ||
using Org.Eclipse.TractusX.Portal.Backend.Registration.Service.Controllers; | ||
using Xunit; | ||
|
||
namespace Org.Eclipse.TractusX.Portal.Backend.Registration.Service.Tests; | ||
|
||
public class StaticDataControllerTest | ||
{ | ||
private readonly IStaticDataBusinessLogic _logic; | ||
private readonly StaticDataController _controller; | ||
private readonly Fixture _fixture; | ||
public StaticDataControllerTest() | ||
{ | ||
_fixture = new Fixture(); | ||
_logic = A.Fake<IStaticDataBusinessLogic>(); | ||
_controller = new StaticDataController(_logic); | ||
} | ||
|
||
[Fact] | ||
public async Task GetCountries_ReturnsExpectedResult() | ||
{ | ||
//Arrange | ||
var data = _fixture.CreateMany<CountryLongNameData>(5).ToAsyncEnumerable(); | ||
A.CallTo(() => _logic.GetAllCountries()) | ||
.Returns(data); | ||
|
||
//Act | ||
var result = await _controller.GetCountries().ToListAsync().ConfigureAwait(false); | ||
|
||
// Assert | ||
A.CallTo(() => _logic.GetAllCountries()).MustHaveHappenedOnceExactly(); | ||
result.Should().HaveCount(5).And.AllBeOfType<CountryLongNameData>(); | ||
} | ||
} |