From aff6f8df8286692e1a7c4bfb3c4162bd5c4f9eda Mon Sep 17 00:00:00 2001 From: Karolis Kundrotas Date: Mon, 25 Oct 2021 22:00:01 +0300 Subject: [PATCH] Huge work --- KTUSAPS.Data/KTUSAPS.Data.csproj | 4 + ....cs => 20211015122630_Initial.Designer.cs} | 40 ++++- ...9_Initial.cs => 20211015122630_Initial.cs} | 50 +++++-- .../SAPSDataContextModelSnapshot.cs | 38 +++++ KTUSAPS.Data/Model/Issue.cs | 12 +- KTUSAPS.Data/Model/IssueType.cs | 18 +++ KTUSAPS.Data/Model/Models.cd | 25 +++- KTUSAPS.Data/Model/PublishedFeedback.cs | 7 +- KTUSAPS.Data/Model/PublishedProblem.cs | 13 +- KTUSAPS.Data/Model/Solution.cs | 9 +- KTUSAPS.Data/Model/Vote.cs | 2 +- KTUSAPS.Data/SAPSDataContext.cs | 1 + KTUSAPS/ClientApp/src/App.vue | 35 +++++ KTUSAPS/ClientApp/src/components/NavMenu.vue | 3 + KTUSAPS/ClientApp/src/pages/Home.vue | 4 +- KTUSAPS/ClientApp/src/store/index.js | 8 +- KTUSAPS/ClientApp/src/store/modules/auth.js | 10 +- KTUSAPS/Controllers/AuthMetadataController.cs | 29 +++- KTUSAPS/Controllers/IssueController.cs | 96 ++++++++++++ KTUSAPS/Controllers/TestController.cs | 26 ---- KTUSAPS/Extensions/EntityEntryExtensions.cs | 44 ++++++ KTUSAPS/KTUSAPS.csproj | 10 +- .../Services/DatabaseInitializationService.cs | 138 ++++++++++++++++++ KTUSAPS/Startup.cs | 18 ++- KTUSAPS/appsettings.Development.json | 3 + KTUSAPS/appsettings.json | 3 + 26 files changed, 578 insertions(+), 68 deletions(-) rename KTUSAPS.Data/Migrations/{20210909173149_Initial.Designer.cs => 20211015122630_Initial.Designer.cs} (85%) rename KTUSAPS.Data/Migrations/{20210909173149_Initial.cs => 20211015122630_Initial.cs} (85%) create mode 100644 KTUSAPS.Data/Model/IssueType.cs create mode 100644 KTUSAPS/Controllers/IssueController.cs delete mode 100644 KTUSAPS/Controllers/TestController.cs create mode 100644 KTUSAPS/Extensions/EntityEntryExtensions.cs create mode 100644 KTUSAPS/Services/DatabaseInitializationService.cs diff --git a/KTUSAPS.Data/KTUSAPS.Data.csproj b/KTUSAPS.Data/KTUSAPS.Data.csproj index 7cddda5..878cdb7 100644 --- a/KTUSAPS.Data/KTUSAPS.Data.csproj +++ b/KTUSAPS.Data/KTUSAPS.Data.csproj @@ -14,4 +14,8 @@ + + + + diff --git a/KTUSAPS.Data/Migrations/20210909173149_Initial.Designer.cs b/KTUSAPS.Data/Migrations/20211015122630_Initial.Designer.cs similarity index 85% rename from KTUSAPS.Data/Migrations/20210909173149_Initial.Designer.cs rename to KTUSAPS.Data/Migrations/20211015122630_Initial.Designer.cs index d6aaba3..0a3f02f 100644 --- a/KTUSAPS.Data/Migrations/20210909173149_Initial.Designer.cs +++ b/KTUSAPS.Data/Migrations/20211015122630_Initial.Designer.cs @@ -9,7 +9,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion; namespace KTUSAPS.Data.Migrations { [DbContext(typeof(SAPSDataContext))] - [Migration("20210909173149_Initial")] + [Migration("20211015122630_Initial")] partial class Initial { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -50,6 +50,9 @@ namespace KTUSAPS.Data.Migrations .HasMaxLength(320) .HasColumnType("varchar(320)"); + b.Property("IssueTypeId") + .HasColumnType("int"); + b.Property("Publishable") .HasColumnType("tinyint(1)"); @@ -62,9 +65,28 @@ namespace KTUSAPS.Data.Migrations b.HasKey("Id"); + b.HasIndex("IssueTypeId"); + b.ToTable("Issues"); }); + modelBuilder.Entity("KTUSAPS.Data.Model.IssueType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Name") + .HasColumnType("longtext"); + + b.Property("NameEn") + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("IssueTypes"); + }); + modelBuilder.Entity("KTUSAPS.Data.Model.PublishedFeedback", b => { b.Property("Id") @@ -169,6 +191,17 @@ namespace KTUSAPS.Data.Migrations b.ToTable("Votes"); }); + modelBuilder.Entity("KTUSAPS.Data.Model.Issue", b => + { + b.HasOne("KTUSAPS.Data.Model.IssueType", "IssueType") + .WithMany("Issues") + .HasForeignKey("IssueTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("IssueType"); + }); + modelBuilder.Entity("KTUSAPS.Data.Model.PublishedFeedback", b => { b.HasOne("KTUSAPS.Data.Model.Issue", "Issue") @@ -211,6 +244,11 @@ namespace KTUSAPS.Data.Migrations b.Navigation("Problem"); }); + modelBuilder.Entity("KTUSAPS.Data.Model.IssueType", b => + { + b.Navigation("Issues"); + }); + modelBuilder.Entity("KTUSAPS.Data.Model.PublishedProblem", b => { b.Navigation("Votes"); diff --git a/KTUSAPS.Data/Migrations/20210909173149_Initial.cs b/KTUSAPS.Data/Migrations/20211015122630_Initial.cs similarity index 85% rename from KTUSAPS.Data/Migrations/20210909173149_Initial.cs rename to KTUSAPS.Data/Migrations/20211015122630_Initial.cs index fe350d6..72ff426 100644 --- a/KTUSAPS.Data/Migrations/20210909173149_Initial.cs +++ b/KTUSAPS.Data/Migrations/20211015122630_Initial.cs @@ -27,24 +27,19 @@ namespace KTUSAPS.Data.Migrations .Annotation("MySql:CharSet", "utf8mb4"); migrationBuilder.CreateTable( - name: "Issues", + name: "IssueTypes", columns: table => new { Id = table.Column(type: "int", nullable: false) .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), - UserID = table.Column(type: "varchar(64)", maxLength: 64, nullable: true) + Name = table.Column(type: "longtext", nullable: true) .Annotation("MySql:CharSet", "utf8mb4"), - Email = table.Column(type: "varchar(320)", maxLength: 320, nullable: true) - .Annotation("MySql:CharSet", "utf8mb4"), - Publishable = table.Column(type: "tinyint(1)", nullable: false), - Solved = table.Column(type: "tinyint(1)", nullable: false), - Created = table.Column(type: "datetime(6)", nullable: false), - Description = table.Column(type: "longtext", nullable: true) + NameEn = table.Column(type: "longtext", nullable: true) .Annotation("MySql:CharSet", "utf8mb4") }, constraints: table => { - table.PrimaryKey("PK_Issues", x => x.Id); + table.PrimaryKey("PK_IssueTypes", x => x.Id); }) .Annotation("MySql:CharSet", "utf8mb4"); @@ -66,6 +61,35 @@ namespace KTUSAPS.Data.Migrations }) .Annotation("MySql:CharSet", "utf8mb4"); + migrationBuilder.CreateTable( + name: "Issues", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + UserID = table.Column(type: "varchar(64)", maxLength: 64, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Email = table.Column(type: "varchar(320)", maxLength: 320, nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + Publishable = table.Column(type: "tinyint(1)", nullable: false), + Solved = table.Column(type: "tinyint(1)", nullable: false), + Created = table.Column(type: "datetime(6)", nullable: false), + Description = table.Column(type: "longtext", nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"), + IssueTypeId = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Issues", x => x.Id); + table.ForeignKey( + name: "FK_Issues_IssueTypes_IssueTypeId", + column: x => x.IssueTypeId, + principalTable: "IssueTypes", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + migrationBuilder.CreateTable( name: "PublishedFeedbacks", columns: table => new @@ -147,6 +171,11 @@ namespace KTUSAPS.Data.Migrations }) .Annotation("MySql:CharSet", "utf8mb4"); + migrationBuilder.CreateIndex( + name: "IX_Issues_IssueTypeId", + table: "Issues", + column: "IssueTypeId"); + migrationBuilder.CreateIndex( name: "IX_PublishedFeedbacks_IssueId", table: "PublishedFeedbacks", @@ -190,6 +219,9 @@ namespace KTUSAPS.Data.Migrations migrationBuilder.DropTable( name: "Solutions"); + + migrationBuilder.DropTable( + name: "IssueTypes"); } } } diff --git a/KTUSAPS.Data/Migrations/SAPSDataContextModelSnapshot.cs b/KTUSAPS.Data/Migrations/SAPSDataContextModelSnapshot.cs index 9ddd6c2..6be2131 100644 --- a/KTUSAPS.Data/Migrations/SAPSDataContextModelSnapshot.cs +++ b/KTUSAPS.Data/Migrations/SAPSDataContextModelSnapshot.cs @@ -48,6 +48,9 @@ namespace KTUSAPS.Data.Migrations .HasMaxLength(320) .HasColumnType("varchar(320)"); + b.Property("IssueTypeId") + .HasColumnType("int"); + b.Property("Publishable") .HasColumnType("tinyint(1)"); @@ -60,9 +63,28 @@ namespace KTUSAPS.Data.Migrations b.HasKey("Id"); + b.HasIndex("IssueTypeId"); + b.ToTable("Issues"); }); + modelBuilder.Entity("KTUSAPS.Data.Model.IssueType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + b.Property("Name") + .HasColumnType("longtext"); + + b.Property("NameEn") + .HasColumnType("longtext"); + + b.HasKey("Id"); + + b.ToTable("IssueTypes"); + }); + modelBuilder.Entity("KTUSAPS.Data.Model.PublishedFeedback", b => { b.Property("Id") @@ -167,6 +189,17 @@ namespace KTUSAPS.Data.Migrations b.ToTable("Votes"); }); + modelBuilder.Entity("KTUSAPS.Data.Model.Issue", b => + { + b.HasOne("KTUSAPS.Data.Model.IssueType", "IssueType") + .WithMany("Issues") + .HasForeignKey("IssueTypeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("IssueType"); + }); + modelBuilder.Entity("KTUSAPS.Data.Model.PublishedFeedback", b => { b.HasOne("KTUSAPS.Data.Model.Issue", "Issue") @@ -209,6 +242,11 @@ namespace KTUSAPS.Data.Migrations b.Navigation("Problem"); }); + modelBuilder.Entity("KTUSAPS.Data.Model.IssueType", b => + { + b.Navigation("Issues"); + }); + modelBuilder.Entity("KTUSAPS.Data.Model.PublishedProblem", b => { b.Navigation("Votes"); diff --git a/KTUSAPS.Data/Model/Issue.cs b/KTUSAPS.Data/Model/Issue.cs index 91c6064..1376493 100644 --- a/KTUSAPS.Data/Model/Issue.cs +++ b/KTUSAPS.Data/Model/Issue.cs @@ -22,7 +22,15 @@ namespace KTUSAPS.Data.Model [MaxLength] public string Description { get; set; } - public PublishedProblem Problem { get; set; } - public PublishedFeedback Feedback { get; set; } + public int IssueTypeId { get; set; } + public virtual IssueType IssueType { get; set; } + + public virtual PublishedProblem Problem { get; set; } + public virtual PublishedFeedback Feedback { get; set; } + + public Issue() + { + Created = DateTime.Now; + } } } diff --git a/KTUSAPS.Data/Model/IssueType.cs b/KTUSAPS.Data/Model/IssueType.cs new file mode 100644 index 0000000..b745503 --- /dev/null +++ b/KTUSAPS.Data/Model/IssueType.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace KTUSAPS.Data.Model +{ + public class IssueType + { + public int Id { get; set; } + public string Name { get; set; } + public string NameEn { get; set; } + + public virtual ICollection Issues { get; set; } + + } +} diff --git a/KTUSAPS.Data/Model/Models.cd b/KTUSAPS.Data/Model/Models.cd index 0422b98..3569aef 100644 --- a/KTUSAPS.Data/Model/Models.cd +++ b/KTUSAPS.Data/Model/Models.cd @@ -1,18 +1,19 @@  - + - AAACAAJAACAgAAAAAAACAAgIAAAAAAQAAAAAAAAAAAA= + AIACAAJQACAgAAAAAAACAAgIAAAAAAQAAAAAAAAAAAA= Model\Issue.cs + - + AAECAAAAAAAAAAAACAIAAAAAAAAAAAQAEAAAAAAAAAA= Model\PublishedFeedback.cs @@ -22,9 +23,9 @@ - + - ACECABAAAAEAAAgAAAABAAAAEAAAQAQAEAAAAAAAAAA= + ACECABAAAAEAAAgAAAABAAAAAAAAAAQAEAAAAAAAAAA= Model\PublishedProblem.cs @@ -36,7 +37,7 @@ - + AAACAAIABAAAAQAAAAAAAAAAAAAAAAQAAAAAAAAAAAA= Model\Solution.cs @@ -46,7 +47,7 @@ - + AAAAAAIAAAAAEAAAAAAAAAgAAAAAAAAAAAAAAAAAAAA= Model\Vote.cs @@ -55,5 +56,15 @@ + + + + AAECAAAAAAAAAAAAACAAAAQAAAAAAAAAAAAAAAAAAAA= + Model\IssueType.cs + + + + + \ No newline at end of file diff --git a/KTUSAPS.Data/Model/PublishedFeedback.cs b/KTUSAPS.Data/Model/PublishedFeedback.cs index 9d23659..b68f9f0 100644 --- a/KTUSAPS.Data/Model/PublishedFeedback.cs +++ b/KTUSAPS.Data/Model/PublishedFeedback.cs @@ -22,6 +22,11 @@ namespace KTUSAPS.Data.Model public DateTime Created { get; set; } public int? IssueId { get; set; } - public Issue Issue { get; set; } + public virtual Issue Issue { get; set; } + + public PublishedFeedback() + { + Created = DateTime.Now; + } } } diff --git a/KTUSAPS.Data/Model/PublishedProblem.cs b/KTUSAPS.Data/Model/PublishedProblem.cs index 35f1fb7..b841209 100644 --- a/KTUSAPS.Data/Model/PublishedProblem.cs +++ b/KTUSAPS.Data/Model/PublishedProblem.cs @@ -18,20 +18,19 @@ namespace KTUSAPS.Data.Model [Required] [MaxLength] public string ProblemEn { get; set; } - [MaxLength] - public string ResponseLt { get; set; } - [MaxLength] - public string ResponseEn { get; set; } public DateTime Created { get; set; } public int? IssueId { get; set; } - public Issue Issue { get; set; } + public virtual Issue Issue { get; set; } public int? SolutionId { get; set; } - public Solution Solution { get; set; } + public virtual Solution Solution { get; set; } public ICollection Votes { get; set; } - + public PublishedProblem() + { + Created = DateTime.Now; + } } } diff --git a/KTUSAPS.Data/Model/Solution.cs b/KTUSAPS.Data/Model/Solution.cs index 4bccc18..fa2f94b 100644 --- a/KTUSAPS.Data/Model/Solution.cs +++ b/KTUSAPS.Data/Model/Solution.cs @@ -14,7 +14,12 @@ namespace KTUSAPS.Data.Model public string SolutionEn { get; set; } - public PublishedProblem Problem { get; set; } - public DateTime Created { get; set; } + public virtual PublishedProblem Problem { get; set; } + public DateTime Created { get; set; } + + public Solution() + { + Created = DateTime.Now; + } } } \ No newline at end of file diff --git a/KTUSAPS.Data/Model/Vote.cs b/KTUSAPS.Data/Model/Vote.cs index a794667..6882d42 100644 --- a/KTUSAPS.Data/Model/Vote.cs +++ b/KTUSAPS.Data/Model/Vote.cs @@ -12,7 +12,7 @@ namespace KTUSAPS.Data.Model [MaxLength(64)] public string UserId { get; set; } public int ProblemId { get; set; } - public PublishedProblem Problem { get; set; } + public virtual PublishedProblem Problem { get; set; } } } diff --git a/KTUSAPS.Data/SAPSDataContext.cs b/KTUSAPS.Data/SAPSDataContext.cs index e5fc284..9cf9274 100644 --- a/KTUSAPS.Data/SAPSDataContext.cs +++ b/KTUSAPS.Data/SAPSDataContext.cs @@ -26,6 +26,7 @@ namespace KTUSAPS.Data } } + public DbSet IssueTypes { get; set; } public DbSet Issues { get; set; } public DbSet PublishedFeedbacks { get; set; } public DbSet PublishedProblems { get; set; } diff --git a/KTUSAPS/ClientApp/src/App.vue b/KTUSAPS/ClientApp/src/App.vue index 12da81c..a9ed8f9 100644 --- a/KTUSAPS/ClientApp/src/App.vue +++ b/KTUSAPS/ClientApp/src/App.vue @@ -19,6 +19,15 @@ +
+
+

Greitai baisis jūsų sesija

+ + Po {{ expiresIn }} baigsis jūsų sesija. + Pratęsti sesija. + +
+
@@ -30,6 +39,12 @@ export default { components: { NavMenu, }, + data() { + return { + expiresIn: '', + interval: null, + } + }, created() { this.$store.dispatch('auth/initialize') }, @@ -43,6 +58,26 @@ export default { return location.protocol !== 'https:' }, }, + methods: { + updateExpiry() { + const totalSeconds = Math.floor( + (this.$store.getters['auth/expires'] - new Date()) / 1000 + ) + const seconds = totalSeconds % 60 + const minutes = Math.floor(totalSeconds / 60) + if (minutes) { + this.expiresIn = `${minutes} min. ir ${seconds} sek.` + } else { + this.expiresIn = `${seconds} sek.` + } + }, + }, + mounted() { + this.interval = setInterval(this.updateExpiry, 1000) + }, + beforeUnmount() { + clearInterval(this.interval) + }, } diff --git a/KTUSAPS/ClientApp/src/components/NavMenu.vue b/KTUSAPS/ClientApp/src/components/NavMenu.vue index bc53f9d..740ce71 100644 --- a/KTUSAPS/ClientApp/src/components/NavMenu.vue +++ b/KTUSAPS/ClientApp/src/components/NavMenu.vue @@ -27,6 +27,9 @@ >Pagrindinis +