feat: working on models (#11)

This commit is contained in:
cswimr 2025-01-29 21:04:56 +00:00
parent 24849b3246
commit 75e18507aa
Signed by: cswimr
GPG key ID: 0EC431A8DA8F8087
6 changed files with 65 additions and 24 deletions

27
Data/Moderation.cs Normal file
View file

@ -0,0 +1,27 @@
namespace Myhm.Data;
public class Moderation
{
public int Id { get; set; }
public string UserId { get; set; } = default!;
public ModerationTypes Type { get; set; }
public string Reason { get; set; } = default!;
public ModerationReasons ReasonType { get; set; }
public DateTime CreatedAt { get; set; }
}
public enum ModerationTypes
{
Ban,
Warn,
}
// TODO: Get reasons from @MYHM and add them here
public enum ModerationReasons
{
Spamming,
Harassment,
HateSpeech,
NSFW,
Other,
}

17
Data/MyhmConfiguration.cs Normal file
View file

@ -0,0 +1,17 @@
namespace Myhm.Data
{
public class MyhmConfiguration
{
public required string AuthToken { get; init; }
public required string DatabaseConnectionString { get; init; }
public required DatabaseTypes DatabaseType { get; init; }
public bool UseSentry { get; init; } = true;
public bool UseSwagger { get; init; } = true;
public bool LogRequests { get; init; } = true;
}
public enum DatabaseTypes
{
PostgresSQL,
}
}

View file

@ -1,15 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Myhm.Models;
using static EnumStringValues.EnumExtensions;
namespace Myhm.Data
{
public class MyhmContext(DbContextOptions<MyhmContext> options) : DbContext(options)
{
public DbSet<Moderation> Moderation { get; set; } = default!;
public DbSet<Token> Token { get; set; } = default!;
//public DbSet<Myhm.Models.Ban> Ban { get; set; } = default!;
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder
.Entity<Moderation>()
.Property(m => m.Type)
.HasConversion(v => v.GetStringValue(), v => v.ParseToEnum<ModerationTypes>());
modelBuilder
.Entity<Moderation>()
.Property(m => m.ReasonType)
.HasConversion(v => v.GetStringValue(), v => v.ParseToEnum<ModerationReasons>());
}
}
}

9
Data/Token.cs Normal file
View file

@ -0,0 +1,9 @@
namespace Myhm.Data;
public class Token
{
public int Id { get; set; }
public string String { get; set; } = default!;
public int DiscordUserId { get; set; }
public DateTime CreatedAt { get; set; }
}