From 3f1bfc1c3ca2686f338292cedbd80e054f7aa76d Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sun, 29 Jun 2025 19:53:56 +0100 Subject: [PATCH] fixies the refact of blog spot index --- src/Yavsc.Abstract/Blogspot/IBlog.cs | 5 ++++- .../Google/Messaging/MessageWithPayloadResponse.cs | 2 +- src/Yavsc.Abstract/Identity/IApplicationUser.cs | 10 +++++----- .../Identity/Security/ICircleAuthorized.cs | 2 +- src/Yavsc.Server/Models/ApplicationUser.cs | 13 +++++++++---- src/Yavsc.Server/Models/Blog/BlogPost.cs | 5 +++-- src/Yavsc.Server/Models/societe.com/CompanyInfo.cs | 8 ++++---- .../Communicating/BlogspotController.cs | 2 +- src/Yavsc/Extensions/PermissionHandler.cs | 2 +- .../ViewComponents/CirclesControlViewComponent.cs | 2 +- src/Yavsc/Views/Blogspot/Index.cshtml | 2 +- .../Shared/DisplayTemplates/ApplicationUser.cshtml | 14 +++++--------- .../DisplayTemplates/IApplicationUser.cshtml | 10 ++++++++++ 13 files changed, 46 insertions(+), 31 deletions(-) create mode 100644 src/Yavsc/Views/Shared/DisplayTemplates/IApplicationUser.cshtml diff --git a/src/Yavsc.Abstract/Blogspot/IBlog.cs b/src/Yavsc.Abstract/Blogspot/IBlog.cs index 7c7b2bff..8d226a10 100644 --- a/src/Yavsc.Abstract/Blogspot/IBlog.cs +++ b/src/Yavsc.Abstract/Blogspot/IBlog.cs @@ -1,6 +1,8 @@  +using Yavsc.Abstract.Identity; + namespace Yavsc { public interface IBlogPostPayLoad @@ -9,8 +11,9 @@ namespace Yavsc string? Photo { get; set; } } - public interface IBlogPost :IBlogPostPayLoad, ITrackedEntity, IIdentified, ITitle + public interface IBlogPost : IBlogPostPayLoad, ITrackedEntity, IIdentified, ITitle { string AuthorId { get; set; } + IApplicationUser Author { get; } } } diff --git a/src/Yavsc.Abstract/Google/Messaging/MessageWithPayloadResponse.cs b/src/Yavsc.Abstract/Google/Messaging/MessageWithPayloadResponse.cs index 308b6a57..59538ca6 100644 --- a/src/Yavsc.Abstract/Google/Messaging/MessageWithPayloadResponse.cs +++ b/src/Yavsc.Abstract/Google/Messaging/MessageWithPayloadResponse.cs @@ -54,7 +54,7 @@ namespace Yavsc.Models.Google.Messaging /// /// The error. /// - public string error; + public string? error; } /// diff --git a/src/Yavsc.Abstract/Identity/IApplicationUser.cs b/src/Yavsc.Abstract/Identity/IApplicationUser.cs index 6a72d8b9..5d1d5b1c 100644 --- a/src/Yavsc.Abstract/Identity/IApplicationUser.cs +++ b/src/Yavsc.Abstract/Identity/IApplicationUser.cs @@ -3,10 +3,10 @@ public interface IApplicationUser { string Id { get; set; } - string UserName { get; set; } - string Avatar { get ; set; } - IAccountBalance AccountBalance { get; set; } - string DedicatedGoogleCalendar { get; set; } - ILocation PostalAddress { get; set; } + string? UserName { get; set; } + string? Avatar { get ; set; } + IAccountBalance? AccountBalance { get; } + string? DedicatedGoogleCalendar { get; } + ILocation? PostalAddress { get; } } } diff --git a/src/Yavsc.Abstract/Identity/Security/ICircleAuthorized.cs b/src/Yavsc.Abstract/Identity/Security/ICircleAuthorized.cs index eb153ec2..cc108d2e 100644 --- a/src/Yavsc.Abstract/Identity/Security/ICircleAuthorized.cs +++ b/src/Yavsc.Abstract/Identity/Security/ICircleAuthorized.cs @@ -3,7 +3,7 @@ namespace Yavsc.Abstract.Identity.Security public interface ICircleAuthorized { long Id { get; set; } - string OwnerId { get; } + string AuthorId { get; } bool AuthorizeCircle(long circleId); ICircleAuthorization [] GetACL(); diff --git a/src/Yavsc.Server/Models/ApplicationUser.cs b/src/Yavsc.Server/Models/ApplicationUser.cs index 9907f58c..4f880d97 100644 --- a/src/Yavsc.Server/Models/ApplicationUser.cs +++ b/src/Yavsc.Server/Models/ApplicationUser.cs @@ -7,10 +7,12 @@ using Yavsc.Models.Identity; using Yavsc.Models.Chat; using Yavsc.Models.Bank; using Yavsc.Models.Access; +using Yavsc.Abstract.Identity; + namespace Yavsc.Models { [Table("AspNetUsers")] - public class ApplicationUser : IdentityUser + public class ApplicationUser : IdentityUser, IApplicationUser { /// /// Another me, as a byte array.TG7@Eu%80rufzkhbb @@ -22,10 +24,10 @@ namespace Yavsc.Models /// /// [MaxLength(512)] - public string Avatar { get; set; } + public string? Avatar { get; set; } [MaxLength(512)] - public string FullName { get; set; } + public string? FullName { get; set; } /// @@ -33,7 +35,7 @@ namespace Yavsc.Models /// /// [Display(Name = "Account balance")] - public virtual AccountBalance AccountBalance { get; set; } + public virtual AccountBalance? AccountBalance { get; set; } /// /// User's posts @@ -113,5 +115,8 @@ namespace Yavsc.Models [InverseProperty("Member")] public virtual List Membership { get; set; } + IAccountBalance? IApplicationUser.AccountBalance => AccountBalance; + + ILocation? IApplicationUser.PostalAddress { get => PostalAddress; } } } diff --git a/src/Yavsc.Server/Models/Blog/BlogPost.cs b/src/Yavsc.Server/Models/Blog/BlogPost.cs index 1daeee83..b519e723 100644 --- a/src/Yavsc.Server/Models/Blog/BlogPost.cs +++ b/src/Yavsc.Server/Models/Blog/BlogPost.cs @@ -5,6 +5,8 @@ using System.ComponentModel.DataAnnotations.Schema; using System.Linq; using Microsoft.EntityFrameworkCore; using Newtonsoft.Json; +using Yavsc; +using Yavsc.Abstract.Identity; using Yavsc.Abstract.Identity.Security; using Yavsc.Attributes.Validation; using Yavsc.Interfaces; @@ -86,7 +88,6 @@ namespace Yavsc.Models.Blog [InverseProperty("Post")] public virtual List Comments { get; set; } - [NotMapped] - public string OwnerId => AuthorId; + IApplicationUser IBlogPost.Author { get => this.Author; } } } diff --git a/src/Yavsc.Server/Models/societe.com/CompanyInfo.cs b/src/Yavsc.Server/Models/societe.com/CompanyInfo.cs index c39221f2..114c4d8e 100644 --- a/src/Yavsc.Server/Models/societe.com/CompanyInfo.cs +++ b/src/Yavsc.Server/Models/societe.com/CompanyInfo.cs @@ -8,10 +8,10 @@ namespace Yavsc.Models.societe.com public class CompanyInfoMessage { public bool success { get; set; } - public string errorType { get; set; } - public string errorCode { get; set; } - public string errorMessage { get; set; } - public CompanyInfo result { get; set; } + public string? errorType { get; set; } + public string? errorCode { get; set; } + public string? errorMessage { get; set; } + public CompanyInfo? result { get; set; } } diff --git a/src/Yavsc/Controllers/Communicating/BlogspotController.cs b/src/Yavsc/Controllers/Communicating/BlogspotController.cs index 4e4fea91..6f0ff24a 100644 --- a/src/Yavsc/Controllers/Communicating/BlogspotController.cs +++ b/src/Yavsc/Controllers/Communicating/BlogspotController.cs @@ -47,7 +47,7 @@ namespace Yavsc.Controllers await blogSpotService.UserPosts(id, User.GetUserId(), skip, take)); } - var byTitle = await this.blogSpotService.IndexByTitle(User, id, skip, take); + IEnumerable> byTitle = await this.blogSpotService.IndexByTitle(User, id, skip, take); return View(byTitle); } diff --git a/src/Yavsc/Extensions/PermissionHandler.cs b/src/Yavsc/Extensions/PermissionHandler.cs index 96fcb7fc..b4243a72 100644 --- a/src/Yavsc/Extensions/PermissionHandler.cs +++ b/src/Yavsc/Extensions/PermissionHandler.cs @@ -85,7 +85,7 @@ public class PermissionHandler : IAuthorizationHandler { return applicationDbContext.CircleMembers .Include(c => c.Circle) - .Where(m=>m.MemberId==user.GetUserId() && m.Circle.OwnerId == blogPost.OwnerId) + .Where(m=>m.MemberId==user.GetUserId() && m.Circle.OwnerId == blogPost.AuthorId) .Any(); } return true; diff --git a/src/Yavsc/ViewComponents/CirclesControlViewComponent.cs b/src/Yavsc/ViewComponents/CirclesControlViewComponent.cs index eacca699..c7af7c86 100644 --- a/src/Yavsc/ViewComponents/CirclesControlViewComponent.cs +++ b/src/Yavsc/ViewComponents/CirclesControlViewComponent.cs @@ -22,7 +22,7 @@ namespace Yavsc.ViewComponents { if (target!=null) { - var oid = target.OwnerId; + var oid = target.AuthorId; ViewBag.ACL = dbContext.Circle.Where( c=>c.OwnerId == oid) .Select( diff --git a/src/Yavsc/Views/Blogspot/Index.cshtml b/src/Yavsc/Views/Blogspot/Index.cshtml index ba7c6cc0..7e1a7f7d 100644 --- a/src/Yavsc/Views/Blogspot/Index.cshtml +++ b/src/Yavsc/Views/Blogspot/Index.cshtml @@ -1,4 +1,4 @@ -@model IEnumerable> +@model IEnumerable> @{ ViewData["Title"] = "Blogs, l'index"; } diff --git a/src/Yavsc/Views/Shared/DisplayTemplates/ApplicationUser.cshtml b/src/Yavsc/Views/Shared/DisplayTemplates/ApplicationUser.cshtml index a9e0e52e..b7bd532f 100644 --- a/src/Yavsc/Views/Shared/DisplayTemplates/ApplicationUser.cshtml +++ b/src/Yavsc/Views/Shared/DisplayTemplates/ApplicationUser.cshtml @@ -1,14 +1,10 @@ +@using Yavsc.Abstract.Identity @model ApplicationUser @{ - var avuri = "/Avatars/"+Model.UserName+".s.png"; - var userPosted = Model.Posts!=null && Model.Posts.Count()>=1; + var avuri = "/Avatars/" + Model.UserName + ".s.png"; }
-@if (userPosted) { -@Model.UserName - -} else { - Html.DisplayFor(m=>m.UserName); -} + + @Model.UserName +
diff --git a/src/Yavsc/Views/Shared/DisplayTemplates/IApplicationUser.cshtml b/src/Yavsc/Views/Shared/DisplayTemplates/IApplicationUser.cshtml new file mode 100644 index 00000000..976ca84c --- /dev/null +++ b/src/Yavsc/Views/Shared/DisplayTemplates/IApplicationUser.cshtml @@ -0,0 +1,10 @@ +@using Yavsc.Abstract.Identity +@model IApplicationUser +@{ + var avuri = "/Avatars/" + Model.UserName + ".s.png"; +} +