Skip to content

Commit

Permalink
Refactor program.cs and update API documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Andronovo-bit committed Mar 21, 2024
1 parent d43f3fb commit 9146bba
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 60 deletions.
98 changes: 39 additions & 59 deletions WebApiCICDWorkFlow/Program.cs
Original file line number Diff line number Diff line change
@@ -1,71 +1,51 @@

using Microsoft.AspNetCore.Mvc;
using Microsoft.OpenApi.Models;
using System.Text.Json.Serialization;

namespace WebApiCICDWorkFlow
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddAuthorization();

// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
});

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebApiCICDWorkFlow API V1");
});
var builder = WebApplication.CreateBuilder(args);

}
// Add services to the container.
builder.Services.AddAuthorization();

app.UseAuthorization();


//create enum type for calculator operations, opertion is body parameter for the post request

app.MapGet("/calculator/{operation}/{a}/{b}", ([FromQuery]Operation operation, float a, float b) =>
{
float result = operation switch
{
Operation.Add => a + b,
Operation.Subtract => a - b,
Operation.Multiply => a * b,
Operation.Divide => a / b,
_ => 0
};
return result;
}).WithName("WebApiCICDWorkFlow")
.WithOpenApi();
// Configure Swagger/OpenAPI
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
});

var app = builder.Build();

// Configure the HTTP request pipeline.
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebApiCICDWorkFlow API V1");
});

app.Run();
}
}
app.UseAuthorization();

//create enum for the operation
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum Operation
app.MapGet("/calculator/{operation}/{a}/{b}", ([FromQuery] Operation operation, float a, float b) =>
{
float result = operation switch
{
Add,
Subtract,
Multiply,
Divide
}
Operation.Add => a + b,
Operation.Subtract => a - b,
Operation.Multiply => a * b,
Operation.Divide => a / b,
_ => 0
};
return result;
}).WithName("WebApiCICDWorkFlow").WithOpenApi();

await app.RunAsync();

// Enum for the operation
[JsonConverter(typeof(JsonStringEnumConverter))]
public enum Operation
{
Add,
Subtract,
Multiply,
Divide
}
2 changes: 1 addition & 1 deletion WebApiCICDWorkFlow/WebApiCICDWorkFlow.http
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@WebApiCICDWorkFlow_HostAddress = http://localhost:5118

GET {{WebApiCICDWorkFlow_HostAddress}}/weatherforecast/
GET {{WebApiCICDWorkFlow_HostAddress}}/swagger/
Accept: application/json

###

0 comments on commit 9146bba

Please sign in to comment.