Class BlogController
- Namespace
- Builvero.Api.Controllers
- Assembly
- Builvero.Api.dll
Provides public API endpoints for viewing published blog posts.
[ApiController]
[Route("api/blog")]
[AllowAnonymous]
public class BlogController : ControllerBase
- Inheritance
-
BlogController
- Inherited Members
Remarks
This controller does not require authentication. All endpoints are prefixed with /api/blog.
The controller handles:
- Listing published blog posts
- Retrieving a single published blog post by slug
Only published posts are returned. Draft posts are not accessible via public endpoints.
Constructors
BlogController(IBlogService, ILogger<BlogController>)
Initializes a new instance of the BlogController class.
public BlogController(IBlogService blogService, ILogger<BlogController> logger)
Parameters
blogServiceIBlogServiceService for blog post operations.
loggerILogger<BlogController>Logger for recording controller operations and errors.
Methods
GetPostBySlug(string, CancellationToken)
Retrieves a published blog post by its slug.
[HttpGet("posts/{slug}")]
[AllowAnonymous]
public Task<ActionResult<BlogPostDetailsDto>> GetPostBySlug(string slug, CancellationToken cancellationToken)
Parameters
slugstringThe slug of the blog post to retrieve.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<ActionResult<BlogPostDetailsDto>>
200 OK: Returns the BlogPostDetailsDto
404 Not Found: Post not found or not published
Remarks
Public endpoint (no authentication required). Returns the post only if it is published. Draft posts are not accessible via this endpoint.
GetPublishedPosts(CancellationToken)
Retrieves all published blog posts.
[HttpGet("posts")]
[AllowAnonymous]
public Task<ActionResult<List<BlogPostSummaryDto>>> GetPublishedPosts(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<ActionResult<List<BlogPostSummaryDto>>>
200 OK: Returns list of BlogPostSummaryDto objects (published posts only)
500 Internal Server Error: Error retrieving posts
Remarks
Public endpoint (no authentication required). Returns only published posts, ordered by creation date (newest first).