AdminPanel/Netina.AdminPanel.PWA/Services/RestServices/RestWrapper.cs

41 lines
3.4 KiB
C#

namespace Netina.AdminPanel.PWA.Services.RestServices;
public class RestWrapper(IConfiguration configuration) : IRestWrapper
{
private string baseApiAddress = configuration.GetValue<string>("ApiUrl") ?? string.Empty;
private static RefitSettings setting = new RefitSettings(new NewtonsoftJsonContentSerializer(new JsonSerializerSettings
{
Formatting = Newtonsoft.Json.Formatting.Indented,
ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore,
}));
public ICrudApiRest<T, TKey> CrudApiRest<T, TKey>(string address) where T : class
{
return RestService.For<ICrudApiRest<T, TKey>>(baseApiAddress + address, setting);
}
public ICrudDtoApiRest<T, TDto, TKey> CrudDtoApiRest<T, TDto, TKey>(string address) where T : class where TDto : class
{
return RestService.For<ICrudDtoApiRest<T, TDto, TKey>>(baseApiAddress + address, setting);
}
public IAuthRestApi AuthRestApi => RestService.For<IAuthRestApi>($"{baseApiAddress}{Address.AuthController}", setting);
public IUserRestApi UserRestApi => RestService.For<IUserRestApi>($"{baseApiAddress}{Address.UserController}", setting);
public IProductCategoryRestApi ProductCategoryRestApi => RestService.For<IProductCategoryRestApi>($"{baseApiAddress}{Address.ProductCategoryController}", setting);
public IProductRestApi ProductRestApi => RestService.For<IProductRestApi>($"{baseApiAddress}{Address.ProductController}", setting);
public IBrandRestApi BrandRestApi => RestService.For<IBrandRestApi>($"{baseApiAddress}{Address.BrandController}", setting);
public IFileRestApi FileRestApi => RestService.For<IFileRestApi>($"{baseApiAddress}{Address.FileController}", setting);
public IBlogRestApi BlogRestApi => RestService.For<IBlogRestApi>($"{baseApiAddress}{Address.BlogController}", setting);
public IDiscountRestApi DiscountRest => RestService.For<IDiscountRestApi>($"{baseApiAddress}{Address.DiscountController}",setting);
public IReviewRestApi ReviewRestApi => RestService.For<IReviewRestApi>($"{baseApiAddress}{Address.CommentController}", setting);
public IBlogCategoryRestApi BlogCategoryRestApi => RestService.For<IBlogCategoryRestApi>($"{baseApiAddress}{Address.BlogCategoryController}", setting);
public IRoleRestApi RoleRestApi => RestService.For<IRoleRestApi>($"{baseApiAddress}{Address.RoleController}", setting);
public IOrderRestApi OrderRestApi => RestService.For<IOrderRestApi>($"{baseApiAddress}{Address.OrderController}", setting);
public IPaymentRestApi PaymentRestApi => RestService.For<IPaymentRestApi>($"{baseApiAddress}{Address.PaymentController}", setting);
public IPageRestApi PageRestApi => RestService.For<IPageRestApi>($"{baseApiAddress}{Address.PageController}", setting);
public IScraperRestApi ScraperRestApi => RestService.For<IScraperRestApi>($"{baseApiAddress}{Address.ScraperController}", setting);
public ISettingRestApi SettingRestApi => RestService.For<ISettingRestApi>($"{baseApiAddress}{Address.SettingController}", setting);
public IDashboardApiRest DashboardApiRest => RestService.For<IDashboardApiRest>($"{baseApiAddress}{Address.DashboardController}", setting);
public IDistrictApiRest DistrictApiRest => RestService.For<IDistrictApiRest>($"{baseApiAddress}{Address.DistrictController}", setting);
public IFaqApiRest FaqApiRest => RestService.For<IFaqApiRest>($"{baseApiAddress}{Address.FaqController}", setting);
}