Fixed controller adding from Api library

This commit is contained in:
2024-07-13 21:59:55 +02:00
parent df93bc410f
commit ec7982471e
9 changed files with 108 additions and 26 deletions

View File

@@ -2,4 +2,3 @@
bin
Migrations
appsettings.Development.json
test.db

View File

@@ -1,4 +1,3 @@
using HopFrame.Api.Controller;
using HopFrame.Security.Authorization;
using HopFrame.Security.Claims;
using Microsoft.AspNetCore.Mvc;
@@ -6,7 +5,8 @@ using Microsoft.AspNetCore.Mvc;
namespace DatabaseTest.Controllers;
[ApiController]
public class TestController(DatabaseContext context, ITokenContext userContext) : SecurityController<DatabaseContext>(context) {
[Route("test")]
public class TestController(ITokenContext userContext) : ControllerBase {
[HttpGet("permissions"), Authorized]
public ActionResult<IList<string>> Permissions() {

View File

@@ -7,6 +7,6 @@ public class DatabaseContext : HopDbContextBase {
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) {
base.OnConfiguring(optionsBuilder);
optionsBuilder.UseSqlite("Data Source=C:\\Users\\Remote\\Documents\\Projekte\\HopFrame\\DatabaseTest\\test.db;Mode=ReadWrite;");
optionsBuilder.UseSqlite("Data Source=C:\\Users\\Remote\\Documents\\Projekte\\HopFrame\\DatabaseTest\\bin\\Debug\\net8.0\\test.db;Mode=ReadWrite;");
}
}

View File

@@ -1,22 +1,18 @@
using DatabaseTest;
using HopFrame.Api;
using HopFrame.Api.Controller;
using HopFrame.Security.Authentication;
using HopFrame.Api.Extensions;
using Microsoft.OpenApi.Models;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers()
.AddController<SecurityController<DatabaseContext>>();
builder.Services.AddControllers();
builder.Services.AddHopFrame<DatabaseContext>();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddDbContext<DatabaseContext>();
builder.Services.AddHopFrameAuthentication<DatabaseContext>();
//builder.Logging.AddFilter<HopFrameAuthentication<DatabaseContext>>(options => options == LogLevel.None);
builder.Services.AddSwaggerGen(c => {
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme {
@@ -51,7 +47,7 @@ if (app.Environment.IsDevelopment()) {
app.UseSwaggerUI();
}
//app.UseHttpsRedirection();
app.UseHttpsRedirection();
app.UseAuthorization();

Binary file not shown.