RSCG–AMS – About My software –WebAPI– part 4

Now it should be an easy way to see in the WebAPI. First, return the data for all software that respected that :

public static IEndpointRouteBuilder UseAMS(this IEndpointRouteBuilder endpoints)
{
    endpoints.MapGet("/ams/All", async app =>
    {
                
            var data = AboutMySoftware.AllDefinitions.Select(it => it).ToArray();
        await app.Response.WriteAsJsonAsync(data);
    });
    return endpoints;
}

Now, how can I make a small html to display things ? I can do with Razor Library – but it is too big and maybe the developers do not want to have this dependency. So I decided for https://www.nuget.org/packages/Transplator/  – fairly easy to use. And is another RSCG that converts template code into C#  code.

So now the code looks like this:

public static IEndpointRouteBuilder UseAMS(this IEndpointRouteBuilder endpoints)
{
    endpoints.MapGet("/ams/All", async app =>
    {
                
            var data = AboutMySoftware.AllDefinitions.Select(it => it).ToArray();
        await app.Response.WriteAsJsonAsync(data);
    });
    endpoints.MapGet("/ams/index", app =>
    {
        var response = new ASMTemplate().Render();
        app.Response.ContentType = "text/html";
        return app.Response.WriteAsync(response);
    });
    return endpoints;
}

where the ASMTemplate is

<style>
table {
  font-family: arial, sans-serif;
  border-collapse: collapse;
  width: 100%;
}

td {
  border: 1px solid #dddddd;
  text-align: left;
  padding: 8px;
}

th{
background-color: black;
  color: white;
  border: 1px solid #dddddd;
  text-align: left;
  padding: 8px;
  }
tr:nth-child(even) {
  background-color: #dddddd;
}
</style>

<table>
<tr>
<th>Nr</td>
<th>Component</th>
<th>Date</th>
<th>Commit</th>
<th>RepoUrl</th>
</tr>

{%~ int i=1; ~%}
{%~ foreach(var item in AMS.AboutMySoftware.AllDefinitions){ %}
<tr>
<td>{% i++ %}</td>
<td>{% item.Key %} </td>
<td>{% item.Value.DateGenerated %} </td>
<td>{% item.Value.CommitId %} </td>
<td>{% item.Value.RepoUrl %}</td>
</tr>
{% } %}
</table>

It is time now to make the nuget packages.