reactredux/webapi/WeatherForecast/Controllers/BlogsController.cs

108 lines
2.8 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Core.Models;
using WeatherForecast.Models;
using Microsoft.AspNetCore.Authorization;
using Core.Abstractions.Models;
namespace WeatherForecast.Controllers;
#region Input models
public class GetBlogsResponse : ResponseModel {
public BlogItemModel FeaturedBlog { get; set; }
public List<CategoryModel> Categories { get; set; }
public PaginationModel<BlogItemModel> BlogItemsPagination { get; set; }
}
#endregion
[AllowAnonymous]
[ApiController]
[Route("api/[controller]")]
public class BlogsController : ControllerBase {
private readonly ILogger<LoginController> _logger;
public BlogsController(ILogger<LoginController> logger) {
_logger = logger;
}
/// <summary>
///
/// </summary>
/// <param name="currentPage"></param>
/// <param name="itemsPerPage"></param>
/// <param name="category"></param>
/// <param name="searchText"></param>
/// <returns></returns>
[HttpGet]
public IActionResult Get([FromQuery] Guid? category, [FromQuery] string? searchText, [FromQuery] int currentPage = 1, [FromQuery] int itemsPerPage = 4) {
var blogItemModel = new BlogItemModel {
Id = Guid.NewGuid(),
Slug = "blog-post-title",
Image = new ImageModel { Src = "https://dummyimage.com/850x350/dee2e6/6c757d.jpg", Alt = "..." },
Badge = "news",
Title = "Blog post title",
ShortText = "Lorem ipsum, dolor sit amet consectetur adipisicing elit. Eaque fugit ratione dicta mollitia. Officiis ad...",
Author = new AuthorModel {
Id = Guid.NewGuid(),
Image = new ImageModel { Src = "https://dummyimage.com/40x40/ced4da/6c757d", Alt = "..." },
NickName = "Admin"
},
Created = DateTime.UtcNow,
ReadTime = 10,
Likes = 200,
Tags = new List<string> { "react", "redux", "webapi" }
};
var blogModels = new List<BlogItemModel>();
for (int i = 0; i < itemsPerPage; i++) {
blogModels.Add(blogItemModel);
}
var blogResponse = new GetBlogsResponse {
FeaturedBlog = blogItemModel,
BlogItemsPagination = new PaginationModel<BlogItemModel> {
CurrentPage = currentPage,
TotalPages = 100,
Items = blogModels
},
Categories = new List<CategoryModel> {
new CategoryModel {
Id = Guid.NewGuid(),
Text = "Web Design"
},
new CategoryModel {
Id = Guid.NewGuid(),
Text = "Html"
},
new CategoryModel {
Id = Guid.NewGuid(),
Text = "Freebies"
},
new CategoryModel {
Id = Guid.NewGuid(),
Text = "Javascript"
},
new CategoryModel {
Id = Guid.NewGuid(),
Text = "CSS"
},
new CategoryModel {
Id = Guid.NewGuid(),
Text = "Tutorials"
}
}
};
return Ok(blogResponse);
}
}