feat(bff): Add App Version management endpoints
Build and Deploy to Production / build-and-deploy (push) Successful in 1m47s
Build and Deploy to Production / build-and-deploy (push) Successful in 1m47s
- Add appversion.proto with GetAll, Get, Update RPCs - Add GetAllAppVersionsQuery and handler - Add UpdateAppVersionCommand and handler - Add AppVersionService gRPC service - Add AppVersionProfile for Mapster mappings - Update IApplicationContractContext with AppVersions client - Bump Configuration.Protobuf to 1.0.20
This commit is contained in:
@@ -23,6 +23,7 @@ using CMSMicroservice.Protobuf.Protos.Configuration;
|
||||
using CMSMicroservice.Protobuf.Protos.DiscountOrder;
|
||||
using CMSMicroservice.Protobuf.Protos.ManualPayment;
|
||||
using CMSMicroservice.Protobuf.Protos.NetworkMembership;
|
||||
using CMSMicroservice.Protobuf.Protos.AppVersion;
|
||||
|
||||
namespace BackOffice.BFF.Application.Common.Interfaces;
|
||||
|
||||
@@ -66,5 +67,8 @@ public interface IApplicationContractContext
|
||||
// Manual Payments (Admin) - BackOffice BFF gRPC
|
||||
ManualPaymentContract.ManualPaymentContractClient ManualPayments { get; }
|
||||
|
||||
// App Version Management
|
||||
AppVersionContract.AppVersionContractClient AppVersions { get; }
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
namespace BackOffice.BFF.Application.ConfigurationCQ.Commands.UpdateAppVersion;
|
||||
|
||||
public class UpdateAppVersionCommand : IRequest<Unit>
|
||||
{
|
||||
/// <summary>
|
||||
/// نام اپلیکیشن (FrontOffice, BackOffice, Mobile)
|
||||
/// </summary>
|
||||
public string AppName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// ورژن فعلی
|
||||
/// </summary>
|
||||
public string CurrentVersion { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// حداقل ورژن مورد نیاز
|
||||
/// </summary>
|
||||
public string? MinRequiredVersion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// آیا نیاز به پاک کردن کامل کش دارد؟
|
||||
/// </summary>
|
||||
public bool RequiresFullCacheClear { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// پیام آپدیت برای کاربران
|
||||
/// </summary>
|
||||
public string? UpdateMessage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// یادداشتهای نسخه
|
||||
/// </summary>
|
||||
public string? ReleaseNotes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// دلیل آپدیت (برای لاگ ادمین)
|
||||
/// </summary>
|
||||
public string? UpdateReason { get; set; }
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
using CMSMicroservice.Protobuf.Protos.AppVersion;
|
||||
|
||||
namespace BackOffice.BFF.Application.ConfigurationCQ.Commands.UpdateAppVersion;
|
||||
|
||||
public class UpdateAppVersionCommandHandler : IRequestHandler<UpdateAppVersionCommand, Unit>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
public UpdateAppVersionCommandHandler(IApplicationContractContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Unit> Handle(UpdateAppVersionCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var cmsRequest = new UpdateAppVersionRequest
|
||||
{
|
||||
AppName = request.AppName,
|
||||
CurrentVersion = request.CurrentVersion,
|
||||
RequiresFullCacheClear = request.RequiresFullCacheClear
|
||||
};
|
||||
|
||||
if (!string.IsNullOrEmpty(request.MinRequiredVersion))
|
||||
cmsRequest.MinRequiredVersion = request.MinRequiredVersion;
|
||||
|
||||
if (!string.IsNullOrEmpty(request.UpdateMessage))
|
||||
cmsRequest.UpdateMessage = request.UpdateMessage;
|
||||
|
||||
if (!string.IsNullOrEmpty(request.ReleaseNotes))
|
||||
cmsRequest.ReleaseNotes = request.ReleaseNotes;
|
||||
|
||||
if (!string.IsNullOrEmpty(request.UpdateReason))
|
||||
cmsRequest.UpdateReason = request.UpdateReason;
|
||||
|
||||
await _context.AppVersions.UpdateAppVersionAsync(cmsRequest, cancellationToken: cancellationToken);
|
||||
|
||||
return Unit.Value;
|
||||
}
|
||||
}
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
namespace BackOffice.BFF.Application.ConfigurationCQ.Queries.GetAllAppVersions;
|
||||
|
||||
public class GetAllAppVersionsQuery : IRequest<GetAllAppVersionsResponseDto>
|
||||
{
|
||||
public bool IncludeInactive { get; set; }
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
using CMSMicroservice.Protobuf.Protos.AppVersion;
|
||||
|
||||
namespace BackOffice.BFF.Application.ConfigurationCQ.Queries.GetAllAppVersions;
|
||||
|
||||
public class GetAllAppVersionsQueryHandler : IRequestHandler<GetAllAppVersionsQuery, GetAllAppVersionsResponseDto>
|
||||
{
|
||||
private readonly IApplicationContractContext _context;
|
||||
|
||||
public GetAllAppVersionsQueryHandler(IApplicationContractContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<GetAllAppVersionsResponseDto> Handle(GetAllAppVersionsQuery request, CancellationToken cancellationToken)
|
||||
{
|
||||
var cmsRequest = new GetAllAppVersionsRequest
|
||||
{
|
||||
IncludeInactive = request.IncludeInactive
|
||||
};
|
||||
|
||||
var response = await _context.AppVersions.GetAllAppVersionsAsync(cmsRequest, cancellationToken: cancellationToken);
|
||||
|
||||
return new GetAllAppVersionsResponseDto
|
||||
{
|
||||
Items = response.Items.Select(item => new AppVersionItemDto
|
||||
{
|
||||
Id = item.Id,
|
||||
AppName = item.AppName,
|
||||
CurrentVersion = item.CurrentVersion,
|
||||
MinRequiredVersion = item.MinRequiredVersion,
|
||||
RequiresFullCacheClear = item.RequiresFullCacheClear,
|
||||
UpdateMessage = item.UpdateMessage,
|
||||
ReleaseNotes = item.ReleaseNotes,
|
||||
IsActive = item.IsActive,
|
||||
Created = item.Created?.ToDateTimeOffset() ?? DateTimeOffset.MinValue,
|
||||
LastModified = item.LastModified?.ToDateTimeOffset() ?? DateTimeOffset.MinValue
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
namespace BackOffice.BFF.Application.ConfigurationCQ.Queries.GetAllAppVersions;
|
||||
|
||||
public class GetAllAppVersionsResponseDto
|
||||
{
|
||||
public List<AppVersionItemDto> Items { get; set; } = new();
|
||||
}
|
||||
|
||||
public class AppVersionItemDto
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string AppName { get; set; } = string.Empty;
|
||||
public string CurrentVersion { get; set; } = string.Empty;
|
||||
public string MinRequiredVersion { get; set; } = string.Empty;
|
||||
public bool RequiresFullCacheClear { get; set; }
|
||||
public string? UpdateMessage { get; set; }
|
||||
public string? ReleaseNotes { get; set; }
|
||||
public bool IsActive { get; set; }
|
||||
public DateTimeOffset Created { get; set; }
|
||||
public DateTimeOffset LastModified { get; set; }
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Afrino.FMSMicroservice.Protobuf" Version="0.0.122" />
|
||||
<PackageReference Include="Foursat.CMSMicroservice.Protobuf" Version="0.0.156" />
|
||||
<PackageReference Include="Foursat.CMSMicroservice.Protobuf" Version="0.0.159" />
|
||||
|
||||
<PackageReference Include="Google.Protobuf" Version="3.23.3" />
|
||||
<PackageReference Include="Grpc.Net.ClientFactory" Version="2.54.0" />
|
||||
|
||||
@@ -24,6 +24,7 @@ using CMSMicroservice.Protobuf.Protos.Configuration;
|
||||
using CMSMicroservice.Protobuf.Protos.DiscountOrder;
|
||||
using CMSMicroservice.Protobuf.Protos.ManualPayment;
|
||||
using CMSMicroservice.Protobuf.Protos.NetworkMembership;
|
||||
using CMSMicroservice.Protobuf.Protos.AppVersion;
|
||||
|
||||
// BFF Protobuf contracts
|
||||
|
||||
@@ -93,5 +94,8 @@ public class ApplicationContractContext : IApplicationContractContext
|
||||
|
||||
// Manual Payments (Admin)
|
||||
public ManualPaymentContract.ManualPaymentContractClient ManualPayments => GetService<ManualPaymentContract.ManualPaymentContractClient>();
|
||||
|
||||
// App Version Management
|
||||
public AppVersionContract.AppVersionContractClient AppVersions => GetService<AppVersionContract.AppVersionContractClient>();
|
||||
#endregion
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
using BackOffice.BFF.Application.ConfigurationCQ.Commands.UpdateAppVersion;
|
||||
using BackOffice.BFF.Application.ConfigurationCQ.Queries.GetAllAppVersions;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using ProtoDto = BackOffice.BFF.Configuration.Protobuf.Protos.AppVersion;
|
||||
|
||||
namespace BackOffice.BFF.WebApi.Common.Mappings;
|
||||
|
||||
public class AppVersionProfile : IRegister
|
||||
{
|
||||
void IRegister.Register(TypeAdapterConfig config)
|
||||
{
|
||||
// Request -> Query mappings
|
||||
config.NewConfig<ProtoDto.GetAllAppVersionsRequest, GetAllAppVersionsQuery>()
|
||||
.Map(dest => dest.IncludeInactive, src => src.IncludeInactive);
|
||||
|
||||
// Request -> Command mappings
|
||||
config.NewConfig<ProtoDto.UpdateAppVersionRequest, UpdateAppVersionCommand>()
|
||||
.Map(dest => dest.AppName, src => src.AppName)
|
||||
.Map(dest => dest.CurrentVersion, src => src.CurrentVersion)
|
||||
.Map(dest => dest.MinRequiredVersion, src => src.MinRequiredVersion)
|
||||
.Map(dest => dest.RequiresFullCacheClear, src => src.RequiresFullCacheClear)
|
||||
.Map(dest => dest.UpdateMessage, src => src.UpdateMessage)
|
||||
.Map(dest => dest.ReleaseNotes, src => src.ReleaseNotes)
|
||||
.Map(dest => dest.UpdateReason, src => src.UpdateReason);
|
||||
|
||||
// Response mappings
|
||||
config.NewConfig<GetAllAppVersionsResponseDto, ProtoDto.GetAllAppVersionsResponse>()
|
||||
.Map(dest => dest.Items, src => src.Items);
|
||||
|
||||
config.NewConfig<AppVersionItemDto, ProtoDto.AppVersionItem>()
|
||||
.Map(dest => dest.Id, src => src.Id)
|
||||
.Map(dest => dest.AppName, src => src.AppName)
|
||||
.Map(dest => dest.CurrentVersion, src => src.CurrentVersion)
|
||||
.Map(dest => dest.MinRequiredVersion, src => src.MinRequiredVersion)
|
||||
.Map(dest => dest.RequiresFullCacheClear, src => src.RequiresFullCacheClear)
|
||||
.Map(dest => dest.UpdateMessage, src => src.UpdateMessage ?? string.Empty)
|
||||
.Map(dest => dest.ReleaseNotes, src => src.ReleaseNotes ?? string.Empty)
|
||||
.Map(dest => dest.IsActive, src => src.IsActive)
|
||||
.Map(dest => dest.Created, src => Timestamp.FromDateTimeOffset(src.Created))
|
||||
.Map(dest => dest.LastModified, src => Timestamp.FromDateTimeOffset(src.LastModified));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using BackOffice.BFF.WebApi.Common.Services;
|
||||
using BackOffice.BFF.Application.ConfigurationCQ.Commands.UpdateAppVersion;
|
||||
using BackOffice.BFF.Application.ConfigurationCQ.Queries.GetAllAppVersions;
|
||||
using BackOffice.BFF.Configuration.Protobuf.Protos.AppVersion;
|
||||
|
||||
namespace BackOffice.BFF.WebApi.Services;
|
||||
|
||||
public class AppVersionService : AppVersionContract.AppVersionContractBase
|
||||
{
|
||||
private readonly IDispatchRequestToCQRS _dispatchRequestToCQRS;
|
||||
|
||||
public AppVersionService(IDispatchRequestToCQRS dispatchRequestToCQRS)
|
||||
{
|
||||
_dispatchRequestToCQRS = dispatchRequestToCQRS;
|
||||
}
|
||||
|
||||
[RequiresPermission(PermissionNames.SettingsView)]
|
||||
public override async Task<GetAllAppVersionsResponse> GetAllAppVersions(
|
||||
GetAllAppVersionsRequest request,
|
||||
ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<GetAllAppVersionsRequest, GetAllAppVersionsQuery, GetAllAppVersionsResponse>(
|
||||
request,
|
||||
context);
|
||||
}
|
||||
|
||||
[RequiresPermission(PermissionNames.SettingsView)]
|
||||
public override async Task<GetAppVersionResponse> GetAppVersion(
|
||||
GetAppVersionRequest request,
|
||||
ServerCallContext context)
|
||||
{
|
||||
// For single app version, we use GetAll and filter
|
||||
var allVersionsResponse = await _dispatchRequestToCQRS.Handle<GetAllAppVersionsRequest, GetAllAppVersionsQuery, GetAllAppVersionsResponse>(
|
||||
new GetAllAppVersionsRequest { IncludeInactive = false },
|
||||
context);
|
||||
|
||||
var item = allVersionsResponse.Items.FirstOrDefault(x => x.AppName == request.AppName);
|
||||
|
||||
return new GetAppVersionResponse
|
||||
{
|
||||
Found = item != null,
|
||||
Item = item
|
||||
};
|
||||
}
|
||||
|
||||
[RequiresPermission(PermissionNames.SettingsManageConfiguration)]
|
||||
public override async Task<Empty> UpdateAppVersion(
|
||||
UpdateAppVersionRequest request,
|
||||
ServerCallContext context)
|
||||
{
|
||||
return await _dispatchRequestToCQRS.Handle<UpdateAppVersionRequest, UpdateAppVersionCommand, Empty>(
|
||||
request,
|
||||
context);
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -6,7 +6,7 @@
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>true</IsPackable>
|
||||
<PackageId>Foursat.BackOffice.BFF.Configuration.Protobuf</PackageId>
|
||||
<Version>1.0.7</Version>
|
||||
<Version>1.0.20</Version>
|
||||
<Authors>FourSat</Authors>
|
||||
<Company>FourSat</Company>
|
||||
<Product>Foursat.BackOffice.BFF.Configuration.Protobuf</Product>
|
||||
@@ -25,6 +25,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Protobuf Include="Protos\configuration.proto" ProtoRoot="Protos\" GrpcServices="Both" AdditionalImportDirs="..\BackOffice.BFF.Common.Protobuf\Protos"/>
|
||||
<Protobuf Include="Protos\appversion.proto" ProtoRoot="Protos\" GrpcServices="Both" AdditionalImportDirs="..\BackOffice.BFF.Common.Protobuf\Protos"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package appversion;
|
||||
|
||||
import "google/protobuf/empty.proto";
|
||||
import "google/protobuf/wrappers.proto";
|
||||
import "google/protobuf/timestamp.proto";
|
||||
import "google/api/annotations.proto";
|
||||
|
||||
option csharp_namespace = "BackOffice.BFF.Configuration.Protobuf.Protos.AppVersion";
|
||||
|
||||
// Service for managing app versions (admin panel)
|
||||
service AppVersionContract
|
||||
{
|
||||
// Get all app versions
|
||||
rpc GetAllAppVersions(GetAllAppVersionsRequest) returns (GetAllAppVersionsResponse){
|
||||
option (google.api.http) = {
|
||||
get: "/AppVersion/GetAll"
|
||||
};
|
||||
};
|
||||
|
||||
// Get single app version
|
||||
rpc GetAppVersion(GetAppVersionRequest) returns (GetAppVersionResponse){
|
||||
option (google.api.http) = {
|
||||
get: "/AppVersion/Get"
|
||||
};
|
||||
};
|
||||
|
||||
// Update/Create app version
|
||||
rpc UpdateAppVersion(UpdateAppVersionRequest) returns (google.protobuf.Empty){
|
||||
option (google.api.http) = {
|
||||
post: "/AppVersion/Update"
|
||||
body: "*"
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
// Request to get all app versions
|
||||
message GetAllAppVersionsRequest
|
||||
{
|
||||
bool include_inactive = 1;
|
||||
}
|
||||
|
||||
// Response with all app versions
|
||||
message GetAllAppVersionsResponse
|
||||
{
|
||||
repeated AppVersionItem items = 1;
|
||||
}
|
||||
|
||||
// Request to get single app version
|
||||
message GetAppVersionRequest
|
||||
{
|
||||
string app_name = 1;
|
||||
}
|
||||
|
||||
// Response with version info
|
||||
message GetAppVersionResponse
|
||||
{
|
||||
bool found = 1;
|
||||
AppVersionItem item = 2;
|
||||
}
|
||||
|
||||
// Request to update/create app version
|
||||
message UpdateAppVersionRequest
|
||||
{
|
||||
string app_name = 1;
|
||||
string current_version = 2;
|
||||
google.protobuf.StringValue min_required_version = 3;
|
||||
bool requires_full_cache_clear = 4;
|
||||
google.protobuf.StringValue update_message = 5;
|
||||
google.protobuf.StringValue release_notes = 6;
|
||||
google.protobuf.StringValue update_reason = 7; // For admin logs
|
||||
}
|
||||
|
||||
// App version item
|
||||
message AppVersionItem
|
||||
{
|
||||
int64 id = 1;
|
||||
string app_name = 2;
|
||||
string current_version = 3;
|
||||
string min_required_version = 4;
|
||||
bool requires_full_cache_clear = 5;
|
||||
string update_message = 6;
|
||||
string release_notes = 7;
|
||||
bool is_active = 8;
|
||||
google.protobuf.Timestamp created = 9;
|
||||
google.protobuf.Timestamp last_modified = 10;
|
||||
}
|
||||
Reference in New Issue
Block a user