added a notes file for important running stuff
Create working for tenant and added in efcore and data layer
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Emergence.api.Models;
|
||||
using Emergence.models;
|
||||
using Emergence.services.Interface;
|
||||
using Microsoft.AspNetCore.Http.HttpResults;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Emergence.api.Controllers;
|
||||
@@ -17,7 +18,7 @@ public class TenantController : ControllerBase
|
||||
}
|
||||
|
||||
[HttpGet(Name = "GetTenants")]
|
||||
public async Task<Results<Ok<IEnumerable<TenantModel>>, NotFound>> Get()
|
||||
public async Task<Results<Ok<IEnumerable<TenantModel>>, NotFound>> GetTenants()
|
||||
{
|
||||
var tenants = await _tenantService.GetAllAsync();
|
||||
if (tenants is null)
|
||||
@@ -26,4 +27,32 @@ public class TenantController : ControllerBase
|
||||
}
|
||||
return TypedResults.Ok(tenants);
|
||||
}
|
||||
|
||||
[HttpGet("{id}", Name = "GetTenantById")]
|
||||
public async Task<Results<Ok<TenantModel>, NotFound, BadRequest>> GetTenantById(Guid id)
|
||||
{
|
||||
var tenant = await _tenantService.GetByIdAsync(id);
|
||||
if (tenant is null)
|
||||
{
|
||||
return TypedResults.NotFound();
|
||||
}
|
||||
return TypedResults.Ok(tenant);
|
||||
}
|
||||
|
||||
[HttpPost(Name = "CreateTenant")]
|
||||
public async Task<Results<Created<TenantModel>, Conflict<ErrorDetailResults>, BadRequest<ValidationProblemResult>, UnprocessableEntity<ErrorDetailResults>>> Create(TenantModel tenant)
|
||||
{
|
||||
if (tenant == null || !ModelState.IsValid)
|
||||
return TypedResults.BadRequest<ValidationProblemResult>(new ValidationProblemResult(ModelState));
|
||||
|
||||
if (tenant.Id.HasValue && tenant.Id.Value != Guid.Empty && _tenantService.GetByIdAsync(tenant.Id.Value).Result != null)
|
||||
return TypedResults.Conflict(new ErrorDetailResults($"Tenant already exists", $"Tenant with the id: {tenant.Id} already exists"));
|
||||
|
||||
var newTenant = await _tenantService.CreateAsync(tenant);
|
||||
if (newTenant is null)
|
||||
{
|
||||
return TypedResults.UnprocessableEntity(new ErrorDetailResults($"Tenant failed to create", $"The new tenant failed to create. Please try again."));
|
||||
}
|
||||
return TypedResults.Created($"/tenant/{newTenant.Id}", newTenant);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user