mirror of
https://github.com/Bubuni-Team/telegram-bot.git
synced 2026-07-31 00:29:24 +03:00
[reputation] Move reputation to separate module.
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
using Kruzya.TelegramBot.Core.EF;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace West.TelegramBot.Reputation.Data;
|
||||
|
||||
public class ReputationContext : AutoSaveDbContext
|
||||
{
|
||||
public DbSet<UserReputation> UserReputation { get; set; } = null!;
|
||||
|
||||
public ReputationContext(DbContextOptions<ReputationContext> options) : base(options)
|
||||
{
|
||||
Database.EnsureCreated();
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<UserReputation>().HasKey(e => new {e.ChatId, e.UserId});
|
||||
modelBuilder.Entity<UserReputation>().HasIndex(e => e.ChatId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace West.TelegramBot.Reputation.Data;
|
||||
|
||||
public class UserReputation
|
||||
{
|
||||
public long UserId { get; set; }
|
||||
|
||||
public long ChatId { get; set; }
|
||||
|
||||
public double Value { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#nullable enable
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Design;
|
||||
|
||||
namespace West.TelegramBot.Reputation.Data;
|
||||
|
||||
public class ReputationContextFactory : IDesignTimeDbContextFactory<ReputationContext>
|
||||
{
|
||||
public ReputationContext CreateDbContext(string[] args)
|
||||
{
|
||||
var optionsBuilder = new DbContextOptionsBuilder<ReputationContext>();
|
||||
if (args.Length != 1)
|
||||
{
|
||||
throw new InvalidDataException("You should pass DSN as CLI argument in order to use this.");
|
||||
}
|
||||
var dsn = args[0];
|
||||
optionsBuilder.UseMySql(dsn, ServerVersion.AutoDetect(dsn));
|
||||
|
||||
return new ReputationContext(optionsBuilder.Options);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user