Compare commits

..

2 Commits

Author SHA1 Message Date
f48713c470
feat: add tag filtering (resolves WEB-1) 2023-09-24 17:03:06 +01:00
856c33a74f
chore: add MailKit 2023-09-24 16:46:49 +01:00
4 changed files with 41 additions and 1 deletions

View File

@ -41,6 +41,17 @@ public sealed class BlogApiController : ControllerBase
return Ok(allPosts.Select(post => CreatePostObject(post))); return Ok(allPosts.Select(post => CreatePostObject(post)));
} }
[HttpGet("posts/tagged/{tag}/{page:int?}")]
public IActionResult GetTaggedBlogPosts(string tag, int page = 0)
{
const int itemsPerPage = 10;
tag = tag.Replace('-', ' ').ToLowerInvariant();
IReadOnlyList<IBlogPost> allPosts = _blogPostService.GetBlogPosts(page, itemsPerPage);
allPosts = allPosts.Where(post => post.Tags.Contains(tag)).ToList();
return Ok(allPosts.Select(post => CreatePostObject(post)));
}
[HttpGet("author/{id:guid}")] [HttpGet("author/{id:guid}")]
public IActionResult GetAuthor(Guid id) public IActionResult GetAuthor(Guid id)
{ {

View File

@ -10,6 +10,8 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Alexinea.Extensions.Configuration.Toml" Version="7.0.0"/> <PackageReference Include="Alexinea.Extensions.Configuration.Toml" Version="7.0.0"/>
<PackageReference Include="Humanizer.Core" Version="2.14.1"/> <PackageReference Include="Humanizer.Core" Version="2.14.1"/>
<PackageReference Include="MailKit" Version="4.1.0"/>
<PackageReference Include="MailKitSimplified.Sender" Version="2.5.2"/>
<PackageReference Include="Markdig" Version="0.32.0"/> <PackageReference Include="Markdig" Version="0.32.0"/>
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.0.10"/> <PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.0.10"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="7.0.10"/> <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="7.0.10"/>

View File

@ -20,6 +20,11 @@ class API {
return response.map(obj => new BlogPost(obj)); return response.map(obj => new BlogPost(obj));
} }
static async getBlogPostsByTag(tag: string, page: number): Promise<BlogPost[]> {
const response = await API.getResponse(`posts/tagged/${tag}/${page}`);
return response.map(obj => new BlogPost(obj));
}
static async getAuthor(id: string): Promise<Author> { static async getAuthor(id: string): Promise<Author> {
const response = await API.getResponse(`author/${id}`); const response = await API.getResponse(`author/${id}`);
return new Author(response); return new Author(response);

View File

@ -2,6 +2,7 @@ import API from "./API";
import UI from "./UI"; import UI from "./UI";
import Input from "./Input"; import Input from "./Input";
import Author from "./Author"; import Author from "./Author";
import BlogPost from "./BlogPost";
declare const Handlebars: any; declare const Handlebars: any;
declare const Prism: any; declare const Prism: any;
@ -27,6 +28,19 @@ declare const Prism: any;
} }
}); });
function getQueryVariable(variable: string): string {
const query = window.location.search.substring(1);
const vars = query.split("&");
for (const element of vars) {
const pair = element.split("=");
if (pair[0] == variable) {
return pair[1];
}
}
return null;
}
Input.registerShortcut(Input.KONAMI_CODE, () => { Input.registerShortcut(Input.KONAMI_CODE, () => {
window.open("https://www.youtube.com/watch?v=dQw4w9WgXcQ", "_blank"); window.open("https://www.youtube.com/watch?v=dQw4w9WgXcQ", "_blank");
}); });
@ -46,7 +60,15 @@ declare const Prism: any;
const template = Handlebars.compile(UI.blogPostTemplate.innerHTML); const template = Handlebars.compile(UI.blogPostTemplate.innerHTML);
API.getBlogPostCount().then(async (count) => { API.getBlogPostCount().then(async (count) => {
for (let i = 0; i <= count / 10; i++) { for (let i = 0; i <= count / 10; i++) {
const posts = await API.getBlogPosts(i); let posts: BlogPost[];
const tag = getQueryVariable("tag");
if (tag !== null) {
posts = await API.getBlogPostsByTag(tag, i);
} else {
posts = await API.getBlogPosts(i);
}
for (const post of posts) { for (const post of posts) {
let author: Author; let author: Author;
if (authors[post.authorId]) { if (authors[post.authorId]) {