From 2350935e8a665275bd7f258664096f52e0448f19 Mon Sep 17 00:00:00 2001 From: eee4 <41441600+eee4@users.noreply.github.com> Date: Thu, 17 Jul 2025 10:55:38 +0200 Subject: [PATCH] fix: fixes to addQuote (don't require categories nor imageUrl) also sends back role upon login --- Controllers/QuoteController.cs | 4 ++-- Controllers/Seed.cs | 3 ++- DTOs/CreateQuoteDTO.cs | 2 +- DTOs/UserInfoDTO.cs | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Controllers/QuoteController.cs b/Controllers/QuoteController.cs index 6a13c86..491f6e5 100644 --- a/Controllers/QuoteController.cs +++ b/Controllers/QuoteController.cs @@ -141,13 +141,13 @@ public class QuotesController : ControllerBase Author = request.Author, CreatedAt = DateTime.UtcNow, LastUpdatedAt = DateTime.UtcNow, - ImageId = image?.Id ?? 0, + ImageId = image?.Id ?? null, UserId = userId, QuoteCategories = new List() }; // Attach categories - foreach (var categoryId in request.CategoryIds) + foreach (var categoryId in request.CategoryIds ?? []) { var categoryExists = await _db.Categories.AnyAsync(c => c.Id == categoryId); if (!categoryExists) diff --git a/Controllers/Seed.cs b/Controllers/Seed.cs index d230c29..76e6250 100644 --- a/Controllers/Seed.cs +++ b/Controllers/Seed.cs @@ -29,7 +29,8 @@ namespace QuotifyBE.Controllers Name="admin", Email = "admin@mail.com", // hashed twice, once by frontend, and second time by backend - PasswordHash = guhf.HashWithSHA512(guhf.HashWithSHA512("admin")) + PasswordHash = guhf.HashWithSHA512(guhf.HashWithSHA512("admin")), + Role = 0 // role 0 - greatest power, admin, role 0 > role 1 }; _db.Users.Add(Admin); await _db.SaveChangesAsync(); diff --git a/DTOs/CreateQuoteDTO.cs b/DTOs/CreateQuoteDTO.cs index 7e95485..f50a530 100644 --- a/DTOs/CreateQuoteDTO.cs +++ b/DTOs/CreateQuoteDTO.cs @@ -2,6 +2,6 @@ public record class CreateQuoteDTO { public string Text { get; set; } public string Author { get; set; } - public List CategoryIds { get; set; } + public List? CategoryIds { get; set; } public string? ImageUrl { get; set; } }; diff --git a/DTOs/UserInfoDTO.cs b/DTOs/UserInfoDTO.cs index 548168d..f30dbda 100644 --- a/DTOs/UserInfoDTO.cs +++ b/DTOs/UserInfoDTO.cs @@ -5,6 +5,6 @@ public record class UserInfoDTO public int Id { get; set; } required public string Name { get; set; } required public string Email { get; set; } - public int Role { get; set; } + public int Role { get; set; } };