fix
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
namespace MyOffice.Web.Controllers;
|
||||
|
||||
using AutoMapper;
|
||||
using Core;
|
||||
using Core.Extensions;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
@@ -18,28 +19,29 @@ using Services.Item;
|
||||
public class AccountController : BaseApiController
|
||||
{
|
||||
private readonly ILogger<AccountController> _logger;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly AccountService _accountService;
|
||||
private readonly ItemService _itemService;
|
||||
|
||||
public AccountController(
|
||||
ILogger<AccountController> logger,
|
||||
IMapper mapper,
|
||||
AccountService accountService,
|
||||
ItemService itemService
|
||||
)
|
||||
{
|
||||
_logger = logger;
|
||||
_mapper = mapper;
|
||||
_accountService = accountService;
|
||||
_itemService = itemService;
|
||||
}
|
||||
|
||||
[HttpGet("~/api/accounts")]
|
||||
public object AccountsGet(string category)
|
||||
public List<AccountDetailedViewModel> AccountsGet(string category)
|
||||
{
|
||||
var list = _accountService.GetByCategoryDetailed(UserId, category!.AsGuid());
|
||||
|
||||
return list
|
||||
.OrderBy(x => x.Account.Name)
|
||||
.Select(x => x.ToModel());
|
||||
return _mapper.Map<List<AccountDetailedViewModel>>(list.OrderBy(x => x.Account.Name).ToList());
|
||||
}
|
||||
|
||||
[HttpGet("~/api/accounts/{id}")]
|
||||
@@ -54,7 +56,8 @@ public class AccountController : BaseApiController
|
||||
return ProblemBadRequest("Account not found.");
|
||||
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!.ToModel();
|
||||
return _mapper.Map<AccountDetailedViewModel>(exec.Result);
|
||||
//return exec.Result!.ToModel();
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
namespace MyOffice.Web.Controllers;
|
||||
|
||||
using AutoMapper;
|
||||
using Core;
|
||||
using Core.Extensions;
|
||||
using Data.Models.Accounts;
|
||||
@@ -15,14 +16,17 @@ using Services.Account.Domain;
|
||||
public class SettingsAccountController : BaseApiController
|
||||
{
|
||||
private readonly ILogger<SettingsAccountController> _logger;
|
||||
private readonly IMapper _mapper;
|
||||
private readonly AccountService _accountService;
|
||||
|
||||
public SettingsAccountController(
|
||||
ILogger<SettingsAccountController> logger,
|
||||
IMapper mapper,
|
||||
AccountService accountService
|
||||
)
|
||||
{
|
||||
_logger = logger;
|
||||
_mapper = mapper;
|
||||
_accountService = accountService;
|
||||
}
|
||||
|
||||
@@ -111,15 +115,13 @@ public class SettingsAccountController : BaseApiController
|
||||
}
|
||||
|
||||
[HttpGet("~/api/settings/accounts")]
|
||||
public object AccountsGet(string? category)
|
||||
public List<AccountViewModel> AccountsGet(string? category)
|
||||
{
|
||||
var list = category.IsPresent()
|
||||
? _accountService.GetByCategory(UserId, category!.AsGuid())
|
||||
: _accountService.GetAllAccounts(UserId);
|
||||
|
||||
return list
|
||||
.OrderBy(x => x.Name)
|
||||
.Select(x => x.ToModel());
|
||||
return _mapper.Map<List<AccountViewModel>>(list.OrderBy(x => x.Name));
|
||||
}
|
||||
|
||||
[HttpPost("~/api/settings/accounts")]
|
||||
@@ -130,6 +132,7 @@ public class SettingsAccountController : BaseApiController
|
||||
Name = request.Name,
|
||||
CurrencyId = request.CurrencyId,
|
||||
CategoryId = request.CategoryId.AsGuid(),
|
||||
Type = request.Type,
|
||||
});
|
||||
|
||||
switch (exec.Status)
|
||||
@@ -158,6 +161,7 @@ public class SettingsAccountController : BaseApiController
|
||||
CurrencyId = request.CurrencyId,
|
||||
CategoryId = request.CategoryId?.AsGuidNull(),
|
||||
UserId = request.UserId?.AsGuidNull(),
|
||||
Type = request.Type,
|
||||
});
|
||||
|
||||
switch (exec.Status)
|
||||
@@ -177,7 +181,23 @@ public class SettingsAccountController : BaseApiController
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HttpDelete("~/api/settings/accounts/{id}")]
|
||||
public object AccountsDelete(string id)
|
||||
{
|
||||
var exec = _accountService.AccountDelete(UserId, id);
|
||||
switch (exec.Status)
|
||||
{
|
||||
case GeneralExecStatus.not_found:
|
||||
return ProblemBadRequest("Account not found.");
|
||||
case GeneralExecStatus.success:
|
||||
return exec.Result!;
|
||||
|
||||
default:
|
||||
throw new NotSupportedException(exec.Status.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[HttpDelete("~/api/settings/accounts/{id}/category/{categoryId}")]
|
||||
public object AccountsCategoryRemove(string id, string categoryId)
|
||||
{
|
||||
|
||||
@@ -13,6 +13,7 @@ using MyOffice.Core.Identity;
|
||||
using Core;
|
||||
using Services.Users;
|
||||
using Services.Users.Domain;
|
||||
using MyOffice.Data.Models.Currencies;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
@@ -40,7 +41,8 @@ public class UserController : BaseApiController
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
UserName = request.UserName,
|
||||
Email = request.UserName
|
||||
Email = request.UserName,
|
||||
CurrencyId = CurrencyGlobalIdEnum.USD.ToString(),
|
||||
};
|
||||
|
||||
var result = await _userManager.CreateAsync(user, request.Password);
|
||||
|
||||
@@ -20,7 +20,6 @@ public class ConfigureIdentityServerOptions : IConfigureNamedOptions<IdentitySer
|
||||
|
||||
public void Configure(string? name, IdentityServerAuthenticationOptions options)
|
||||
{
|
||||
//_logger.LogError($"Configure: {_globalSettings.Host}");
|
||||
if (name == IdentityServerAuthenticationDefaults.AuthenticationScheme)
|
||||
{
|
||||
options.RequireHttpsMetadata = false;
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
namespace MyOffice.Web.Identity;
|
||||
|
||||
using Data.Repositories.Users;
|
||||
using MyOffice.Data.Models.Users;
|
||||
using MyOffice.Services.Identity;
|
||||
|
||||
public class ContextProvider : IContextProvider
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly IUserRepository _userRepository;
|
||||
|
||||
public ContextProvider(
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
IUserRepository userRepository
|
||||
)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_userRepository = userRepository;
|
||||
}
|
||||
|
||||
private User? _user = null;
|
||||
public User User
|
||||
{
|
||||
get
|
||||
{
|
||||
_user ??= _userRepository.GetUser(UserId);
|
||||
|
||||
return _user!;
|
||||
}
|
||||
}
|
||||
|
||||
public Guid UserId
|
||||
{
|
||||
get
|
||||
{
|
||||
return Guid.Parse(_httpContextAccessor!.HttpContext!.User!.Claims!.FirstOrDefault(x => x.Type == "sub")!.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
namespace MyOffice.Web.Models.Account
|
||||
{
|
||||
using Data.Models.Accounts;
|
||||
using Services.Account.Domain;
|
||||
using User;
|
||||
|
||||
public class AccessRightsViewModel
|
||||
@@ -13,7 +14,7 @@
|
||||
|
||||
public static class AccessRightsViewModelExtensions
|
||||
{
|
||||
public static AccessRightsViewModel ToModel(this AccountAccess accountAccess)
|
||||
public static AccessRightsViewModel ToModel(this AccountAccessDto accountAccess)
|
||||
{
|
||||
return new AccessRightsViewModel
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
namespace MyOffice.Web.Models.Account;
|
||||
|
||||
using Data.Models.Accounts;
|
||||
using Services.Account.Domain;
|
||||
|
||||
public class AccountDetailedViewModel
|
||||
{
|
||||
@@ -8,9 +9,9 @@ public class AccountDetailedViewModel
|
||||
public decimal Rest { get; set; }
|
||||
}
|
||||
|
||||
public static class AccountDetailedViewModelExtensions
|
||||
/*public static class AccountDetailedViewModelExtensions
|
||||
{
|
||||
public static AccountDetailedViewModel ToModel(this AccountDetailed input)
|
||||
public static AccountDetailedViewModel ToModel(this AccountDetailedDto input)
|
||||
{
|
||||
return new AccountDetailedViewModel
|
||||
{
|
||||
@@ -18,4 +19,4 @@ public static class AccountDetailedViewModelExtensions
|
||||
Rest = input.Rest,
|
||||
};
|
||||
}
|
||||
}
|
||||
}*/
|
||||
@@ -8,6 +8,7 @@ public class AccountEditRequestModel
|
||||
public string Name { get; set; } = null!;
|
||||
[Required]
|
||||
public string CurrencyId { get; set; } = null!;
|
||||
public string? CategoryId { get; set; } = null!;
|
||||
public string? UserId { get; set; } = null!;
|
||||
public string? CategoryId { get; set; }
|
||||
public string? UserId { get; set; }
|
||||
public string? Type { get; set; }
|
||||
}
|
||||
@@ -1,19 +1,25 @@
|
||||
namespace MyOffice.Web.Models.Account
|
||||
{
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using AutoMapper;
|
||||
using Core.Extensions;
|
||||
using Data.Models.Accounts;
|
||||
using Services.Account.Domain;
|
||||
using Services.Identity;
|
||||
using User;
|
||||
|
||||
public class AccountViewModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
|
||||
[Required]
|
||||
[Required]
|
||||
public string Name { get; set; } = null!;
|
||||
public string Type { get; set; } = null!;
|
||||
|
||||
[Required]
|
||||
[Required]
|
||||
public string CurrencyId { get; set; } = null!;
|
||||
public string? CurrencyName { get; set; }
|
||||
public bool AllowDelete { get; set; }
|
||||
|
||||
public List<AccountCategoryViewModel>? Categories { get; set; }
|
||||
|
||||
@@ -23,9 +29,48 @@
|
||||
public List<AccessRightsViewModel>? AccessRights { get; set; }
|
||||
}
|
||||
|
||||
public static class AccountViewModelExtensions
|
||||
public class ViewModelProfile : Profile
|
||||
{
|
||||
public static AccountViewModel ToModel(this Account input)
|
||||
public ViewModelProfile()
|
||||
{
|
||||
CreateMap<Guid, string>().ConvertUsing(x => x.ToShort());
|
||||
}
|
||||
}
|
||||
|
||||
public class AccountViewModelProfile : Profile
|
||||
{
|
||||
public AccountViewModelProfile(
|
||||
IContextProvider contextProvider
|
||||
)
|
||||
{
|
||||
|
||||
CreateMap<AccountDetailedDto, AccountDetailedViewModel>()
|
||||
.ForMember(x => x.Account, o => o.MapFrom(x => x.Account))
|
||||
;
|
||||
|
||||
CreateMap<UserDto, UserViewModel>();
|
||||
|
||||
CreateMap<MyOffice.Data.Models.Users.User, UserViewModel>();
|
||||
|
||||
CreateMap<AccountDto, AccountViewModel>()
|
||||
.ForMember(x => x.Type, o => o.MapFrom(x => x.AccessRights!.FirstOrDefault(a => a.UserId == contextProvider.UserId)!.Type.ToString()))
|
||||
.ForMember(x => x.CurrencyId, o => o.MapFrom(x => x.CurrencyGlobalId))
|
||||
.ForMember(x => x.CurrencyName, o => o.MapFrom(x => x.Currency!.Name))
|
||||
.ForMember(x => x.AllowDelete, o => o.MapFrom(x => !x.HasMotions))
|
||||
;
|
||||
|
||||
CreateMap<AccountAccountCategoryDto, AccountCategoryViewModel>()
|
||||
.ForMember(x => x.Id, o => o.MapFrom(x => x.CategoryId))
|
||||
.ForMember(x => x.Name, o => o.MapFrom(x => x.Category!.Name))
|
||||
;
|
||||
|
||||
CreateMap<AccountAccessDto, AccessRightsViewModel>();
|
||||
}
|
||||
}
|
||||
|
||||
/*public static class AccountViewModelExtensions
|
||||
{
|
||||
public static AccountViewModel ToModel(this AccountDto input)
|
||||
{
|
||||
return new AccountViewModel
|
||||
{
|
||||
@@ -41,5 +86,5 @@
|
||||
.ToList(),
|
||||
};
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
<PackageReference Include="Auth0.AuthenticationApi" Version="7.17.4" />
|
||||
<PackageReference Include="Auth0.Core" Version="7.17.4" />
|
||||
<PackageReference Include="Auth0.ManagementApi" Version="7.17.4" />
|
||||
<PackageReference Include="AutoMapper" Version="12.0.1" />
|
||||
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
|
||||
<PackageReference Include="Google.Apis.Auth" Version="1.58.0-beta01" />
|
||||
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="3.0.1" />
|
||||
<PackageReference Include="IdentityServer4.AspNetIdentity" Version="4.1.2" />
|
||||
|
||||
+36
-2
@@ -37,10 +37,14 @@ using Identity.Configure;
|
||||
using Infrastructure;
|
||||
using Microsoft.Extensions.Logging.Console;
|
||||
using IdentityServer4.Services;
|
||||
using Models.Account;
|
||||
using MyOffice.Services.Currency;
|
||||
using Services.Account;
|
||||
using Services.Item;
|
||||
using MyOffice.Services.Dashboard;
|
||||
using Services.Account.Domain;
|
||||
using MyOffice.Services.Identity;
|
||||
using AutoMapper;
|
||||
|
||||
public class Program
|
||||
{
|
||||
@@ -92,6 +96,10 @@ public class Program
|
||||
|
||||
AddIdentityServices(builder);
|
||||
|
||||
builder.Services.AddScoped<IContextProvider, ContextProvider>();
|
||||
|
||||
AddMapping(builder);
|
||||
|
||||
AddRepositories(builder);
|
||||
|
||||
AddBusinessServices(builder);
|
||||
@@ -205,6 +213,20 @@ public class Program
|
||||
}
|
||||
}
|
||||
|
||||
private static void AddMapping(WebApplicationBuilder builder)
|
||||
{
|
||||
builder.Services.AddSingleton(provider => new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.AddProfile(new AccountMappingProfile());
|
||||
cfg.AddProfile(new ViewModelProfile());
|
||||
cfg.AddProfile(new AccountViewModelProfile(provider.CreateScope().ServiceProvider.GetService<IContextProvider>()!));
|
||||
}).CreateMapper());
|
||||
|
||||
//builder.Services.AddAutoMapper(typeof(AccountMappingProfile));
|
||||
//builder.Services.AddAutoMapper(typeof(AccountViewModelProfile));
|
||||
//builder.Services.AddAutoMapper(typeof(ViewModelProfile));
|
||||
}
|
||||
|
||||
private static void AddRepositories(WebApplicationBuilder builder)
|
||||
{
|
||||
builder.Services.AddScoped<IUserRepository, UserRepository>();
|
||||
@@ -216,6 +238,7 @@ public class Program
|
||||
|
||||
builder.Services.AddScoped<IAccountCategoryRepository, AccountCategoryRepository>();
|
||||
builder.Services.AddScoped<IAccountRepository, AccountRepository>();
|
||||
builder.Services.AddScoped<IAccountAccessRepository, AccountAccessRepository>();
|
||||
builder.Services.AddScoped<IAccountAccountCategoryRepository, AccountAccountCategoryRepository>();
|
||||
|
||||
builder.Services.AddScoped<IItemCategoryRepository, ItemCategoryRepository>();
|
||||
@@ -274,9 +297,20 @@ public class Program
|
||||
{
|
||||
_firstRequest = false;
|
||||
|
||||
// set real frontend host
|
||||
globalSettings = ctx.RequestServices.GetRequiredService<GlobalSettings>();
|
||||
globalSettings.Host = GetFrontendHost(ctx, logger);
|
||||
|
||||
var configuration = ctx.RequestServices.GetRequiredService<IConfiguration>();
|
||||
var frontEndHost = configuration.GetValue<string>("FrontEnd:Host");
|
||||
var isDynamicFrontEndHost = frontEndHost.IsMissing();
|
||||
if (!isDynamicFrontEndHost)
|
||||
{
|
||||
globalSettings.Host = frontEndHost;
|
||||
}
|
||||
else
|
||||
{
|
||||
// set real frontend host
|
||||
globalSettings.Host = GetFrontendHost(ctx, logger);
|
||||
}
|
||||
|
||||
// update identity server
|
||||
var options = ctx.RequestServices.GetRequiredService<IdentityServerOptions>();
|
||||
|
||||
Reference in New Issue
Block a user