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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,5 +3,9 @@
|
||||
GET {{Emergence.api_HostAddress}}/tenant/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
GET {{Emergence.api_HostAddress}}/tenant/cc641668-862d-4101-8581-14574d58fd7f/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
GET {{Emergence.api_HostAddress}}/openapi/v1.json
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace Emergence.api.Models;
|
||||
|
||||
public class ErrorDetailResults
|
||||
{
|
||||
public string Title { get; set; }
|
||||
public string Description { get; set; }
|
||||
|
||||
public ErrorDetailResults(string Title, string Description)
|
||||
{
|
||||
this.Title = Title;
|
||||
this.Description = Description;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using Microsoft.AspNetCore.Mvc.ModelBinding;
|
||||
|
||||
namespace Emergence.api.Models;
|
||||
|
||||
public class ValidationProblemResult
|
||||
{
|
||||
public ModelStateDictionary ModelState { get; set; }
|
||||
public ValidationProblemResult(ModelStateDictionary modelState)
|
||||
{
|
||||
ModelState = modelState;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
To add a migration
|
||||
Add-Migration <migrationname> -Project Emergence.data -Startup Emergence.data
|
||||
|
||||
To update the database
|
||||
Update-Database -Project Emergence.data -Startup Emergence.data
|
||||
@@ -4,7 +4,7 @@ using Scalar.AspNetCore;
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddEmergenceServices();
|
||||
builder.Services.AddEmergenceServices(builder.Configuration);
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"AdminConnection": "Data Source=10.1.2.240;Database=Emergence;Integrated Security=false;User Id=emergence;Password=Bed7432Rank!;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
|
||||
},
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
|
||||
Reference in New Issue
Block a user