Skip to content

Commit

Permalink
Added swagger.
Browse files Browse the repository at this point in the history
  • Loading branch information
exegeteio committed Aug 12, 2021
1 parent 1fd4376 commit 968cd4e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 7 additions & 4 deletions subscriber/Program.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
using Dapr;
using Dapr.Client;
using Dapr.AspNetCore;
using Microsoft.AspNetCore.Mvc;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(o => o.SwaggerDoc("v1", new() { Title = "Counter API", Version = "v1" }));
var app = builder.Build();

if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseSwagger();
app.UseSwaggerUI();

app.UseCloudEvents();
app.UseRouting();
app.UseEndpoints(endpoints => endpoints.MapSubscribeHandler());
Expand All @@ -19,12 +22,12 @@

app.MapGet("/", async () => await dapr.GetStateAsync<int>("statestore", "counter"));

app.MapPost("/counter", [Topic("pubsub", "counter")] async ([FromBody] int counter) =>
app.MapPost("/counter", async ([FromBody] int counter) =>
{
var newCounter = counter * counter;
Console.WriteLine($"Updating counter: {newCounter}");
await dapr.SaveStateAsync("statestore", "counter", newCounter);
return Results.Accepted("/", newCounter);
});
}).WithTopic("pubsub", "counter");

app.Run();
2 changes: 2 additions & 0 deletions subscriber/subscriber.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapr.AspNetCore" Version="1.3.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.5" />
</ItemGroup>

</Project>

0 comments on commit 968cd4e

Please sign in to comment.