Class AdminBlogController
- Namespace
- Builvero.Api.Controllers
- Assembly
- Builvero.Api.dll
Provides administrative API endpoints for blog post management including creation, updates, deletion, and image upload URL generation.
[ApiController]
[Route("api/admin/blog")]
[Authorize(Policy = "AdminWrite")]
public class AdminBlogController : ControllerBase
- Inheritance
-
AdminBlogController
- Inherited Members
Remarks
This controller requires authorization via the "AdminWrite" policy for all operations.
All endpoints are prefixed with /api/admin/blog.
The controller handles:
- Blog post CRUD operations (create, read, update, delete)
- Blog image upload URL generation for rich text editor
Error responses follow a consistent format: { "error": "error message" } for client errors (400, 404).
Constructors
AdminBlogController(IBlogService, ILogger<AdminBlogController>)
Initializes a new instance of the AdminBlogController class.
public AdminBlogController(IBlogService blogService, ILogger<AdminBlogController> logger)
Parameters
blogServiceIBlogServiceService for blog post operations.
loggerILogger<AdminBlogController>Logger for recording controller operations and errors.
Methods
CreatePost(CreateBlogPostRequest, CancellationToken)
Creates a new blog post.
[HttpPost("posts")]
public Task<ActionResult<BlogPostDetailsDto>> CreatePost(CreateBlogPostRequest request, CancellationToken cancellationToken)
Parameters
requestCreateBlogPostRequestThe blog post creation request.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<ActionResult<BlogPostDetailsDto>>
201 Created: Returns the created BlogPostDetailsDto
400 Bad Request: Invalid request data
500 Internal Server Error: Error creating post
Remarks
Requires "AdminWrite" policy. The slug is automatically generated from the subject and made unique. HTML content is sanitized before storage to prevent XSS attacks.
DeletePost(Guid, CancellationToken)
Deletes a blog post.
[HttpDelete("posts/{id}")]
public Task<IActionResult> DeletePost(Guid id, CancellationToken cancellationToken)
Parameters
idGuidThe unique identifier of the blog post to delete.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<IActionResult>
200 OK: Returns
{ "message": "Blog post deleted successfully" }404 Not Found: Post not found
500 Internal Server Error: Error deleting post
Remarks
Requires "AdminWrite" policy. This operation is permanent and cannot be undone.
GenerateImageUploadUrl(string, string, CancellationToken)
Generates a presigned URL for uploading a blog image to S3.
[HttpPost("image-upload-url")]
public Task<ActionResult<BlogImageUploadResponse>> GenerateImageUploadUrl(string fileExtension, string contentType, CancellationToken cancellationToken)
Parameters
fileExtensionstringThe file extension of the image (e.g., "jpg", "png").
contentTypestringThe MIME type of the image (e.g., "image/jpeg", "image/png").
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<ActionResult<BlogImageUploadResponse>>
200 OK: Returns BlogImageUploadResponse with upload URL, object key, and read URL
400 Bad Request: Invalid file extension or content type
500 Internal Server Error: Error generating upload URL
Remarks
Requires "AdminWrite" policy. The upload URL expires after 5 minutes. The read URL expires after 15 minutes. Allowed file extensions: jpg, jpeg, png, gif, webp Allowed content types: image/jpeg, image/jpg, image/png, image/gif, image/webp
GetAllPosts(CancellationToken)
Retrieves all blog posts (both published and draft).
[HttpGet("posts")]
public Task<ActionResult<List<BlogPostSummaryDto>>> GetAllPosts(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<ActionResult<List<BlogPostSummaryDto>>>
200 OK: Returns list of BlogPostSummaryDto objects
500 Internal Server Error: Error retrieving posts
Remarks
Requires "AdminWrite" policy. Returns all posts regardless of publication status, ordered by creation date (newest first).
GetPost(Guid, CancellationToken)
Retrieves a blog post by its unique identifier.
[HttpGet("posts/{id}")]
public Task<ActionResult<BlogPostDetailsDto>> GetPost(Guid id, CancellationToken cancellationToken)
Parameters
idGuidThe unique identifier of the blog post.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<ActionResult<BlogPostDetailsDto>>
200 OK: Returns the BlogPostDetailsDto
404 Not Found: Post not found
Remarks
Requires "AdminWrite" policy. Returns both published and draft posts.
UpdatePost(Guid, UpdateBlogPostRequest, CancellationToken)
Updates an existing blog post.
[HttpPut("posts/{id}")]
public Task<ActionResult<BlogPostDetailsDto>> UpdatePost(Guid id, UpdateBlogPostRequest request, CancellationToken cancellationToken)
Parameters
idGuidThe unique identifier of the blog post to update.
requestUpdateBlogPostRequestThe blog post update request.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task<ActionResult<BlogPostDetailsDto>>
200 OK: Returns the updated BlogPostDetailsDto
400 Bad Request: Invalid request data
404 Not Found: Post not found
500 Internal Server Error: Error updating post
Remarks
Requires "AdminWrite" policy. The slug is regenerated if the subject changes. HTML content is sanitized before storage.