From 3529b0a41bed5140326a7ad26a6bd23262116c33 Mon Sep 17 00:00:00 2001 From: Goran Date: Sat, 17 Jan 2026 22:17:50 +0100 Subject: [PATCH] endpoints --- Endpoints/UserAccess.cs | 42 +++++++++++++++++++++++++++++++++++++++++ Program.cs | 8 +++----- 2 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 Endpoints/UserAccess.cs diff --git a/Endpoints/UserAccess.cs b/Endpoints/UserAccess.cs new file mode 100644 index 0000000..02f0878 --- /dev/null +++ b/Endpoints/UserAccess.cs @@ -0,0 +1,42 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; + +namespace Emberend.Endpoints; + +public static class UserAccess +{ + public static void MapUserAccessEndpoints(this IEndpointRouteBuilder routes) + { + MapGetLogin(routes); + MapGetUserById(routes); + MapGetRegister(routes); + } + + private static void MapGetLogin(IEndpointRouteBuilder routes) + { + routes.MapGet("/login", async context => + { + await context.Response.WriteAsync("/login"); + }); + } + + private static void MapGetRegister(IEndpointRouteBuilder routes) + { + routes.MapGet("/register", async context => + { + await context.Response.WriteAsync("/register"); + }); + } + + private static void MapGetUserById(IEndpointRouteBuilder routes) + { + routes.MapGet("/user/{id}", async context => + { + var id = context.Request.RouteValues["id"]; + //Dodaj null check ^ + + await context.Response.WriteAsync($"User: {id}"); + }); + } +} + diff --git a/Program.cs b/Program.cs index dbbff81..3ab515d 100644 --- a/Program.cs +++ b/Program.cs @@ -1,9 +1,8 @@ +using Emberend.Endpoints; using System.Net; var builder = WebApplication.CreateBuilder(args); -// Add services to the container. -// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); @@ -23,7 +22,6 @@ builder.WebHost.ConfigureKestrel(options => var app = builder.Build(); -// Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { app.UseSwagger(); @@ -31,7 +29,9 @@ if (app.Environment.IsDevelopment()) } +app.MapUserAccessEndpoints(); +//Ne treba jer koristimo nginx kao relay/proxy... //app.UseHttpsRedirection(); @@ -40,14 +40,12 @@ app.MapGet("/", async (HttpContext context) => await context.Response.WriteAsync("Hello, alex-api.onlystefan.com"); }); - app.MapGet("/test", async (HttpContext context) => { await context.Response.WriteAsync("test"); }); - app.Run();