Finally got the api working properly
This commit is contained in:
@@ -2,11 +2,12 @@
|
|||||||
using Emergence.models;
|
using Emergence.models;
|
||||||
using Emergence.services.Interface;
|
using Emergence.services.Interface;
|
||||||
using Microsoft.AspNetCore.Http.HttpResults;
|
using Microsoft.AspNetCore.Http.HttpResults;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
namespace Emergence.api.Controllers;
|
namespace Emergence.api.Controllers;
|
||||||
|
|
||||||
[ApiController]
|
[ApiController]
|
||||||
[Route("[controller]", Name = "Tenant", Order = 1)]
|
[Route("[controller]")]
|
||||||
public class TenantController : ControllerBase
|
public class TenantController : ControllerBase
|
||||||
{
|
{
|
||||||
private readonly ITenantService _tenantService;
|
private readonly ITenantService _tenantService;
|
||||||
@@ -15,10 +16,14 @@ public class TenantController : ControllerBase
|
|||||||
_tenantService = tenantService;
|
_tenantService = tenantService;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet(Name = "GetTenants"), ProducesResponseType(StatusCodes.Status200OK), ProducesResponseType(StatusCodes.Status404NotFound)]
|
[HttpGet(Name = "GetTenants")]
|
||||||
public async Task<Results<Ok<IList<TenantModel>>, NotFound>> GetAsync()
|
public async Task<Results<Ok<IEnumerable<TenantModel>>, NotFound>> Get()
|
||||||
{
|
{
|
||||||
var tenants = await _tenantService.GetAllAsync();
|
var tenants = await _tenantService.GetAllAsync();
|
||||||
return tenants is IList<TenantModel> result ? TypedResults.Ok(result) : TypedResults.NotFound();
|
if (tenants is null)
|
||||||
|
{
|
||||||
|
return TypedResults.NotFound();
|
||||||
|
}
|
||||||
|
return TypedResults.Ok(tenants);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Emergence.services.Extensions;
|
using Emergence.services.Extensions;
|
||||||
|
using Scalar.AspNetCore;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
@@ -15,6 +16,7 @@ var app = builder.Build();
|
|||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
app.MapOpenApi();
|
app.MapOpenApi();
|
||||||
|
app.MapScalarApiReference();
|
||||||
}
|
}
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
|||||||
@@ -2,13 +2,12 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace Emergence.models
|
namespace Emergence.models;
|
||||||
|
|
||||||
|
public class TenantModel
|
||||||
{
|
{
|
||||||
public class TenantModel
|
public Guid Id { get; set; }
|
||||||
{
|
public string TenantCode { get; set; }
|
||||||
public Guid Id = new Guid();
|
public string CompanyName { get; set; }
|
||||||
public string TenantCode = string.Empty;
|
public bool IsInactive { get; set; }
|
||||||
public string CompanyName = string.Empty;
|
|
||||||
public bool IsInactive = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ namespace Emergence.services.Extensions
|
|||||||
{
|
{
|
||||||
public static IServiceCollection AddEmergenceServices(this IServiceCollection services)
|
public static IServiceCollection AddEmergenceServices(this IServiceCollection services)
|
||||||
{
|
{
|
||||||
services = services.AddTransient<IUserService, UserService>();
|
|
||||||
services = services.AddTransient<ITenantService, TenantService>();
|
services = services.AddTransient<ITenantService, TenantService>();
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace Emergence.services.Interface
|
|||||||
{
|
{
|
||||||
public interface IService<T, I> where T : class
|
public interface IService<T, I> where T : class
|
||||||
{
|
{
|
||||||
public Task<IList<T>> GetAllAsync();
|
public Task<IEnumerable<T>> GetAllAsync();
|
||||||
public Task<T> GetByIdAsync(I id);
|
public Task<T> GetByIdAsync(I id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,13 +9,13 @@ namespace Emergence.services.Services;
|
|||||||
public class TenantService : ITenantService
|
public class TenantService : ITenantService
|
||||||
{
|
{
|
||||||
private List<TenantModel> testList = [
|
private List<TenantModel> testList = [
|
||||||
new TenantModel {TenantCode = "FJP", CompanyName ="Fred J Potter" },
|
new TenantModel {Id = Guid.NewGuid(), TenantCode = "FJP", CompanyName = "Fred J Potter", IsInactive = false },
|
||||||
new TenantModel {TenantCode = "JAZZ", CompanyName ="Jazzbond" },
|
new TenantModel {Id = Guid.NewGuid(), TenantCode = "JAZZ", CompanyName = "Jazzbond", IsInactive = false },
|
||||||
new TenantModel {TenantCode = "TDT", CompanyName ="The Digital Tailor" },
|
new TenantModel {Id = Guid.NewGuid(), TenantCode = "TDT", CompanyName = "The Digital Tailor", IsInactive = false },
|
||||||
new TenantModel {TenantCode = "HBAS", CompanyName ="Hicks Building and Asbestos Services" },
|
new TenantModel {Id = Guid.NewGuid(), TenantCode = "HBAS", CompanyName = "Hicks Building and Asbestos Services", IsInactive = false },
|
||||||
];
|
];
|
||||||
|
|
||||||
public async Task<IList<TenantModel>> GetAllAsync()
|
public async Task<IEnumerable<TenantModel>> GetAllAsync()
|
||||||
{
|
{
|
||||||
return testList;
|
return testList;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user