Initial API setup and basic program functioning

This commit is contained in:
2026-03-24 12:29:07 +10:30
parent e5fcaad365
commit f26ff6e04a
17 changed files with 279 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
using Emergence.api.Interfaces;
using Emergence.models;
using Emergence.services.Interface;
using Microsoft.AspNetCore.Http.HttpResults;
namespace Emergence.api.Endpoints;
public class UserEndpoints : IEndpoint
{
private readonly IUserService _userService;
public UserEndpoints(IUserService userService)
{
_userService = userService;
}
public void MapEndPoint(IEndpointRouteBuilder app)
{
var endpoints = app.MapGroup("/users")
.WithTags("User Items");
endpoints.MapGet("/", GetAll).Produces<List<UserModel>>(StatusCodes.Status200OK).Produces(StatusCodes.Status404NotFound).WithName("Get All Users");
endpoints.MapGet("/{id}", GetById).Produces<string>(StatusCodes.Status200OK).Produces(StatusCodes.Status404NotFound).WithName("Get User By Id");
}
public async Task<Results<Ok<List<UserModel>>, NotFound>> GetAll() =>
await _userService.GetAllAsync() is List<UserModel> result ? TypedResults.Ok(result) : TypedResults.NotFound();
public async Task<Results<Ok<UserModel>, NotFound>> GetById(int id) =>
await _userService.GetByIdAsync(id) is UserModel result ? TypedResults.Ok(result) : TypedResults.NotFound();
}