transactions

This commit is contained in:
2025-08-24 14:18:20 +02:00
parent 1b2d95344a
commit 5777e351bf
107 changed files with 4940 additions and 1266 deletions

View File

@@ -5,41 +5,41 @@ using Microsoft.Extensions.Options;
namespace back.persistance.blob;
public class FileSystemImageStorageService(
IOptions<Databases> systemOptions,
IOptions<Databases> systemOptions,
IOptionsMonitor<DatabaseConfig> options,
IMemoryCache memoryCache
) : IBlobStorageService
) : IBlobStorageService
{
private readonly string RootPath = systemOptions.Value.BaseDirectory ?? "";
private readonly string RootPath = systemOptions.Value.BaseDirectory ?? "data";
private readonly DatabaseConfig config = options.Get(DatabaseConfig.BlobStorage);
private readonly IMemoryCache cache = memoryCache;
private string GetFullPath(string fileName)
{
// Ensure the directory exists
var directory = Path.Join(RootPath, config.SystemContainer, fileName);
var path = Path.Join(RootPath, config.SystemContainer, fileName);
var directory = Path.GetDirectoryName(path);
if (directory != null && !Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
return fileName;
return path;
}
public async Task DeleteAsync(string fileName)
public async Task Delete(string fileName)
{
var path = GetFullPath(fileName);
if (cache.TryGetValue(path, out Stream cachedStream))
{
cachedStream.Dispose(); // Dispose the cached stream if it exists
cache.Remove(path); // Remove from cache
}
if (!File.Exists(path))
{
return; // No file to delete
}
try
{
File.Delete(path);
var path = GetFullPath(fileName);
if (cache.TryGetValue(path, out Stream? cachedStream))
{
cachedStream?.Dispose(); // Dispose the cached stream if it exists
cache.Remove(path); // Remove from cache
}
if (File.Exists(path))
{
File.Delete(path);
}
}
catch (Exception ex)
{
@@ -47,14 +47,14 @@ public class FileSystemImageStorageService(
}
}
public Task<Stream?> GetStreamAsync(string fileName)
public async Task<Stream?> GetStream(string fileName)
{
var path = GetFullPath(fileName);
if (File.Exists(path))
{
if (cache.TryGetValue(path, out Stream? cachedStream))
{
return Task.FromResult<Stream?>(cachedStream);
return cachedStream;
}
// open the file stream for multiple reads and cache it for performance
var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
@@ -63,14 +63,14 @@ public class FileSystemImageStorageService(
.SetValue(fileStream)
.SetSlidingExpiration(TimeSpan.FromMinutes(30)); // Cache for 30 minutes
return Task.FromResult<Stream?>(fileStream);
return fileStream;
}
return Task.FromResult<Stream?>(null);
return null;
}
public async Task<byte[]?> GetBytesAsync(string fileName)
public async Task<byte[]?> GetBytes(string fileName)
{
var stream = await GetStreamAsync(fileName);
var stream = await GetStream(fileName);
if (stream != null)
{
using var memoryStream = new MemoryStream();
@@ -80,25 +80,25 @@ public class FileSystemImageStorageService(
return null;
}
public async Task SaveAsync(Stream blobStream, string fileName)
public async Task Save(Stream blobStream, string fileName)
{
var path = GetFullPath(fileName);
if (cache.TryGetValue(path, out Stream? _) || File.Exists(path))
{
throw new InvalidOperationException($"File {fileName} already exists. Use Update for updating file info.");
}
using var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write);
using var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read);
await blobStream.CopyToAsync(fileStream);
}
public async Task UpdateAsync(Stream blobStream, string fileName)
public async Task Update(Stream blobStream, string fileName)
{
var path = GetFullPath(fileName);
if (File.Exists(path))
{
await DeleteAsync(fileName);
await Delete(fileName);
}
await SaveAsync(blobStream, fileName);
await Save(blobStream, fileName);
}
}

View File

@@ -1,11 +1,13 @@
namespace back.persistance.blob;
using DependencyInjector.Lifetimes;
public interface IBlobStorageService
namespace back.persistance.blob;
public interface IBlobStorageService : ISingleton
{
Task SaveAsync(Stream blobStream, string fileName);
Task<Stream?> GetStreamAsync(string fileName);
Task<byte[]?> GetBytesAsync(string fileName);
Task DeleteAsync(string fileName);
Task UpdateAsync(Stream blobStream, string fileName);
Task Save(Stream blobStream, string fileName);
Task<Stream?> GetStream(string fileName);
Task<byte[]?> GetBytes(string fileName);
Task Delete(string fileName);
Task Update(Stream blobStream, string fileName);
}

View File

@@ -0,0 +1,65 @@
using back.DataModels;
using back.persistance.data.relations;
using Microsoft.EntityFrameworkCore;
namespace back.persistance.data;
public partial class DataContext : DbContext
{
public DataContext() { }
public DataContext(DbContextOptions<DataContext> options) : base(options) { }
public virtual DbSet<EfmigrationsLock> EfmigrationsLocks { get; set; }
public virtual DbSet<Event> Events { get; set; }
public virtual DbSet<Gallery> Galleries { get; set; }
public virtual DbSet<Permission> Permissions { get; set; }
public virtual DbSet<Person> Persons { get; set; }
public virtual DbSet<Photo> Photos { get; set; }
public virtual DbSet<Ranking> Rankings { get; set; }
public virtual DbSet<Role> Roles { get; set; }
public virtual DbSet<SocialMedia> SocialMedia { get; set; }
public virtual DbSet<Tag> Tags { get; set; }
public virtual DbSet<User> Users { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<EfmigrationsLock>(entity =>
{
entity.ToTable("__EFMigrationsLock");
entity.Property(e => e.Id).ValueGeneratedNever();
});
typeof(IRelationEstablisher).Assembly.GetExportedTypes()
.Where(t => typeof(IRelationEstablisher).IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract)
.ToList()
.ForEach(seederType =>
{
var relationEstablisher = (IRelationEstablisher?)Activator.CreateInstance(seederType);
relationEstablisher?.EstablishRelation(modelBuilder);
});
//typeof(ISeeder).Assembly.GetExportedTypes()
// .Where(t => typeof(ISeeder).IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract)
// .ToList()
// .ForEach(seederType =>
// {
// var seeder = (ISeeder?)Activator.CreateInstance(seederType);
// seeder?.Seed(modelBuilder);
// });
OnModelCreatingPartial(modelBuilder);
}
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}

View File

@@ -0,0 +1,752 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using back.persistance.data;
#nullable disable
namespace back.Migrations
{
[DbContext(typeof(DataContext))]
[Migration("20250824120656_InitialSetup")]
partial class InitialSetup
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "9.0.8");
modelBuilder.Entity("EventTag", b =>
{
b.Property<string>("EventId")
.HasColumnType("TEXT");
b.Property<string>("TagId")
.HasColumnType("TEXT");
b.HasKey("EventId", "TagId");
b.HasIndex("TagId");
b.ToTable("EventTags", (string)null);
});
modelBuilder.Entity("GalleryPhoto", b =>
{
b.Property<string>("GalleryId")
.HasColumnType("TEXT");
b.Property<string>("PhotoId")
.HasColumnType("TEXT");
b.HasKey("GalleryId", "PhotoId");
b.HasIndex("PhotoId");
b.ToTable("GalleryPhotos", (string)null);
});
modelBuilder.Entity("GalleryTag", b =>
{
b.Property<string>("GalleryId")
.HasColumnType("TEXT");
b.Property<string>("TagId")
.HasColumnType("TEXT");
b.HasKey("GalleryId", "TagId");
b.HasIndex("TagId");
b.ToTable("GalleryTags", (string)null);
});
modelBuilder.Entity("GalleryUserViewer", b =>
{
b.Property<string>("GalleryId")
.HasColumnType("TEXT");
b.Property<string>("UserId")
.HasColumnType("TEXT");
b.HasKey("GalleryId", "UserId");
b.HasIndex("UserId");
b.ToTable("GalleryUserViewers", (string)null);
});
modelBuilder.Entity("PhotoPerson", b =>
{
b.Property<string>("PhotoId")
.HasColumnType("TEXT");
b.Property<string>("PersonId")
.HasColumnType("TEXT");
b.HasKey("PhotoId", "PersonId");
b.HasIndex("PersonId");
b.ToTable("PhotoPersons", (string)null);
});
modelBuilder.Entity("PhotoTag", b =>
{
b.Property<string>("PhotoId")
.HasColumnType("TEXT");
b.Property<string>("TagId")
.HasColumnType("TEXT");
b.HasKey("PhotoId", "TagId");
b.HasIndex("TagId");
b.ToTable("PhotoTags", (string)null);
});
modelBuilder.Entity("PhotoUserBuyer", b =>
{
b.Property<string>("PhotoId")
.HasColumnType("TEXT");
b.Property<string>("UserId")
.HasColumnType("TEXT");
b.HasKey("PhotoId", "UserId");
b.HasIndex("UserId");
b.ToTable("PhotoUserBuyers", (string)null);
});
modelBuilder.Entity("RolePermission", b =>
{
b.Property<string>("RoleId")
.HasColumnType("TEXT");
b.Property<string>("PermissionId")
.HasColumnType("TEXT");
b.HasKey("RoleId", "PermissionId");
b.HasIndex("PermissionId");
b.ToTable("RolePermissions", (string)null);
});
modelBuilder.Entity("UserRole", b =>
{
b.Property<string>("UserId")
.HasColumnType("TEXT");
b.Property<string>("RoleId")
.HasColumnType("TEXT");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("UserRoles", (string)null);
});
modelBuilder.Entity("back.DataModels.EfmigrationsLock", b =>
{
b.Property<int>("Id")
.HasColumnType("INTEGER");
b.Property<string>("Timestamp")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("__EFMigrationsLock", (string)null);
});
modelBuilder.Entity("back.DataModels.Event", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreatedAt")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("CreatedBy")
.HasColumnType("TEXT");
b.Property<string>("Date")
.HasColumnType("TEXT");
b.Property<string>("DeletedAt")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<int>("IsDeleted")
.HasColumnType("INTEGER");
b.Property<string>("Location")
.HasColumnType("TEXT");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("UpdatedAt")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("UpdatedBy")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Events");
});
modelBuilder.Entity("back.DataModels.Gallery", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("DeletedAt")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<string>("EventId")
.HasColumnType("TEXT");
b.Property<int?>("IsArchived")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasDefaultValue(0);
b.Property<int>("IsDeleted")
.HasColumnType("INTEGER");
b.Property<int?>("IsFavorite")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasDefaultValue(0);
b.Property<int?>("IsPublic")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasDefaultValue(1);
b.Property<string>("Title")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("UpdatedAt")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("CreatedBy");
b.HasIndex("EventId");
b.ToTable("Galleries");
});
modelBuilder.Entity("back.DataModels.Permission", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasMaxLength(255)
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Permissions");
});
modelBuilder.Entity("back.DataModels.Person", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("Avatar")
.HasColumnType("TEXT");
b.Property<string>("Bio")
.HasMaxLength(250)
.HasColumnType("TEXT");
b.Property<string>("CreatedAt")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("DeletedAt")
.HasColumnType("TEXT");
b.Property<int>("IsDeleted")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("ProfilePicture")
.HasColumnType("TEXT");
b.Property<string>("SocialMediaId")
.HasColumnType("TEXT");
b.Property<string>("UpdatedAt")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("SocialMediaId");
b.ToTable("Persons");
});
modelBuilder.Entity("back.DataModels.Photo", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<string>("EventId")
.HasColumnType("TEXT");
b.Property<string>("Extension")
.HasColumnType("TEXT");
b.Property<string>("HighResUrl")
.HasColumnType("TEXT");
b.Property<int?>("IsArchived")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasDefaultValue(0);
b.Property<int?>("IsFavorite")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasDefaultValue(0);
b.Property<int?>("IsPublic")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasDefaultValue(1);
b.Property<string>("LowResUrl")
.HasColumnType("TEXT");
b.Property<string>("MidResUrl")
.HasColumnType("TEXT");
b.Property<string>("RankingId")
.HasColumnType("TEXT");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("UpdatedAt")
.HasColumnType("TEXT");
b.Property<string>("UpdatedBy")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("CreatedBy");
b.HasIndex("EventId");
b.ToTable("Photos");
});
modelBuilder.Entity("back.DataModels.Ranking", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<int>("DownVotes")
.HasColumnType("INTEGER");
b.Property<int>("TotalVotes")
.HasColumnType("INTEGER");
b.Property<int>("UpVotes")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.ToTable("Rankings");
});
modelBuilder.Entity("back.DataModels.Role", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("BaseRoleModelId")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasMaxLength(250)
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("BaseRoleModelId");
b.ToTable("Roles");
});
modelBuilder.Entity("back.DataModels.SocialMedia", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("BlueSky")
.HasColumnType("TEXT");
b.Property<string>("Discord")
.HasColumnType("TEXT");
b.Property<string>("Facebook")
.HasColumnType("TEXT");
b.Property<string>("Instagram")
.HasColumnType("TEXT");
b.Property<string>("Linkedin")
.HasColumnType("TEXT");
b.Property<string>("Other")
.HasColumnType("TEXT");
b.Property<string>("Pinterest")
.HasColumnType("TEXT");
b.Property<string>("Reddit")
.HasColumnType("TEXT");
b.Property<string>("Tiktok")
.HasColumnType("TEXT");
b.Property<string>("Twitter")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("SocialMedia");
});
modelBuilder.Entity("back.DataModels.Tag", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreatedAt")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(25)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex(new[] { "Name" }, "IX_Tags_Name")
.IsUnique();
b.ToTable("Tags");
});
modelBuilder.Entity("back.DataModels.User", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreatedAt")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Salt")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("EventTag", b =>
{
b.HasOne("back.DataModels.Event", null)
.WithMany()
.HasForeignKey("EventId")
.IsRequired();
b.HasOne("back.DataModels.Tag", null)
.WithMany()
.HasForeignKey("TagId")
.IsRequired();
});
modelBuilder.Entity("GalleryPhoto", b =>
{
b.HasOne("back.DataModels.Gallery", null)
.WithMany()
.HasForeignKey("GalleryId")
.IsRequired();
b.HasOne("back.DataModels.Photo", null)
.WithMany()
.HasForeignKey("PhotoId")
.IsRequired();
});
modelBuilder.Entity("GalleryTag", b =>
{
b.HasOne("back.DataModels.Gallery", null)
.WithMany()
.HasForeignKey("GalleryId")
.IsRequired();
b.HasOne("back.DataModels.Tag", null)
.WithMany()
.HasForeignKey("TagId")
.IsRequired();
});
modelBuilder.Entity("GalleryUserViewer", b =>
{
b.HasOne("back.DataModels.Gallery", null)
.WithMany()
.HasForeignKey("GalleryId")
.IsRequired();
b.HasOne("back.DataModels.User", null)
.WithMany()
.HasForeignKey("UserId")
.IsRequired();
});
modelBuilder.Entity("PhotoPerson", b =>
{
b.HasOne("back.DataModels.Person", null)
.WithMany()
.HasForeignKey("PersonId")
.IsRequired();
b.HasOne("back.DataModels.Photo", null)
.WithMany()
.HasForeignKey("PhotoId")
.IsRequired();
});
modelBuilder.Entity("PhotoTag", b =>
{
b.HasOne("back.DataModels.Photo", null)
.WithMany()
.HasForeignKey("PhotoId")
.IsRequired();
b.HasOne("back.DataModels.Tag", null)
.WithMany()
.HasForeignKey("TagId")
.IsRequired();
});
modelBuilder.Entity("PhotoUserBuyer", b =>
{
b.HasOne("back.DataModels.Photo", null)
.WithMany()
.HasForeignKey("PhotoId")
.IsRequired();
b.HasOne("back.DataModels.User", null)
.WithMany()
.HasForeignKey("UserId")
.IsRequired();
});
modelBuilder.Entity("RolePermission", b =>
{
b.HasOne("back.DataModels.Permission", null)
.WithMany()
.HasForeignKey("PermissionId")
.IsRequired();
b.HasOne("back.DataModels.Role", null)
.WithMany()
.HasForeignKey("RoleId")
.IsRequired();
});
modelBuilder.Entity("UserRole", b =>
{
b.HasOne("back.DataModels.Role", null)
.WithMany()
.HasForeignKey("RoleId")
.IsRequired();
b.HasOne("back.DataModels.User", null)
.WithMany()
.HasForeignKey("UserId")
.IsRequired();
});
modelBuilder.Entity("back.DataModels.Gallery", b =>
{
b.HasOne("back.DataModels.User", "CreatedByNavigation")
.WithMany("Galleries")
.HasForeignKey("CreatedBy")
.IsRequired();
b.HasOne("back.DataModels.Event", "Event")
.WithMany("Galleries")
.HasForeignKey("EventId");
b.Navigation("CreatedByNavigation");
b.Navigation("Event");
});
modelBuilder.Entity("back.DataModels.Person", b =>
{
b.HasOne("back.DataModels.SocialMedia", "SocialMedia")
.WithMany("People")
.HasForeignKey("SocialMediaId");
b.Navigation("SocialMedia");
});
modelBuilder.Entity("back.DataModels.Photo", b =>
{
b.HasOne("back.DataModels.Person", "CreatedByNavigation")
.WithMany("Photos")
.HasForeignKey("CreatedBy")
.IsRequired();
b.HasOne("back.DataModels.Event", "Event")
.WithMany("Photos")
.HasForeignKey("EventId");
b.Navigation("CreatedByNavigation");
b.Navigation("Event");
});
modelBuilder.Entity("back.DataModels.Role", b =>
{
b.HasOne("back.DataModels.Role", "BaseRoleModel")
.WithMany("InverseBaseRoleModel")
.HasForeignKey("BaseRoleModelId");
b.Navigation("BaseRoleModel");
});
modelBuilder.Entity("back.DataModels.User", b =>
{
b.HasOne("back.DataModels.Person", "IdNavigation")
.WithOne("User")
.HasForeignKey("back.DataModels.User", "Id")
.IsRequired();
b.Navigation("IdNavigation");
});
modelBuilder.Entity("back.DataModels.Event", b =>
{
b.Navigation("Galleries");
b.Navigation("Photos");
});
modelBuilder.Entity("back.DataModels.Person", b =>
{
b.Navigation("Photos");
b.Navigation("User");
});
modelBuilder.Entity("back.DataModels.Role", b =>
{
b.Navigation("InverseBaseRoleModel");
});
modelBuilder.Entity("back.DataModels.SocialMedia", b =>
{
b.Navigation("People");
});
modelBuilder.Entity("back.DataModels.User", b =>
{
b.Navigation("Galleries");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,583 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace back.Migrations
{
/// <inheritdoc />
public partial class InitialSetup : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "__EFMigrationsLock",
columns: table => new
{
Id = table.Column<int>(type: "INTEGER", nullable: false),
Timestamp = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK___EFMigrationsLock", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Events",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", nullable: false),
Title = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
Description = table.Column<string>(type: "TEXT", maxLength: 500, nullable: true),
Date = table.Column<string>(type: "TEXT", nullable: true),
Location = table.Column<string>(type: "TEXT", nullable: true),
CreatedAt = table.Column<string>(type: "TEXT", nullable: false),
UpdatedAt = table.Column<string>(type: "TEXT", nullable: false),
CreatedBy = table.Column<string>(type: "TEXT", nullable: true),
UpdatedBy = table.Column<string>(type: "TEXT", nullable: true),
IsDeleted = table.Column<int>(type: "INTEGER", nullable: false),
DeletedAt = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Events", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Permissions",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
Description = table.Column<string>(type: "TEXT", maxLength: 255, nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Permissions", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Rankings",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", nullable: false),
TotalVotes = table.Column<int>(type: "INTEGER", nullable: false),
UpVotes = table.Column<int>(type: "INTEGER", nullable: false),
DownVotes = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Rankings", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Roles",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
Description = table.Column<string>(type: "TEXT", maxLength: 250, nullable: true),
BaseRoleModelId = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Roles", x => x.Id);
table.ForeignKey(
name: "FK_Roles_Roles_BaseRoleModelId",
column: x => x.BaseRoleModelId,
principalTable: "Roles",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "SocialMedia",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", nullable: false),
Facebook = table.Column<string>(type: "TEXT", nullable: true),
Instagram = table.Column<string>(type: "TEXT", nullable: true),
Twitter = table.Column<string>(type: "TEXT", nullable: true),
BlueSky = table.Column<string>(type: "TEXT", nullable: true),
Tiktok = table.Column<string>(type: "TEXT", nullable: true),
Linkedin = table.Column<string>(type: "TEXT", nullable: true),
Pinterest = table.Column<string>(type: "TEXT", nullable: true),
Discord = table.Column<string>(type: "TEXT", nullable: true),
Reddit = table.Column<string>(type: "TEXT", nullable: true),
Other = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_SocialMedia", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Tags",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", maxLength: 25, nullable: false),
CreatedAt = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Tags", x => x.Id);
});
migrationBuilder.CreateTable(
name: "RolePermissions",
columns: table => new
{
RoleId = table.Column<string>(type: "TEXT", nullable: false),
PermissionId = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_RolePermissions", x => new { x.RoleId, x.PermissionId });
table.ForeignKey(
name: "FK_RolePermissions_Permissions_PermissionId",
column: x => x.PermissionId,
principalTable: "Permissions",
principalColumn: "Id");
table.ForeignKey(
name: "FK_RolePermissions_Roles_RoleId",
column: x => x.RoleId,
principalTable: "Roles",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Persons",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", nullable: false),
Name = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
ProfilePicture = table.Column<string>(type: "TEXT", nullable: true),
Avatar = table.Column<string>(type: "TEXT", nullable: true),
SocialMediaId = table.Column<string>(type: "TEXT", nullable: true),
Bio = table.Column<string>(type: "TEXT", maxLength: 250, nullable: true),
CreatedAt = table.Column<string>(type: "TEXT", nullable: false),
UpdatedAt = table.Column<string>(type: "TEXT", nullable: true),
IsDeleted = table.Column<int>(type: "INTEGER", nullable: false),
DeletedAt = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Persons", x => x.Id);
table.ForeignKey(
name: "FK_Persons_SocialMedia_SocialMediaId",
column: x => x.SocialMediaId,
principalTable: "SocialMedia",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "EventTags",
columns: table => new
{
EventId = table.Column<string>(type: "TEXT", nullable: false),
TagId = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_EventTags", x => new { x.EventId, x.TagId });
table.ForeignKey(
name: "FK_EventTags_Events_EventId",
column: x => x.EventId,
principalTable: "Events",
principalColumn: "Id");
table.ForeignKey(
name: "FK_EventTags_Tags_TagId",
column: x => x.TagId,
principalTable: "Tags",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Photos",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", nullable: false),
Title = table.Column<string>(type: "TEXT", maxLength: 100, nullable: false),
Description = table.Column<string>(type: "TEXT", maxLength: 500, nullable: true),
Extension = table.Column<string>(type: "TEXT", nullable: true),
LowResUrl = table.Column<string>(type: "TEXT", nullable: true),
MidResUrl = table.Column<string>(type: "TEXT", nullable: true),
HighResUrl = table.Column<string>(type: "TEXT", nullable: true),
CreatedAt = table.Column<string>(type: "TEXT", nullable: true),
UpdatedAt = table.Column<string>(type: "TEXT", nullable: true),
CreatedBy = table.Column<string>(type: "TEXT", nullable: false),
UpdatedBy = table.Column<string>(type: "TEXT", nullable: true),
EventId = table.Column<string>(type: "TEXT", nullable: true),
RankingId = table.Column<string>(type: "TEXT", nullable: true),
IsFavorite = table.Column<int>(type: "INTEGER", nullable: true, defaultValue: 0),
IsPublic = table.Column<int>(type: "INTEGER", nullable: true, defaultValue: 1),
IsArchived = table.Column<int>(type: "INTEGER", nullable: true, defaultValue: 0)
},
constraints: table =>
{
table.PrimaryKey("PK_Photos", x => x.Id);
table.ForeignKey(
name: "FK_Photos_Events_EventId",
column: x => x.EventId,
principalTable: "Events",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Photos_Persons_CreatedBy",
column: x => x.CreatedBy,
principalTable: "Persons",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", nullable: false),
Email = table.Column<string>(type: "TEXT", nullable: false),
Password = table.Column<string>(type: "TEXT", nullable: false),
Salt = table.Column<string>(type: "TEXT", nullable: false),
CreatedAt = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Users", x => x.Id);
table.ForeignKey(
name: "FK_Users_Persons_Id",
column: x => x.Id,
principalTable: "Persons",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "PhotoPersons",
columns: table => new
{
PhotoId = table.Column<string>(type: "TEXT", nullable: false),
PersonId = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PhotoPersons", x => new { x.PhotoId, x.PersonId });
table.ForeignKey(
name: "FK_PhotoPersons_Persons_PersonId",
column: x => x.PersonId,
principalTable: "Persons",
principalColumn: "Id");
table.ForeignKey(
name: "FK_PhotoPersons_Photos_PhotoId",
column: x => x.PhotoId,
principalTable: "Photos",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "PhotoTags",
columns: table => new
{
PhotoId = table.Column<string>(type: "TEXT", nullable: false),
TagId = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PhotoTags", x => new { x.PhotoId, x.TagId });
table.ForeignKey(
name: "FK_PhotoTags_Photos_PhotoId",
column: x => x.PhotoId,
principalTable: "Photos",
principalColumn: "Id");
table.ForeignKey(
name: "FK_PhotoTags_Tags_TagId",
column: x => x.TagId,
principalTable: "Tags",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Galleries",
columns: table => new
{
Id = table.Column<string>(type: "TEXT", nullable: false),
Title = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
Description = table.Column<string>(type: "TEXT", maxLength: 500, nullable: true),
CreatedAt = table.Column<string>(type: "TEXT", nullable: true),
UpdatedAt = table.Column<string>(type: "TEXT", nullable: true),
CreatedBy = table.Column<string>(type: "TEXT", nullable: false),
IsPublic = table.Column<int>(type: "INTEGER", nullable: true, defaultValue: 1),
IsArchived = table.Column<int>(type: "INTEGER", nullable: true, defaultValue: 0),
IsFavorite = table.Column<int>(type: "INTEGER", nullable: true, defaultValue: 0),
IsDeleted = table.Column<int>(type: "INTEGER", nullable: false),
DeletedAt = table.Column<string>(type: "TEXT", nullable: true),
EventId = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Galleries", x => x.Id);
table.ForeignKey(
name: "FK_Galleries_Events_EventId",
column: x => x.EventId,
principalTable: "Events",
principalColumn: "Id");
table.ForeignKey(
name: "FK_Galleries_Users_CreatedBy",
column: x => x.CreatedBy,
principalTable: "Users",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "PhotoUserBuyers",
columns: table => new
{
PhotoId = table.Column<string>(type: "TEXT", nullable: false),
UserId = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PhotoUserBuyers", x => new { x.PhotoId, x.UserId });
table.ForeignKey(
name: "FK_PhotoUserBuyers_Photos_PhotoId",
column: x => x.PhotoId,
principalTable: "Photos",
principalColumn: "Id");
table.ForeignKey(
name: "FK_PhotoUserBuyers_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "UserRoles",
columns: table => new
{
UserId = table.Column<string>(type: "TEXT", nullable: false),
RoleId = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_UserRoles", x => new { x.UserId, x.RoleId });
table.ForeignKey(
name: "FK_UserRoles_Roles_RoleId",
column: x => x.RoleId,
principalTable: "Roles",
principalColumn: "Id");
table.ForeignKey(
name: "FK_UserRoles_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "GalleryPhotos",
columns: table => new
{
GalleryId = table.Column<string>(type: "TEXT", nullable: false),
PhotoId = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GalleryPhotos", x => new { x.GalleryId, x.PhotoId });
table.ForeignKey(
name: "FK_GalleryPhotos_Galleries_GalleryId",
column: x => x.GalleryId,
principalTable: "Galleries",
principalColumn: "Id");
table.ForeignKey(
name: "FK_GalleryPhotos_Photos_PhotoId",
column: x => x.PhotoId,
principalTable: "Photos",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "GalleryTags",
columns: table => new
{
GalleryId = table.Column<string>(type: "TEXT", nullable: false),
TagId = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GalleryTags", x => new { x.GalleryId, x.TagId });
table.ForeignKey(
name: "FK_GalleryTags_Galleries_GalleryId",
column: x => x.GalleryId,
principalTable: "Galleries",
principalColumn: "Id");
table.ForeignKey(
name: "FK_GalleryTags_Tags_TagId",
column: x => x.TagId,
principalTable: "Tags",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "GalleryUserViewers",
columns: table => new
{
GalleryId = table.Column<string>(type: "TEXT", nullable: false),
UserId = table.Column<string>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_GalleryUserViewers", x => new { x.GalleryId, x.UserId });
table.ForeignKey(
name: "FK_GalleryUserViewers_Galleries_GalleryId",
column: x => x.GalleryId,
principalTable: "Galleries",
principalColumn: "Id");
table.ForeignKey(
name: "FK_GalleryUserViewers_Users_UserId",
column: x => x.UserId,
principalTable: "Users",
principalColumn: "Id");
});
migrationBuilder.CreateIndex(
name: "IX_EventTags_TagId",
table: "EventTags",
column: "TagId");
migrationBuilder.CreateIndex(
name: "IX_Galleries_CreatedBy",
table: "Galleries",
column: "CreatedBy");
migrationBuilder.CreateIndex(
name: "IX_Galleries_EventId",
table: "Galleries",
column: "EventId");
migrationBuilder.CreateIndex(
name: "IX_GalleryPhotos_PhotoId",
table: "GalleryPhotos",
column: "PhotoId");
migrationBuilder.CreateIndex(
name: "IX_GalleryTags_TagId",
table: "GalleryTags",
column: "TagId");
migrationBuilder.CreateIndex(
name: "IX_GalleryUserViewers_UserId",
table: "GalleryUserViewers",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_Persons_SocialMediaId",
table: "Persons",
column: "SocialMediaId");
migrationBuilder.CreateIndex(
name: "IX_PhotoPersons_PersonId",
table: "PhotoPersons",
column: "PersonId");
migrationBuilder.CreateIndex(
name: "IX_Photos_CreatedBy",
table: "Photos",
column: "CreatedBy");
migrationBuilder.CreateIndex(
name: "IX_Photos_EventId",
table: "Photos",
column: "EventId");
migrationBuilder.CreateIndex(
name: "IX_PhotoTags_TagId",
table: "PhotoTags",
column: "TagId");
migrationBuilder.CreateIndex(
name: "IX_PhotoUserBuyers_UserId",
table: "PhotoUserBuyers",
column: "UserId");
migrationBuilder.CreateIndex(
name: "IX_RolePermissions_PermissionId",
table: "RolePermissions",
column: "PermissionId");
migrationBuilder.CreateIndex(
name: "IX_Roles_BaseRoleModelId",
table: "Roles",
column: "BaseRoleModelId");
migrationBuilder.CreateIndex(
name: "IX_Tags_Name",
table: "Tags",
column: "Name",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_UserRoles_RoleId",
table: "UserRoles",
column: "RoleId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "__EFMigrationsLock");
migrationBuilder.DropTable(
name: "EventTags");
migrationBuilder.DropTable(
name: "GalleryPhotos");
migrationBuilder.DropTable(
name: "GalleryTags");
migrationBuilder.DropTable(
name: "GalleryUserViewers");
migrationBuilder.DropTable(
name: "PhotoPersons");
migrationBuilder.DropTable(
name: "PhotoTags");
migrationBuilder.DropTable(
name: "PhotoUserBuyers");
migrationBuilder.DropTable(
name: "Rankings");
migrationBuilder.DropTable(
name: "RolePermissions");
migrationBuilder.DropTable(
name: "UserRoles");
migrationBuilder.DropTable(
name: "Galleries");
migrationBuilder.DropTable(
name: "Tags");
migrationBuilder.DropTable(
name: "Photos");
migrationBuilder.DropTable(
name: "Permissions");
migrationBuilder.DropTable(
name: "Roles");
migrationBuilder.DropTable(
name: "Users");
migrationBuilder.DropTable(
name: "Events");
migrationBuilder.DropTable(
name: "Persons");
migrationBuilder.DropTable(
name: "SocialMedia");
}
}
}

View File

@@ -0,0 +1,749 @@
// <auto-generated />
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using back.persistance.data;
#nullable disable
namespace back.Migrations
{
[DbContext(typeof(DataContext))]
partial class DataContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "9.0.8");
modelBuilder.Entity("EventTag", b =>
{
b.Property<string>("EventId")
.HasColumnType("TEXT");
b.Property<string>("TagId")
.HasColumnType("TEXT");
b.HasKey("EventId", "TagId");
b.HasIndex("TagId");
b.ToTable("EventTags", (string)null);
});
modelBuilder.Entity("GalleryPhoto", b =>
{
b.Property<string>("GalleryId")
.HasColumnType("TEXT");
b.Property<string>("PhotoId")
.HasColumnType("TEXT");
b.HasKey("GalleryId", "PhotoId");
b.HasIndex("PhotoId");
b.ToTable("GalleryPhotos", (string)null);
});
modelBuilder.Entity("GalleryTag", b =>
{
b.Property<string>("GalleryId")
.HasColumnType("TEXT");
b.Property<string>("TagId")
.HasColumnType("TEXT");
b.HasKey("GalleryId", "TagId");
b.HasIndex("TagId");
b.ToTable("GalleryTags", (string)null);
});
modelBuilder.Entity("GalleryUserViewer", b =>
{
b.Property<string>("GalleryId")
.HasColumnType("TEXT");
b.Property<string>("UserId")
.HasColumnType("TEXT");
b.HasKey("GalleryId", "UserId");
b.HasIndex("UserId");
b.ToTable("GalleryUserViewers", (string)null);
});
modelBuilder.Entity("PhotoPerson", b =>
{
b.Property<string>("PhotoId")
.HasColumnType("TEXT");
b.Property<string>("PersonId")
.HasColumnType("TEXT");
b.HasKey("PhotoId", "PersonId");
b.HasIndex("PersonId");
b.ToTable("PhotoPersons", (string)null);
});
modelBuilder.Entity("PhotoTag", b =>
{
b.Property<string>("PhotoId")
.HasColumnType("TEXT");
b.Property<string>("TagId")
.HasColumnType("TEXT");
b.HasKey("PhotoId", "TagId");
b.HasIndex("TagId");
b.ToTable("PhotoTags", (string)null);
});
modelBuilder.Entity("PhotoUserBuyer", b =>
{
b.Property<string>("PhotoId")
.HasColumnType("TEXT");
b.Property<string>("UserId")
.HasColumnType("TEXT");
b.HasKey("PhotoId", "UserId");
b.HasIndex("UserId");
b.ToTable("PhotoUserBuyers", (string)null);
});
modelBuilder.Entity("RolePermission", b =>
{
b.Property<string>("RoleId")
.HasColumnType("TEXT");
b.Property<string>("PermissionId")
.HasColumnType("TEXT");
b.HasKey("RoleId", "PermissionId");
b.HasIndex("PermissionId");
b.ToTable("RolePermissions", (string)null);
});
modelBuilder.Entity("UserRole", b =>
{
b.Property<string>("UserId")
.HasColumnType("TEXT");
b.Property<string>("RoleId")
.HasColumnType("TEXT");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("UserRoles", (string)null);
});
modelBuilder.Entity("back.DataModels.EfmigrationsLock", b =>
{
b.Property<int>("Id")
.HasColumnType("INTEGER");
b.Property<string>("Timestamp")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("__EFMigrationsLock", (string)null);
});
modelBuilder.Entity("back.DataModels.Event", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreatedAt")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("CreatedBy")
.HasColumnType("TEXT");
b.Property<string>("Date")
.HasColumnType("TEXT");
b.Property<string>("DeletedAt")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<int>("IsDeleted")
.HasColumnType("INTEGER");
b.Property<string>("Location")
.HasColumnType("TEXT");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(50)
.HasColumnType("TEXT");
b.Property<string>("UpdatedAt")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("UpdatedBy")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Events");
});
modelBuilder.Entity("back.DataModels.Gallery", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("DeletedAt")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<string>("EventId")
.HasColumnType("TEXT");
b.Property<int?>("IsArchived")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasDefaultValue(0);
b.Property<int>("IsDeleted")
.HasColumnType("INTEGER");
b.Property<int?>("IsFavorite")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasDefaultValue(0);
b.Property<int?>("IsPublic")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasDefaultValue(1);
b.Property<string>("Title")
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("UpdatedAt")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("CreatedBy");
b.HasIndex("EventId");
b.ToTable("Galleries");
});
modelBuilder.Entity("back.DataModels.Permission", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasMaxLength(255)
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Permissions");
});
modelBuilder.Entity("back.DataModels.Person", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("Avatar")
.HasColumnType("TEXT");
b.Property<string>("Bio")
.HasMaxLength(250)
.HasColumnType("TEXT");
b.Property<string>("CreatedAt")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("DeletedAt")
.HasColumnType("TEXT");
b.Property<int>("IsDeleted")
.HasColumnType("INTEGER");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("ProfilePicture")
.HasColumnType("TEXT");
b.Property<string>("SocialMediaId")
.HasColumnType("TEXT");
b.Property<string>("UpdatedAt")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("SocialMediaId");
b.ToTable("Persons");
});
modelBuilder.Entity("back.DataModels.Photo", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreatedAt")
.HasColumnType("TEXT");
b.Property<string>("CreatedBy")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasMaxLength(500)
.HasColumnType("TEXT");
b.Property<string>("EventId")
.HasColumnType("TEXT");
b.Property<string>("Extension")
.HasColumnType("TEXT");
b.Property<string>("HighResUrl")
.HasColumnType("TEXT");
b.Property<int?>("IsArchived")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasDefaultValue(0);
b.Property<int?>("IsFavorite")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasDefaultValue(0);
b.Property<int?>("IsPublic")
.ValueGeneratedOnAdd()
.HasColumnType("INTEGER")
.HasDefaultValue(1);
b.Property<string>("LowResUrl")
.HasColumnType("TEXT");
b.Property<string>("MidResUrl")
.HasColumnType("TEXT");
b.Property<string>("RankingId")
.HasColumnType("TEXT");
b.Property<string>("Title")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.Property<string>("UpdatedAt")
.HasColumnType("TEXT");
b.Property<string>("UpdatedBy")
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("CreatedBy");
b.HasIndex("EventId");
b.ToTable("Photos");
});
modelBuilder.Entity("back.DataModels.Ranking", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<int>("DownVotes")
.HasColumnType("INTEGER");
b.Property<int>("TotalVotes")
.HasColumnType("INTEGER");
b.Property<int>("UpVotes")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.ToTable("Rankings");
});
modelBuilder.Entity("back.DataModels.Role", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("BaseRoleModelId")
.HasColumnType("TEXT");
b.Property<string>("Description")
.HasMaxLength(250)
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(100)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex("BaseRoleModelId");
b.ToTable("Roles");
});
modelBuilder.Entity("back.DataModels.SocialMedia", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("BlueSky")
.HasColumnType("TEXT");
b.Property<string>("Discord")
.HasColumnType("TEXT");
b.Property<string>("Facebook")
.HasColumnType("TEXT");
b.Property<string>("Instagram")
.HasColumnType("TEXT");
b.Property<string>("Linkedin")
.HasColumnType("TEXT");
b.Property<string>("Other")
.HasColumnType("TEXT");
b.Property<string>("Pinterest")
.HasColumnType("TEXT");
b.Property<string>("Reddit")
.HasColumnType("TEXT");
b.Property<string>("Tiktok")
.HasColumnType("TEXT");
b.Property<string>("Twitter")
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("SocialMedia");
});
modelBuilder.Entity("back.DataModels.Tag", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreatedAt")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Name")
.IsRequired()
.HasMaxLength(25)
.HasColumnType("TEXT");
b.HasKey("Id");
b.HasIndex(new[] { "Name" }, "IX_Tags_Name")
.IsUnique();
b.ToTable("Tags");
});
modelBuilder.Entity("back.DataModels.User", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("CreatedAt")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Email")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("TEXT");
b.Property<string>("Salt")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("Id");
b.ToTable("Users");
});
modelBuilder.Entity("EventTag", b =>
{
b.HasOne("back.DataModels.Event", null)
.WithMany()
.HasForeignKey("EventId")
.IsRequired();
b.HasOne("back.DataModels.Tag", null)
.WithMany()
.HasForeignKey("TagId")
.IsRequired();
});
modelBuilder.Entity("GalleryPhoto", b =>
{
b.HasOne("back.DataModels.Gallery", null)
.WithMany()
.HasForeignKey("GalleryId")
.IsRequired();
b.HasOne("back.DataModels.Photo", null)
.WithMany()
.HasForeignKey("PhotoId")
.IsRequired();
});
modelBuilder.Entity("GalleryTag", b =>
{
b.HasOne("back.DataModels.Gallery", null)
.WithMany()
.HasForeignKey("GalleryId")
.IsRequired();
b.HasOne("back.DataModels.Tag", null)
.WithMany()
.HasForeignKey("TagId")
.IsRequired();
});
modelBuilder.Entity("GalleryUserViewer", b =>
{
b.HasOne("back.DataModels.Gallery", null)
.WithMany()
.HasForeignKey("GalleryId")
.IsRequired();
b.HasOne("back.DataModels.User", null)
.WithMany()
.HasForeignKey("UserId")
.IsRequired();
});
modelBuilder.Entity("PhotoPerson", b =>
{
b.HasOne("back.DataModels.Person", null)
.WithMany()
.HasForeignKey("PersonId")
.IsRequired();
b.HasOne("back.DataModels.Photo", null)
.WithMany()
.HasForeignKey("PhotoId")
.IsRequired();
});
modelBuilder.Entity("PhotoTag", b =>
{
b.HasOne("back.DataModels.Photo", null)
.WithMany()
.HasForeignKey("PhotoId")
.IsRequired();
b.HasOne("back.DataModels.Tag", null)
.WithMany()
.HasForeignKey("TagId")
.IsRequired();
});
modelBuilder.Entity("PhotoUserBuyer", b =>
{
b.HasOne("back.DataModels.Photo", null)
.WithMany()
.HasForeignKey("PhotoId")
.IsRequired();
b.HasOne("back.DataModels.User", null)
.WithMany()
.HasForeignKey("UserId")
.IsRequired();
});
modelBuilder.Entity("RolePermission", b =>
{
b.HasOne("back.DataModels.Permission", null)
.WithMany()
.HasForeignKey("PermissionId")
.IsRequired();
b.HasOne("back.DataModels.Role", null)
.WithMany()
.HasForeignKey("RoleId")
.IsRequired();
});
modelBuilder.Entity("UserRole", b =>
{
b.HasOne("back.DataModels.Role", null)
.WithMany()
.HasForeignKey("RoleId")
.IsRequired();
b.HasOne("back.DataModels.User", null)
.WithMany()
.HasForeignKey("UserId")
.IsRequired();
});
modelBuilder.Entity("back.DataModels.Gallery", b =>
{
b.HasOne("back.DataModels.User", "CreatedByNavigation")
.WithMany("Galleries")
.HasForeignKey("CreatedBy")
.IsRequired();
b.HasOne("back.DataModels.Event", "Event")
.WithMany("Galleries")
.HasForeignKey("EventId");
b.Navigation("CreatedByNavigation");
b.Navigation("Event");
});
modelBuilder.Entity("back.DataModels.Person", b =>
{
b.HasOne("back.DataModels.SocialMedia", "SocialMedia")
.WithMany("People")
.HasForeignKey("SocialMediaId");
b.Navigation("SocialMedia");
});
modelBuilder.Entity("back.DataModels.Photo", b =>
{
b.HasOne("back.DataModels.Person", "CreatedByNavigation")
.WithMany("Photos")
.HasForeignKey("CreatedBy")
.IsRequired();
b.HasOne("back.DataModels.Event", "Event")
.WithMany("Photos")
.HasForeignKey("EventId");
b.Navigation("CreatedByNavigation");
b.Navigation("Event");
});
modelBuilder.Entity("back.DataModels.Role", b =>
{
b.HasOne("back.DataModels.Role", "BaseRoleModel")
.WithMany("InverseBaseRoleModel")
.HasForeignKey("BaseRoleModelId");
b.Navigation("BaseRoleModel");
});
modelBuilder.Entity("back.DataModels.User", b =>
{
b.HasOne("back.DataModels.Person", "IdNavigation")
.WithOne("User")
.HasForeignKey("back.DataModels.User", "Id")
.IsRequired();
b.Navigation("IdNavigation");
});
modelBuilder.Entity("back.DataModels.Event", b =>
{
b.Navigation("Galleries");
b.Navigation("Photos");
});
modelBuilder.Entity("back.DataModels.Person", b =>
{
b.Navigation("Photos");
b.Navigation("User");
});
modelBuilder.Entity("back.DataModels.Role", b =>
{
b.Navigation("InverseBaseRoleModel");
});
modelBuilder.Entity("back.DataModels.SocialMedia", b =>
{
b.Navigation("People");
});
modelBuilder.Entity("back.DataModels.User", b =>
{
b.Navigation("Galleries");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,200 @@
-- Tabla de redes sociales (SocialMedia) y relación uno a uno con Person
CREATE TABLE IF NOT EXISTS SocialMedia (
Id TEXT PRIMARY KEY,
Facebook TEXT,
Instagram TEXT,
Twitter TEXT,
BlueSky TEXT,
Tiktok TEXT,
Linkedin TEXT,
Pinterest TEXT,
Discord TEXT,
Reddit TEXT,
Other TEXT
);
-- Person: cada persona tiene un grupo de redes sociales (uno a uno, fk opcional)
CREATE TABLE IF NOT EXISTS Persons (
Id TEXT PRIMARY KEY,
Name TEXT NOT NULL,
ProfilePicture TEXT,
Avatar TEXT,
SocialMediaId TEXT,
Bio TEXT,
CreatedAt TEXT NOT NULL,
UpdatedAt TEXT,
FOREIGN KEY (SocialMediaId) REFERENCES SocialMedia(Id)
);
-- User: es una persona (herencia por clave primaria compartida)
CREATE TABLE IF NOT EXISTS Users (
Id TEXT PRIMARY KEY, -- MISMA clave y valor que Persons.Id
Email TEXT NOT NULL,
Password TEXT NOT NULL,
Salt TEXT NOT NULL,
FOREIGN KEY (Id) REFERENCES Persons(Id)
);
-- Un usuario puede ver muchas galerías (muchos-a-muchos: Galleries <-> Users)
CREATE TABLE IF NOT EXISTS GalleryUserViewers (
GalleryId TEXT NOT NULL,
UserId TEXT NOT NULL,
PRIMARY KEY (GalleryId, UserId),
FOREIGN KEY (GalleryId) REFERENCES Galleries(Id),
FOREIGN KEY (UserId) REFERENCES Users(Id)
);
-- Un usuario ha creado muchas galerías (uno a muchos)
-- Una galería solo puede ser creada por un usuario
CREATE TABLE IF NOT EXISTS Galleries (
Id TEXT PRIMARY KEY,
Title TEXT,
Description TEXT,
CreatedAt TEXT,
UpdatedAt TEXT,
CreatedBy TEXT NOT NULL, -- FK a Users
IsPublic INTEGER DEFAULT 1,
IsArchived INTEGER DEFAULT 0,
IsFavorite INTEGER DEFAULT 0,
EventId TEXT, -- FK opcional a Events (una galería puede asociarse a un evento)
FOREIGN KEY (CreatedBy) REFERENCES Users(Id),
FOREIGN KEY (EventId) REFERENCES Events(Id)
);
-- Galería-Photo: una galería contiene muchas imagenes, una imagen puede estar en muchas galerías (muchos-a-muchos)
CREATE TABLE IF NOT EXISTS GalleryPhotos (
GalleryId TEXT NOT NULL,
PhotoId TEXT NOT NULL,
PRIMARY KEY (GalleryId, PhotoId),
FOREIGN KEY (GalleryId) REFERENCES Galleries(Id),
FOREIGN KEY (PhotoId) REFERENCES Photos(Id)
);
-- Tabla de eventos
CREATE TABLE IF NOT EXISTS Events (
Id TEXT PRIMARY KEY,
Title TEXT NOT NULL,
Description TEXT,
Date TEXT,
Location TEXT,
CreatedAt TEXT NOT NULL,
UpdatedAt TEXT NOT NULL,
CreatedBy TEXT,
UpdatedBy TEXT,
IsDeleted INTEGER NOT NULL DEFAULT 0,
DeletedAt TEXT
);
-- Tabla de fotos
CREATE TABLE IF NOT EXISTS Photos (
Id TEXT PRIMARY KEY,
Title TEXT NOT NULL,
Description TEXT,
Extension TEXT,
LowResUrl TEXT,
MidResUrl TEXT,
HighResUrl TEXT,
CreatedAt TEXT,
UpdatedAt TEXT,
CreatedBy TEXT NOT NULL, -- Persona que subió la foto: FK a Persons
UpdatedBy TEXT,
EventId TEXT, -- Una photo solo puede tener un evento asociado (FK)
RankingId TEXT,
IsFavorite INTEGER DEFAULT 0,
IsPublic INTEGER DEFAULT 1,
IsArchived INTEGER DEFAULT 0,
FOREIGN KEY (CreatedBy) REFERENCES Persons(Id),
FOREIGN KEY (EventId) REFERENCES Events(Id)
);
-- Una persona puede salir en muchas fotos, y una foto puede tener muchas personas (muchos-a-muchos)
CREATE TABLE IF NOT EXISTS PhotoPersons (
PhotoId TEXT NOT NULL,
PersonId TEXT NOT NULL,
PRIMARY KEY (PhotoId, PersonId),
FOREIGN KEY (PhotoId) REFERENCES Photos(Id),
FOREIGN KEY (PersonId) REFERENCES Persons(Id)
);
-- Un usuario puede comprar muchas fotos para verlas, y una foto puede haber sido comprada por muchos usuarios
-- (solo necesario si IsPublic = 0)
CREATE TABLE IF NOT EXISTS PhotoUserBuyers (
PhotoId TEXT NOT NULL,
UserId TEXT NOT NULL,
PRIMARY KEY (PhotoId, UserId),
FOREIGN KEY (PhotoId) REFERENCES Photos(Id),
FOREIGN KEY (UserId) REFERENCES Users(Id)
);
-- Tabla de tags (únicos)
CREATE TABLE IF NOT EXISTS Tags (
Id TEXT PRIMARY KEY,
Name TEXT NOT NULL UNIQUE,
CreatedAt TEXT NOT NULL
);
-- Una foto puede tener muchos tags (muchos-a-muchos)
CREATE TABLE IF NOT EXISTS PhotoTags (
PhotoId TEXT NOT NULL,
TagId TEXT NOT NULL,
PRIMARY KEY (PhotoId, TagId),
FOREIGN KEY (PhotoId) REFERENCES Photos(Id),
FOREIGN KEY (TagId) REFERENCES Tags(Id)
);
-- Un evento puede tener muchos tags (muchos-a-muchos)
CREATE TABLE IF NOT EXISTS EventTags (
EventId TEXT NOT NULL,
TagId TEXT NOT NULL,
PRIMARY KEY (EventId, TagId),
FOREIGN KEY (EventId) REFERENCES Events(Id),
FOREIGN KEY (TagId) REFERENCES Tags(Id)
);
-- Una galería puede tener muchos tags (muchos-a-muchos)
CREATE TABLE IF NOT EXISTS GalleryTags (
GalleryId TEXT NOT NULL,
TagId TEXT NOT NULL,
PRIMARY KEY (GalleryId, TagId),
FOREIGN KEY (GalleryId) REFERENCES Galleries(Id),
FOREIGN KEY (TagId) REFERENCES Tags(Id)
);
-- Rankings (por si corresponde)
CREATE TABLE IF NOT EXISTS Rankings (
Id TEXT PRIMARY KEY,
TotalVotes INTEGER NOT NULL,
UpVotes INTEGER NOT NULL,
DownVotes INTEGER NOT NULL
);
-- Permissions y Roles, tal y como en el mensaje anterior...
CREATE TABLE IF NOT EXISTS Permissions (
Id TEXT PRIMARY KEY,
Name TEXT NOT NULL,
Description TEXT
);
CREATE TABLE IF NOT EXISTS Roles (
Id TEXT PRIMARY KEY,
Name TEXT NOT NULL,
Description TEXT,
BaseRoleModelId TEXT,
FOREIGN KEY (BaseRoleModelId) REFERENCES Roles(Id)
);
CREATE TABLE IF NOT EXISTS UserRoles (
UserId TEXT NOT NULL,
RoleId TEXT NOT NULL,
PRIMARY KEY (UserId, RoleId),
FOREIGN KEY (UserId) REFERENCES Users(Id),
FOREIGN KEY (RoleId) REFERENCES Roles(Id)
);
CREATE TABLE IF NOT EXISTS RolePermissions (
RoleId TEXT NOT NULL,
PermissionId TEXT NOT NULL,
PRIMARY KEY (RoleId, PermissionId),
FOREIGN KEY (RoleId) REFERENCES Roles(Id),
FOREIGN KEY (PermissionId) REFERENCES Permissions(Id)
);

View File

@@ -0,0 +1,28 @@
using back.DataModels;
using Microsoft.EntityFrameworkCore;
namespace back.persistance.data.relations;
public class EventRelationEstablisher: IRelationEstablisher
{
public void EstablishRelation(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Event>(entity =>
{
entity.HasMany(d => d.Tags).WithMany(p => p.Events)
.UsingEntity<Dictionary<string, object>>(
"EventTag",
r => r.HasOne<Tag>().WithMany()
.HasForeignKey("TagId")
.OnDelete(DeleteBehavior.ClientSetNull),
l => l.HasOne<Event>().WithMany()
.HasForeignKey("EventId")
.OnDelete(DeleteBehavior.ClientSetNull),
j =>
{
j.HasKey("EventId", "TagId");
j.ToTable("EventTags");
});
});
}
}

View File

@@ -0,0 +1,68 @@
using back.DataModels;
using Microsoft.EntityFrameworkCore;
namespace back.persistance.data.relations;
public class GalleryRelationEstablisher : IRelationEstablisher
{
public void EstablishRelation(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Gallery>(entity =>
{
entity.Property(e => e.IsArchived).HasDefaultValue(0);
entity.Property(e => e.IsFavorite).HasDefaultValue(0);
entity.Property(e => e.IsPublic).HasDefaultValue(1);
entity.HasOne(d => d.CreatedByNavigation).WithMany(p => p.Galleries)
.HasForeignKey(d => d.CreatedBy)
.OnDelete(DeleteBehavior.ClientSetNull);
entity.HasOne(d => d.Event).WithMany(p => p.Galleries).HasForeignKey(d => d.EventId);
entity.HasMany(d => d.Photos).WithMany(p => p.Galleries)
.UsingEntity<Dictionary<string, object>>(
"GalleryPhoto",
r => r.HasOne<Photo>().WithMany()
.HasForeignKey("PhotoId")
.OnDelete(DeleteBehavior.ClientSetNull),
l => l.HasOne<Gallery>().WithMany()
.HasForeignKey("GalleryId")
.OnDelete(DeleteBehavior.ClientSetNull),
j =>
{
j.HasKey("GalleryId", "PhotoId");
j.ToTable("GalleryPhotos");
});
entity.HasMany(d => d.Tags).WithMany(p => p.Galleries)
.UsingEntity<Dictionary<string, object>>(
"GalleryTag",
r => r.HasOne<Tag>().WithMany()
.HasForeignKey("TagId")
.OnDelete(DeleteBehavior.ClientSetNull),
l => l.HasOne<Gallery>().WithMany()
.HasForeignKey("GalleryId")
.OnDelete(DeleteBehavior.ClientSetNull),
j =>
{
j.HasKey("GalleryId", "TagId");
j.ToTable("GalleryTags");
});
entity.HasMany(d => d.Users).WithMany(p => p.GalleriesNavigation)
.UsingEntity<Dictionary<string, object>>(
"GalleryUserViewer",
r => r.HasOne<User>().WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.ClientSetNull),
l => l.HasOne<Gallery>().WithMany()
.HasForeignKey("GalleryId")
.OnDelete(DeleteBehavior.ClientSetNull),
j =>
{
j.HasKey("GalleryId", "UserId");
j.ToTable("GalleryUserViewers");
});
});
}
}

View File

@@ -0,0 +1,8 @@
using Microsoft.EntityFrameworkCore;
namespace back.persistance.data.relations;
public interface IRelationEstablisher
{
void EstablishRelation(ModelBuilder modelBuilder);
}

View File

@@ -0,0 +1,68 @@
using back.DataModels;
using Microsoft.EntityFrameworkCore;
namespace back.persistance.data.relations;
public class PersonRelationEstablisher : IRelationEstablisher
{
public void EstablishRelation(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Photo>(entity =>
{
entity.Property(e => e.IsArchived).HasDefaultValue(0);
entity.Property(e => e.IsFavorite).HasDefaultValue(0);
entity.Property(e => e.IsPublic).HasDefaultValue(1);
entity.HasOne(d => d.CreatedByNavigation).WithMany(p => p.Photos)
.HasForeignKey(d => d.CreatedBy)
.OnDelete(DeleteBehavior.ClientSetNull);
entity.HasOne(d => d.Event).WithMany(p => p.Photos).HasForeignKey(d => d.EventId);
entity.HasMany(d => d.People).WithMany(p => p.PhotosNavigation)
.UsingEntity<Dictionary<string, object>>(
"PhotoPerson",
r => r.HasOne<Person>().WithMany()
.HasForeignKey("PersonId")
.OnDelete(DeleteBehavior.ClientSetNull),
l => l.HasOne<Photo>().WithMany()
.HasForeignKey("PhotoId")
.OnDelete(DeleteBehavior.ClientSetNull),
j =>
{
j.HasKey("PhotoId", "PersonId");
j.ToTable("PhotoPersons");
});
entity.HasMany(d => d.Tags).WithMany(p => p.Photos)
.UsingEntity<Dictionary<string, object>>(
"PhotoTag",
r => r.HasOne<Tag>().WithMany()
.HasForeignKey("TagId")
.OnDelete(DeleteBehavior.ClientSetNull),
l => l.HasOne<Photo>().WithMany()
.HasForeignKey("PhotoId")
.OnDelete(DeleteBehavior.ClientSetNull),
j =>
{
j.HasKey("PhotoId", "TagId");
j.ToTable("PhotoTags");
});
entity.HasMany(d => d.Users).WithMany(p => p.Photos)
.UsingEntity<Dictionary<string, object>>(
"PhotoUserBuyer",
r => r.HasOne<User>().WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.ClientSetNull),
l => l.HasOne<Photo>().WithMany()
.HasForeignKey("PhotoId")
.OnDelete(DeleteBehavior.ClientSetNull),
j =>
{
j.HasKey("PhotoId", "UserId");
j.ToTable("PhotoUserBuyers");
});
});
}
}

View File

@@ -0,0 +1,307 @@
//using back.DataModels;
//using back.DTO;
//using back.persistance.blob;
//using back.services.ImageResizer;
//using Microsoft.EntityFrameworkCore;
//using Microsoft.Extensions.Hosting.Internal;
//namespace back.persistance.data.relations;
//public class PhotoContext : DbContext
//{
// private readonly IImageResizer _Resizer;
// private readonly IBlobStorageService _BlobStorage;
// private readonly TagContext _tagContext;
// private readonly EventContext _eventContext;
// private readonly PersonRelationEstablisher _personContext;
// public PhotoContext(DbContextOptions<PhotoContext> options, IHostEnvironment hostingEnvironment,
// IImageResizer resizer,
// IBlobStorageService blobStorage,
// TagContext tags,
// EventContext events,
// PersonRelationEstablisher persons
// ) : base(options)
// {
// _Resizer = resizer;
// _BlobStorage = blobStorage;
// _tagContext = tags;
// _eventContext = events;
// _personContext = persons;
// if (hostingEnvironment.IsDevelopment())
// {
// Database.EnsureCreated();
// }
// else
// {
// Database.Migrate();
// }
// }
// protected override void OnModelCreating(ModelBuilder modelBuilder)
// {
// // Photo -> Tags (muchos-a-muchos)
// modelBuilder.Entity<Photo>()
// .HasMany(p => p.Tags)
// .WithMany(t => t.Photos)
// .UsingEntity(j => j.ToTable("PhotoTags"));
// // Photo -> Persons (muchos-a-muchos)
// modelBuilder.Entity<Photo>()
// .HasMany(p => p.PersonsIn)
// .WithMany(per => per.Photos)
// .UsingEntity(j => j.ToTable("PhotoPersons"));
// // Photo -> Event (muchos-a-uno)
// modelBuilder.Entity<Photo>()
// .HasOne(p => p.Event)
// .WithMany() // Un evento puede tener múltiples fotos
// .HasForeignKey(p => p.EventId);
// // Photo -> Ranking (uno-a-uno)
// modelBuilder.Entity<Photo>()
// .HasOne(p => p.Ranking)
// .WithOne(r => r.Photo) // Un ranking está asociado a una sola foto
// .HasForeignKey<Photo>(p => p.RankingId);
// base.OnModelCreating(modelBuilder);
// }
// public async Task CreateNew(PhotoFormModel? form)
// {
// if (form == null) { return; }
// var photo = new Photo(
// Guid.NewGuid().ToString(),
// form.Title,
// form.Description ?? string.Empty,
// string.Empty, // LowResUrl will be set later
// string.Empty, // MidResUrl will be set later
// string.Empty, // HighResUrl will be set later
// DateTime.UtcNow,
// DateTime.UtcNow,
// form.UserId,
// form.UserId
// )
// {
// IsPublic = form.IsPublic
// };
// List<Task> tasks = [
// SaveBlob(photo, form),
// LinkTags(photo, form.Tags ?? [], form.UserId),
// LinkEvent(photo, form.Evento ?? "", form.UserId),
// LinkPersons(photo, form.People ?? [], form.UserId),
// ];
// await Task.WhenAll(tasks);
// await Photos.AddAsync(photo);
// await SaveChangesAsync();
// }
// private async Task LinkPersons(Photo photo, string[] personas, string updatedBy = "SYSTEM")
// {
// if (photo == null || personas == null || personas.Length == 0) return;
// foreach (var personId in personas)
// {
// var person = await _personContext.GetById(personId);
// if (person != null)
// {
// await LinkPersons(photo, person, updatedBy);
// }
// }
// }
// private async Task LinkPersons(Photo photo, Person tag, string updatedBy = "SYSTEM")
// {
// if (tag == null) return;
// // Ensure the tag exists
// if (await _personContext.Exists(tag.Id))
// {
// photo.PersonsIn ??= [];
// photo.PersonsIn.Add(tag);
// photo.UpdatedAt = DateTime.UtcNow;
// photo.UpdatedBy = updatedBy; // or use a more appropriate value
// }
// }
// private async Task LinkTags(Photo photo, string[] tags, string updatedBy = "SYSTEM")
// {
// if (photo == null || tags == null || tags.Length == 0) return;
// foreach (var tagId in tags)
// {
// var tag = await _tagContext.GetById(tagId);
// if (tag != null)
// {
// await LinkTag(photo, tag, updatedBy);
// }
// }
// }
// private async Task LinkTag(Photo photo, Tag tag, string updatedBy = "SYSTEM")
// {
// if (tag == null) return;
// // Ensure the tag exists
// if (await _tagContext.Exists(tag.Id))
// {
// photo.Tags.Add(tag);
// photo.UpdatedAt = DateTime.UtcNow;
// photo.UpdatedBy = updatedBy; // or use a more appropriate value
// }
// }
// private async Task LinkEvent(Photo photo, string eventId, string updatedBy = "SYSTEM")
// {
// if (string.IsNullOrEmpty(eventId)) return;
// var evento = await _eventContext.GetById(eventId);
// if (evento != null)
// {
// await LinkEvent(photo, evento, updatedBy);
// }
// }
// private async Task LinkEvent(Photo photo, Event? evento, string updatedBy = "SYSTEM")
// {
// if (evento == null) return;
// // Ensure the event exists
// if (await _eventContext.Exists(evento.Id))
// {
// photo.Event = evento;
// photo.UpdatedAt = DateTime.UtcNow;
// photo.UpdatedBy = updatedBy;
// }
// }
// private async Task SaveBlob(Photo photo, PhotoFormModel form)
// {
// if (form.Image != null && form.Image.Length > 0)
// {
// var lowRes = await _Resizer.ResizeImage(form.Image, 480);
// var midRes = await _Resizer.ResizeImage(form.Image, 720);
// // Upload images to blob storage
// photo.Extension = form.Image.FileName.Split('.').Last();
// photo.LowResUrl = $"low/{photo.Id}.webp";
// photo.MidResUrl = $"mid/{photo.Id}.webp";
// photo.HighResUrl = $"high/{photo.Id}.{photo.Extension}";
// await _BlobStorage.SaveAsync(lowRes, photo.LowResUrl);
// await _BlobStorage.SaveAsync(midRes, photo.MidResUrl);
// await _BlobStorage.SaveAsync(form.Image.OpenReadStream(), photo.HighResUrl);
// }
// }
// public async Task<Photo?> GetById(string id)
// {
// return await GetById(Guid.Parse(id));
// }
// public async Task<Photo?> GetById(Guid id)
// {
// try
// {
// return await Photos.FindAsync(id);
// }
// catch
// {
// return null;
// }
// }
// public async Task<int> GetTotalItems()
// {
// try
// {
// return await Photos.CountAsync();
// }
// catch
// {
// return 0;
// }
// }
// public async Task<IEnumerable<Photo>?> GetPage(int page = 1, int pageSize = 20)
// {
// if (page < 1) page = 1;
// if (pageSize < 1) pageSize = 20;
// try
// {
// return await Photos
// .OrderByDescending(p => p.CreatedAt)
// .Skip((page - 1) * pageSize)
// .Take(pageSize)
// .ToListAsync();
// }
// catch
// {
// return null;
// }
// }
// public async Task<bool> Exists(Photo? photo)
// {
// try
// {
// if (photo == null) return false;
// if (string.IsNullOrEmpty(photo.Id)) return false;
// return await Photos.AnyAsync(p => p.Id == photo.Id);
// }
// catch
// {
// return false; // Handle exceptions gracefully
// }
// }
// public async Task<bool> Exists(string id)
// {
// try
// {
// if (string.IsNullOrEmpty(id)) return false;
// return await Photos.AnyAsync(p => p.Id == id);
// }
// catch
// {
// return false; // Handle exceptions gracefully
// }
// }
// public async Task Delete(Photo photo)
// {
// if (photo == null) return;
// if (await Exists(photo))
// {
// // Delete the photo from blob storage
// if (!string.IsNullOrEmpty(photo.LowResUrl))
// await _BlobStorage.DeleteAsync(photo.LowResUrl);
// if (!string.IsNullOrEmpty(photo.MidResUrl))
// await _BlobStorage.DeleteAsync(photo.MidResUrl);
// if (!string.IsNullOrEmpty(photo.HighResUrl))
// await _BlobStorage.DeleteAsync(photo.HighResUrl);
// Photos.Remove(photo);
// await SaveChangesAsync();
// }
// }
// public async Task Update(Photo photo)
// {
// if (photo == null) return;
// if (await Exists(photo))
// {
// var evento = photo.Event;
// photo.Event = null;
// await LinkEvent(photo, evento, photo.UpdatedBy);
// var tags = photo.Tags.Select(t => t.Id);
// photo.Tags.Clear();
// await LinkTags(photo, [.. tags], photo.UpdatedBy);
// var persons = photo.PersonsIn?.Select(t => t.Id) ?? [];
// photo.PersonsIn = null;
// await LinkPersons(photo, [.. persons], photo.UpdatedBy);
// Photos.Update(photo);
// await SaveChangesAsync();
// }
// }
//}

View File

@@ -0,0 +1,15 @@
using back.DataModels;
using Microsoft.EntityFrameworkCore;
namespace back.persistance.data.relations;
public class PhotoRelationEstablisher : IRelationEstablisher
{
public void EstablishRelation(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Person>(entity =>
{
entity.HasOne(d => d.SocialMedia).WithMany(p => p.People).HasForeignKey(d => d.SocialMediaId);
});
}
}

View File

@@ -0,0 +1,25 @@
//using back.DataModels;
//using Microsoft.EntityFrameworkCore;
//namespace back.persistance.data.relations;
//public class RoleContext : DbContext
//{
// protected override void OnModelCreating(ModelBuilder modelBuilder)
// {
// // Role -> Permissions (muchos-a-muchos)
// modelBuilder.Entity<Role>()
// .HasMany(r => r.Permissions)
// .WithMany(p => p.Roles)
// .UsingEntity(j => j.ToTable("RolePermissions"));
// // Role -> BaseRole (auto-referencial)
// modelBuilder.Entity<Role>()
// .HasOne(r => r.BaseRoleModel)
// .WithMany() // Un rol base puede ser heredado por múltiples roles
// .HasForeignKey(r => r.BaseRoleModelId);
// base.OnModelCreating(modelBuilder);
// }
//}

View File

@@ -0,0 +1,30 @@
using back.DataModels;
using Microsoft.EntityFrameworkCore;
namespace back.persistance.data.relations;
public class RoleRelationEstablisher : IRelationEstablisher
{
public void EstablishRelation(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Role>(entity =>
{
entity.HasOne(d => d.BaseRoleModel).WithMany(p => p.InverseBaseRoleModel).HasForeignKey(d => d.BaseRoleModelId);
entity.HasMany(d => d.Permissions).WithMany(p => p.Roles)
.UsingEntity<Dictionary<string, object>>(
"RolePermission",
r => r.HasOne<Permission>().WithMany()
.HasForeignKey("PermissionId")
.OnDelete(DeleteBehavior.ClientSetNull),
l => l.HasOne<Role>().WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.ClientSetNull),
j =>
{
j.HasKey("RoleId", "PermissionId");
j.ToTable("RolePermissions");
});
});
}
}

View File

@@ -0,0 +1,40 @@
//using back.DataModels;
//using Microsoft.EntityFrameworkCore;
//namespace back.persistance.data.relations;
//public class SeedingDbContext : DbContext
//{
// protected override void OnModelCreating(ModelBuilder modelBuilder)
// {
// // 3. CONFIGURAR RELACIONES
// modelBuilder.Entity<Role>()
// .HasMany(r => r.Permissions)
// .WithMany(p => p.Roles)
// .UsingEntity<Dictionary<string, object>>(
// "RolePermissions",
// j => j.HasOne<Permission>().WithMany().HasForeignKey("PermissionsId"),
// j => j.HasOne<Role>().WithMany().HasForeignKey("RolesId"),
// j => j.HasData(
// // Usuario: VIEW_CONTENT y LIKE_CONTENT
// new { RolesId = "1", PermissionsId = "1" },
// new { RolesId = "1", PermissionsId = "2" },
// // Content Manager: permisos adicionales
// new { RolesId = "2", PermissionsId = "5" },
// new { RolesId = "2", PermissionsId = "3" },
// new { RolesId = "2", PermissionsId = "4" },
// new { RolesId = "2", PermissionsId = "9" },
// new { RolesId = "2", PermissionsId = "8" },
// // Admin: permisos adicionales
// new { RolesId = "3", PermissionsId = "6" },
// new { RolesId = "3", PermissionsId = "7" },
// new { RolesId = "3", PermissionsId = "10" }
// )
// );
// // Resto de configuraciones...
// base.OnModelCreating(modelBuilder);
// }
//}

View File

@@ -0,0 +1,15 @@
using back.DataModels;
using Microsoft.EntityFrameworkCore;
namespace back.persistance.data.relations;
public class TagRelationEstablisher : IRelationEstablisher
{
public void EstablishRelation(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Tag>(entity =>
{
entity.HasIndex(e => e.Name, "IX_Tags_Name").IsUnique();
});
}
}

View File

@@ -0,0 +1,32 @@
using back.DataModels;
using Microsoft.EntityFrameworkCore;
namespace back.persistance.data.relations;
public class UserRelationEstablisher : IRelationEstablisher
{
public void EstablishRelation(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>(entity =>
{
entity.HasOne(d => d.IdNavigation).WithOne(p => p.User)
.HasForeignKey<User>(d => d.Id)
.OnDelete(DeleteBehavior.ClientSetNull);
entity.HasMany(d => d.Roles).WithMany(p => p.Users)
.UsingEntity<Dictionary<string, object>>(
"UserRole",
r => r.HasOne<Role>().WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.ClientSetNull),
l => l.HasOne<User>().WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.ClientSetNull),
j =>
{
j.HasKey("UserId", "RoleId");
j.ToTable("UserRoles");
});
});
}
}

View File

@@ -0,0 +1,9 @@
using back.DataModels;
using DependencyInjector.Lifetimes;
using Transactional.Abstractions.Interfaces;
namespace back.persistance.data.repositories.Abstracts;
public interface IPersonRepository : IRepository<Person, string>, IScoped
{
}

View File

@@ -0,0 +1,8 @@
using back.DataModels;
using DependencyInjector.Lifetimes;
using Transactional.Abstractions.Interfaces;
namespace back.persistance.data.repositories.Abstracts;
public interface IPhotoRepository : IRepository<Photo, string>, IScoped
{ }

View File

@@ -0,0 +1,14 @@
using back.DataModels;
using DependencyInjector.Lifetimes;
using Transactional.Abstractions.Interfaces;
namespace back.persistance.data.repositories.Abstracts;
public interface IUserRepository : IRepository<User, string>, IScoped
{
Task<User?> GetByEmail(string email);
Task<string?> GetUserSaltByEmail(string email);
Task<User?> Login(string email, string password);
Task<bool> ExistsByEmail(string email);
//Task<bool> IsContentManager(string userId);
}

View File

@@ -0,0 +1,10 @@
using back.DataModels;
using back.persistance.data.repositories.Abstracts;
using Transactional.Implementations.EntityFramework;
namespace back.persistance.data.repositories;
public class PersonRepository(DataContext context) : ReadWriteRepository<Person, string>(context), IPersonRepository
{
// Implement methods specific to Photo repository if needed
}

View File

@@ -0,0 +1,10 @@
using back.DataModels;
using back.persistance.data.repositories.Abstracts;
using Transactional.Implementations.EntityFramework;
namespace back.persistance.data.repositories;
public class PhotoRepository(DataContext context) : ReadWriteRepository<Photo, string>(context), IPhotoRepository
{
// Implement methods specific to Photo repository if needed
}

View File

@@ -0,0 +1,70 @@
using back.DataModels;
using back.persistance.data.repositories.Abstracts;
using Microsoft.EntityFrameworkCore;
using Transactional.Implementations.EntityFramework;
namespace back.persistance.data.repositories;
public class UserRepository(DataContext context) : ReadWriteRepository<User, string>(context), IUserRepository
{
public async Task<User?> GetByEmail(string email)
{
try
{
if (string.IsNullOrEmpty(email)) return null;
return await Entity.FirstOrDefaultAsync(u => u.Email == email);
}
catch
{
return null;
}
}
public async Task<string?> GetUserSaltByEmail(string email)
{
try
{
if (string.IsNullOrEmpty(email)) return string.Empty;
var user = await Entity.FirstOrDefaultAsync(u => u.Email == email);
return user?.Salt ?? string.Empty;
}
catch
{
return string.Empty;
}
}
public async Task<User?> Login(string email, string password)
{
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password)) return null;
try
{
return await Entity.FirstOrDefaultAsync(u => u.Email == email && u.Password == password);
}
catch
{
return null;
}
}
public async Task<bool> ExistsByEmail(string email)
{
try
{
if (string.IsNullOrEmpty(email)) return false;
return await Entity.AnyAsync(u => u.Email == email);
}
catch
{
return false;
}
}
//public async Task<bool> IsContentManager(string userId)
//{
// var user = await GetById(userId);
// if (user == null)
// return false;
// return user.Roles.Any(role => role.IsContentManager() || role.IsAdmin());
//}
}

View File

@@ -0,0 +1,8 @@
using Microsoft.EntityFrameworkCore;
namespace back.persistance.data.seeders;
public interface ISeeder
{
void Seed(ModelBuilder modelBuilder);
}

View File

@@ -0,0 +1,23 @@
//using back.DataModels;
//using Microsoft.EntityFrameworkCore;
//namespace back.persistance.data.seeders;
//public class PermissionSeeder : ISeeder
//{
// public void Seed(ModelBuilder modelBuilder)
// {
// modelBuilder.Entity<Permission>().HasData(
// Permission.ViewContentPermission,
// Permission.LikeContentPermission,
// Permission.EditContentPermission,
// Permission.DeleteContentPermission,
// Permission.CreateContentPermission,
// Permission.EditUserPermission,
// Permission.DeleteUserPermission,
// Permission.DisableUserPermission,
// Permission.CreateUserPermission,
// Permission.EditWebConfigPermission
// );
// }
//}

View File

@@ -0,0 +1,16 @@
//using back.DataModels;
//using Microsoft.EntityFrameworkCore;
//namespace back.persistance.data.seeders;
//public class RoleSeeder : ISeeder
//{
// public void Seed(ModelBuilder modelBuilder)
// {
// modelBuilder.Entity<Permission>().HasData(
// new Role { Id = "1", Name = "User", Description = "Role for regular users", BaseRoleModelId = null },
// new Role { Id = "2", Name = "Content Manager", Description = "Role for managing content", BaseRoleModelId = "1" },
// new Role { Id = "3", Name = "Admin", Description = "Administrator role with full permissions", BaseRoleModelId = "2" }
// );
// }
//}

View File

@@ -0,0 +1,14 @@
using back.DataModels;
using Microsoft.EntityFrameworkCore;
namespace back.persistance.data.seeders;
public class SystemUserSeeder : ISeeder
{
public void Seed(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Permission>().HasData(
User.SystemUser
);
}
}