Adding MaidBotApi

This commit is contained in:
Zeeshaun
2026-03-11 13:21:47 -05:00
parent f3cb730f3b
commit f004c8205a
122 changed files with 4227 additions and 0 deletions
@@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.0.2</Version>
<Description>
1.0.0 - Initial Creation
1.0.1 - Add BusinessOperations Group Enum
1.0.2 - Add IndirectLending Group Enum
</Description>
<PackageReleaseNotes>
1.0.0 - Initial Creation
1.0.1 - Add BusinessOperations Group Enum
1.0.2 - Add IndirectLending Group Enum
</PackageReleaseNotes>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="3.1.10" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.7.0" />
</ItemGroup>
</Project>
@@ -0,0 +1,20 @@
namespace LCU.Api.Internal.MaidBotLib.Models
{
public class DebugEventLog
{
public const int DebugMaxLength = 3000;
public DebugEventLog()
{
}
public DebugEventLog(EventLog eventLog)
{
RawLog = eventLog.DebugData.Length > DebugMaxLength ? eventLog.DebugData.Substring(0, DebugMaxLength) : eventLog.DebugData;
}
public int DebugEventLogId { get; set; }
public string RawLog { get; set; }
}
}
@@ -0,0 +1,16 @@
using System;
namespace LCU.Api.Internal.MaidBotLib.Models
{
public class EventLog
{
public int EventLogId { get; set; }
public string Application { get; set; }
public string Level { get; set; }
public string Group { get; set; }
public DateTime LogTimeStamp { get; set; }
public string Message { get; set; }
public string Environment { get; set; }
public string DebugData { get; set; }
}
}
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace LCU.Api.Internal.MaidBotLib.Models
{
public enum GroupEnum
{
Testing,
ITDevelopment,
BusinessOperations,
IndirectLending
}
}
@@ -0,0 +1,18 @@
using System.ComponentModel.DataAnnotations;
namespace LCU.Api.Internal.MaidBotLib.Models
{
public class LoggingMatrix
{
public int LoggingMatrixId { get; set; }
[StringLength(200, MinimumLength = 1, ErrorMessage = "Application field must have a length between 1 and 200 characters")]
public string Application { get; set; }
[StringLength(50, MinimumLength = 1, ErrorMessage = "Level field must have a length between 1 and 50 characters")]
public string Level { get; set; }
[StringLength(100, MinimumLength = 1, ErrorMessage = "Groups field must have a length between 1 and 100 characters")]
public string Group { get; set; }
[StringLength(100, MinimumLength = 1, ErrorMessage = "Emails field must have a length between 1 and 100 characters")]
public string Email { get; set; }
public bool Disabled { get; set; }
}
}
@@ -0,0 +1,7 @@
namespace LCU.Api.Internal.MaidBotLib.Models
{
public enum PropertyEnum
{
Group
}
}
@@ -0,0 +1,23 @@
using LCU.Api.Internal.MaidBotLib.Models;
using Microsoft.EntityFrameworkCore;
namespace LCU.Api.Internal.MaidBotLib.Persistence
{
public class AppDbContext : DbContext
{
public DbSet<LoggingMatrix> LoggingMatrixs { get; set; }
public DbSet<EventLog> EventLogs { get; set; }
public DbSet<DebugEventLog> DebugEventLogs { get; set; }
public AppDbContext(DbContextOptions<AppDbContext> options) : base(options) { }
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<LoggingMatrix>().ToTable("LoggingMatrix");
builder.Entity<EventLog>().ToTable("EventLog");
builder.Entity<DebugEventLog>().ToTable("DebugEventLog");
}
}
}
@@ -0,0 +1,17 @@
using LCU.Api.Internal.MaidBotLib.Persistence;
using System;
using System.Collections.Generic;
using System.Text;
namespace LCU.Api.Internal.MaidBotLib.Repositories
{
public abstract class BaseRepository
{
protected readonly AppDbContext _context;
public BaseRepository(AppDbContext context)
{
_context = context;
}
}
}
@@ -0,0 +1,20 @@
using LCU.Api.Internal.MaidBotLib.Models;
using LCU.Api.Internal.MaidBotLib.Persistence;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace LCU.Api.Internal.MaidBotLib.Repositories
{
public class DebugEventLogRepository : BaseRepository, IDebugEventLogRepository
{
public DebugEventLogRepository(AppDbContext context) : base(context) { }
public async Task<DebugEventLog> AddAsync(DebugEventLog debugEventLog)
{
var result = await _context.DebugEventLogs.AddAsync(debugEventLog);
return result.Entity;
}
}
}
@@ -0,0 +1,29 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using LCU.Api.Internal.MaidBotLib.Models;
using LCU.Api.Internal.MaidBotLib.Persistence;
namespace LCU.Api.Internal.MaidBotLib.Repositories
{
public class EventLogRepository : BaseRepository, IEventLogRepository
{
public EventLogRepository(AppDbContext context) : base(context) { }
public async Task<IEnumerable<EventLog>> ListAsync()
{
return await _context.EventLogs.ToListAsync();
}
public async Task<EventLog> AddAsync(EventLog eventLog)
{
var result = await _context.EventLogs.AddAsync(eventLog);
return result.Entity;
}
public void RemoveRange(List<EventLog> eventLog)
{
_context.EventLogs.RemoveRange(eventLog);
}
}
}
@@ -0,0 +1,13 @@
using LCU.Api.Internal.MaidBotLib.Models;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace LCU.Api.Internal.MaidBotLib.Repositories
{
public interface IDebugEventLogRepository
{
Task<DebugEventLog> AddAsync(DebugEventLog debugEventLog);
}
}
@@ -0,0 +1,13 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using LCU.Api.Internal.MaidBotLib.Models;
namespace LCU.Api.Internal.MaidBotLib.Repositories
{
public interface IEventLogRepository
{
Task<IEnumerable<EventLog>> ListAsync();
Task<EventLog> AddAsync(EventLog eventLog);
void RemoveRange(List<EventLog> eventLog);
}
}
@@ -0,0 +1,19 @@
using LCU.Api.Internal.MaidBotLib.Models;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace LCU.Api.Internal.MaidBotLib.Repositories
{
public interface ILoggingMatrixRepository
{
Task<IEnumerable<LoggingMatrix>> ListAsync();
Task<IEnumerable<LoggingMatrix>> ListActiveAsync();
Task<LoggingMatrix> FindByIdAsync(int id);
Task<IEnumerable<LoggingMatrix>> RetrieveByApplicationLevelAndGroup(string application, string level, string group);
Task<IEnumerable<LoggingMatrix>> RetrieveByApplciationAndLevel(string application, string level);
Task<LoggingMatrix> AddAsync(LoggingMatrix loggingMatrix);
void Update(LoggingMatrix loggingMatrix);
}
}
@@ -0,0 +1,10 @@
using System.Threading.Tasks;
namespace LCU.Api.Internal.MaidBotLib.Repositories
{
public interface IUnitOfWork
{
Task CompleteAsync();
void Complete();
}
}
@@ -0,0 +1,59 @@
using LCU.Api.Internal.MaidBotLib.Models;
using LCU.Api.Internal.MaidBotLib.Persistence;
using Microsoft.EntityFrameworkCore;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace LCU.Api.Internal.MaidBotLib.Repositories
{
public class LoggingMatrixRepository : BaseRepository, ILoggingMatrixRepository
{
public LoggingMatrixRepository(AppDbContext context) : base(context) { }
public async Task<IEnumerable<LoggingMatrix>> ListAsync()
{
return await _context.LoggingMatrixs.ToListAsync();
}
public async Task<IEnumerable<LoggingMatrix>> ListActiveAsync()
{
return await _context.LoggingMatrixs.Where(loggingMatrix => !loggingMatrix.Disabled).ToListAsync();
}
public async Task<LoggingMatrix> FindByIdAsync(int id)
{
return await _context.LoggingMatrixs.Where(loggingMatrix => loggingMatrix.LoggingMatrixId == id).FirstOrDefaultAsync();
}
public async Task<IEnumerable<LoggingMatrix>> RetrieveByApplicationLevelAndGroup(string application, string level, string group)
{
return await _context.LoggingMatrixs
.Where(matrix => matrix.Application == application &&
matrix.Level == level &&
matrix.Group == group &&
!matrix.Disabled)
.ToListAsync();
}
public async Task<IEnumerable<LoggingMatrix>> RetrieveByApplciationAndLevel(string application, string level)
{
return await _context.LoggingMatrixs
.Where(matrix => matrix.Application == application &&
matrix.Level == level &&
!matrix.Disabled)
.ToListAsync();
}
public async Task<LoggingMatrix> AddAsync(LoggingMatrix loggingMatrix)
{
var result = await _context.LoggingMatrixs.AddAsync(loggingMatrix);
return result.Entity;
}
public void Update(LoggingMatrix loggingMatrix)
{
_context.LoggingMatrixs.Update(loggingMatrix);
}
}
}
@@ -0,0 +1,25 @@
using LCU.Api.Internal.MaidBotLib.Persistence;
using System.Threading.Tasks;
namespace LCU.Api.Internal.MaidBotLib.Repositories
{
public class UnitOfWork : IUnitOfWork
{
private readonly AppDbContext _context;
public UnitOfWork(AppDbContext context)
{
_context = context;
}
public async Task CompleteAsync()
{
await _context.SaveChangesAsync();
}
public void Complete()
{
_context.SaveChanges();
}
}
}