Update post comments
This commit is contained in:
parent
c6538b8d0d
commit
2b25c55a70
@ -1,5 +1,6 @@
|
|||||||
using Asp.Versioning;
|
using Asp.Versioning;
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
|
using Microsoft.AspNetCore.Http.HttpResults;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using PortBlog.API.Entities;
|
using PortBlog.API.Entities;
|
||||||
using PortBlog.API.Models;
|
using PortBlog.API.Models;
|
||||||
@ -122,5 +123,26 @@ namespace PortBlog.API.Controllers
|
|||||||
|
|
||||||
return Ok(post.Likes);
|
return Ok(post.Likes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpPost("UpdatePostCommentsCount")]
|
||||||
|
public async Task<ActionResult> UpdatePostCommentsCount(string blogUrl, string postSlug, int commentsCount)
|
||||||
|
{
|
||||||
|
if (!await _blogRepository.PostExistsAsync(blogUrl, postSlug))
|
||||||
|
{
|
||||||
|
_logger.LogInformation($"Post with id {postSlug} wasn't found when fetching post likes and views.");
|
||||||
|
return NotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
var post = await _blogRepository.GetPostAsync(blogUrl, postSlug);
|
||||||
|
|
||||||
|
post.Comments = commentsCount;
|
||||||
|
|
||||||
|
_blogRepository.UpdatePost(post);
|
||||||
|
|
||||||
|
await _blogRepository.SaveChangesAsync();
|
||||||
|
|
||||||
|
return NoContent();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user