Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
485 changes: 485 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions ParkingLotManager.ReportApi/Configuration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace ParkingLotManager.ReportApi;

public static class Configuration
{
public const string Uri = "https://localhost:7255/v1/vehicles";
public const string ApiKeyName = "api_key";
public const string ApiKey = "parking_oPt4oylWx0X4wfnj";
}
62 changes: 62 additions & 0 deletions ParkingLotManager.ReportApi/Controller/ReportController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Microsoft.AspNetCore.Mvc;
using ParkingLotManager.ReportApi.REST;
using ParkingLotManager.ReportApi.Services;

namespace ParkingLotManager.ReportApi.Controller;

[ApiController]
public class ReportController : ControllerBase
{
private readonly FlowManagementService _flowManagementService;

public ReportController(FlowManagementService flowManagementService)
=> _flowManagementService = flowManagementService;

[HttpGet("v1/report/entered-vehicles")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetEnteredVehicles()
{
var enteredVehicles = await _flowManagementService.CheckInFlowCalc();

return new JsonResult(new { message = $"There are {enteredVehicles} vehicles in the parking lot" });
}

[HttpGet("v1/report/departured-vehicles")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetDeparturedVehicles()
{
var departuredVehicles = await _flowManagementService.DepartureFlowCalc();

return new JsonResult(new { message = $"{departuredVehicles} vehicles have already departured" });
}

[HttpGet("v1/report/entered-vehiclesLH")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetEnteredVehiclesLastHour()
{
var vehiclesLastHour = await _flowManagementService.EnteredVehiclesInTheLastHour();

return new JsonResult(new { message = $"{vehiclesLastHour} vehicles entered in the last hour" });
}

[HttpGet("v1/report/departured-vehiclesLH")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> GetDeparturedVehiclesLastHour()
{
var vehiclesLastHour = await _flowManagementService.DeparturedVehiclesInTheLastHour();

return new JsonResult(new { message = $"{vehiclesLastHour} vehicles departured in the last hour" });
}
}
36 changes: 36 additions & 0 deletions ParkingLotManager.ReportApi/DTOs/ParkingLotGenericResponseDTO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Dynamic;
using System.Net;

namespace ParkingLotManager.ReportApi.DTOs;

public class ParkingLotGenericResponseDto<T> where T : class
{
public ParkingLotGenericResponseDto()
{
}

public ParkingLotGenericResponseDto(T data)
{
Data = data;
}

public ParkingLotGenericResponseDto(T data, List<string> errors)
{
Data = data;
Errors = errors;
}

public ParkingLotGenericResponseDto(string error)
{
Errors.Add(error);
}

public ParkingLotGenericResponseDto(List<string> errors)
{
Errors = errors;
}

public HttpStatusCode StatusCode { get; set; }
public T? Data { get; set; }
public List<string>? Errors { get; set; } = new();
}
15 changes: 15 additions & 0 deletions ParkingLotManager.ReportApi/DTOs/VehicleModelDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace ParkingLotManager.ReportApi.DTOs;

public class VehicleModelDto
{
public string licensePlate { get; set; }
public string brand { get; set; }
public string model { get; set; }
public string color { get; set; }
public int type { get; set; }
public DateTime createdAt { get; set; }
public DateTime lastUpdateDate { get; set; }
public bool isActive { get; set; }
public object company { get; set; }
public string companyName { get; set; }
}
13 changes: 13 additions & 0 deletions ParkingLotManager.ReportApi/Interfaces/IVehicleFlowManagement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Mvc;
using ParkingLotManager.ReportApi.DTOs;
using ParkingLotManager.ReportApi.Models;

namespace ParkingLotManager.ReportApi.Interfaces;

public interface IVehicleFlowManagement
{
public Task<int> CheckInFlowCalc();
public Task<int> DepartureFlowCalc();
public Task<int> EnteredVehiclesInTheLastHour();
public Task<int> DeparturedVehiclesInTheLastHour();
}
9 changes: 9 additions & 0 deletions ParkingLotManager.ReportApi/Interfaces/IVehicleQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using ParkingLotManager.ReportApi.DTOs;
using ParkingLotManager.ReportApi.Models;

namespace ParkingLotManager.ReportApi.Interfaces;

public interface IVehicleQuery
{
public Task<List<VehicleModel>> GetVehiclesAsync();
}
15 changes: 15 additions & 0 deletions ParkingLotManager.ReportApi/Mappings/VehicleMapping.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using AutoMapper;
using ParkingLotManager.ReportApi.DTOs;
using ParkingLotManager.ReportApi.Models;

namespace ParkingLotManager.ReportApi.Mappings;

public class VehicleMapping : Profile
{
public VehicleMapping()
{
CreateMap<VehicleModel, VehicleModelDto>();

CreateMap(typeof(ParkingLotGenericResponseDto<>), typeof(ParkingLotGenericResponseDto<>));
}
}
21 changes: 21 additions & 0 deletions ParkingLotManager.ReportApi/Models/VehicleModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using AutoMapper.Configuration.Annotations;
using Newtonsoft.Json;
using ParkingLotManager.WebApi.Enums;
using ParkingLotManager.WebApi.Models;
using System.Text.Json.Serialization;

namespace ParkingLotManager.ReportApi.Models;

public class VehicleModel
{
public string licensePlate { get; set; }
public string brand { get; set; }
public string model { get; set; }
public string color { get; set; }
public int type { get; set; }
public DateTime createdAt { get; set; }
public DateTime lastUpdateDate { get; set; }
public bool isActive { get; set; }
public object company { get; set; }
public string companyName { get; set; }
}
20 changes: 20 additions & 0 deletions ParkingLotManager.ReportApi/ParkingLotManager.ReportApi.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<DocumentationFile>ParkingLotManager.ReportApi.xml</DocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ParkingLotManager.WebApi\ParkingLotManager.WebApi.csproj" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions ParkingLotManager.ReportApi/ParkingLotManager.ReportApi.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@ParkingLotManager.ReportApi_HostAddress = http://localhost:5144

GET {{ParkingLotManager.ReportApi_HostAddress}}/
Accept: application/json

###
14 changes: 14 additions & 0 deletions ParkingLotManager.ReportApi/ParkingLotManager.ReportApi.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 72 additions & 0 deletions ParkingLotManager.ReportApi/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using Microsoft.OpenApi.Models;
using ParkingLotManager.ReportApi.Interfaces;
using ParkingLotManager.ReportApi.Mappings;
using ParkingLotManager.ReportApi.Models;
using ParkingLotManager.ReportApi.REST;
using ParkingLotManager.ReportApi.Services;

var builder = WebApplication.CreateBuilder(args);

ConfigureMvc(builder);
ConfigureSwagger(builder);
ConfigureMappings(builder);

//builder.Services.AddSingleton<IVehicleQuery, ParkingLotManagerApiRest>();
builder.Services.AddSingleton<ParkingLotManagerWebApiService>();
builder.Services.AddSingleton<FlowManagementService>();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();
//app.UseAuthorization();
app.MapControllers();

app.Run();

static void ConfigureMvc(WebApplicationBuilder builder)
{
builder.Services.AddControllers().ConfigureApiBehaviorOptions(x =>
{
x.SuppressModelStateInvalidFilter = true;
});
}
static void ConfigureSwagger(WebApplicationBuilder builder)
{
var linkedin = "https://www.linkedin.com/in/matheusarb/";
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(x =>
{
x.SwaggerDoc("v1", new OpenApiInfo
{
Title = "Parking Lot Report API",
Description = "A Report Api which generates specific reports with the given request",
Contact = new OpenApiContact
{
Name = "Matheus Ribeiro",
Email = "mat.araujoribeiro@gmail.com",
Url = new Uri(linkedin)
},
License = new OpenApiLicense
{
Name = "Mit License"
},
Version = "v1"
});

var xmlFile = "ParkingLotManager.ReportApi.xml";
var xmlPath = Path.Combine(Directory.GetCurrentDirectory(), xmlFile);
x.IncludeXmlComments(xmlPath);
});

}
static void ConfigureMappings(WebApplicationBuilder builder)
{
builder.Services.AddAutoMapper(typeof(VehicleMapping));
}
41 changes: 41 additions & 0 deletions ParkingLotManager.ReportApi/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:60636",
"sslPort": 44385
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5144",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7010;http://localhost:5144",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Loading