refacto BlogPost
This commit is contained in:
parent
84f3ffa9c2
commit
e35bc273a3
17 changed files with 177 additions and 203 deletions
|
|
@ -1,7 +1,6 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Newtonsoft.Json;
|
||||
using Yavsc.Abstract.Identity;
|
||||
using Yavsc.Abstract.Identity.Security;
|
||||
using Yavsc.Models.Access;
|
||||
using Yavsc.Models.Relationship;
|
||||
|
|
@ -69,7 +68,7 @@ namespace Yavsc.Models.Blog
|
|||
|
||||
public ICircleAuthorization[] GetACL()
|
||||
{
|
||||
return ACL.ToArray();
|
||||
return ACL?.ToArray() ?? Array.Empty<ICircleAuthorization>();
|
||||
}
|
||||
|
||||
public void Tag(Tag tag)
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class BlogSpotService
|
|||
this.fileSystemAuthManager = fileSystemAuthManager;
|
||||
}
|
||||
|
||||
public BlogPost Create(string userId, BlogPost post, IFormFileCollection files)
|
||||
public Yavsc.Models.Blog.BlogPost Create(string userId, Yavsc.Models.Blog.BlogPost post, IFormFileCollection files)
|
||||
{
|
||||
// Sauvegarder le post d'abord pour obtenir son ID
|
||||
// Le créateur vient de l'authentification, donc on ne le prend pas du post
|
||||
|
|
@ -103,9 +103,9 @@ public class BlogSpotService
|
|||
return new BlogPostEditViewModel(blog, pub);
|
||||
}
|
||||
|
||||
public async Task<BlogPost> Details(ClaimsPrincipal user, long blogPostId)
|
||||
public async Task<Yavsc.Models.Blog.BlogPost> Details(ClaimsPrincipal user, long blogPostId)
|
||||
{
|
||||
BlogPost blog = await _context.BlogSpot
|
||||
Yavsc.Models.Blog.BlogPost blog = await _context.BlogSpot
|
||||
.Include(p => p.Author)
|
||||
.Include(p => p.Tags)
|
||||
.Include(p => p.Comments)
|
||||
|
|
@ -170,7 +170,7 @@ public class BlogSpotService
|
|||
_context.SaveChanges(user.GetUserId());
|
||||
}
|
||||
|
||||
public async Task Modify(ClaimsPrincipal user, BlogPost blog)
|
||||
public async Task Modify(ClaimsPrincipal user, Yavsc.Models.Blog.BlogPost blog)
|
||||
{
|
||||
var existing = await _context.BlogSpot.Include(b => b.ACL).SingleOrDefaultAsync(b => b.Id == blog.Id);
|
||||
if (existing == null)
|
||||
|
|
@ -238,7 +238,7 @@ public class BlogSpotService
|
|||
// the N+1 of one AnyAsync per post. The published ids
|
||||
// are loaded once and matched against the post list
|
||||
// in memory.
|
||||
var postIds = materialised.OfType<BlogPost>().Select(p => p.Id).ToList();
|
||||
var postIds = materialised.Select(p => p.Id).ToList();
|
||||
if (postIds.Count > 0)
|
||||
{
|
||||
var publishedIds = await _context.blogSpotPublications
|
||||
|
|
@ -246,7 +246,7 @@ public class BlogSpotService
|
|||
.Select(pub => pub.BlogpostId)
|
||||
.ToListAsync();
|
||||
var publishedSet = publishedIds.ToHashSet();
|
||||
foreach (var post in materialised.OfType<BlogPost>())
|
||||
foreach (var post in materialised.OfType<Yavsc.Models.Blog.BlogPost>())
|
||||
post.IsPublished = publishedSet.Contains(post.Id);
|
||||
}
|
||||
|
||||
|
|
@ -259,20 +259,20 @@ public class BlogSpotService
|
|||
public async Task Delete(ClaimsPrincipal user, long id)
|
||||
{
|
||||
var uid = user.GetUserId();
|
||||
BlogPost blog = _context.BlogSpot.Single(m => m.Id == id);
|
||||
Yavsc.Models.Blog.BlogPost blog = _context.BlogSpot.Single(m => m.Id == id);
|
||||
|
||||
_context.BlogSpot.Remove(blog);
|
||||
_context.SaveChanges(user.GetUserId());
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<BlogPost>> UserPosts(
|
||||
public async Task<IEnumerable<Yavsc.Models.Blog.BlogPost>> UserPosts(
|
||||
string posterName,
|
||||
string? readerId,
|
||||
int pageLen = 10,
|
||||
int pageNum = 0)
|
||||
{
|
||||
string? posterId = (await _context.Users.SingleOrDefaultAsync(u => u.UserName == posterName))?.Id ?? null;
|
||||
if (posterId == null) return Array.Empty<BlogPost>();
|
||||
if (posterId == null) return Array.Empty<Yavsc.Models.Blog.BlogPost>();
|
||||
return _context.UserPosts(posterId, readerId);
|
||||
}
|
||||
|
||||
|
|
@ -285,7 +285,7 @@ public class BlogSpotService
|
|||
).ToList();
|
||||
}
|
||||
|
||||
public async Task<BlogPost?> GetBlogPostAsync(long value)
|
||||
public async Task<Yavsc.Models.Blog.BlogPost?> GetBlogPostAsync(long value)
|
||||
{
|
||||
return await _context.BlogSpot
|
||||
.Include(b => b.Author)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue