From 83b75bed07c2f3e311aa6aca05425f9f5cccfbf0 Mon Sep 17 00:00:00 2001 From: mfnefd Date: Wed, 27 Nov 2024 02:40:02 +0400 Subject: [PATCH] =?UTF-8?q?add:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BC=D0=B8=D0=B3=D1=80=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D1=8F.=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=B3=D1=80?= =?UTF-8?q?=D1=83=D0=BF=D0=BF=D1=8B=20=D1=80=D0=B0=D1=81=D1=85=D0=BE=D0=B4?= =?UTF-8?q?=D0=BE=D0=B2=20=D0=B2=D0=BE=D0=B7=D0=B2=D1=80=D0=B0=D1=89=D0=B0?= =?UTF-8?q?=D1=8E=D1=82=D1=81=D1=8F=20=D1=81=20=D0=BF=D0=BB=D0=B0=D0=BD?= =?UTF-8?q?=D0=B0=D0=BC=D0=B8=20=D1=80=D0=B0=D1=81=D1=85=D0=BE=D0=B4=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/Contracts/DTOs/SpendingGroupDto.cs | 1 + back/Contracts/Mappers/SpendingGroupMapper.cs | 3 +- .../ViewModels/SpendingGroupViewModel.cs | 1 + ...20241126222847_AddSpendingPlan.Designer.cs | 177 ++++++++++++++++++ .../20241126222847_AddSpendingPlan.cs | 48 +++++ .../DatabaseContextModelSnapshot.cs | 38 ++++ back/Infrastructure/Models/SpendingGroup.cs | 1 + .../Repositories/SpendingGroupRepo.cs | 7 +- .../Support/Mappers/SpendingGroupMapper.cs | 3 +- 9 files changed, 276 insertions(+), 3 deletions(-) create mode 100644 back/Infrastructure/Migrations/20241126222847_AddSpendingPlan.Designer.cs create mode 100644 back/Infrastructure/Migrations/20241126222847_AddSpendingPlan.cs diff --git a/back/Contracts/DTOs/SpendingGroupDto.cs b/back/Contracts/DTOs/SpendingGroupDto.cs index 2adf558..dd001fd 100644 --- a/back/Contracts/DTOs/SpendingGroupDto.cs +++ b/back/Contracts/DTOs/SpendingGroupDto.cs @@ -6,4 +6,5 @@ public class SpendingGroupDto public string Name { get; set; } = string.Empty; public Guid UserId { get; set; } public List ChangeRecords { get; set; } = new(); + public List SpendingPlans { get; set; } = new(); } \ No newline at end of file diff --git a/back/Contracts/Mappers/SpendingGroupMapper.cs b/back/Contracts/Mappers/SpendingGroupMapper.cs index f9d4cac..fd6a987 100644 --- a/back/Contracts/Mappers/SpendingGroupMapper.cs +++ b/back/Contracts/Mappers/SpendingGroupMapper.cs @@ -10,6 +10,7 @@ public static class SpendingGroupMapper { Id = dto.Id, Name = dto.Name, - ChangeRecords = dto.ChangeRecords.Select(x => x.ToView()).ToList() + ChangeRecords = dto.ChangeRecords.Select(x => x.ToView()).ToList(), + SpendingPlans = dto.SpendingPlans.Select(x => x.ToView()).ToList() }; } \ No newline at end of file diff --git a/back/Contracts/ViewModels/SpendingGroupViewModel.cs b/back/Contracts/ViewModels/SpendingGroupViewModel.cs index c22ae62..1a94317 100644 --- a/back/Contracts/ViewModels/SpendingGroupViewModel.cs +++ b/back/Contracts/ViewModels/SpendingGroupViewModel.cs @@ -5,4 +5,5 @@ public class SpendingGroupViewModel public Guid Id { get; set; } public string Name { get; set; } = string.Empty; public List ChangeRecords { get; set; } = new(); + public List SpendingPlans { get; set; } = new(); } \ No newline at end of file diff --git a/back/Infrastructure/Migrations/20241126222847_AddSpendingPlan.Designer.cs b/back/Infrastructure/Migrations/20241126222847_AddSpendingPlan.Designer.cs new file mode 100644 index 0000000..e43fe93 --- /dev/null +++ b/back/Infrastructure/Migrations/20241126222847_AddSpendingPlan.Designer.cs @@ -0,0 +1,177 @@ +// +using System; +using Infrastructure; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Infrastructure.Migrations +{ + [DbContext(typeof(DatabaseContext))] + [Migration("20241126222847_AddSpendingPlan")] + partial class AddSpendingPlan + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.0") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Infrastructure.Models.ChangeRecord", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ChangedAt") + .HasColumnType("timestamp with time zone"); + + b.Property("SpendingGroupId") + .HasColumnType("uuid"); + + b.Property("Sum") + .HasColumnType("numeric"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("SpendingGroupId"); + + b.HasIndex("UserId"); + + b.ToTable("ChangeRecords"); + }); + + modelBuilder.Entity("Infrastructure.Models.SpendingGroup", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("SpendingGroups"); + }); + + modelBuilder.Entity("Infrastructure.Models.SpendingPlan", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("EndAt") + .HasColumnType("timestamp with time zone"); + + b.Property("SpendingGroupId") + .HasColumnType("uuid"); + + b.Property("StartAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Sum") + .HasColumnType("numeric"); + + b.HasKey("Id"); + + b.HasIndex("SpendingGroupId"); + + b.ToTable("SpendingPlans"); + }); + + modelBuilder.Entity("Infrastructure.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Balance") + .HasColumnType("numeric"); + + b.Property("Name") + .IsRequired() + .HasColumnType("text"); + + b.Property("Password") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Infrastructure.Models.ChangeRecord", b => + { + b.HasOne("Infrastructure.Models.SpendingGroup", "SpendingGroup") + .WithMany("ChangeRecords") + .HasForeignKey("SpendingGroupId"); + + b.HasOne("Infrastructure.Models.User", "User") + .WithMany("ChangeRecords") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("SpendingGroup"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Infrastructure.Models.SpendingGroup", b => + { + b.HasOne("Infrastructure.Models.User", "User") + .WithMany("SpendingGroups") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("Infrastructure.Models.SpendingPlan", b => + { + b.HasOne("Infrastructure.Models.SpendingGroup", "SpendingGroup") + .WithMany("SpendingPlans") + .HasForeignKey("SpendingGroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("SpendingGroup"); + }); + + modelBuilder.Entity("Infrastructure.Models.SpendingGroup", b => + { + b.Navigation("ChangeRecords"); + + b.Navigation("SpendingPlans"); + }); + + modelBuilder.Entity("Infrastructure.Models.User", b => + { + b.Navigation("ChangeRecords"); + + b.Navigation("SpendingGroups"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/back/Infrastructure/Migrations/20241126222847_AddSpendingPlan.cs b/back/Infrastructure/Migrations/20241126222847_AddSpendingPlan.cs new file mode 100644 index 0000000..fcc2f3e --- /dev/null +++ b/back/Infrastructure/Migrations/20241126222847_AddSpendingPlan.cs @@ -0,0 +1,48 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Infrastructure.Migrations +{ + /// + public partial class AddSpendingPlan : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "SpendingPlans", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + StartAt = table.Column(type: "timestamp with time zone", nullable: false), + EndAt = table.Column(type: "timestamp with time zone", nullable: false), + Sum = table.Column(type: "numeric", nullable: false), + SpendingGroupId = table.Column(type: "uuid", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_SpendingPlans", x => x.Id); + table.ForeignKey( + name: "FK_SpendingPlans_SpendingGroups_SpendingGroupId", + column: x => x.SpendingGroupId, + principalTable: "SpendingGroups", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_SpendingPlans_SpendingGroupId", + table: "SpendingPlans", + column: "SpendingGroupId"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "SpendingPlans"); + } + } +} diff --git a/back/Infrastructure/Migrations/DatabaseContextModelSnapshot.cs b/back/Infrastructure/Migrations/DatabaseContextModelSnapshot.cs index 2c7a5ef..93d0295 100644 --- a/back/Infrastructure/Migrations/DatabaseContextModelSnapshot.cs +++ b/back/Infrastructure/Migrations/DatabaseContextModelSnapshot.cs @@ -69,6 +69,31 @@ namespace Infrastructure.Migrations b.ToTable("SpendingGroups"); }); + modelBuilder.Entity("Infrastructure.Models.SpendingPlan", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("EndAt") + .HasColumnType("timestamp with time zone"); + + b.Property("SpendingGroupId") + .HasColumnType("uuid"); + + b.Property("StartAt") + .HasColumnType("timestamp with time zone"); + + b.Property("Sum") + .HasColumnType("numeric"); + + b.HasKey("Id"); + + b.HasIndex("SpendingGroupId"); + + b.ToTable("SpendingPlans"); + }); + modelBuilder.Entity("Infrastructure.Models.User", b => { b.Property("Id") @@ -119,9 +144,22 @@ namespace Infrastructure.Migrations b.Navigation("User"); }); + modelBuilder.Entity("Infrastructure.Models.SpendingPlan", b => + { + b.HasOne("Infrastructure.Models.SpendingGroup", "SpendingGroup") + .WithMany("SpendingPlans") + .HasForeignKey("SpendingGroupId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("SpendingGroup"); + }); + modelBuilder.Entity("Infrastructure.Models.SpendingGroup", b => { b.Navigation("ChangeRecords"); + + b.Navigation("SpendingPlans"); }); modelBuilder.Entity("Infrastructure.Models.User", b => diff --git a/back/Infrastructure/Models/SpendingGroup.cs b/back/Infrastructure/Models/SpendingGroup.cs index 889bdb6..23758eb 100644 --- a/back/Infrastructure/Models/SpendingGroup.cs +++ b/back/Infrastructure/Models/SpendingGroup.cs @@ -8,4 +8,5 @@ public class SpendingGroup public Guid UserId { get; set; } public User User { get; set; } = null!; public List? ChangeRecords { get; set; } + public List? SpendingPlans { get; set; } } \ No newline at end of file diff --git a/back/Infrastructure/Repositories/SpendingGroupRepo.cs b/back/Infrastructure/Repositories/SpendingGroupRepo.cs index d7e879e..6c8382a 100644 --- a/back/Infrastructure/Repositories/SpendingGroupRepo.cs +++ b/back/Infrastructure/Repositories/SpendingGroupRepo.cs @@ -47,6 +47,7 @@ public class SpendingGroupRepo : ISpendingGroupRepo var group = await context.SpendingGroups .Include(x => x.ChangeRecords) + .Include(x => x.SpendingPlans) .FirstOrDefaultAsync(x => x.Id == search.Id || x.Name == search.Name); @@ -72,7 +73,11 @@ public class SpendingGroupRepo : ISpendingGroupRepo } } - return await query.Include(x => x.ChangeRecords).Select(x => x.ToDto()).ToListAsync(); + return await query + .Include(x => x.ChangeRecords) + .Include(x => x.SpendingPlans) + .Select(x => x.ToDto()) + .ToListAsync(); } public async Task Update(SpendingGroupDto spendingGroup) diff --git a/back/Infrastructure/Support/Mappers/SpendingGroupMapper.cs b/back/Infrastructure/Support/Mappers/SpendingGroupMapper.cs index d74490f..9432073 100644 --- a/back/Infrastructure/Support/Mappers/SpendingGroupMapper.cs +++ b/back/Infrastructure/Support/Mappers/SpendingGroupMapper.cs @@ -11,7 +11,8 @@ public static class SpendingGroupMapper Id = group.Id, Name = group.Name, UserId = group.UserId, - ChangeRecords = group.ChangeRecords?.Select(x => x.ToDto()).ToList() ?? [] + ChangeRecords = group.ChangeRecords?.Select(x => x.ToDto()).ToList() ?? [], + SpendingPlans = group.SpendingPlans?.Select(x => x.ToDto()).ToList() ?? [] }; public static SpendingGroup ToModel(this SpendingGroupDto group) => new()