This commit is contained in:
2026-06-06 00:21:48 +03:30
parent eb9437fe06
commit c0618a5b25
3 changed files with 142 additions and 37 deletions
+32 -1
View File
@@ -1,10 +1,41 @@
using System.Threading;
using System.Threading.Tasks;
using xCategoryService.Models.Dtos; using xCategoryService.Models.Dtos;
using xCategoryService.Models.Entities; using xCategoryService.Models.Entities;
using xCategoryService.Providers.Dtos; using xCategoryService.Providers.Dtos;
using xIdentityModels.Models;
using xPushService.Interfaces; using xPushService.Interfaces;
namespace xCategoryService.Interfaces namespace xCategoryService.Interfaces
{ {
public interface IXCategoryProvider : IXBaseProvided<XCategory, XCategoryDto, int, XCategoryDtoHub> public interface IXCategoryProvider : IXBaseProvided<XCategory, XCategoryDto, int, XCategoryDtoHub>
{ } {
/// <summary>
/// Load an Item by all of it's Related Translations ...
/// </summary>
/// <param name="id"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XCategoryResourceDto> GetResource(
int id,
CancellationToken cancellationToken = default
);
/// <summary>
/// Add Category Item for Specified Language ...
/// </summary>
/// <param name="item"></param>
/// <param name="langauge"></param>
/// <param name="connectionId"></param>
/// <param name="userInfo"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
Task<XCategoryResourceDto> Add(
XCategoryDto item,
string langauge = null,
string connectionId = null,
XUserClaimsInfoDto userInfo = null,
CancellationToken cancellationToken = default
);
}
} }
+16
View File
@@ -0,0 +1,16 @@
using xCategoryService.Models.Dtos;
using xModels.Base;
using xModels.Dtos;
namespace xCategoryService.Providers.Dtos
{
/// <summary>
/// Represent a Category by all of it's Resources ...
/// </summary>
public class XCategoryResourceDto : XBaseDto
{
public XCategoryDto Item { get; set; }
public XResourceDto Titles { get; set; }
public XResourceDto Descriptions { get; set; }
}
}
+94 -36
View File
@@ -1,6 +1,3 @@
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using xCategoryService.Interfaces; using xCategoryService.Interfaces;
@@ -56,35 +53,54 @@ namespace xCategoryService.Providers
return !item.IsNullOrDefault(); return !item.IsNullOrDefault();
} }
// public async Task<(string, string)> LoadResources( /// <summary>
// int id, /// Load an Item by all of it's Related Translations ...
// string language = null /// </summary>
// ) /// <param name="id"></param>
// { /// <param name="cancellationToken"></param>
// // /// <returns></returns>
// // Normalize Language ... public async Task<XCategoryResourceDto> GetResource(
// language = int id,
// !language.IsNullOrEmpty() CancellationToken cancellationToken = default
// ? language )
// : appConfiguration.DefaultLanguage; {
//
var category = await Get(
id: id,
includeBuilder: null,
cancellationToken: cancellationToken
);
var titleResource = await titleResourceProvider.GetResource(
identifier: id,
cancellationToken: cancellationToken
);
var descriptionResource = await titleResourceProvider.GetResource(
identifier: id,
cancellationToken: cancellationToken
);
// // //
// // Validate Args ... var result = new XCategoryResourceDto
// var isValid = {
// id.IsValidIntId() && Item = category,
// !language.IsNullOrEmpty(); Titles = titleResource,
// if (!isValid) Descriptions = descriptionResource
// { };
// XException.InvalidArgs.Throw();
// }
// // //
// // Reading Resources ... return result;
// // var title = await titleResourceProvider.GetResourceLocales() }
// XException.InvalidArgs.Throw();
// }
public async Task<bool> Add( /// <summary>
/// Add Category Item for Specified Language ...
/// </summary>
/// <param name="item"></param>
/// <param name="langauge"></param>
/// <param name="connectionId"></param>
/// <param name="userInfo"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public async Task<XCategoryResourceDto> Add(
XCategoryDto item, XCategoryDto item,
string langauge = null, string langauge = null,
string connectionId = null, string connectionId = null,
@@ -108,6 +124,7 @@ namespace xCategoryService.Providers
} }
// //
var id = -1;
try try
{ {
// //
@@ -117,7 +134,7 @@ namespace xCategoryService.Providers
// //
// Add Item Pure for ID Generating ... // Add Item Pure for ID Generating ...
item = await base.Add( item = await base.Add(
item: item, item: item,
userInfo: userInfo, userInfo: userInfo,
connectionId: null, // Since here We dont want notification ... connectionId: null, // Since here We dont want notification ...
cancellationToken: cancellationToken cancellationToken: cancellationToken
@@ -129,7 +146,7 @@ namespace xCategoryService.Providers
} }
// //
var id = item.Id; id = item.Id;
var titleResourceTitle = await titleResourceProvider.AddOrUpdateItemResourcer( var titleResourceTitle = await titleResourceProvider.AddOrUpdateItemResourcer(
identifier: id, identifier: id,
language: langauge, language: langauge,
@@ -158,18 +175,59 @@ namespace xCategoryService.Providers
connectionId: connectionId, connectionId: connectionId,
cancellationToken: cancellationToken cancellationToken: cancellationToken
); );
var result = XCategoryTitleResourceProvider;
//
return result;
} }
catch catch
{ {
XException.InvalidArgs.Throw(); XException.InvalidArgs.Throw();
} }
//
// Validate Id ...
isValid = id.IsValidIntId();
if (!isValid)
{
XException.ActionFailed.Throw();
}
// //
throw new NotImplementedException(); // Retrieve Category Resourv=ce ...
var result = await GetResource(
id: id,
cancellationToken: cancellationToken
);
//
return result;
}
public async Task<bool> RemoveResaource(
int id,
CancellationToken cancellationToken
)
{
//
// Validate ...
var isValid = id.IsValidIntId();
if (!isValid)
{
XException.InvalidArgs.Throw();
}
//
// Retrieve Resource ...
var resource = await GetResource(
id: id,
cancellationToken: cancellationToken
);
isValid = !resource.IsNullOrDefault();
if (!isValid)
{
XException.NotFound.Throw();
}
//
await titleResourceProvider.RemoveResource();
} }
} }
} }