Skip to content

Commit

Permalink
Merge pull request #179 from soat-fiap/api_version
Browse files Browse the repository at this point in the history
feat: add API versioning to Dockerfile and Swagger configuration
  • Loading branch information
italopessoa authored Nov 25, 2024
2 parents b705fc8 + 32e7884 commit 2e4726f
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 57 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
build-args: |
API_VERSION=${{ steps.sanitize-version.outputs.version }}
file: ./src/FIAP.TechChallenge.ByteMeBurger.Api/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
Expand Down
20 changes: 4 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ Endpoints are protected since JWT token is now required. Since this application

### Prerequisites
- Docker with Minikube configured
- [webhook.site](https://webhook.site) token


<details>
Expand Down Expand Up @@ -124,10 +123,6 @@ kubectl port-forward service/svc-seq 30008:80
```bash
minikube tunnel
```
#### To forward mercado pago webhook notifications to host
```bash
whcli forward --token=f513d4a6-4dbd-4e32-93f5-b35376f33c89 --target=http://localhost/api/notifications/mercadopago
```

#### Testing
You can use the [postman collection](/postman) for testing
Expand Down Expand Up @@ -156,23 +151,16 @@ Once you are done, you can stop the services running [rollback.ps1](kubernetes/r
- **Endpoint:** `POST /api/customers`
- Requires `Customer/Admin` role
### PaymentsController
- **Endpoint:** `POST /api/payments`
- Requires `Admin` role
### OrdersController
- **Endpoint:** `POST /api/orders`
- Requires `Customer/Admin` role
- **Endpoint:** `GET /api/orders/{id}`
- Requires `Admin/Kitchen` role
### NotificationsController
- **Endpoint:** `POST /api/notifications`
- No role required
## This repo on the infrastructure
![Architecture Diagram](aws-infra-phase-4.png)
![Architecture Diagram](doc/aws-infra-phase-4.png)
### K8S
![Architecture Diagram](doc/k8s.png)
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added doc/k8s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.ComponentModel.DataAnnotations;
using Bmb.Auth;
using Bmb.Tools.Auth;
using FIAP.TechChallenge.ByteMeBurger.Api.Model.Customers;
using FIAP.TechChallenge.ByteMeBurger.Controllers.Contracts;
using FIAP.TechChallenge.ByteMeBurger.Controllers.Dto;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.ObjectModel;
using Bmb.Auth;
using Bmb.Domain.Core.ValueObjects;
using Bmb.Tools.Auth;
using FIAP.TechChallenge.ByteMeBurger.Api.Model.Orders;
using FIAP.TechChallenge.ByteMeBurger.Controllers.Contracts;
using FIAP.TechChallenge.ByteMeBurger.Controllers.Dto;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Bmb.Auth;
using FIAP.TechChallenge.ByteMeBurger.Api.Model.Products;
using FIAP.TechChallenge.ByteMeBurger.Controllers.Contracts;
using FIAP.TechChallenge.ByteMeBurger.Controllers.Dto;
using Bmb.Domain.Core.ValueObjects;
using Bmb.Tools.Auth;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

Expand Down
3 changes: 2 additions & 1 deletion src/FIAP.TechChallenge.ByteMeBurger.Api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ RUN dotnet restore src/FIAP.TechChallenge.ByteMeBurger.Api

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "src/FIAP.TechChallenge.ByteMeBurger.Api/FIAP.TechChallenge.ByteMeBurger.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
ARG API_VERSION
RUN dotnet publish "src/FIAP.TechChallenge.ByteMeBurger.Api/FIAP.TechChallenge.ByteMeBurger.Api.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false /p:Version=$API_VERSION


FROM base AS final
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Windows</DockerDefaultTargetOS>
<AssemblyVersion>1.0.0</AssemblyVersion>
<Product>Bmb Orders/Customer API</Product>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
Expand All @@ -18,8 +20,8 @@
<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.MySql" Version="8.0.1" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="8.0.1" />
<PackageReference Include="Bmb.Auth" Version="0.0.1" />
<PackageReference Include="Bmb.Domain.Core" Version="0.0.17" />
<PackageReference Include="Bmb.Tools" Version="0.0.4" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.3"/>
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" Version="8.0.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.2" />
Expand All @@ -28,7 +30,6 @@
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Serilog.Sinks.Seq" Version="7.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0"/>
</ItemGroup>

<ItemGroup>
Expand Down
39 changes: 4 additions & 35 deletions src/FIAP.TechChallenge.ByteMeBurger.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Text.Json.Serialization;
using Bmb.Auth;
using Bmb.Tools.Auth;
using Bmb.Tools.OpenApi;
using FIAP.TechChallenge.ByteMeBurger.DI;
using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Serilog;
using Serilog.Events;
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
Expand Down Expand Up @@ -52,36 +50,7 @@ public static void Main(string[] args)
// https://learn.microsoft.com/en-us/aspnet/core/web-api/?view=aspnetcore-8.0#log-automatic-400-responses
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddRouting(options => options.LowercaseUrls = true);
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "Tech Challenge Restaurant API", Version = "v1", Extensions =
{
{
"x-logo",
new OpenApiObject
{
{
"url",
new OpenApiString(
"https://avatars.githubusercontent.com/u/165858718?s=384")
},
{
"background",
new OpenApiString(
"#FF0000")
}
}
}
}
});

var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});

builder.Services.ConfigBmbSwaggerGen();
var jwtOptions = builder.Configuration
.GetSection("JwtOptions")
.Get<JwtOptions>();
Expand All @@ -107,7 +76,7 @@ public static void Main(string[] args)
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
app.UseBmbSwaggerUi();
}

app.UseSerilogRequestLogging();
Expand Down

0 comments on commit 2e4726f

Please sign in to comment.