using System.Text.Json.Serialization; using OptixServe.Core.Services; using OptixServe.Api.Dtos; namespace OptixServe.Api.Endpoints; [JsonSerializable(typeof(UserDto))] [JsonSerializable(typeof(IEnumerable))] public partial class UserJsonContext : JsonSerializerContext { } public static class UserEndpoint { public static void Register(WebApplication app) { var group = app.MapGroup("/users"); group.MapGet("/", GetAllUsers); group.MapGet("/{id}", GetUserById); } public static IResult GetAllUsers(IUserService userService) { var users = userService.GetUsers() .Select(u => new UserDto { Id = u.Id, UserName = u.UserName }); return Results.Ok(users); } public static IResult GetUserById(string id, IUserService userService) { var user = userService.GetUserById(id); if (user == null) return Results.NotFound(); return Results.Ok(new UserDto { Id = user.Id, UserName = user.UserName }); } }