Add EF objects

This commit is contained in:
Jiří Vrabec 2025-08-09 01:00:49 +02:00
parent 6c5a4bfb26
commit b7996872cb
16 changed files with 167 additions and 8 deletions

View file

@ -1,10 +1,10 @@
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
public class ApplicationDbContext : IdentityDbContext<IdentityUser>
namespace DrinkRateAPI.Contexts;
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) :
public ApplicationDbContext(DbContextOptions<DbContext> options) :
base(options)
{ }
}

View file

@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
namespace DrinkRateAPI.Contexts;
public class IdentityDbContext : IdentityDbContext<IdentityUser>
{
public IdentityDbContext(DbContextOptions<IdentityDbContext> options) :
base(options)
{ }
}

View file

@ -0,0 +1,14 @@
namespace DrinkRateAPI.DbEntities;
public class DbCompany
{
public Guid Id { get; set; }
public Guid TableId { get; set; }
public ICollection<DbProduct> Products { get; set; }
public ICollection<DbCompanyRating> CompanyRatings { get; set; }
public string CompanyName { get; set; }
}

View file

@ -0,0 +1,14 @@
namespace DrinkRateAPI.DbEntities;
public class DbCompanyRating
{
public Guid UserId { get; set; }
public Guid CompanyId { get; set; }
public Guid CompanyTableId { get; set; }
public byte Rating { get; set; }
public string? Comment { get; set; }
}

View file

@ -0,0 +1,10 @@
namespace DrinkRateAPI.DbEntities;
public class DbCompanyTable
{
public string TableName { get; set; }
public ICollection<DbCompany> Companies { get; set; }
public ICollection<DbCompanyRating> CompanyRatings { get; set; }
}

View file

@ -0,0 +1,12 @@
namespace DrinkRateAPI.DbEntities;
public class DbCompanyTableView
{
public Guid Id { get; set; }
public Guid CompanyTableId { get; set; }
public ICollection<DbUser> Users { get; set; }
// to do: permission types
}

View file

@ -0,0 +1,12 @@
namespace DrinkRateAPI.DbEntities;
public class DbProduct
{
public Guid Id { get; set; }
public Guid CompanyId { get; set; }
public Guid TableId { get; set; }
public ICollection<DbProductRating> ProductRatings { get; set; }
}

View file

@ -0,0 +1,14 @@
namespace DrinkRateAPI.DbEntities;
public class DbProductRating
{
public Guid UserId { get; set; }
public Guid ProductId { get; set; }
public Guid ProductTableId { get; set; }
public byte Rating { get; set; }
public string? Comment { get; set; }
}

View file

@ -0,0 +1,12 @@
namespace DrinkRateAPI.DbEntities;
public class DbProductTable
{
public Guid Id { get; set; }
public string TableName { get; set; }
public ICollection<DbProduct> Products { get; set; }
public ICollection<DbProductRating> ProductRatings { get; set; }
}

View file

@ -0,0 +1,13 @@
namespace DrinkRateAPI.DbEntities;
public class DbProductTableView
{
public Guid Id { get; set; }
public Guid ProductTableId { get; set; }
public ICollection<DbUser> Users { get; set; }
// to do: permission types
}

View file

@ -0,0 +1,17 @@
namespace DrinkRateAPI.DbEntities;
public class DbUser
{
public Guid Id { get; set; }
public ICollection<DbCompanyTableView> CompanyTableViews { get; set; }
public ICollection<DbProductTableView> ProductTableViews { get; set; }
public ICollection<DbCompanyRating> CompanyRatings { get; set; }
public ICollection<DbProductRating> ProductRatings { get; set; }
public ICollection<DbUserCompanyTableStats> UserCompanyTableStats { get; set; }
public ICollection<DbUserProductTableStats> UserProductTableStats { get; set; }
public string UserName { get; set; }
}

View file

@ -0,0 +1,14 @@
namespace DrinkRateAPI.DbEntities;
public class DbUserCompanyTableStats
{
public Guid UserId { get; set; }
public Guid CompanyTabelId { get; set; }
public int Count { get; set; }
public int MaxCount { get; set; }
public int Credits { get; set; }
}

View file

@ -0,0 +1,14 @@
namespace DrinkRateAPI.DbEntities;
public class DbUserProductTableStats
{
public Guid UserId { get; set; }
public Guid ProductTabelId { get; set; }
public int Count { get; set; }
public int MaxCount { get; set; }
public int Credits { get; set; }
}

View file

@ -1,3 +1,4 @@
using DrinkRateAPI.Contexts;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.OpenApi.Models;
@ -11,7 +12,7 @@ builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddAuthorization();
builder.Services.AddIdentityApiEndpoints<IdentityUser>()
.AddEntityFrameworkStores<ApplicationDbContext>();
.AddEntityFrameworkStores<IdentityDbContext>();
builder.Services.AddSwaggerGen(c =>
{
@ -48,7 +49,7 @@ builder.Services.AddSwaggerGen(c =>
});
// to do: remove
builder.Services.AddDbContext<ApplicationDbContext>(
builder.Services.AddDbContext<IdentityDbContext>(
options => options.UseInMemoryDatabase("AppDb"));
var app = builder.Build();

View file

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("DrinkRateAPI")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+6c5a4bfb26569a7e7265bb1c583a538c85c2e021")]
[assembly: System.Reflection.AssemblyProductAttribute("DrinkRateAPI")]
[assembly: System.Reflection.AssemblyTitleAttribute("DrinkRateAPI")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View file

@ -1 +1 @@
a800cf208542da2e16464ad5cac9564d078e4662a36df15e3e96ae4fd84319f7
b838a9c23df8ad83db19dac2d0874f8f00f1219871c8dec6180564b8a5404e88