Enhance app management with 'IsRecommended' feature
- Added 'IsRecommended' property to app-related data models, allowing apps to be marked as recommended. - Updated API endpoints for creating and updating apps to include 'IsRecommended' in request bodies. - Modified database schema to accommodate the new 'IsRecommended' field. - Enhanced frontend components to display recommended apps with a star icon and updated forms to manage this property. - Improved sorting logic in app listings to prioritize recommended apps. - Updated documentation to reflect changes in API and data models.
This commit is contained in:
+8
-4
@@ -18,7 +18,8 @@ public class DeleteDisabledAppsCommandHandlerTests
|
||||
OsPlatform.Android,
|
||||
null,
|
||||
null,
|
||||
0
|
||||
0,
|
||||
isRecommended: false
|
||||
);
|
||||
disabledApp.Update(
|
||||
disabledApp.Name,
|
||||
@@ -27,7 +28,8 @@ public class DeleteDisabledAppsCommandHandlerTests
|
||||
null,
|
||||
null,
|
||||
0,
|
||||
isEnabled: false
|
||||
isEnabled: false,
|
||||
isRecommended: false
|
||||
);
|
||||
|
||||
var enabledApp = ClientApp.Create(
|
||||
@@ -36,7 +38,8 @@ public class DeleteDisabledAppsCommandHandlerTests
|
||||
OsPlatform.IOS,
|
||||
null,
|
||||
null,
|
||||
0
|
||||
0,
|
||||
isRecommended: false
|
||||
);
|
||||
|
||||
dbContext.ClientApps.AddRange(disabledApp, enabledApp);
|
||||
@@ -65,7 +68,8 @@ public class DeleteDisabledAppsCommandHandlerTests
|
||||
OsPlatform.IOS,
|
||||
null,
|
||||
null,
|
||||
0
|
||||
0,
|
||||
isRecommended: false
|
||||
);
|
||||
dbContext.ClientApps.Add(enabledApp);
|
||||
await dbContext.SaveChangesAsync(CancellationToken.None);
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
using PnvPanel.Application.Apps;
|
||||
using PnvPanel.Application.Tests.TestSupport;
|
||||
using PnvPanel.Domain.Apps;
|
||||
using Xunit;
|
||||
|
||||
namespace PnvPanel.Application.Tests.Apps;
|
||||
|
||||
public class ListAppsQueryHandlerTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task Handle_SortsRecommendedFirstWithinEachOsGroup()
|
||||
{
|
||||
using var dbContext = InMemoryDbContextFactory.Create();
|
||||
|
||||
var regular1 = ClientApp.Create(
|
||||
"Regular 1",
|
||||
new Uri("https://a.example.com"),
|
||||
OsPlatform.Android,
|
||||
null,
|
||||
null,
|
||||
10,
|
||||
isRecommended: false
|
||||
);
|
||||
var recommended = ClientApp.Create(
|
||||
"Recommended",
|
||||
new Uri("https://b.example.com"),
|
||||
OsPlatform.Android,
|
||||
null,
|
||||
null,
|
||||
20,
|
||||
isRecommended: true
|
||||
);
|
||||
var regular2 = ClientApp.Create(
|
||||
"Regular 2",
|
||||
new Uri("https://c.example.com"),
|
||||
OsPlatform.Android,
|
||||
null,
|
||||
null,
|
||||
30,
|
||||
isRecommended: false
|
||||
);
|
||||
|
||||
dbContext.ClientApps.AddRange(regular1, recommended, regular2);
|
||||
await dbContext.SaveChangesAsync(CancellationToken.None);
|
||||
|
||||
var handler = new ListAppsQueryHandler(dbContext);
|
||||
|
||||
var result = await handler.Handle(new ListAppsQuery(), CancellationToken.None);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
var androidApps = result.Value[OsPlatform.Android];
|
||||
Assert.Equal(["Recommended", "Regular 1", "Regular 2"], androidApps.Select(a => a.Name));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Handle_ExcludesDisabledApps()
|
||||
{
|
||||
using var dbContext = InMemoryDbContextFactory.Create();
|
||||
|
||||
var enabled = ClientApp.Create(
|
||||
"Enabled",
|
||||
new Uri("https://a.example.com"),
|
||||
OsPlatform.IOS,
|
||||
null,
|
||||
null,
|
||||
10,
|
||||
isRecommended: false
|
||||
);
|
||||
var disabled = ClientApp.Create(
|
||||
"Disabled",
|
||||
new Uri("https://b.example.com"),
|
||||
OsPlatform.IOS,
|
||||
null,
|
||||
null,
|
||||
20,
|
||||
isRecommended: false
|
||||
);
|
||||
disabled.Update(
|
||||
disabled.Name,
|
||||
disabled.DownloadUrl,
|
||||
disabled.OperatingSystem,
|
||||
null,
|
||||
null,
|
||||
disabled.SortOrder,
|
||||
isEnabled: false,
|
||||
isRecommended: false
|
||||
);
|
||||
|
||||
dbContext.ClientApps.AddRange(enabled, disabled);
|
||||
await dbContext.SaveChangesAsync(CancellationToken.None);
|
||||
|
||||
var handler = new ListAppsQueryHandler(dbContext);
|
||||
|
||||
var result = await handler.Handle(new ListAppsQuery(), CancellationToken.None);
|
||||
|
||||
Assert.True(result.IsSuccess);
|
||||
var iosApps = result.Value[OsPlatform.IOS];
|
||||
Assert.Equal(["Enabled"], iosApps.Select(a => a.Name));
|
||||
}
|
||||
}
|
||||
@@ -14,13 +14,15 @@ public class ClientAppTests
|
||||
OsPlatform.Android,
|
||||
"desc",
|
||||
null,
|
||||
1
|
||||
1,
|
||||
isRecommended: false
|
||||
);
|
||||
|
||||
Assert.Equal("v2rayNG", app.Name);
|
||||
Assert.Equal(OsPlatform.Android, app.OperatingSystem);
|
||||
Assert.True(app.IsEnabled);
|
||||
Assert.Equal(1, app.SortOrder);
|
||||
Assert.False(app.IsRecommended);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -32,7 +34,8 @@ public class ClientAppTests
|
||||
OsPlatform.IOS,
|
||||
"old",
|
||||
"old-icon",
|
||||
1
|
||||
1,
|
||||
isRecommended: false
|
||||
);
|
||||
|
||||
app.Update(
|
||||
@@ -42,7 +45,8 @@ public class ClientAppTests
|
||||
"new",
|
||||
"new-icon",
|
||||
2,
|
||||
isEnabled: false
|
||||
isEnabled: false,
|
||||
isRecommended: true
|
||||
);
|
||||
|
||||
Assert.Equal("New", app.Name);
|
||||
@@ -52,5 +56,6 @@ public class ClientAppTests
|
||||
Assert.Equal("new-icon", app.IconUrl);
|
||||
Assert.Equal(2, app.SortOrder);
|
||||
Assert.False(app.IsEnabled);
|
||||
Assert.True(app.IsRecommended);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user