Created services for remaining database models

This commit is contained in:
quentin 2024-04-22 18:04:14 -05:00
parent 10cce72fbc
commit 27846f596e
11 changed files with 151 additions and 1 deletions

View File

@ -10,6 +10,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.1"/> <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.1"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0-preview.3.24172.4"/> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0-preview.3.24172.4"/>
<PackageReference Include="Serilog.AspNetCore" Version="8.0.2-dev-00338" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0"/> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0"/>
</ItemGroup> </ItemGroup>

View File

@ -2,7 +2,7 @@ using DAL.Models;
namespace API.Authentication.Interfaces namespace API.Authentication.Interfaces
{ {
public interface IGenericAuthentication<T, TModel> public interface IGenericAuthentication<in T, in TModel>
{ {
bool canGetAll(User user); bool canGetAll(User user);
bool canGet(TModel model, User user); bool canGet(TModel model, User user);

View File

@ -0,0 +1,6 @@
namespace API.Authentication.Interfaces
{
public interface IYesAuthentication : IGenericAuthentication<object, object>
{
}
}

View File

@ -0,0 +1,41 @@
using API.Authentication.Interfaces;
using DAL.Models;
namespace API.Authentication
{
public class YesAuthentication : IYesAuthentication
{
private readonly ILogger<YesAuthentication> _logger;
public YesAuthentication(ILogger<YesAuthentication> logger)
{
_logger = logger;
_logger.Log(LogLevel.Warning, "Yes Authentication being used.");
}
public bool canGetAll(User user)
{
_logger.Log(LogLevel.Warning, "Yes Authentication being used.");
return true;
}
public bool canGet(object model, User user)
{
_logger.Log(LogLevel.Warning, "Yes Authentication being used.");
return true;
}
public bool canAdd(object item, User user)
{
_logger.Log(LogLevel.Warning, "Yes Authentication being used.");
return true;
}
public bool canUpdate(object model, User user)
{
_logger.Log(LogLevel.Warning, "Yes Authentication being used.");
return true;
}
public bool canDelete(object model, User user)
{
_logger.Log(LogLevel.Warning, "Yes Authentication being used.");
return true;
}
}
}

View File

@ -1,6 +1,7 @@
using API.Services; using API.Services;
using DAL.Contexts; using DAL.Contexts;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Serilog;
using System.Reflection; using System.Reflection;
using InvalidOperationException = System.InvalidOperationException; using InvalidOperationException = System.InvalidOperationException;
@ -22,9 +23,17 @@ namespace API
options.IncludeXmlComments(xmlPath, true); options.IncludeXmlComments(xmlPath, true);
}); });
builder.Host.UseSerilog((context, configuration) => configuration.ReadFrom.Configuration(context.Configuration));
builder.Services.AddDbContext<SASGContext>(options => { options.UseMySQL(builder.Configuration["connectionString"] ?? throw new InvalidOperationException("Connection String is null")); }); builder.Services.AddDbContext<SASGContext>(options => { options.UseMySQL(builder.Configuration["connectionString"] ?? throw new InvalidOperationException("Connection String is null")); });
builder.Services.AddTransient<ColorService>(); builder.Services.AddTransient<ColorService>();
builder.Services.AddTransient<EventService>();
builder.Services.AddTransient<GrantService>();
builder.Services.AddTransient<ImageService>();
builder.Services.AddTransient<PermissionService>();
builder.Services.AddTransient<SavedEventService>();
builder.Services.AddTransient<UserService>();
WebApplication app = builder.Build(); WebApplication app = builder.Build();

View File

@ -0,0 +1,15 @@
using API.Authentication.Interfaces;
using API.DTO.Base;
using DAL.Contexts;
using DAL.Models;
using DAL.Models.Audits;
namespace API.Services
{
public class EventService : ServiceBase<EventService, EventDTO, Event, AuditEvent, IYesAuthentication>
{
public EventService(ILogger<EventService> logger, SASGContext context, IYesAuthentication auth) : base(logger, context, auth)
{
}
}
}

View File

@ -0,0 +1,15 @@
using API.Authentication.Interfaces;
using API.DTO.Base;
using DAL.Contexts;
using DAL.Models;
using DAL.Models.Audits;
namespace API.Services
{
public class GrantService : ServiceBase<GrantService, GrantDTO, Grant, AuditGrant, IYesAuthentication>
{
public GrantService(ILogger<GrantService> logger, SASGContext context, IYesAuthentication auth) : base(logger, context, auth)
{
}
}
}

View File

@ -0,0 +1,15 @@
using API.Authentication.Interfaces;
using API.DTO.Base;
using DAL.Contexts;
using DAL.Models;
using DAL.Models.Audits;
namespace API.Services
{
public class ImageService : ServiceBase<ImageService, ImageDTO, Image, AuditImage, IYesAuthentication>
{
public ImageService(ILogger<ImageService> logger, SASGContext context, IYesAuthentication auth) : base(logger, context, auth)
{
}
}
}

View File

@ -0,0 +1,16 @@
using API.Authentication.Interfaces;
using API.DTO.Base;
using DAL.Contexts;
using DAL.Models;
using DAL.Models.Audits;
namespace API.Services
{
public class PermissionService : ServiceBase<PermissionService, PermissionDTO, Permission, AuditPermission, IYesAuthentication>
{
public PermissionService(ILogger<PermissionService> logger, SASGContext context, IYesAuthentication auth) : base(logger, context, auth)
{
}
}
}

View File

@ -0,0 +1,16 @@
using API.Authentication.Interfaces;
using API.DTO.Base;
using DAL.Contexts;
using DAL.Models;
using DAL.Models.Audits;
namespace API.Services
{
public class SavedEventService : ServiceBase<SavedEventService, SavedEventDTO, SavedEvent, AuditSavedEvent, IYesAuthentication>
{
public SavedEventService(ILogger<SavedEventService> logger, SASGContext context, IYesAuthentication auth) : base(logger, context, auth)
{
}
}
}

View File

@ -0,0 +1,16 @@
using API.Authentication.Interfaces;
using API.DTO.Base;
using DAL.Contexts;
using DAL.Models;
using DAL.Models.Audits;
namespace API.Services
{
public class UserService : ServiceBase<UserService, UserDTO, User, AuditUser, IYesAuthentication>
{
public UserService(ILogger<UserService> logger, SASGContext context, IYesAuthentication auth) : base(logger, context, auth)
{
}
}
}