0.1.0 #2
@ -6,4 +6,5 @@ public class SpendingGroupDto
|
|||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
public Guid UserId { get; set; }
|
public Guid UserId { get; set; }
|
||||||
public List<ChangeRecordDto> ChangeRecords { get; set; } = new();
|
public List<ChangeRecordDto> ChangeRecords { get; set; } = new();
|
||||||
|
public List<SpendingPlanDto> SpendingPlans { get; set; } = new();
|
||||||
}
|
}
|
@ -10,6 +10,7 @@ public static class SpendingGroupMapper
|
|||||||
{
|
{
|
||||||
Id = dto.Id,
|
Id = dto.Id,
|
||||||
Name = dto.Name,
|
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()
|
||||||
};
|
};
|
||||||
}
|
}
|
@ -5,4 +5,5 @@ public class SpendingGroupViewModel
|
|||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
public string Name { get; set; } = string.Empty;
|
public string Name { get; set; } = string.Empty;
|
||||||
public List<ChangeRecordViewModel> ChangeRecords { get; set; } = new();
|
public List<ChangeRecordViewModel> ChangeRecords { get; set; } = new();
|
||||||
|
public List<SpendingPlanViewModel> SpendingPlans { get; set; } = new();
|
||||||
}
|
}
|
177
back/Infrastructure/Migrations/20241126222847_AddSpendingPlan.Designer.cs
generated
Normal file
177
back/Infrastructure/Migrations/20241126222847_AddSpendingPlan.Designer.cs
generated
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
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
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
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<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateTime>("ChangedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<Guid?>("SpendingGroupId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<decimal>("Sum")
|
||||||
|
.HasColumnType("numeric");
|
||||||
|
|
||||||
|
b.Property<Guid>("UserId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("SpendingGroupId");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("ChangeRecords");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Infrastructure.Models.SpendingGroup", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<Guid>("UserId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("SpendingGroups");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Infrastructure.Models.SpendingPlan", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateTime>("EndAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<Guid>("SpendingGroupId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateTime>("StartAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<decimal>("Sum")
|
||||||
|
.HasColumnType("numeric");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("SpendingGroupId");
|
||||||
|
|
||||||
|
b.ToTable("SpendingPlans");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Infrastructure.Models.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<decimal>("Balance")
|
||||||
|
.HasColumnType("numeric");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Infrastructure.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class AddSpendingPlan : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "SpendingPlans",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<Guid>(type: "uuid", nullable: false),
|
||||||
|
StartAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
|
EndAt = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||||
|
Sum = table.Column<decimal>(type: "numeric", nullable: false),
|
||||||
|
SpendingGroupId = table.Column<Guid>(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");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "SpendingPlans");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -69,6 +69,31 @@ namespace Infrastructure.Migrations
|
|||||||
b.ToTable("SpendingGroups");
|
b.ToTable("SpendingGroups");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Infrastructure.Models.SpendingPlan", b =>
|
||||||
|
{
|
||||||
|
b.Property<Guid>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateTime>("EndAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<Guid>("SpendingGroupId")
|
||||||
|
.HasColumnType("uuid");
|
||||||
|
|
||||||
|
b.Property<DateTime>("StartAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<decimal>("Sum")
|
||||||
|
.HasColumnType("numeric");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("SpendingGroupId");
|
||||||
|
|
||||||
|
b.ToTable("SpendingPlans");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Infrastructure.Models.User", b =>
|
modelBuilder.Entity("Infrastructure.Models.User", b =>
|
||||||
{
|
{
|
||||||
b.Property<Guid>("Id")
|
b.Property<Guid>("Id")
|
||||||
@ -119,9 +144,22 @@ namespace Infrastructure.Migrations
|
|||||||
b.Navigation("User");
|
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 =>
|
modelBuilder.Entity("Infrastructure.Models.SpendingGroup", b =>
|
||||||
{
|
{
|
||||||
b.Navigation("ChangeRecords");
|
b.Navigation("ChangeRecords");
|
||||||
|
|
||||||
|
b.Navigation("SpendingPlans");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Infrastructure.Models.User", b =>
|
modelBuilder.Entity("Infrastructure.Models.User", b =>
|
||||||
|
@ -8,4 +8,5 @@ public class SpendingGroup
|
|||||||
public Guid UserId { get; set; }
|
public Guid UserId { get; set; }
|
||||||
public User User { get; set; } = null!;
|
public User User { get; set; } = null!;
|
||||||
public List<ChangeRecord>? ChangeRecords { get; set; }
|
public List<ChangeRecord>? ChangeRecords { get; set; }
|
||||||
|
public List<SpendingPlan>? SpendingPlans { get; set; }
|
||||||
}
|
}
|
@ -47,6 +47,7 @@ public class SpendingGroupRepo : ISpendingGroupRepo
|
|||||||
|
|
||||||
var group = await context.SpendingGroups
|
var group = await context.SpendingGroups
|
||||||
.Include(x => x.ChangeRecords)
|
.Include(x => x.ChangeRecords)
|
||||||
|
.Include(x => x.SpendingPlans)
|
||||||
.FirstOrDefaultAsync(x => x.Id == search.Id
|
.FirstOrDefaultAsync(x => x.Id == search.Id
|
||||||
|| x.Name == search.Name);
|
|| 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<SpendingGroupDto?> Update(SpendingGroupDto spendingGroup)
|
public async Task<SpendingGroupDto?> Update(SpendingGroupDto spendingGroup)
|
||||||
|
@ -11,7 +11,8 @@ public static class SpendingGroupMapper
|
|||||||
Id = group.Id,
|
Id = group.Id,
|
||||||
Name = group.Name,
|
Name = group.Name,
|
||||||
UserId = group.UserId,
|
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)
|
public static SpendingGroup ToModel(this SpendingGroupDto group)
|
||||||
=> new()
|
=> new()
|
||||||
|
Loading…
Reference in New Issue
Block a user