<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Milan Martiniak on Medium]]></title>
        <description><![CDATA[Stories by Milan Martiniak on Medium]]></description>
        <link>https://medium.com/@mino.martiniak?source=rss-6243604a89e9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*3-IcmWAeSmpWixaNd7uTlg.jpeg</url>
            <title>Stories by Milan Martiniak on Medium</title>
            <link>https://medium.com/@mino.martiniak?source=rss-6243604a89e9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 07:02:06 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mino.martiniak/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ASP.NET CORE Minimal API — Filters & Validation]]></title>
            <link>https://medium.com/@mino.martiniak/asp-net-core-minimal-api-filters-validation-5b610a86e3b7?source=rss-6243604a89e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b610a86e3b7</guid>
            <dc:creator><![CDATA[Milan Martiniak]]></dc:creator>
            <pubDate>Tue, 17 Jan 2023 09:04:23 GMT</pubDate>
            <atom:updated>2023-01-18T08:35:17.677Z</atom:updated>
            <content:encoded><![CDATA[<h3>ASP.NET CORE Minimal API — Filters &amp; Validation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*NYkQU83dbn1bD-hyBtWwiw.png" /></figure><p>ASP.NET CORE Minimal API je ešte stále relatívna novinka, ktorá okolo seba nesie veľkú diskusiu o tom či je to dobrý alebo zlý koncept. Ako pri väčšine si myslím, že pravda je niekde uprostred a je to závislé od toho čo chceme robiť. Minimal API je skvelý spôsob ako vytvoriť svoje prvé API. Žiadne komplikované triedy, nastavovanie. Jeden súbor, pár riadkov a je to.</p><p><a href="https://learn.microsoft.com/en-us/aspnet/core/release-notes/aspnetcore-7.0?view=aspnetcore-7.0#minimal-apis">Vďaka novinkám, ktoré prišli v .NET 7</a>, sa Minimal API stáva ešte viac atraktívnym <em>(Filtes, Route Groups, ..)</em> aj pri vývoji komplexnejších API.</p><h3>Dnes sa pozrieme na to ako využiť vlastné filtre na validáciu dát</h3><p>Pokiaľ ste doteraz vytvárali API pomocou ASP.NET CORE tak ste s najväčšou pravdepodobnosťou používali triedy, ktoré dedia z ControllerBase. Táto trieda obsahuje veľa vecí, ktoré sú pre vás už pripravené. Jednou z nich je aj validácia dát. Všetko čo musíte urobiť je pridať atribút ApiController a všetky dáta, ktoré prídu do vašej akcie budú automaticky validované. Ak boli dáta nevalidné tak sa vráti 400 Bad Request.</p><p>Prípadne ste mohli validáciu vynútiť aj manuálne pomocou ModelState.IsValid.</p><pre>if (!ModelState.IsValid)<br>{<br>    //return 400 Bad Request<br>}</pre><p>Bohužiaľ, alebo možno našťastie toto pri minimal API nemôžeme využiť. Dôvod je ten, že model validation mechanizmus je historicky súčasťou MVC a Minimal API sa cielene snaží očistiť tvorbu API od MVC.</p><p>Novinkou .NET 7 sú práve <a href="https://learn.microsoft.com/en-us/aspnet/core/fundamentals/minimal-apis/min-api-filters?view=aspnetcore-7.0">action filtes</a>, ktoré sa na to dajú elegantne použiť. Ja na validáciu rád používam <a href="https://docs.fluentvalidation.net/en/latest/">Fluent Validation</a>. Pridajme si preto do projektu balíček FluentValidation.AspNetCore dotnet add package FluentValidation.AspNetCore a vytvorme si validátor pre zakladanie nového projektu.</p><pre>internal class NewProjectValidator : AbstractValidator&lt;CreateProjetDto&gt;<br>{<br>    public NewProjectValidator()<br>    {<br>        RuleFor(x =&gt; x.Name).NotEmpty().MaximumLength(20);<br>        RuleFor(x =&gt; x.Description).NotEmpty().MaximumLength(100);<br>    }<br>}</pre><p>Aby sme mohli použiť tento validátor musíme ho najskôr zaregistrovať. To urobíme v Program.cs.</p><pre>builder.Services.AddScoped&lt;IValidator&lt;CreateProjetDto&gt;, NewProjectValidator&gt;();</pre><p>Filter môžeme definovať priamo pri definícií endpointu, ale my chceme tento filter využiť opakovanie, takže si ho definujeme pomocou rozhrania IEndpointFilter.</p><pre>internal class ValidationFilter&lt;T&gt; : IEndpointFilter<br>    where T : class<br>{<br>    private readonly IValidator&lt;T&gt; _validator;<br><br>    public ValidationFilter(IValidator&lt;T&gt; validator)<br>    {<br>        _validator = validator;<br>    }<br><br>    public async ValueTask&lt;object?&gt; InvokeAsync(EndpointFilterInvocationContext context, EndpointFilterDelegate next)<br>    {<br>        // 👇 this can be more complicated<br>        if (context.Arguments.FirstOrDefault(a =&gt; a is T) is not T model)<br>        {<br>            throw new InvalidOperationException(&quot;Model is null&quot;);<br>        }<br>        var validationResult = await _validator.ValidateAsync(model);<br>        if (!validationResult.IsValid)<br>        {<br>            return Results.ValidationProblem(validationResult.ToDictionary());<br>        }<br>        return await next(context);<br>    }<br></pre><p>Náš filter je generický, pričom generikum T predstavuje validované dáta. Cez konštruktor si injektneme validátor, ktorý sme si vytvorili vyššie. V metóde InvokeAsync najskôr vyhľadáme náš argument, ktorý je typu T a potom ho validujeme. Ak validácia prebehne úspešne tak sa zavolá ďalší filter. Ak validácia zlyhá tak sa vráti 400 Bad Request s chybovou správou pomocou novej triedy Results.</p><p>Filter pridáme do endpointu pomocou extension metódy AddEndpointFilter.</p><pre>app.MapPost(&quot;/projects&quot;, (CreateProjetDto project) =&gt; project)<br>    .AddEndpointFilter&lt;ValidationFilter&lt;CreateProjetDto&gt;&gt;();</pre><p>Prípadne si môžeme vytvoriť extension metódu, ktorá nám toto zjednoduší.</p><pre>internal static class ValidationFilter<br>{<br>    public static IEndpointConventionBuilder WithValidation&lt;T&gt;(this RouteHandlerBuilder builder)<br>        where T : class<br>        =&gt; builder.AddEndpointFilter&lt;ValidationFilter&lt;T&gt;&gt;();<br>}</pre><p>Použitie môže vyzerať takto.</p><pre>app.MapPost(&quot;/projects&quot;, (CreateProjetDto project) =&gt; project)<br>    .WithValidation&lt;CreateProjetDto&gt;();<br>app.MapPut(&quot;/projects/{id}/description&quot;, (ChangeProjectDescriptionDto description) =&gt; description)<br>    .WithValidation&lt;ChangeProjectDescriptionDto&gt;();</pre><p>Celý projekt nájdete na GitHub-e <a href="https://github.com/Burgyn/Samples.MinimalApiFilters">tu</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b610a86e3b7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[✅ How to create a good poll?]]></title>
            <link>https://medium.com/@mino.martiniak/how-to-create-a-good-poll-f029261c6f1?source=rss-6243604a89e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/f029261c6f1</guid>
            <category><![CDATA[apps]]></category>
            <category><![CDATA[poll]]></category>
            <category><![CDATA[how-to]]></category>
            <dc:creator><![CDATA[Milan Martiniak]]></dc:creator>
            <pubDate>Thu, 12 Jan 2023 10:19:14 GMT</pubDate>
            <atom:updated>2023-01-12T10:19:14.971Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*auoAOwVwOEIlQH-m3ixdTg.png" /><figcaption>How to create a good poll?</figcaption></figure><p><a href="https://app.swallowpoll.com/">Creating an effective online poll</a> can be a great way to gather valuable feedback and insights from your audience. However, there are a few key things to keep in mind to ensure that your poll is well-designed and effective.</p><ol><li>Clearly define the purpose of your poll. Before you begin creating your poll, it’s important to have a clear understanding of what you’re trying to achieve. Are you trying to gather feedback on a new product, or gauge public opinion on a particular issue? Having a clear purpose in mind will help you create a more effective poll.</li><li>Keep your questions clear and concise. When crafting the questions for your poll, it’s important to make sure they are clear and easy to understand. Avoid using jargon or complex language, and keep your questions as brief as possible.</li><li>Offer a variety of answer options. To get the most useful responses, make sure to give your respondents a variety of answer options to choose from. This could include multiple-choice options, a scale (e.g. strongly disagree, disagree, neutral, agree, strongly agree), or even a free-form text box.</li><li>Make it easy to share. If you want to get as many responses as possible, make it easy for people to share your poll with their friends and followers. Include social sharing buttons on your poll, and encourage people to share it with their network.</li><li>Analyze your results. Once you’ve collected your responses, be sure to analyze the data and use it to inform your decisions. Share the results with your team and stakeholders, and use the insights to make improvements and drive change.</li></ol><p>By following these tips, you can create an effective online poll that will help you gather valuable feedback and insights from your audience.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f029261c6f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Swallow Poll — Free online poll and survey tool]]></title>
            <link>https://medium.com/@mino.martiniak/swallow-poll-free-online-poll-and-survey-tool-54dc14915d48?source=rss-6243604a89e9------2</link>
            <guid isPermaLink="false">https://medium.com/p/54dc14915d48</guid>
            <category><![CDATA[free-polling-app]]></category>
            <category><![CDATA[tools]]></category>
            <category><![CDATA[apps]]></category>
            <category><![CDATA[poll-maker]]></category>
            <category><![CDATA[survey-app]]></category>
            <dc:creator><![CDATA[Milan Martiniak]]></dc:creator>
            <pubDate>Tue, 03 Jan 2023 12:14:23 GMT</pubDate>
            <atom:updated>2024-05-08T14:57:48.397Z</atom:updated>
            <content:encoded><![CDATA[<h3>🥂 POLLMEA — Free online poll and survey tool</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*STE0f4y_cxZlYiVQfI9CWQ.png" /></figure><p><a href="https://pollmea.com/">POLLMEA</a> is a new web-based tool for <a href="https://pollmea.com/NewPoll">creating online polls and surveys</a>. With Swallow Poll, you can easily create professional-looking polls and surveys that can be shared with your audience via a link on your website, social media or messaging app.</p><p>One of the standout features of Swallow Poll is its user-friendly interface. Creating a poll is as simple as filling out a form.</p><p>Overall, Swallow Poll is a great tool for anyone looking to create professional-quality online polls and surveys. Whether you’re a business owner, marketer, or just looking to gather feedback from your friends and family, Swallow Poll is a powerful and easy-to-use tool that can help you get the insights you need.</p><p>If you need to <a href="https://pollmea.com/NewPoll">create a poll or survey</a>, don’t hesitate to try <a href="https://pollmea.com/">POLLMEA</a>. No sign-up required, totally free and no ads.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=54dc14915d48" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>