reactredux/webapi/WeatherForecast/Controllers/BlogCatalogController.cs

104 lines
2.9 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Core.Models;
using WeatherForecast.Models;
using Microsoft.AspNetCore.Authorization;
using Core.Abstractions.Models;
using WeatherForecast.Models.Responses;
namespace WeatherForecast.Controllers;
[AllowAnonymous]
[ApiController]
[Route("api/[controller]")]
public class BlogCatalogController : ControllerBase {
private readonly ILogger<BlogCatalogController> _logger;
public BlogCatalogController(ILogger<BlogCatalogController> 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 blogModels = new List<BlogItemModel>();
//for (int i = 0; i < 100; i++) {
// 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 {i}",
// ShortText = "Lorem ipsum, dolor sit amet consectetur adipisicing elit. Eaque fugit ratione dicta mollitia. Officiis ad...",
// Text = "",
// Author = new AuthorModel {
// Image = new ImageModel { Src = "https://dummyimage.com/40x40/ced4da/6c757d", Alt = "..." },
// NickName = "Admin"
// },
// Created = DateTime.UtcNow,
// Tags = new List<string> { "react", "redux", "webapi" },
// ReadTime = 10,
// Likes = 200,
// };
// blogModels.Add(blogItemModel);
//}
//var totalPages = blogModels.Count() / itemsPerPage;
var blogCatalogResponse = new GetBlogCatalogResponseModel {
/*
FeaturedBlog = blogModels[0],
BlogItemsPagination = new PaginationModelBase<BlogItemModel> {
CurrentPage = currentPage,
TotalPages = totalPages,
Items = blogModels.Skip((currentPage -1) * itemsPerPage).Take(itemsPerPage).ToList()
},
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(blogCatalogResponse);
}
}