diff --git a/Aberwyn/Controllers/AdminController.cs b/Aberwyn/Controllers/AdminController.cs index 7599e0f..bbc109c 100644 --- a/Aberwyn/Controllers/AdminController.cs +++ b/Aberwyn/Controllers/AdminController.cs @@ -305,18 +305,19 @@ namespace Aberwyn.Controllers existing.Title = task.Title; existing.Status = task.Status; existing.Priority = task.Priority; + existing.Description = task.Description; + existing.Tags = task.Tags; + existing.AssignedTo = task.AssignedTo; + existing.IsArchived = task.IsArchived; _context.SaveChanges(); return Ok(); } - - - } - public class AdminUserViewModel + public class AdminUserViewModel { public string UserId { get; set; } public string Email { get; set; } diff --git a/Aberwyn/Data/ApplicationDbContextFactory.cs b/Aberwyn/Data/ApplicationDbContextFactory.cs index 5916799..284459f 100644 --- a/Aberwyn/Data/ApplicationDbContextFactory.cs +++ b/Aberwyn/Data/ApplicationDbContextFactory.cs @@ -1,8 +1,10 @@ -using Microsoft.EntityFrameworkCore; +using Aberwyn.Models; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; using Microsoft.Extensions.Configuration; using System; using System.IO; +using System.Text.Json; namespace Aberwyn.Data { @@ -10,47 +12,59 @@ namespace Aberwyn.Data { public ApplicationDbContext CreateDbContext(string[] args) { - var basePath = Directory.GetCurrentDirectory(); - var config = new ConfigurationBuilder() - .SetBasePath(basePath) - .AddJsonFile("appsettings.json", optional: false) - .AddJsonFile("appsettings.Development.json", optional: true) - .AddEnvironmentVariables() - .Build(); + var setup = LoadSetup(); - var connectionString = config.GetConnectionString("DefaultConnection"); - - File.WriteAllText("connection-log.txt", $"Connection string: {connectionString}"); - Console.WriteLine($"Anslutningssträng: {connectionString}"); - - if (string.IsNullOrEmpty(connectionString)) + var csBuilder = new MySqlConnector.MySqlConnectionStringBuilder { - throw new InvalidOperationException("Connection string 'DefaultConnection' not found."); - } + Server = setup.DbHost, + Port = (uint)setup.DbPort, + Database = setup.DbName, + UserID = setup.DbUser, + Password = setup.DbPassword, + AllowUserVariables = true + }; var optionsBuilder = new DbContextOptionsBuilder(); - optionsBuilder.UseMySql( - connectionString, - new MySqlServerVersion(new Version(8, 0, 36))); + optionsBuilder.UseMySql(csBuilder.ConnectionString, new MySqlServerVersion(new Version(8, 0, 36))); return new ApplicationDbContext(optionsBuilder.Options); } + public static ApplicationDbContext CreateWithConfig(IConfiguration config, IHostEnvironment env, bool useProdDb = false) { - var connectionString = useProdDb - ? config.GetConnectionString("ProdConnection") // <--- FIX HÄR - : config.GetConnectionString("DefaultConnection"); + var setup = LoadSetup(); - if (string.IsNullOrWhiteSpace(connectionString)) - throw new InvalidOperationException("Connection string saknas."); + var csBuilder = new MySqlConnector.MySqlConnectionStringBuilder + { + Server = setup.DbHost, + Port = (uint)setup.DbPort, + Database = setup.DbName, + UserID = setup.DbUser, + Password = setup.DbPassword, + AllowUserVariables = true + }; var optionsBuilder = new DbContextOptionsBuilder(); - optionsBuilder.UseMySql(connectionString, new MySqlServerVersion(new Version(8, 0, 36))); + optionsBuilder.UseMySql(csBuilder.ConnectionString, new MySqlServerVersion(new Version(8, 0, 36))); return new ApplicationDbContext(optionsBuilder.Options); } + private static SetupSettings LoadSetup() + { + var basePath = Directory.GetCurrentDirectory(); + var setupPath = Path.Combine(basePath, "infrastructure", "setup.json"); + if (!File.Exists(setupPath)) + throw new FileNotFoundException("setup.json saknas i infrastructure-mappen."); + var json = File.ReadAllText(setupPath); + var setup = JsonSerializer.Deserialize(json); + + if (setup == null || !setup.IsConfigured) + throw new InvalidOperationException("setup.json är inte korrekt konfigurerad."); + + return setup; + } } } diff --git a/Aberwyn/Data/MenuService.cs b/Aberwyn/Data/MenuService.cs index 405dc2b..334bfd0 100644 --- a/Aberwyn/Data/MenuService.cs +++ b/Aberwyn/Data/MenuService.cs @@ -16,20 +16,38 @@ public class MenuService _context = context; } - // Detta är en alternativ konstruktör – används manuellt vid t.ex. import - public static MenuService CreateWithConfig(IConfiguration config, IHostEnvironment env, bool useProdDb = false) - { - var builder = new DbContextOptionsBuilder(); + // Detta är en alternativ konstruktör – används manuellt vid t.ex. import + public static MenuService CreateWithConfig(IConfiguration config, IHostEnvironment env, bool useProdDb = false) + { + var basePath = env.ContentRootPath ?? Directory.GetCurrentDirectory(); + var setupPath = Path.Combine(basePath, "infrastructure", "setup.json"); - var connStr = useProdDb - ? config.GetConnectionString("ProdConnection") - : config.GetConnectionString("DefaultConnection"); + if (!File.Exists(setupPath)) + throw new FileNotFoundException("setup.json saknas i infrastructure/"); - builder.UseMySql(connStr, ServerVersion.AutoDetect(connStr)); - var context = new ApplicationDbContext(builder.Options); + var setupJson = File.ReadAllText(setupPath); + var setup = System.Text.Json.JsonSerializer.Deserialize(setupJson)!; + + if (!setup.IsConfigured || string.IsNullOrWhiteSpace(setup.DbPassword)) + throw new InvalidOperationException("setup.json är ofullständig."); + + var csBuilder = new MySqlConnector.MySqlConnectionStringBuilder + { + Server = setup.DbHost, + Port = (uint)setup.DbPort, + Database = setup.DbName, + UserID = setup.DbUser, + Password = setup.DbPassword, + AllowUserVariables = true + }; + + var builder = new DbContextOptionsBuilder(); + builder.UseMySql(csBuilder.ConnectionString, ServerVersion.AutoDetect(csBuilder.ConnectionString)); + + var context = new ApplicationDbContext(builder.Options); + return new MenuService(context); + } - return new MenuService(context); - } public void UpdateWeeklyMenu(MenuViewModel model) { var existing = _context.WeeklyMenus diff --git a/Aberwyn/Views/Admin/Todo.cshtml b/Aberwyn/Views/Admin/Todo.cshtml index e9a24a5..1f8a049 100644 --- a/Aberwyn/Views/Admin/Todo.cshtml +++ b/Aberwyn/Views/Admin/Todo.cshtml @@ -80,8 +80,19 @@
- {{ task.Title }} + task="task" + ng-if="!task.IsArchived"> + + {{ task.Title }} + +
+ 👤 {{ task.AssignedTo || 'Ingen' }}
+ 🏷️ {{ task.Tags }}
+ 📅 {{ task.CreatedAt | date:'yyyy-MM-dd HH:mm' }} +
+ +

{{ task.Description }}

+
Prioritet: + + +
+