Merge branch 'dev' into docker-branch

This commit is contained in:
Santhosh S
2023-09-03 18:47:12 -04:00
40 changed files with 2052 additions and 394 deletions

View File

@ -1,100 +0,0 @@
using DamageAssesment.Api.Locations.Interfaces;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace DamageAssesment.Api.Locations.Controllers
{
//[Route("api")]
[ApiController]
public class LocationsController : ControllerBase
{
private ILocationsProvider LocationProvider;
public LocationsController(ILocationsProvider LocationsProvider)
{
this.LocationProvider = LocationsProvider;
}
/// <summary>
/// Get all locations.
/// </summary>
[HttpGet("Locations")]
public async Task<ActionResult> GetLocationsAsync()
{
var result = await LocationProvider.GetLocationsAsync();
if (result.IsSuccess)
{
return Ok(result.locations);
}
return NotFound();
}
/// <summary>
/// Get all locations based on locationdId.
/// </summary>
[HttpGet("Locations/{id}")]
public async Task<ActionResult> GetLocationByIdAsync(string id)
{
var result = await LocationProvider.GetLocationByIdAsync(id);
if (result.IsSuccess)
{
return Ok(result.Location);
}
return NotFound();
}
/// <summary>
/// Update a Location.
/// </summary>
[HttpPut("Locations")]
public async Task<IActionResult> UpdateLocation(Models.Location Location)
{
if (Location != null)
{
var result = await this.LocationProvider.UpdateLocationAsync(Location);
if (result.IsSuccess)
{
return Ok(result.ErrorMessage);
}
return NotFound();
}
return NotFound();
}
/// <summary>
/// Save a new location.
/// </summary>
[HttpPost("Locations")]
public async Task<IActionResult> CreateLocation(Models.Location Location)
{
if (Location != null)
{
var result = await this.LocationProvider.PostLocationAsync(Location);
if (result.IsSuccess)
{
return Ok(result.Question);
}
return NotFound();
}
return CreatedAtRoute("DefaultApi", new { id = Location.Id }, Location);
}
/// <summary>
/// Delete an existing location.
/// </summary>
[HttpDelete("Locations/{id}")]
public async Task<IActionResult> DeleteLocation(string id)
{
var result = await this.LocationProvider.DeleteLocationAsync(id);
if (result.IsSuccess)
{
return Ok(result.ErrorMessage);
}
return NotFound();
}
}
}

View File

@ -1,91 +0,0 @@
using DamageAssesment.Api.Locations.Interfaces;
using Microsoft.AspNetCore.Mvc;
namespace DamageAssesment.Api.Locations.Controllers
{
//[Route("api/[controller]")]
[ApiController]
public class RegionsController : ControllerBase
{
private readonly IRegionsProvider regionProvider;
public RegionsController(IRegionsProvider regionProvider)
{
this.regionProvider = regionProvider;
}
/// <summary>
/// Get all regions.
/// </summary>
[HttpGet]
public async Task<ActionResult> GetRegionsAsync()
{
var result = await regionProvider.GetRegionsAsync();
if (result.IsSuccess)
{
return Ok(result.regions);
}
return NoContent();
}
/// <summary>
/// GET request for retrieving a region by its ID.
/// </summary>
[HttpGet("{Id}")]
public async Task<ActionResult> GetRegionAsync(string Id)
{
var result = await this.regionProvider.GetRegionByIdAsync(Id);
if (result.IsSuccess)
{
return Ok(result.Region);
}
return NotFound();
}
/// <summary>
/// POST request for creating a new region.
/// </summary>
[HttpPost]
public async Task<ActionResult> PostRegionAsync(Models.Region region)
{
var result = await this.regionProvider.PostRegionAsync(region);
if (result.IsSuccess)
{
return Ok(result.Region);
}
return BadRequest(result.ErrorMessage);
}
/// <summary>
/// PUT request for updating an existing region.
/// </summary>
[HttpPut]
public async Task<ActionResult> PutRegionAsync(Models.Region region)
{
var result = await this.regionProvider.PutRegionAsync(region);
if (result.IsSuccess)
{
return Ok(result.Region);
}
if (result.ErrorMessage.Equals("Not Found"))
return NotFound(result.ErrorMessage);
return BadRequest(result.ErrorMessage);
}
/// <summary>
/// DELETE request for deleting a region based on ID.
/// </summary>
[HttpDelete("{Id}")]
public async Task<ActionResult> DeleteRegionAsync(string Id)
{
var result = await this.regionProvider.DeleteRegionAsync(Id);
if (result.IsSuccess)
{
return Ok(result.Region);
}
return NotFound();
}
}
}

View File

@ -1,46 +0,0 @@
using DamageAssesment.Api.Locations.Db;
using DamageAssesment.Api.Locations.Interfaces;
using DamageAssesment.Api.Locations.Providers;
using Microsoft.EntityFrameworkCore;
using System.Reflection;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
//builder.Services.AddSwaggerGen();
builder.Services.AddSwaggerGen(c =>
{
// Include XML comments from your assembly
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});
builder.Services.AddScoped<ILocationsProvider, LocationsProvider>();
builder.Services.AddScoped<IRegionsProvider, RegionsProvider>();
builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); //4/30
builder.Services.AddDbContext<LocationDbContext>(option =>
{
option.UseInMemoryDatabase("Locations");
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "");
// options.RoutePrefix = ""; // Serve Swagger UI at the root URL
});
}
app.UseAuthorization();
app.MapControllers();
app.Run();