From c7062b4d6d230e697791c1ad73a7d356c21e3d70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mate=20Anti=C4=8Devi=C4=87?= Date: Wed, 8 Apr 2020 00:05:12 +0200 Subject: [PATCH] App modules added --- .../Handlers/Security/SecurityHandler.cs | 1 + .../Handlers/User/UserHandler.cs | 2 ++ .../Handlers/Webhooks/DialogflowHandler.cs | 4 ++-- src/ProjectIvy.Data/DbContexts/MainContext.cs | 3 +++ .../Database/Main/App/Application.cs | 2 +- .../Database/Main/App/Module.cs | 16 ++++++++++++++ .../Database/Main/User/User.cs | 2 ++ .../Database/Main/User/UserModule.cs | 21 +++++++++++++++++++ src/ProjectIvy.Model/View/User/User.cs | 3 +++ 9 files changed, 51 insertions(+), 3 deletions(-) create mode 100644 src/ProjectIvy.Model/Database/Main/App/Module.cs create mode 100644 src/ProjectIvy.Model/Database/Main/User/UserModule.cs diff --git a/src/ProjectIvy.Business/Handlers/Security/SecurityHandler.cs b/src/ProjectIvy.Business/Handlers/Security/SecurityHandler.cs index 9144a2b2..1d059294 100644 --- a/src/ProjectIvy.Business/Handlers/Security/SecurityHandler.cs +++ b/src/ProjectIvy.Business/Handlers/Security/SecurityHandler.cs @@ -24,6 +24,7 @@ public Model.Database.Main.User.User GetUser(string token) { return db.AccessTokens.Include(x => x.User) .ThenInclude(x => x.DefaultCurrency) + .Include(x => x.User) .SingleOrDefault(x => x.Token == token && x.IsActive) .User; } diff --git a/src/ProjectIvy.Business/Handlers/User/UserHandler.cs b/src/ProjectIvy.Business/Handlers/User/UserHandler.cs index 953e769b..3384075e 100644 --- a/src/ProjectIvy.Business/Handlers/User/UserHandler.cs +++ b/src/ProjectIvy.Business/Handlers/User/UserHandler.cs @@ -37,6 +37,8 @@ public View.User Get(int? id = null) var userEntity = db.Users.Include(x => x.UserRoles) .ThenInclude(x => x.Role) .Include(x => x.DefaultCurrency) + .Include(x => x.Modules) + .Include("Modules.Module") .SingleOrDefault(x => x.Id == id); return new View.User(userEntity); diff --git a/src/ProjectIvy.Business/Handlers/Webhooks/DialogflowHandler.cs b/src/ProjectIvy.Business/Handlers/Webhooks/DialogflowHandler.cs index c60b7df1..b72da89f 100644 --- a/src/ProjectIvy.Business/Handlers/Webhooks/DialogflowHandler.cs +++ b/src/ProjectIvy.Business/Handlers/Webhooks/DialogflowHandler.cs @@ -90,7 +90,7 @@ public async Task CreateExpense(GoogleCl CurrencyId = string.IsNullOrEmpty(currencyId) ? User.DefaultCurrency.Code : currencyId, Comment = (string)request.QueryResult.Parameters["description"], Date = (DateTime)request.QueryResult.Parameters["date"], - ExpenseTypeId = (string)request.QueryResult.Parameters["expense-type"], + ExpenseTypeId = ((string)request.QueryResult.Parameters["expense-type"]).Replace(" ", "-"), NeedsReview = true, PaymentTypeId = (string)request.QueryResult.Parameters["payment-type"] }; @@ -148,7 +148,7 @@ public async Task GetExpenseSum(GoogleCl { var binding = new ExpenseSumGetBinding(request.ToFilteredBinding()); - binding.TypeId = request.QueryResult.Parameters.ContainsKey("ExpenseType") ? ((JArray)request.QueryResult.Parameters["ExpenseType"]).Select(x => (string)x) : null; + binding.TypeId = request.QueryResult.Parameters.ContainsKey("ExpenseType") ? ((JArray)request.QueryResult.Parameters["ExpenseType"]).Select(x => ((string)x).Replace(" ", "-")) : null; decimal sum = await _expenseHandler.SumAmount(binding); diff --git a/src/ProjectIvy.Data/DbContexts/MainContext.cs b/src/ProjectIvy.Data/DbContexts/MainContext.cs index 630a275a..5a4cecd1 100644 --- a/src/ProjectIvy.Data/DbContexts/MainContext.cs +++ b/src/ProjectIvy.Data/DbContexts/MainContext.cs @@ -283,6 +283,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity() .HasKey(x => new { x.UserId, x.RoleId }); + modelBuilder.Entity() + .HasKey(x => new { x.UserId, x.ModuleId }); + modelBuilder.Entity() .HasOne(x => x.User) .WithMany(x => x.UserRoles); diff --git a/src/ProjectIvy.Model/Database/Main/App/Application.cs b/src/ProjectIvy.Model/Database/Main/App/Application.cs index fc57f1de..e7eede9a 100644 --- a/src/ProjectIvy.Model/Database/Main/App/Application.cs +++ b/src/ProjectIvy.Model/Database/Main/App/Application.cs @@ -4,7 +4,7 @@ namespace ProjectIvy.Model.Database.Main.App { - [Table("Application", Schema = "App")] + [Table(nameof(Application), Schema = nameof(App))] public class Application : IHasValueId { [Key] diff --git a/src/ProjectIvy.Model/Database/Main/App/Module.cs b/src/ProjectIvy.Model/Database/Main/App/Module.cs new file mode 100644 index 00000000..f7a5efbe --- /dev/null +++ b/src/ProjectIvy.Model/Database/Main/App/Module.cs @@ -0,0 +1,16 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace ProjectIvy.Model.Database.Main.App +{ + [Table(nameof(Module), Schema = nameof(App))] + public class Module : IHasValueId + { + [Key] + public int Id { get; set; } + + public string ValueId { get; set; } + + public string Name { get; set; } + } +} diff --git a/src/ProjectIvy.Model/Database/Main/User/User.cs b/src/ProjectIvy.Model/Database/Main/User/User.cs index 35c537ec..4fc99180 100644 --- a/src/ProjectIvy.Model/Database/Main/User/User.cs +++ b/src/ProjectIvy.Model/Database/Main/User/User.cs @@ -46,5 +46,7 @@ public class User : IHasCreatedModified public ICollection UserRoles { get; set; } public ICollection Trackings { get; set; } + + public ICollection Modules { get; set; } } } diff --git a/src/ProjectIvy.Model/Database/Main/User/UserModule.cs b/src/ProjectIvy.Model/Database/Main/User/UserModule.cs new file mode 100644 index 00000000..1fa87a68 --- /dev/null +++ b/src/ProjectIvy.Model/Database/Main/User/UserModule.cs @@ -0,0 +1,21 @@ +using System; +using System.ComponentModel.DataAnnotations.Schema; + +namespace ProjectIvy.Model.Database.Main.User +{ + [Table(nameof(UserModule), Schema = nameof(User))] + public class UserModule + { + public int UserId { get; set; } + + public int ModuleId { get; set; } + + public bool IsActive { get; set; } + + public DateTime AvailableFrom { get; set; } + + public User User { get; set; } + + public App.Module Module { get; set; } + } +} diff --git a/src/ProjectIvy.Model/View/User/User.cs b/src/ProjectIvy.Model/View/User/User.cs index 18aa95df..8fded101 100644 --- a/src/ProjectIvy.Model/View/User/User.cs +++ b/src/ProjectIvy.Model/View/User/User.cs @@ -14,6 +14,7 @@ public User(DatabaseModel.User.User x) Email = x.Email; Username = x.Username; Roles = x.UserRoles.Select(y => new Role.Role(y.Role)); + Modules = x.Modules.Where(x => x.IsActive).Select(x => x.Module.ValueId); } public Currency.Currency DefaultCurrency { get; set; } @@ -27,5 +28,7 @@ public User(DatabaseModel.User.User x) public string Username { get; set; } public IEnumerable Roles { get; set; } + + public IEnumerable Modules { get; set; } } }