diff --git a/src/BuildingBlocks/Masa.BuildingBlocks.StackSdks.Sapp/ISappClient.cs b/src/BuildingBlocks/Masa.BuildingBlocks.StackSdks.Sapp/ISappClient.cs index 1d7016b..b37c853 100644 --- a/src/BuildingBlocks/Masa.BuildingBlocks.StackSdks.Sapp/ISappClient.cs +++ b/src/BuildingBlocks/Masa.BuildingBlocks.StackSdks.Sapp/ISappClient.cs @@ -6,4 +6,6 @@ namespace Masa.BuildingBlocks.StackSdks.Sapp; public interface ISappClient { public IGlobalNavService GlobalNavService { get; init; } + + public IModuleService ModuleService { get; init; } } diff --git a/src/BuildingBlocks/Masa.BuildingBlocks.StackSdks.Sapp/Model/MaintenanceDto.cs b/src/BuildingBlocks/Masa.BuildingBlocks.StackSdks.Sapp/Model/MaintenanceDto.cs new file mode 100644 index 0000000..fc2e3da --- /dev/null +++ b/src/BuildingBlocks/Masa.BuildingBlocks.StackSdks.Sapp/Model/MaintenanceDto.cs @@ -0,0 +1,10 @@ +namespace Masa.BuildingBlocks.StackSdks.Sapp.Model; + +public class MaintainceDto +{ + public string Reason { get; set; } = default!; + + public DateTime StartTime { get; set; } + + public DateTime EndTime { get; set; } +} diff --git a/src/BuildingBlocks/Masa.BuildingBlocks.StackSdks.Sapp/Model/ModuleDetailDto.cs b/src/BuildingBlocks/Masa.BuildingBlocks.StackSdks.Sapp/Model/ModuleDetailDto.cs new file mode 100644 index 0000000..1783222 --- /dev/null +++ b/src/BuildingBlocks/Masa.BuildingBlocks.StackSdks.Sapp/Model/ModuleDetailDto.cs @@ -0,0 +1,20 @@ +namespace Masa.BuildingBlocks.StackSdks.Sapp.Model; + +public class ModuleDetailDto +{ + public string Code { get; set; } = default!; + + public string Name { get; set; } = default!; + + public string? Icon { get; set; } + + public string PmIdentity { get; set; } = default!; + + public bool Enable { get; set; } = default!; + + public bool Show { get; set; } = default!; + + public StatusTypes Status { get; set; } + + public MaintainceDto? Maintaince { get; set; } +} \ No newline at end of file diff --git a/src/BuildingBlocks/Masa.BuildingBlocks.StackSdks.Sapp/Service/IModuleService.cs b/src/BuildingBlocks/Masa.BuildingBlocks.StackSdks.Sapp/Service/IModuleService.cs new file mode 100644 index 0000000..8b218f4 --- /dev/null +++ b/src/BuildingBlocks/Masa.BuildingBlocks.StackSdks.Sapp/Service/IModuleService.cs @@ -0,0 +1,6 @@ +namespace Masa.BuildingBlocks.StackSdks.Sapp.Service; + +public interface IModuleService +{ + Task GetByPmIdentityAsync(string pmIdentity); +} \ No newline at end of file diff --git a/src/Contrib.Wasm/Masa.Contrib.StackSdks.Sapp.Wasm/SappClient.cs b/src/Contrib.Wasm/Masa.Contrib.StackSdks.Sapp.Wasm/SappClient.cs index 7f49fe8..0748999 100644 --- a/src/Contrib.Wasm/Masa.Contrib.StackSdks.Sapp.Wasm/SappClient.cs +++ b/src/Contrib.Wasm/Masa.Contrib.StackSdks.Sapp.Wasm/SappClient.cs @@ -8,7 +8,10 @@ public class SappClient : ISappClient public SappClient(ICaller caller) { GlobalNavService = new GlobalNavService(caller); + ModuleService = new ModuleService(caller); } public IGlobalNavService GlobalNavService { get; init; } + + public IModuleService ModuleService { get; init; } } diff --git a/src/Contrib.Wasm/Masa.Contrib.StackSdks.Sapp.Wasm/Service/ModuleService.cs b/src/Contrib.Wasm/Masa.Contrib.StackSdks.Sapp.Wasm/Service/ModuleService.cs new file mode 100644 index 0000000..5984d97 --- /dev/null +++ b/src/Contrib.Wasm/Masa.Contrib.StackSdks.Sapp.Wasm/Service/ModuleService.cs @@ -0,0 +1,22 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the MIT License. See LICENSE.txt in the project root for license information. + +namespace Masa.Contrib.StackSdks.Sapp.Service; + +public class ModuleService : IModuleService +{ + private const string MODULE_ROUTE_PREFIX = "api/module"; + + private readonly ICaller _caller; + + public ModuleService(ICaller caller) + { + _caller = caller; + } + + public Task GetByPmIdentityAsync(string pmIdentity) + { + var requestUri = $"{MODULE_ROUTE_PREFIX}/byPmIdentity"; + return _caller.GetAsync(requestUri, new { pmIdentity }); + } +} diff --git a/src/Contrib/Masa.Contrib.StackSdks.Sapp/SappClient.cs b/src/Contrib/Masa.Contrib.StackSdks.Sapp/SappClient.cs index 7f49fe8..0748999 100644 --- a/src/Contrib/Masa.Contrib.StackSdks.Sapp/SappClient.cs +++ b/src/Contrib/Masa.Contrib.StackSdks.Sapp/SappClient.cs @@ -8,7 +8,10 @@ public class SappClient : ISappClient public SappClient(ICaller caller) { GlobalNavService = new GlobalNavService(caller); + ModuleService = new ModuleService(caller); } public IGlobalNavService GlobalNavService { get; init; } + + public IModuleService ModuleService { get; init; } } diff --git a/src/Contrib/Masa.Contrib.StackSdks.Sapp/Service/ModuleService.cs b/src/Contrib/Masa.Contrib.StackSdks.Sapp/Service/ModuleService.cs new file mode 100644 index 0000000..897f314 --- /dev/null +++ b/src/Contrib/Masa.Contrib.StackSdks.Sapp/Service/ModuleService.cs @@ -0,0 +1,19 @@ +namespace Masa.Contrib.StackSdks.Sapp.Service; + +public class ModuleService : IModuleService +{ + private const string MODULE_ROUTE_PREFIX = "api/module"; + + private readonly ICaller _caller; + + public ModuleService(ICaller caller) + { + _caller = caller; + } + + public Task GetByPmIdentityAsync(string pmIdentity) + { + var requestUri = $"{MODULE_ROUTE_PREFIX}/byPmIdentity"; + return _caller.GetAsync(requestUri, new { pmIdentity }); + } +} diff --git a/src/Contrib/Tests/Masa.Contrib.StackSdks.Sapp.Tests/ModuleServiceTest.cs b/src/Contrib/Tests/Masa.Contrib.StackSdks.Sapp.Tests/ModuleServiceTest.cs new file mode 100644 index 0000000..3cb499c --- /dev/null +++ b/src/Contrib/Tests/Masa.Contrib.StackSdks.Sapp.Tests/ModuleServiceTest.cs @@ -0,0 +1,43 @@ +// Copyright (c) MASA Stack All rights reserved. +// Licensed under the MIT License. See LICENSE.txt in the project root for license information. + +namespace Masa.Contrib.StackSdks.Sapp.Tests; + +[TestClass] +public class ModuleServiceTest +{ + [TestMethod] + [DataRow("pm.identity")] + public async Task TestGetByPmIdentityAsync(string pmIdentity) + { + var data = new ModuleDetailDto { PmIdentity = pmIdentity }; + + var requestUri = $"api/module/byPmIdentity/{pmIdentity}"; + var caller = new Mock(); + caller.Setup(provider => provider.GetAsync(requestUri, default)).ReturnsAsync(data).Verifiable(); + var sappClient = new SappClient(caller.Object); + + var result = await sappClient.ModuleService.GetByPmIdentityAsync(pmIdentity); + caller.Verify(provider => provider.GetAsync(requestUri, default), Times.Once); + + Assert.IsNotNull(result); + Assert.AreEqual(pmIdentity, result.PmIdentity); + } + + [TestMethod] + [DataRow("pm.identity")] + public async Task TestGetByPmIdentityWhenNullAsync(string pmIdentity) + { + ModuleDetailDto? data = null; + + var requestUri = $"api/module/byPmIdentity/{pmIdentity}"; + var caller = new Mock(); + caller.Setup(provider => provider.GetAsync(It.IsAny(), default)).ReturnsAsync(data).Verifiable(); + var sappClient = new SappClient(caller.Object); + + var result = await sappClient.ModuleService.GetByPmIdentityAsync(pmIdentity); + caller.Verify(provider => provider.GetAsync(requestUri, default), Times.Once); + + Assert.IsNull(result); + } +}