From dee2e37a4a8759108390c664e06bf147b8385cbf Mon Sep 17 00:00:00 2001 From: transtrike Date: Mon, 14 Dec 2020 23:29:14 +0200 Subject: Stabalized project for compilation. Next step after init architecture --- src/DevHive.Web/DevHive.Web.csproj | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'src/DevHive.Web/DevHive.Web.csproj') diff --git a/src/DevHive.Web/DevHive.Web.csproj b/src/DevHive.Web/DevHive.Web.csproj index 218b809..5b5478d 100644 --- a/src/DevHive.Web/DevHive.Web.csproj +++ b/src/DevHive.Web/DevHive.Web.csproj @@ -1,13 +1,20 @@ - - - - net5.0 - - - - - - - - - + + + net5.0 + + + + + + + + + + + + + + + + + \ No newline at end of file -- cgit v1.2.3 From 791c559712a161c745a407a87d0f7e8d1f00492c Mon Sep 17 00:00:00 2001 From: transtrike Date: Tue, 15 Dec 2020 21:56:11 +0200 Subject: Updated packages to latest --- src/DevHive.Data/DevHive.Data.csproj | 2 +- src/DevHive.Data/Repositories/DevHiveContext.cs | 3 +-- src/DevHive.Web/DevHive.Web.csproj | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) (limited to 'src/DevHive.Web/DevHive.Web.csproj') diff --git a/src/DevHive.Data/DevHive.Data.csproj b/src/DevHive.Data/DevHive.Data.csproj index d7d59c0..d472d1c 100644 --- a/src/DevHive.Data/DevHive.Data.csproj +++ b/src/DevHive.Data/DevHive.Data.csproj @@ -8,7 +8,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/DevHive.Data/Repositories/DevHiveContext.cs b/src/DevHive.Data/Repositories/DevHiveContext.cs index dad4672..2f0fa55 100644 --- a/src/DevHive.Data/Repositories/DevHiveContext.cs +++ b/src/DevHive.Data/Repositories/DevHiveContext.cs @@ -1,12 +1,11 @@ using System; using DevHive.Data.Models; -using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace DevHive.Data.Repositories { - public class DevHiveContext : IdentityDbContext, Guid> + public class DevHiveContext : IdentityDbContext { public DevHiveContext(DbContextOptions options) : base(options) { } diff --git a/src/DevHive.Web/DevHive.Web.csproj b/src/DevHive.Web/DevHive.Web.csproj index 5b5478d..7f7ba49 100644 --- a/src/DevHive.Web/DevHive.Web.csproj +++ b/src/DevHive.Web/DevHive.Web.csproj @@ -6,7 +6,7 @@ - + -- cgit v1.2.3 From 6f4d5ea241b07b8701df08a678baff417ae56ccf Mon Sep 17 00:00:00 2001 From: Syndamia Date: Tue, 15 Dec 2020 22:07:58 +0200 Subject: Added initial migrations and partially fixed migrations --- .../20201215200508_InitDatabase.Designer.cs | 317 +++++++++++++++++++++ .../Migrations/20201215200508_InitDatabase.cs | 257 +++++++++++++++++ .../Migrations/DevHiveContextModelSnapshot.cs | 315 ++++++++++++++++++++ src/DevHive.Web/DevHive.Web.csproj | 4 + 4 files changed, 893 insertions(+) create mode 100644 src/DevHive.Data/Migrations/20201215200508_InitDatabase.Designer.cs create mode 100644 src/DevHive.Data/Migrations/20201215200508_InitDatabase.cs create mode 100644 src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs (limited to 'src/DevHive.Web/DevHive.Web.csproj') diff --git a/src/DevHive.Data/Migrations/20201215200508_InitDatabase.Designer.cs b/src/DevHive.Data/Migrations/20201215200508_InitDatabase.Designer.cs new file mode 100644 index 0000000..c52ce9e --- /dev/null +++ b/src/DevHive.Data/Migrations/20201215200508_InitDatabase.Designer.cs @@ -0,0 +1,317 @@ +// +using System; +using DevHive.Data.Repositories; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +namespace DevHive.Data.Migrations +{ + [DbContext(typeof(DevHiveContext))] + [Migration("20201215200508_InitDatabase")] + partial class InitDatabase + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .UseIdentityByDefaultColumns() + .HasAnnotation("Relational:MaxIdentifierLength", 63) + .HasAnnotation("ProductVersion", "5.0.1"); + + modelBuilder.Entity("DevHive.Data.Models.Language", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Languages"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Technology", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("Technologies"); + }); + + modelBuilder.Entity("DevHive.Data.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("ProfilePicture") + .HasColumnType("text"); + + b.Property("Role") + .HasColumnType("text"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserName") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.HasIndex("UserName") + .IsUnique(); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .UseIdentityByDefaultColumn(); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .UseIdentityByDefaultColumn(); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("ProviderKey") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("LoginProvider") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("Name") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("DevHive.Data.Models.Role", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("DevHive.Data.Models.Role", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/DevHive.Data/Migrations/20201215200508_InitDatabase.cs b/src/DevHive.Data/Migrations/20201215200508_InitDatabase.cs new file mode 100644 index 0000000..7145c6c --- /dev/null +++ b/src/DevHive.Data/Migrations/20201215200508_InitDatabase.cs @@ -0,0 +1,257 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +namespace DevHive.Data.Migrations +{ + public partial class InitDatabase : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "AspNetRoles", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + NormalizedName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + ConcurrencyStamp = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoles", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetUsers", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + UserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: false), + FirstName = table.Column(type: "text", nullable: false), + LastName = table.Column(type: "text", nullable: false), + ProfilePicture = table.Column(type: "text", nullable: true), + Role = table.Column(type: "text", nullable: true), + NormalizedUserName = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + Email = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + NormalizedEmail = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + EmailConfirmed = table.Column(type: "boolean", nullable: false), + PasswordHash = table.Column(type: "text", nullable: true), + SecurityStamp = table.Column(type: "text", nullable: true), + ConcurrencyStamp = table.Column(type: "text", nullable: true), + PhoneNumber = table.Column(type: "text", nullable: true), + PhoneNumberConfirmed = table.Column(type: "boolean", nullable: false), + TwoFactorEnabled = table.Column(type: "boolean", nullable: false), + LockoutEnd = table.Column(type: "timestamp with time zone", nullable: true), + LockoutEnabled = table.Column(type: "boolean", nullable: false), + AccessFailedCount = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUsers", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Languages", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Name = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Languages", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Technologies", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Technologies", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "AspNetRoleClaims", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + RoleId = table.Column(type: "uuid", nullable: false), + ClaimType = table.Column(type: "text", nullable: true), + ClaimValue = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserClaims", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + UserId = table.Column(type: "uuid", nullable: false), + ClaimType = table.Column(type: "text", nullable: true), + ClaimValue = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); + table.ForeignKey( + name: "FK_AspNetUserClaims_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserLogins", + columns: table => new + { + LoginProvider = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), + ProviderKey = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), + ProviderDisplayName = table.Column(type: "text", nullable: true), + UserId = table.Column(type: "uuid", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); + table.ForeignKey( + name: "FK_AspNetUserLogins_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserRoles", + columns: table => new + { + UserId = table.Column(type: "uuid", nullable: false), + RoleId = table.Column(type: "uuid", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetRoles_RoleId", + column: x => x.RoleId, + principalTable: "AspNetRoles", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_AspNetUserRoles_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "AspNetUserTokens", + columns: table => new + { + UserId = table.Column(type: "uuid", nullable: false), + LoginProvider = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), + Name = table.Column(type: "character varying(20)", maxLength: 20, nullable: false), + Value = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); + table.ForeignKey( + name: "FK_AspNetUserTokens_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_AspNetRoleClaims_RoleId", + table: "AspNetRoleClaims", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "RoleNameIndex", + table: "AspNetRoles", + column: "NormalizedName", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserClaims_UserId", + table: "AspNetUserClaims", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserLogins_UserId", + table: "AspNetUserLogins", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserRoles_RoleId", + table: "AspNetUserRoles", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "EmailIndex", + table: "AspNetUsers", + column: "NormalizedEmail"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUsers_UserName", + table: "AspNetUsers", + column: "UserName", + unique: true); + + migrationBuilder.CreateIndex( + name: "UserNameIndex", + table: "AspNetUsers", + column: "NormalizedUserName", + unique: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "AspNetRoleClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserClaims"); + + migrationBuilder.DropTable( + name: "AspNetUserLogins"); + + migrationBuilder.DropTable( + name: "AspNetUserRoles"); + + migrationBuilder.DropTable( + name: "AspNetUserTokens"); + + migrationBuilder.DropTable( + name: "Languages"); + + migrationBuilder.DropTable( + name: "Technologies"); + + migrationBuilder.DropTable( + name: "AspNetRoles"); + + migrationBuilder.DropTable( + name: "AspNetUsers"); + } + } +} diff --git a/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs b/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs new file mode 100644 index 0000000..81580b8 --- /dev/null +++ b/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs @@ -0,0 +1,315 @@ +// +using System; +using DevHive.Data.Repositories; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +namespace DevHive.Data.Migrations +{ + [DbContext(typeof(DevHiveContext))] + partial class DevHiveContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .UseIdentityByDefaultColumns() + .HasAnnotation("Relational:MaxIdentifierLength", 63) + .HasAnnotation("ProductVersion", "5.0.1"); + + modelBuilder.Entity("DevHive.Data.Models.Language", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Languages"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Technology", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("Technologies"); + }); + + modelBuilder.Entity("DevHive.Data.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("FirstName") + .IsRequired() + .HasColumnType("text"); + + b.Property("LastName") + .IsRequired() + .HasColumnType("text"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("ProfilePicture") + .HasColumnType("text"); + + b.Property("Role") + .HasColumnType("text"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserName") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.HasIndex("UserName") + .IsUnique(); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .UseIdentityByDefaultColumn(); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .UseIdentityByDefaultColumn(); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("ProviderKey") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("LoginProvider") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("Name") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("DevHive.Data.Models.Role", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("DevHive.Data.Models.Role", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/DevHive.Web/DevHive.Web.csproj b/src/DevHive.Web/DevHive.Web.csproj index 7f7ba49..2a1faf1 100644 --- a/src/DevHive.Web/DevHive.Web.csproj +++ b/src/DevHive.Web/DevHive.Web.csproj @@ -5,6 +5,10 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + -- cgit v1.2.3 From cd02428e748e691a0005b2687edf69a99766aac6 Mon Sep 17 00:00:00 2001 From: transtrike Date: Wed, 16 Dec 2020 22:38:25 +0200 Subject: Added DevHive.Common; Changed repositories behavior; Abstracted some common logic --- src/DevHive.Common/DevHive.Common.csproj | 12 ++++++++++++ src/DevHive.Common/Models/Data/RepositoryMethods.cs | 15 +++++++++++++++ src/DevHive.Common/Models/Identity/TokenModel.cs | 12 ++++++++++++ src/DevHive.Data/DevHive.Data.csproj | 4 ++++ src/DevHive.Data/Repositories/LanguageRepository.cs | 14 ++++---------- src/DevHive.Data/Repositories/RoleRepository.cs | 20 ++++++++++++-------- src/DevHive.Data/Repositories/UserRepository.cs | 13 +++++++------ src/DevHive.Services/DevHive.Services.csproj | 4 ++++ .../Models/Identity/User/TokenServiceModel.cs | 12 ------------ src/DevHive.Services/Services/UserService.cs | 20 +++++++++++++------- .../Configurations/Mapping/UserMappings.cs | 4 ++-- src/DevHive.Web/Controllers/UserController.cs | 10 +++++----- src/DevHive.Web/DevHive.Web.csproj | 1 + src/DevHive.code-workspace | 4 ++++ 14 files changed, 95 insertions(+), 50 deletions(-) create mode 100644 src/DevHive.Common/DevHive.Common.csproj create mode 100644 src/DevHive.Common/Models/Data/RepositoryMethods.cs create mode 100644 src/DevHive.Common/Models/Identity/TokenModel.cs delete mode 100644 src/DevHive.Services/Models/Identity/User/TokenServiceModel.cs (limited to 'src/DevHive.Web/DevHive.Web.csproj') diff --git a/src/DevHive.Common/DevHive.Common.csproj b/src/DevHive.Common/DevHive.Common.csproj new file mode 100644 index 0000000..1aca8a6 --- /dev/null +++ b/src/DevHive.Common/DevHive.Common.csproj @@ -0,0 +1,12 @@ + + + + net5.0 + + + + + + + + diff --git a/src/DevHive.Common/Models/Data/RepositoryMethods.cs b/src/DevHive.Common/Models/Data/RepositoryMethods.cs new file mode 100644 index 0000000..b56aad9 --- /dev/null +++ b/src/DevHive.Common/Models/Data/RepositoryMethods.cs @@ -0,0 +1,15 @@ +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; + +namespace DevHive.Common.Models.Data +{ + public static class RepositoryMethods + { + public static async Task SaveChangesAsync(DbContext context) + { + int result = await context.SaveChangesAsync(); + + return result >= 1; + } + } +} \ No newline at end of file diff --git a/src/DevHive.Common/Models/Identity/TokenModel.cs b/src/DevHive.Common/Models/Identity/TokenModel.cs new file mode 100644 index 0000000..0fb6c82 --- /dev/null +++ b/src/DevHive.Common/Models/Identity/TokenModel.cs @@ -0,0 +1,12 @@ +namespace DevHive.Common.Models.Identity +{ + public class TokenModel + { + public TokenModel(string token) + { + this.Token = token; + } + + public string Token { get; set; } + } +} \ No newline at end of file diff --git a/src/DevHive.Data/DevHive.Data.csproj b/src/DevHive.Data/DevHive.Data.csproj index d472d1c..c1e1592 100644 --- a/src/DevHive.Data/DevHive.Data.csproj +++ b/src/DevHive.Data/DevHive.Data.csproj @@ -16,4 +16,8 @@ + + + + diff --git a/src/DevHive.Data/Repositories/LanguageRepository.cs b/src/DevHive.Data/Repositories/LanguageRepository.cs index 08efd18..a33bd5b 100644 --- a/src/DevHive.Data/Repositories/LanguageRepository.cs +++ b/src/DevHive.Data/Repositories/LanguageRepository.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using Data.Models.Interfaces.Database; +using DevHive.Common.Models.Data; using DevHive.Data.Models; using Microsoft.EntityFrameworkCore; @@ -22,7 +23,7 @@ namespace DevHive.Data.Repositories .Set() .AddAsync(entity); - return await this.SaveChangesAsync(); + return await RepositoryMethods.SaveChangesAsync(this._context); } //Read @@ -56,7 +57,7 @@ namespace DevHive.Data.Repositories .Set() .Update(newEntity); - return await this.SaveChangesAsync(); + return await RepositoryMethods.SaveChangesAsync(this._context); } //Delete @@ -66,14 +67,7 @@ namespace DevHive.Data.Repositories .Set() .Remove(entity); - return await this.SaveChangesAsync(); + return await RepositoryMethods.SaveChangesAsync(this._context); } - - private async Task SaveChangesAsync() - { - int result = await this._context.SaveChangesAsync(); - - return result >= 0; - } } } \ No newline at end of file diff --git a/src/DevHive.Data/Repositories/RoleRepository.cs b/src/DevHive.Data/Repositories/RoleRepository.cs index 9b6cf14..ad9bda0 100644 --- a/src/DevHive.Data/Repositories/RoleRepository.cs +++ b/src/DevHive.Data/Repositories/RoleRepository.cs @@ -1,6 +1,7 @@ using System; using System.Threading.Tasks; using Data.Models.Interfaces.Database; +using DevHive.Common.Models.Data; using DevHive.Data.Models; using Microsoft.EntityFrameworkCore; @@ -16,13 +17,13 @@ namespace DevHive.Data.Repositories } //Create - public async Task AddAsync(Role entity) + public async Task AddAsync(Role entity) { await this._context .Set() .AddAsync(entity); - await this._context.SaveChangesAsync(); + return await RepositoryMethods.SaveChangesAsync(this._context); } //Read @@ -35,23 +36,26 @@ namespace DevHive.Data.Repositories } //Update - public async Task EditAsync(Role newEntity) + public async Task EditAsync(Role newEntity) { + Role role = await this.GetByIdAsync(newEntity.Id); + this._context - .Set() - .Update(newEntity); + .Entry(role) + .CurrentValues + .SetValues(newEntity); - await this._context.SaveChangesAsync(); + return await RepositoryMethods.SaveChangesAsync(this._context); } //Delete - public async Task DeleteAsync(Role entity) + public async Task DeleteAsync(Role entity) { this._context .Set() .Remove(entity); - await this._context.SaveChangesAsync(); + return await RepositoryMethods.SaveChangesAsync(this._context); } public async Task DoesNameExist(string name) diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs index 714218d..f5a074b 100644 --- a/src/DevHive.Data/Repositories/UserRepository.cs +++ b/src/DevHive.Data/Repositories/UserRepository.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Data.Models.Interfaces.Database; +using DevHive.Common.Models.Data; using DevHive.Data.Models; using Microsoft.EntityFrameworkCore; @@ -18,13 +19,13 @@ namespace DevHive.Data.Repositories } //Create - public async Task AddAsync(User entity) + public async Task AddAsync(User entity) { await this._context .Set() .AddAsync(entity); - await this._context.SaveChangesAsync(); + return await RepositoryMethods.SaveChangesAsync(this._context); } //Read @@ -51,7 +52,7 @@ namespace DevHive.Data.Repositories } //Update - public async Task EditAsync(User newEntity) + public async Task EditAsync(User newEntity) { User user = await this.GetByIdAsync(newEntity.Id); @@ -60,17 +61,17 @@ namespace DevHive.Data.Repositories .CurrentValues .SetValues(newEntity); - await this._context.SaveChangesAsync(); + return await RepositoryMethods.SaveChangesAsync(this._context); } //Delete - public async Task DeleteAsync(User entity) + public async Task DeleteAsync(User entity) { this._context .Set() .Remove(entity); - await this._context.SaveChangesAsync(); + return await RepositoryMethods.SaveChangesAsync(this._context); } //Validations diff --git a/src/DevHive.Services/DevHive.Services.csproj b/src/DevHive.Services/DevHive.Services.csproj index 280610d..19f67d8 100644 --- a/src/DevHive.Services/DevHive.Services.csproj +++ b/src/DevHive.Services/DevHive.Services.csproj @@ -16,5 +16,9 @@ + + + + diff --git a/src/DevHive.Services/Models/Identity/User/TokenServiceModel.cs b/src/DevHive.Services/Models/Identity/User/TokenServiceModel.cs deleted file mode 100644 index 631808e..0000000 --- a/src/DevHive.Services/Models/Identity/User/TokenServiceModel.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace DevHive.Services.Models.Identity.User -{ - public class TokenServiceModel - { - public TokenServiceModel(string token) - { - this.Token = token; - } - - public string Token { get; set; } - } -} \ No newline at end of file diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs index 24f74f5..63b8389 100644 --- a/src/DevHive.Services/Services/UserService.cs +++ b/src/DevHive.Services/Services/UserService.cs @@ -3,7 +3,6 @@ using DevHive.Data.Repositories; using DevHive.Services.Options; using DevHive.Services.Models.Identity.User; using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; using DevHive.Data.Models; using System; using System.IdentityModel.Tokens.Jwt; @@ -12,6 +11,7 @@ using Microsoft.IdentityModel.Tokens; using System.Security.Cryptography; using System.Text; using System.Collections.Generic; +using DevHive.Common.Models.Identity; namespace DevHive.Services.Services { @@ -28,7 +28,7 @@ namespace DevHive.Services.Services this._jwtOptions = jwtOptions; } - public async Task LoginUser(LoginServiceModel loginModel) + public async Task LoginUser(LoginServiceModel loginModel) { if (!await this._userRepository.IsUsernameValid(loginModel.UserName)) throw new ArgumentException("Invalid username!"); @@ -38,10 +38,10 @@ namespace DevHive.Services.Services if (user.PasswordHash != GeneratePasswordHash(loginModel.Password)) throw new ArgumentException("Incorrect password!"); - return new TokenServiceModel(WriteJWTSecurityToken(user.Role)); + return new TokenModel(WriteJWTSecurityToken(user.Role)); } - public async Task RegisterUser(RegisterServiceModel registerModel) + public async Task RegisterUser(RegisterServiceModel registerModel) { if (await this._userRepository.DoesUsernameExist(registerModel.UserName)) throw new ArgumentException("Username already exists!"); @@ -55,7 +55,7 @@ namespace DevHive.Services.Services await this._userRepository.AddAsync(user); - return new TokenServiceModel(WriteJWTSecurityToken(user.Role)); + return new TokenModel(WriteJWTSecurityToken(user.Role)); } public async Task GetUserById(Guid id) @@ -76,7 +76,10 @@ namespace DevHive.Services.Services throw new ArgumentException("Username already exists!"); User user = this._userMapper.Map(updateModel); - await this._userRepository.EditAsync(user); + bool result = await this._userRepository.EditAsync(user); + + if (!result) + throw new InvalidOperationException("Unable to edit user!"); return this._userMapper.Map(user);; } @@ -87,7 +90,10 @@ namespace DevHive.Services.Services throw new ArgumentException("User does not exist!"); User user = await this._userRepository.GetByIdAsync(id); - await this._userRepository.DeleteAsync(user); + bool result = await this._userRepository.DeleteAsync(user); + + if (!result) + throw new InvalidOperationException("Unable to delete user!"); } private string GeneratePasswordHash(string password) diff --git a/src/DevHive.Web/Configurations/Mapping/UserMappings.cs b/src/DevHive.Web/Configurations/Mapping/UserMappings.cs index 1fdfc6a..4420368 100644 --- a/src/DevHive.Web/Configurations/Mapping/UserMappings.cs +++ b/src/DevHive.Web/Configurations/Mapping/UserMappings.cs @@ -1,7 +1,7 @@ -using DevHive.Data.Models; using AutoMapper; using DevHive.Services.Models.Identity.User; using DevHive.Web.Models.Identity.User; +using DevHive.Common.Models.Identity; namespace DevHive.Web.Configurations.Mapping { @@ -16,7 +16,7 @@ namespace DevHive.Web.Configurations.Mapping CreateMap(); - CreateMap(); + CreateMap(); } } } diff --git a/src/DevHive.Web/Controllers/UserController.cs b/src/DevHive.Web/Controllers/UserController.cs index 80e1bde..1360bfe 100644 --- a/src/DevHive.Web/Controllers/UserController.cs +++ b/src/DevHive.Web/Controllers/UserController.cs @@ -1,7 +1,6 @@ using System; using System.Threading.Tasks; using AutoMapper; -using DevHive.Data.Models; using DevHive.Data.Repositories; using DevHive.Services.Models.Identity.User; using DevHive.Services.Options; @@ -9,6 +8,7 @@ using DevHive.Services.Services; using DevHive.Web.Models.Identity.User; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using DevHive.Common.Models.Identity; namespace DevHive.Web.Controllers { @@ -33,8 +33,8 @@ namespace DevHive.Web.Controllers { LoginServiceModel loginServiceModel = this._userMapper.Map(loginModel); - TokenServiceModel tokenServiceModel = await this._userService.LoginUser(loginServiceModel); - TokenWebModel tokenWebModel = this._userMapper.Map(tokenServiceModel); + TokenModel TokenModel = await this._userService.LoginUser(loginServiceModel); + TokenWebModel tokenWebModel = this._userMapper.Map(TokenModel); return new OkObjectResult(tokenWebModel); } @@ -46,8 +46,8 @@ namespace DevHive.Web.Controllers { RegisterServiceModel registerServiceModel = this._userMapper.Map(registerModel); - TokenServiceModel tokenServiceModel = await this._userService.RegisterUser(registerServiceModel); - TokenWebModel tokenWebModel = this._userMapper.Map(tokenServiceModel); + TokenModel TokenModel = await this._userService.RegisterUser(registerServiceModel); + TokenWebModel tokenWebModel = this._userMapper.Map(TokenModel); return new CreatedResult("Register", tokenWebModel); } diff --git a/src/DevHive.Web/DevHive.Web.csproj b/src/DevHive.Web/DevHive.Web.csproj index 2a1faf1..0be5bdc 100644 --- a/src/DevHive.Web/DevHive.Web.csproj +++ b/src/DevHive.Web/DevHive.Web.csproj @@ -20,5 +20,6 @@ + \ No newline at end of file diff --git a/src/DevHive.code-workspace b/src/DevHive.code-workspace index 730aab1..7e952c7 100644 --- a/src/DevHive.code-workspace +++ b/src/DevHive.code-workspace @@ -12,6 +12,10 @@ "name": "DevHive.Data", "path": "./DevHive.Data" }, + { + "name": "DevHive.Common", + "path": "./DevHive.Common" + }, ], "settings": { "files.exclude": { -- cgit v1.2.3 From 94a3b0661106e91ab3a1a523af3c60df131a4f63 Mon Sep 17 00:00:00 2001 From: transtrike Date: Thu, 17 Dec 2020 19:13:01 +0200 Subject: Friends implementation added. UserController/AddAFriend added --- src/DevHive.Common/Models/IdModel.cs | 9 + src/DevHive.Data/Models/User.cs | 4 +- src/DevHive.Data/Repositories/DevHiveContext.cs | 8 +- src/DevHive.Data/Repositories/UserRepository.cs | 9 + .../Models/Identity/User/UserServiceModel.cs | 7 +- src/DevHive.Services/Services/UserService.cs | 22 +- .../Configurations/Mapping/RoleMappings.cs | 1 + src/DevHive.Web/Controllers/UserController.cs | 11 + src/DevHive.Web/DevHive.Web.csproj | 22 +- .../20201217163729_Friends_Implemented.Designer.cs | 364 +++++++++++++++++++++ .../20201217163729_Friends_Implemented.cs | 45 +++ .../Migrations/DevHiveContextModelSnapshot.cs | 17 + .../Models/Identity/User/UserWebModel.cs | 6 +- 13 files changed, 505 insertions(+), 20 deletions(-) create mode 100644 src/DevHive.Common/Models/IdModel.cs create mode 100644 src/DevHive.Web/Migrations/20201217163729_Friends_Implemented.Designer.cs create mode 100644 src/DevHive.Web/Migrations/20201217163729_Friends_Implemented.cs (limited to 'src/DevHive.Web/DevHive.Web.csproj') diff --git a/src/DevHive.Common/Models/IdModel.cs b/src/DevHive.Common/Models/IdModel.cs new file mode 100644 index 0000000..a342e6d --- /dev/null +++ b/src/DevHive.Common/Models/IdModel.cs @@ -0,0 +1,9 @@ +using System; + +namespace DevHive.Common.Models +{ + public class IdModel + { + public Guid Id { get; set; } + } +} \ No newline at end of file diff --git a/src/DevHive.Data/Models/User.cs b/src/DevHive.Data/Models/User.cs index fd0ee7b..eef0af2 100644 --- a/src/DevHive.Data/Models/User.cs +++ b/src/DevHive.Data/Models/User.cs @@ -14,8 +14,8 @@ namespace DevHive.Data.Models public string ProfilePicture { get; set; } - public virtual IList Roles { get; set; } + public virtual IList Roles { get; set; } = new List(); - //public List Friends { get; set; } + public IList Friends { get; set; } = new List(); } } diff --git a/src/DevHive.Data/Repositories/DevHiveContext.cs b/src/DevHive.Data/Repositories/DevHiveContext.cs index 373eb5e..7fa8130 100644 --- a/src/DevHive.Data/Repositories/DevHiveContext.cs +++ b/src/DevHive.Data/Repositories/DevHiveContext.cs @@ -18,7 +18,13 @@ namespace DevHive.Data.Repositories builder.Entity() .HasIndex(x => x.UserName) .IsUnique(); - + + builder.Entity() + .HasMany(x => x.Roles); + + builder.Entity() + .HasMany(x => x.Friends); + builder.Entity() .HasIndex(x => x.Id) .IsUnique(); diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs index 130f96e..577f02f 100644 --- a/src/DevHive.Data/Repositories/UserRepository.cs +++ b/src/DevHive.Data/Repositories/UserRepository.cs @@ -43,6 +43,7 @@ namespace DevHive.Data.Repositories return await this._context .Set() .Include(x => x.Roles) + .Include(x => x.Friends) .FirstOrDefaultAsync(x => x.Id == id); } @@ -115,5 +116,13 @@ namespace DevHive.Data.Repositories .AsNoTracking() .AnyAsync(u => u.Email == email); } + + public async Task AddFriend(User user, User friend) + { + this._context.Update(user); + user.Friends.Add(friend); + + return await RepositoryMethods.SaveChangesAsync(this._context); + } } } diff --git a/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs b/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs index 576e502..868e7ba 100644 --- a/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs +++ b/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs @@ -1,7 +1,12 @@ +using System.Collections.Generic; +using DevHive.Data.Models; +using DevHive.Services.Models.Identity.Role; + namespace DevHive.Services.Models.Identity.User { public class UserServiceModel : BaseUserServiceModel { - public string Role { get; set;} + public IList Role { get; set; } = new List(); + public List Friends { get; set; } = new List(); } } diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs index bd9eaa6..3e65dab 100644 --- a/src/DevHive.Services/Services/UserService.cs +++ b/src/DevHive.Services/Services/UserService.cs @@ -72,7 +72,13 @@ namespace DevHive.Services.Services User user = await this._userRepository.GetByIdAsync(id) ?? throw new ArgumentException("User does not exist!"); - return this._userMapper.Map(user); + //Here User has 1 role + + UserServiceModel model = this._userMapper.Map(user); + + //here model has 0 roles + + return model; } public async Task UpdateUser(UpdateUserServiceModel updateModel) @@ -105,6 +111,16 @@ namespace DevHive.Services.Services throw new InvalidOperationException("Unable to delete user!"); } + public async Task AddFriend(Guid userId, Guid friendId) + { + User user = await this._userRepository.GetByIdAsync(userId); + User friend = await this._userRepository.GetByIdAsync(friendId); + + return user != default(User) && friend != default(User) ? + await this._userRepository.AddFriend(user, friend) : + throw new ArgumentException("Invalid user!"); + } + private string GeneratePasswordHash(string password) { return string.Join(string.Empty, SHA512.HashData(Encoding.ASCII.GetBytes(password))); @@ -114,9 +130,9 @@ namespace DevHive.Services.Services { byte[] signingKey = Encoding.ASCII.GetBytes(_jwtOptions.Secret); - List claims = new List() + List claims = new() { - new Claim(ClaimTypes.Role, roles[0].Name) // TODO: add support for mulitple roles + new Claim(ClaimTypes.Role, roles[0].Name) // TODO: add support for multiple roles }; SecurityTokenDescriptor tokenDescriptor = new() diff --git a/src/DevHive.Web/Configurations/Mapping/RoleMappings.cs b/src/DevHive.Web/Configurations/Mapping/RoleMappings.cs index 2743df3..4bc25c4 100644 --- a/src/DevHive.Web/Configurations/Mapping/RoleMappings.cs +++ b/src/DevHive.Web/Configurations/Mapping/RoleMappings.cs @@ -10,6 +10,7 @@ namespace DevHive.Web.Configurations.Mapping { CreateMap(); CreateMap(); + CreateMap(); CreateMap(); } diff --git a/src/DevHive.Web/Controllers/UserController.cs b/src/DevHive.Web/Controllers/UserController.cs index 1360bfe..cdb8dc1 100644 --- a/src/DevHive.Web/Controllers/UserController.cs +++ b/src/DevHive.Web/Controllers/UserController.cs @@ -9,6 +9,7 @@ using DevHive.Web.Models.Identity.User; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using DevHive.Common.Models.Identity; +using DevHive.Common.Models; namespace DevHive.Web.Controllers { @@ -39,6 +40,7 @@ namespace DevHive.Web.Controllers return new OkObjectResult(tokenWebModel); } + //Create [HttpPost] [Route("Register")] [AllowAnonymous] @@ -52,6 +54,15 @@ namespace DevHive.Web.Controllers return new CreatedResult("Register", tokenWebModel); } + [HttpPost] + [Route("AddAFriend")] + public async Task AddAFriend(Guid userId, [FromBody] IdModel friendIdModel) + { + return await this._userService.AddFriend(userId, friendIdModel.Id) ? + new OkResult() : + new BadRequestResult(); + } + //Read [HttpGet] public async Task GetById(Guid id) diff --git a/src/DevHive.Web/DevHive.Web.csproj b/src/DevHive.Web/DevHive.Web.csproj index 0be5bdc..ad23ce9 100644 --- a/src/DevHive.Web/DevHive.Web.csproj +++ b/src/DevHive.Web/DevHive.Web.csproj @@ -3,23 +3,21 @@ net5.0 - - + + runtime; build; native; contentfiles; analyzers; buildtransitive all - - - - - - - - + + + + + + - - + + \ No newline at end of file diff --git a/src/DevHive.Web/Migrations/20201217163729_Friends_Implemented.Designer.cs b/src/DevHive.Web/Migrations/20201217163729_Friends_Implemented.Designer.cs new file mode 100644 index 0000000..d066f18 --- /dev/null +++ b/src/DevHive.Web/Migrations/20201217163729_Friends_Implemented.Designer.cs @@ -0,0 +1,364 @@ +// +using System; +using DevHive.Data.Repositories; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +namespace DevHive.Web.Migrations +{ + [DbContext(typeof(DevHiveContext))] + [Migration("20201217163729_Friends_Implemented")] + partial class Friends_Implemented + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .UseIdentityByDefaultColumns() + .HasAnnotation("Relational:MaxIdentifierLength", 63) + .HasAnnotation("ProductVersion", "5.0.1"); + + modelBuilder.Entity("DevHive.Data.Models.Language", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Languages"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("Id") + .IsUnique(); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("AspNetRoles"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Technology", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Name") + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("Technologies"); + }); + + modelBuilder.Entity("DevHive.Data.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("AccessFailedCount") + .HasColumnType("integer"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean"); + + b.Property("FirstName") + .HasColumnType("text"); + + b.Property("LastName") + .HasColumnType("text"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("PasswordHash") + .HasColumnType("text"); + + b.Property("PhoneNumber") + .HasColumnType("text"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean"); + + b.Property("ProfilePicture") + .HasColumnType("text"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.HasKey("Id"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.HasIndex("UserId"); + + b.HasIndex("UserName") + .IsUnique(); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .UseIdentityByDefaultColumn(); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetRoleClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .UseIdentityByDefaultColumn(); + + b.Property("ClaimType") + .HasColumnType("text"); + + b.Property("ClaimValue") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserClaims"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("ProviderKey") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("ProviderDisplayName") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("LoginProvider", "ProviderKey"); + + b.HasIndex("UserId"); + + b.ToTable("AspNetUserLogins"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("RoleId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "RoleId"); + + b.HasIndex("RoleId"); + + b.ToTable("AspNetUserRoles"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("LoginProvider") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("Name") + .HasMaxLength(20) + .HasColumnType("character varying(20)"); + + b.Property("Value") + .HasColumnType("text"); + + b.HasKey("UserId", "LoginProvider", "Name"); + + b.ToTable("AspNetUserTokens"); + }); + + modelBuilder.Entity("RoleUser", b => + { + b.Property("RolesId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("RolesId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("RoleUser"); + }); + + modelBuilder.Entity("DevHive.Data.Models.User", b => + { + b.HasOne("DevHive.Data.Models.User", null) + .WithMany("Friends") + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("DevHive.Data.Models.Role", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("DevHive.Data.Models.Role", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("RoleUser", b => + { + b.HasOne("DevHive.Data.Models.Role", null) + .WithMany() + .HasForeignKey("RolesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("DevHive.Data.Models.User", b => + { + b.Navigation("Friends"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/DevHive.Web/Migrations/20201217163729_Friends_Implemented.cs b/src/DevHive.Web/Migrations/20201217163729_Friends_Implemented.cs new file mode 100644 index 0000000..e20bfc1 --- /dev/null +++ b/src/DevHive.Web/Migrations/20201217163729_Friends_Implemented.cs @@ -0,0 +1,45 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace DevHive.Web.Migrations +{ + public partial class Friends_Implemented : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "UserId", + table: "AspNetUsers", + type: "uuid", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUsers_UserId", + table: "AspNetUsers", + column: "UserId"); + + migrationBuilder.AddForeignKey( + name: "FK_AspNetUsers_AspNetUsers_UserId", + table: "AspNetUsers", + column: "UserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_AspNetUsers_AspNetUsers_UserId", + table: "AspNetUsers"); + + migrationBuilder.DropIndex( + name: "IX_AspNetUsers_UserId", + table: "AspNetUsers"); + + migrationBuilder.DropColumn( + name: "UserId", + table: "AspNetUsers"); + } + } +} diff --git a/src/DevHive.Web/Migrations/DevHiveContextModelSnapshot.cs b/src/DevHive.Web/Migrations/DevHiveContextModelSnapshot.cs index c1464d4..328eb9c 100644 --- a/src/DevHive.Web/Migrations/DevHiveContextModelSnapshot.cs +++ b/src/DevHive.Web/Migrations/DevHiveContextModelSnapshot.cs @@ -135,6 +135,9 @@ namespace DevHive.Web.Migrations b.Property("TwoFactorEnabled") .HasColumnType("boolean"); + b.Property("UserId") + .HasColumnType("uuid"); + b.Property("UserName") .HasMaxLength(256) .HasColumnType("character varying(256)"); @@ -148,6 +151,8 @@ namespace DevHive.Web.Migrations .IsUnique() .HasDatabaseName("UserNameIndex"); + b.HasIndex("UserId"); + b.HasIndex("UserName") .IsUnique(); @@ -274,6 +279,13 @@ namespace DevHive.Web.Migrations b.ToTable("RoleUser"); }); + modelBuilder.Entity("DevHive.Data.Models.User", b => + { + b.HasOne("DevHive.Data.Models.User", null) + .WithMany("Friends") + .HasForeignKey("UserId"); + }); + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { b.HasOne("DevHive.Data.Models.Role", null) @@ -339,6 +351,11 @@ namespace DevHive.Web.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); }); + + modelBuilder.Entity("DevHive.Data.Models.User", b => + { + b.Navigation("Friends"); + }); #pragma warning restore 612, 618 } } diff --git a/src/DevHive.Web/Models/Identity/User/UserWebModel.cs b/src/DevHive.Web/Models/Identity/User/UserWebModel.cs index 88ee1b7..e7bdb2a 100644 --- a/src/DevHive.Web/Models/Identity/User/UserWebModel.cs +++ b/src/DevHive.Web/Models/Identity/User/UserWebModel.cs @@ -1,7 +1,11 @@ +using System.Collections.Generic; +using DevHive.Web.Models.Identity.Role; + namespace DevHive.Web.Models.Identity.User { public class UserWebModel : BaseUserWebModel { - public string Role { get; set; } + public IList Role { get; set; } = new List(); + public IList Friends { get; set; } = new List(); } } -- cgit v1.2.3 From c69c21b2fe8aaca47b27277e0686ef37602a4813 Mon Sep 17 00:00:00 2001 From: transtrike Date: Sat, 19 Dec 2020 09:44:14 +0200 Subject: Friends insert validations --- src/DevHive.Services/Services/FriendsService.cs | 7 +++++++ .../Extensions/ConfigureProblemDetails.cs | 19 +++++++++++++++++++ src/DevHive.Web/Controllers/FriendsController.cs | 8 ++++---- src/DevHive.Web/DevHive.Web.csproj | 21 +++++++++++---------- 4 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 src/DevHive.Web/Configurations/Extensions/ConfigureProblemDetails.cs (limited to 'src/DevHive.Web/DevHive.Web.csproj') diff --git a/src/DevHive.Services/Services/FriendsService.cs b/src/DevHive.Services/Services/FriendsService.cs index 21a2aac..c0ec551 100644 --- a/src/DevHive.Services/Services/FriendsService.cs +++ b/src/DevHive.Services/Services/FriendsService.cs @@ -26,6 +26,9 @@ namespace DevHive.Services.Services User user = await this._friendsRepository.GetByIdAsync(userId); User friend = await this._friendsRepository.GetByIdAsync(friendId); + if (DoesUserHaveThisFriend(user, friend)) + throw new ArgumentException("Friend already exists in your friends list."); + return user != default(User) && friend != default(User) ? await this._friendsRepository.AddFriendAsync(user, friend) : throw new ArgumentException("Invalid user!"); @@ -49,10 +52,14 @@ namespace DevHive.Services.Services throw new ArgumentException("Invalid user!"); User user = await this._friendsRepository.GetByIdAsync(userId); + User friend = await this._friendsRepository.GetByIdAsync(friendId); if(!this.DoesUserHaveFriends(user)) throw new ArgumentException("User does not have any friends."); + if (!DoesUserHaveThisFriend(user, friend)) + throw new ArgumentException("This ain't your friend, amigo."); + return await this.RemoveFriend(user.Id, friendId); } diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureProblemDetails.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureProblemDetails.cs new file mode 100644 index 0000000..f945f03 --- /dev/null +++ b/src/DevHive.Web/Configurations/Extensions/ConfigureProblemDetails.cs @@ -0,0 +1,19 @@ +using Hellang.Middleware.ProblemDetails; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.DependencyInjection; + +namespace DevHive.Web.Configurations.Extensions +{ + public static class ConfigureProblemDetails + { + public static void ProblemDetailsConfiguration(this IServiceCollection services) + { + services.AddProblemDetails(); + } + + public static void UseProblemDetailsConfiguration(this IApplicationBuilder app) + { + app.UseProblemDetails(); + } + } +} \ No newline at end of file diff --git a/src/DevHive.Web/Controllers/FriendsController.cs b/src/DevHive.Web/Controllers/FriendsController.cs index 1c69bc3..216228b 100644 --- a/src/DevHive.Web/Controllers/FriendsController.cs +++ b/src/DevHive.Web/Controllers/FriendsController.cs @@ -13,14 +13,14 @@ using Microsoft.AspNetCore.Mvc; namespace DevHive.Web.Controllers { [ApiController] + [Route("/api")] [Authorize(Roles = "User")] - public class FriendsController : UserController + public class FriendsController { private readonly FriendsService _friendsService; private readonly IMapper _friendsMapper; - public FriendsController(DevHiveContext context, IMapper mapper, JWTOptions jwtOptions) - : base(context, mapper, jwtOptions) + public FriendsController(DevHiveContext context, IMapper mapper, JWTOptions jwtOptions) { this._friendsService = new FriendsService(context, mapper, jwtOptions); this._friendsMapper = mapper; @@ -49,7 +49,7 @@ namespace DevHive.Web.Controllers //Delete [HttpDelete] - [Route("GetAFriend")] + [Route("RemoveAFriend")] public async Task RemoveAFriend(Guid userId, Guid friendId) { await this._friendsService.RemoveFriend(userId, friendId); diff --git a/src/DevHive.Web/DevHive.Web.csproj b/src/DevHive.Web/DevHive.Web.csproj index ad23ce9..515d2f5 100644 --- a/src/DevHive.Web/DevHive.Web.csproj +++ b/src/DevHive.Web/DevHive.Web.csproj @@ -3,21 +3,22 @@ net5.0 - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - - - - - - + + + + + + - - + + \ No newline at end of file -- cgit v1.2.3 From 623bb66183be1349325ca9364f5bbf2e451f7578 Mon Sep 17 00:00:00 2001 From: transtrike Date: Wed, 13 Jan 2021 23:05:57 +0200 Subject: Added .csproj wide code analyzer support --- src/DevHive.Common/DevHive.Common.csproj | 5 ++++- src/DevHive.Data/DevHive.Data.csproj | 15 ++++++++++----- src/DevHive.Services/DevHive.Services.csproj | 17 ++++++++++------- .../DevHive.Data.Tests/DevHive.Data.Tests.csproj | 4 ++++ .../DevHive.Services.Tests.csproj | 4 ++++ .../DevHive.Web.Tests/DevHive.Web.Tests.csproj | 4 ++++ src/DevHive.Web/DevHive.Web.csproj | 5 +++++ 7 files changed, 41 insertions(+), 13 deletions(-) (limited to 'src/DevHive.Web/DevHive.Web.csproj') diff --git a/src/DevHive.Common/DevHive.Common.csproj b/src/DevHive.Common/DevHive.Common.csproj index 1aca8a6..ace4997 100644 --- a/src/DevHive.Common/DevHive.Common.csproj +++ b/src/DevHive.Common/DevHive.Common.csproj @@ -8,5 +8,8 @@ - + + true + latest + diff --git a/src/DevHive.Data/DevHive.Data.csproj b/src/DevHive.Data/DevHive.Data.csproj index 34a5431..d91728d 100644 --- a/src/DevHive.Data/DevHive.Data.csproj +++ b/src/DevHive.Data/DevHive.Data.csproj @@ -10,16 +10,21 @@ - - runtime; build; native; contentfiles; analyzers; buildtransitive - all + + runtime; build; native; contentfiles; analyzers; buildtransitive + all - - + + + + true + latest + + diff --git a/src/DevHive.Services/DevHive.Services.csproj b/src/DevHive.Services/DevHive.Services.csproj index 19f67d8..52f0323 100644 --- a/src/DevHive.Services/DevHive.Services.csproj +++ b/src/DevHive.Services/DevHive.Services.csproj @@ -5,9 +5,9 @@ - - runtime; build; native; contentfiles; analyzers; buildtransitive - all + + runtime; build; native; contentfiles; analyzers; buildtransitive + all @@ -16,9 +16,12 @@ - - + + - - + + + true + latest + diff --git a/src/DevHive.Tests/DevHive.Data.Tests/DevHive.Data.Tests.csproj b/src/DevHive.Tests/DevHive.Data.Tests/DevHive.Data.Tests.csproj index c414811..509ceef 100644 --- a/src/DevHive.Tests/DevHive.Data.Tests/DevHive.Data.Tests.csproj +++ b/src/DevHive.Tests/DevHive.Data.Tests/DevHive.Data.Tests.csproj @@ -17,4 +17,8 @@ + + true + latest + diff --git a/src/DevHive.Tests/DevHive.Services.Tests/DevHive.Services.Tests.csproj b/src/DevHive.Tests/DevHive.Services.Tests/DevHive.Services.Tests.csproj index fb94b61..c96dfb8 100644 --- a/src/DevHive.Tests/DevHive.Services.Tests/DevHive.Services.Tests.csproj +++ b/src/DevHive.Tests/DevHive.Services.Tests/DevHive.Services.Tests.csproj @@ -18,4 +18,8 @@ + + true + latest + diff --git a/src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj b/src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj index bdcca5d..e527713 100644 --- a/src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj +++ b/src/DevHive.Tests/DevHive.Web.Tests/DevHive.Web.Tests.csproj @@ -16,4 +16,8 @@ + + true + latest + diff --git a/src/DevHive.Web/DevHive.Web.csproj b/src/DevHive.Web/DevHive.Web.csproj index 515d2f5..84cd92f 100644 --- a/src/DevHive.Web/DevHive.Web.csproj +++ b/src/DevHive.Web/DevHive.Web.csproj @@ -21,4 +21,9 @@ + + + true + latest + \ No newline at end of file -- cgit v1.2.3 From 5514f1109cb3689fa81b29bb2d7dcf84cc05f65f Mon Sep 17 00:00:00 2001 From: transtrike Date: Fri, 15 Jan 2021 16:45:30 +0200 Subject: Extracted Interfaces from every DevHive.Data class; Tidied up the DevHive.Interfaces --- src/DevHive.Data/Interfaces/ILanguageRepository.cs | 14 -------- src/DevHive.Data/Interfaces/IPostRepository.cs | 20 ------------ src/DevHive.Data/Interfaces/IRepository.cs | 21 ------------ src/DevHive.Data/Interfaces/IRoleRepository.cs | 15 --------- .../Interfaces/ITechnologyRepository.cs | 14 -------- src/DevHive.Data/Interfaces/IUserRepository.cs | 38 ---------------------- src/DevHive.Data/Interfaces/Models/IComment.cs | 11 +++++++ src/DevHive.Data/Interfaces/Models/ILanguage.cs | 7 ++++ src/DevHive.Data/Interfaces/Models/IModel.cs | 9 +++++ src/DevHive.Data/Interfaces/Models/IPost.cs | 13 ++++++++ src/DevHive.Data/Interfaces/Models/IRole.cs | 10 ++++++ src/DevHive.Data/Interfaces/Models/ITechnology.cs | 7 ++++ src/DevHive.Data/Interfaces/Models/IUser.cs | 16 +++++++++ .../Interfaces/Repositories/ILanguageRepository.cs | 14 ++++++++ .../Interfaces/Repositories/IPostRepository.cs | 20 ++++++++++++ .../Interfaces/Repositories/IRepository.cs | 21 ++++++++++++ .../Interfaces/Repositories/IRoleRepository.cs | 15 +++++++++ .../Repositories/ITechnologyRepository.cs | 14 ++++++++ .../Interfaces/Repositories/IUserRepository.cs | 38 ++++++++++++++++++++++ src/DevHive.Data/Models/Comment.cs | 6 ++-- src/DevHive.Data/Models/IModel.cs | 9 ----- src/DevHive.Data/Models/Language.cs | 4 ++- src/DevHive.Data/Models/Post.cs | 3 +- src/DevHive.Data/Models/Role.cs | 7 ++-- src/DevHive.Data/Models/Technology.cs | 3 +- src/DevHive.Data/Models/User.cs | 3 +- .../Repositories/LanguageRepository.cs | 2 +- src/DevHive.Data/Repositories/PostRepository.cs | 4 +-- src/DevHive.Data/Repositories/RoleRepository.cs | 2 +- .../Repositories/TechnologyRepository.cs | 2 +- src/DevHive.Data/Repositories/UserRepository.cs | 2 +- src/DevHive.Services/Services/LanguageService.cs | 2 +- src/DevHive.Services/Services/PostService.cs | 2 +- src/DevHive.Services/Services/RoleService.cs | 2 +- src/DevHive.Services/Services/TechnologyService.cs | 2 +- src/DevHive.Services/Services/UserService.cs | 2 +- .../DevHive.Data.Tests/DevHive.Data.Tests.csproj | 1 + .../DevHive.Data.Tests/UserRepositoryTests.cs | 17 +++++++++- .../TechnologyServices.Tests.cs | 2 +- .../Extensions/ConfigureDependencyInjection.cs | 2 +- src/DevHive.Web/DevHive.Web.csproj | 31 +++++++++--------- 41 files changed, 257 insertions(+), 170 deletions(-) delete mode 100644 src/DevHive.Data/Interfaces/ILanguageRepository.cs delete mode 100644 src/DevHive.Data/Interfaces/IPostRepository.cs delete mode 100644 src/DevHive.Data/Interfaces/IRepository.cs delete mode 100644 src/DevHive.Data/Interfaces/IRoleRepository.cs delete mode 100644 src/DevHive.Data/Interfaces/ITechnologyRepository.cs delete mode 100644 src/DevHive.Data/Interfaces/IUserRepository.cs create mode 100644 src/DevHive.Data/Interfaces/Models/IComment.cs create mode 100644 src/DevHive.Data/Interfaces/Models/ILanguage.cs create mode 100644 src/DevHive.Data/Interfaces/Models/IModel.cs create mode 100644 src/DevHive.Data/Interfaces/Models/IPost.cs create mode 100644 src/DevHive.Data/Interfaces/Models/IRole.cs create mode 100644 src/DevHive.Data/Interfaces/Models/ITechnology.cs create mode 100644 src/DevHive.Data/Interfaces/Models/IUser.cs create mode 100644 src/DevHive.Data/Interfaces/Repositories/ILanguageRepository.cs create mode 100644 src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs create mode 100644 src/DevHive.Data/Interfaces/Repositories/IRepository.cs create mode 100644 src/DevHive.Data/Interfaces/Repositories/IRoleRepository.cs create mode 100644 src/DevHive.Data/Interfaces/Repositories/ITechnologyRepository.cs create mode 100644 src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs delete mode 100644 src/DevHive.Data/Models/IModel.cs (limited to 'src/DevHive.Web/DevHive.Web.csproj') diff --git a/src/DevHive.Data/Interfaces/ILanguageRepository.cs b/src/DevHive.Data/Interfaces/ILanguageRepository.cs deleted file mode 100644 index 0612116..0000000 --- a/src/DevHive.Data/Interfaces/ILanguageRepository.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Threading.Tasks; -using DevHive.Data.Models; -using DevHive.Data.Repositories.Interfaces; - -namespace DevHive.Data.Interfaces -{ - public interface ILanguageRepository : IRepository - { - Task DoesLanguageExistAsync(Guid id); - Task DoesLanguageNameExistAsync(string languageName); - Task GetByNameAsync(string name); - } -} diff --git a/src/DevHive.Data/Interfaces/IPostRepository.cs b/src/DevHive.Data/Interfaces/IPostRepository.cs deleted file mode 100644 index a02fd08..0000000 --- a/src/DevHive.Data/Interfaces/IPostRepository.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Threading.Tasks; -using DevHive.Data.Models; -using DevHive.Data.Repositories.Interfaces; - -namespace DevHive.Data.Interfaces -{ - public interface IPostRepository : IRepository - { - Task AddCommentAsync(Comment entity); - - Task GetCommentByIdAsync(Guid id); - - Task EditCommentAsync(Comment newEntity); - - Task DeleteCommentAsync(Comment entity); - Task DoesCommentExist(Guid id); - Task DoesPostExist(Guid postId); - } -} diff --git a/src/DevHive.Data/Interfaces/IRepository.cs b/src/DevHive.Data/Interfaces/IRepository.cs deleted file mode 100644 index 40a78de..0000000 --- a/src/DevHive.Data/Interfaces/IRepository.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Threading.Tasks; - -namespace DevHive.Data.Repositories.Interfaces -{ - public interface IRepository - where TEntity : class - { - //Add Entity to database - Task AddAsync(TEntity entity); - - //Find entity by id - Task GetByIdAsync(Guid id); - - //Modify Entity from database - Task EditAsync(TEntity newEntity); - - //Delete Entity from database - Task DeleteAsync(TEntity entity); - } -} \ No newline at end of file diff --git a/src/DevHive.Data/Interfaces/IRoleRepository.cs b/src/DevHive.Data/Interfaces/IRoleRepository.cs deleted file mode 100644 index a1080bb..0000000 --- a/src/DevHive.Data/Interfaces/IRoleRepository.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Threading.Tasks; -using DevHive.Data.Models; -using DevHive.Data.Repositories.Interfaces; - -namespace DevHive.Data.Interfaces -{ - public interface IRoleRepository : IRepository - { - Task GetByNameAsync(string name); - - Task DoesNameExist(string name); - Task DoesRoleExist(Guid id); - } -} diff --git a/src/DevHive.Data/Interfaces/ITechnologyRepository.cs b/src/DevHive.Data/Interfaces/ITechnologyRepository.cs deleted file mode 100644 index d0de096..0000000 --- a/src/DevHive.Data/Interfaces/ITechnologyRepository.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Threading.Tasks; -using DevHive.Data.Models; -using DevHive.Data.Repositories.Interfaces; - -namespace DevHive.Data.Interfaces -{ - public interface ITechnologyRepository : IRepository - { - Task DoesTechnologyExistAsync(Guid id); - Task DoesTechnologyNameExistAsync(string technologyName); - Task GetByNameAsync(string name); - } -} diff --git a/src/DevHive.Data/Interfaces/IUserRepository.cs b/src/DevHive.Data/Interfaces/IUserRepository.cs deleted file mode 100644 index a4a6fdd..0000000 --- a/src/DevHive.Data/Interfaces/IUserRepository.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using DevHive.Data.Models; -using DevHive.Data.Repositories.Interfaces; - -namespace DevHive.Data.Interfaces -{ - public interface IUserRepository : IRepository - { - Task AddFriendAsync(User user, User friend); - Task AddLanguageToUserAsync(User user, Language language); - Task AddTechnologyToUserAsync(User user, Technology technology); - - Task GetByUsernameAsync(string username); - Language GetUserLanguage(User user, Language language); - IList GetUserLanguages(User user); - IList GetUserTechnologies(User user); - Technology GetUserTechnology(User user, Technology technology); - IEnumerable QueryAll(); - - Task EditUserLanguageAsync(User user, Language oldLang, Language newLang); - Task EditUserTechnologyAsync(User user, Technology oldTech, Technology newTech); - - Task RemoveFriendAsync(User user, User friend); - Task RemoveLanguageFromUserAsync(User user, Language language); - Task RemoveTechnologyFromUserAsync(User user, Technology technology); - - Task DoesEmailExistAsync(string email); - Task DoesUserExistAsync(Guid id); - Task DoesUserHaveThisFriendAsync(Guid userId, Guid friendId); - Task DoesUsernameExistAsync(string username); - bool DoesUserHaveThisLanguage(User user, Language language); - bool DoesUserHaveThisUsername(Guid id, string username); - bool DoesUserHaveFriends(User user); - bool DoesUserHaveThisTechnology(User user, Technology technology); - } -} diff --git a/src/DevHive.Data/Interfaces/Models/IComment.cs b/src/DevHive.Data/Interfaces/Models/IComment.cs new file mode 100644 index 0000000..f6afb3f --- /dev/null +++ b/src/DevHive.Data/Interfaces/Models/IComment.cs @@ -0,0 +1,11 @@ +using System; + +namespace DevHive.Data.Interfaces.Models +{ + public interface IComment : IModel + { + Guid IssuerId { get; set; } + string Message { get; set; } + DateTime TimeCreated { get; set; } + } +} diff --git a/src/DevHive.Data/Interfaces/Models/ILanguage.cs b/src/DevHive.Data/Interfaces/Models/ILanguage.cs new file mode 100644 index 0000000..f757a3f --- /dev/null +++ b/src/DevHive.Data/Interfaces/Models/ILanguage.cs @@ -0,0 +1,7 @@ +namespace DevHive.Data.Interfaces.Models +{ + public interface ILanguage : IModel + { + string Name { get; set; } + } +} diff --git a/src/DevHive.Data/Interfaces/Models/IModel.cs b/src/DevHive.Data/Interfaces/Models/IModel.cs new file mode 100644 index 0000000..f903af3 --- /dev/null +++ b/src/DevHive.Data/Interfaces/Models/IModel.cs @@ -0,0 +1,9 @@ +using System; + +namespace DevHive.Data.Interfaces.Models +{ + public interface IModel + { + Guid Id { get; set; } + } +} diff --git a/src/DevHive.Data/Interfaces/Models/IPost.cs b/src/DevHive.Data/Interfaces/Models/IPost.cs new file mode 100644 index 0000000..117d859 --- /dev/null +++ b/src/DevHive.Data/Interfaces/Models/IPost.cs @@ -0,0 +1,13 @@ +using System; +using DevHive.Data.Models; + +namespace DevHive.Data.Interfaces.Models +{ + public interface IPost : IModel + { + Guid IssuerId { get; set; } + DateTime TimeCreated { get; set; } + string Message { get; set; } + Comment[] Comments { get; set; } + } +} diff --git a/src/DevHive.Data/Interfaces/Models/IRole.cs b/src/DevHive.Data/Interfaces/Models/IRole.cs new file mode 100644 index 0000000..0623f07 --- /dev/null +++ b/src/DevHive.Data/Interfaces/Models/IRole.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; +using DevHive.Data.Models; + +namespace DevHive.Data.Interfaces.Models +{ + public interface IRole + { + List Users { get; set; } + } +} diff --git a/src/DevHive.Data/Interfaces/Models/ITechnology.cs b/src/DevHive.Data/Interfaces/Models/ITechnology.cs new file mode 100644 index 0000000..9bd97f9 --- /dev/null +++ b/src/DevHive.Data/Interfaces/Models/ITechnology.cs @@ -0,0 +1,7 @@ +namespace DevHive.Data.Interfaces.Models +{ + public interface ITechnology : IModel + { + string Name { get; set; } + } +} diff --git a/src/DevHive.Data/Interfaces/Models/IUser.cs b/src/DevHive.Data/Interfaces/Models/IUser.cs new file mode 100644 index 0000000..0a770f0 --- /dev/null +++ b/src/DevHive.Data/Interfaces/Models/IUser.cs @@ -0,0 +1,16 @@ +using System.Collections.Generic; +using DevHive.Data.Models; + +namespace DevHive.Data.Interfaces.Models +{ + public interface IUser : IModel + { + string FirstName { get; set; } + string LastName { get; set; } + string ProfilePictureUrl { get; set; } + IList Langauges { get; set; } + IList Technologies { get; set; } + IList Roles { get; set; } + IList Friends { get; set; } + } +} diff --git a/src/DevHive.Data/Interfaces/Repositories/ILanguageRepository.cs b/src/DevHive.Data/Interfaces/Repositories/ILanguageRepository.cs new file mode 100644 index 0000000..f1d7248 --- /dev/null +++ b/src/DevHive.Data/Interfaces/Repositories/ILanguageRepository.cs @@ -0,0 +1,14 @@ +using System; +using System.Threading.Tasks; +using DevHive.Data.Models; +using DevHive.Data.Repositories.Interfaces; + +namespace DevHive.Data.Interfaces.Repositories +{ + public interface ILanguageRepository : IRepository + { + Task DoesLanguageExistAsync(Guid id); + Task DoesLanguageNameExistAsync(string languageName); + Task GetByNameAsync(string name); + } +} diff --git a/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs new file mode 100644 index 0000000..913d8c4 --- /dev/null +++ b/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs @@ -0,0 +1,20 @@ +using System; +using System.Threading.Tasks; +using DevHive.Data.Models; +using DevHive.Data.Repositories.Interfaces; + +namespace DevHive.Data.Interfaces.Repositories +{ + public interface IPostRepository : IRepository + { + Task AddCommentAsync(Comment entity); + + Task GetCommentByIdAsync(Guid id); + + Task EditCommentAsync(Comment newEntity); + + Task DeleteCommentAsync(Comment entity); + Task DoesCommentExist(Guid id); + Task DoesPostExist(Guid postId); + } +} diff --git a/src/DevHive.Data/Interfaces/Repositories/IRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IRepository.cs new file mode 100644 index 0000000..40a78de --- /dev/null +++ b/src/DevHive.Data/Interfaces/Repositories/IRepository.cs @@ -0,0 +1,21 @@ +using System; +using System.Threading.Tasks; + +namespace DevHive.Data.Repositories.Interfaces +{ + public interface IRepository + where TEntity : class + { + //Add Entity to database + Task AddAsync(TEntity entity); + + //Find entity by id + Task GetByIdAsync(Guid id); + + //Modify Entity from database + Task EditAsync(TEntity newEntity); + + //Delete Entity from database + Task DeleteAsync(TEntity entity); + } +} \ No newline at end of file diff --git a/src/DevHive.Data/Interfaces/Repositories/IRoleRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IRoleRepository.cs new file mode 100644 index 0000000..e834369 --- /dev/null +++ b/src/DevHive.Data/Interfaces/Repositories/IRoleRepository.cs @@ -0,0 +1,15 @@ +using System; +using System.Threading.Tasks; +using DevHive.Data.Models; +using DevHive.Data.Repositories.Interfaces; + +namespace DevHive.Data.Interfaces.Repositories +{ + public interface IRoleRepository : IRepository + { + Task GetByNameAsync(string name); + + Task DoesNameExist(string name); + Task DoesRoleExist(Guid id); + } +} diff --git a/src/DevHive.Data/Interfaces/Repositories/ITechnologyRepository.cs b/src/DevHive.Data/Interfaces/Repositories/ITechnologyRepository.cs new file mode 100644 index 0000000..fb0ba20 --- /dev/null +++ b/src/DevHive.Data/Interfaces/Repositories/ITechnologyRepository.cs @@ -0,0 +1,14 @@ +using System; +using System.Threading.Tasks; +using DevHive.Data.Models; +using DevHive.Data.Repositories.Interfaces; + +namespace DevHive.Data.Interfaces.Repositories +{ + public interface ITechnologyRepository : IRepository + { + Task DoesTechnologyExistAsync(Guid id); + Task DoesTechnologyNameExistAsync(string technologyName); + Task GetByNameAsync(string name); + } +} diff --git a/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs new file mode 100644 index 0000000..3a22911 --- /dev/null +++ b/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using DevHive.Data.Models; +using DevHive.Data.Repositories.Interfaces; + +namespace DevHive.Data.Interfaces.Repositories +{ + public interface IUserRepository : IRepository + { + Task AddFriendAsync(User user, User friend); + Task AddLanguageToUserAsync(User user, Language language); + Task AddTechnologyToUserAsync(User user, Technology technology); + + Task GetByUsernameAsync(string username); + Language GetUserLanguage(User user, Language language); + IList GetUserLanguages(User user); + IList GetUserTechnologies(User user); + Technology GetUserTechnology(User user, Technology technology); + IEnumerable QueryAll(); + + Task EditUserLanguageAsync(User user, Language oldLang, Language newLang); + Task EditUserTechnologyAsync(User user, Technology oldTech, Technology newTech); + + Task RemoveFriendAsync(User user, User friend); + Task RemoveLanguageFromUserAsync(User user, Language language); + Task RemoveTechnologyFromUserAsync(User user, Technology technology); + + Task DoesEmailExistAsync(string email); + Task DoesUserExistAsync(Guid id); + Task DoesUserHaveThisFriendAsync(Guid userId, Guid friendId); + Task DoesUsernameExistAsync(string username); + bool DoesUserHaveThisLanguage(User user, Language language); + bool DoesUserHaveThisUsername(Guid id, string username); + bool DoesUserHaveFriends(User user); + bool DoesUserHaveThisTechnology(User user, Technology technology); + } +} diff --git a/src/DevHive.Data/Models/Comment.cs b/src/DevHive.Data/Models/Comment.cs index 8cf848f..a07bd59 100644 --- a/src/DevHive.Data/Models/Comment.cs +++ b/src/DevHive.Data/Models/Comment.cs @@ -1,11 +1,13 @@ using System; +using DevHive.Data.Interfaces.Models; + namespace DevHive.Data.Models { - public class Comment : IModel + public class Comment : IComment { public Guid Id { get; set; } public Guid IssuerId { get; set; } public string Message { get; set; } public DateTime TimeCreated { get; set; } } -} \ No newline at end of file +} diff --git a/src/DevHive.Data/Models/IModel.cs b/src/DevHive.Data/Models/IModel.cs deleted file mode 100644 index 64942ee..0000000 --- a/src/DevHive.Data/Models/IModel.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -namespace DevHive.Data.Models -{ - interface IModel - { - Guid Id { get; set; } - } -} \ No newline at end of file diff --git a/src/DevHive.Data/Models/Language.cs b/src/DevHive.Data/Models/Language.cs index 556d019..2983107 100644 --- a/src/DevHive.Data/Models/Language.cs +++ b/src/DevHive.Data/Models/Language.cs @@ -1,7 +1,9 @@ using System; +using DevHive.Data.Interfaces.Models; + namespace DevHive.Data.Models { - public class Language : IModel + public class Language : ILanguage { public Guid Id { get; set; } public string Name { get; set; } diff --git a/src/DevHive.Data/Models/Post.cs b/src/DevHive.Data/Models/Post.cs index a5abf12..54576b7 100644 --- a/src/DevHive.Data/Models/Post.cs +++ b/src/DevHive.Data/Models/Post.cs @@ -1,10 +1,11 @@ using System; using System.ComponentModel.DataAnnotations.Schema; +using DevHive.Data.Interfaces.Models; namespace DevHive.Data.Models { [Table("Posts")] - public class Post + public class Post : IPost { public Guid Id { get; set; } diff --git a/src/DevHive.Data/Models/Role.cs b/src/DevHive.Data/Models/Role.cs index 63e6c7c..e63f007 100644 --- a/src/DevHive.Data/Models/Role.cs +++ b/src/DevHive.Data/Models/Role.cs @@ -1,12 +1,13 @@ -using System; -using Microsoft.AspNetCore.Identity; using System.ComponentModel.DataAnnotations.Schema; using System.Collections.Generic; +using DevHive.Data.Interfaces.Models; +using Microsoft.AspNetCore.Identity; +using System; namespace DevHive.Data.Models { [Table("Roles")] - public class Role : IdentityRole + public class Role : IdentityRole, IRole { public const string DefaultRole = "User"; public const string AdminRole = "Admin"; diff --git a/src/DevHive.Data/Models/Technology.cs b/src/DevHive.Data/Models/Technology.cs index a462d20..36cec32 100644 --- a/src/DevHive.Data/Models/Technology.cs +++ b/src/DevHive.Data/Models/Technology.cs @@ -1,8 +1,9 @@ using System; +using DevHive.Data.Interfaces.Models; namespace DevHive.Data.Models { - public class Technology : IModel + public class Technology : ITechnology { public Guid Id { get; set; } public string Name { get; set; } diff --git a/src/DevHive.Data/Models/User.cs b/src/DevHive.Data/Models/User.cs index 7a213c7..944bf6a 100644 --- a/src/DevHive.Data/Models/User.cs +++ b/src/DevHive.Data/Models/User.cs @@ -1,12 +1,13 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; +using DevHive.Data.Interfaces.Models; using Microsoft.AspNetCore.Identity; namespace DevHive.Data.Models { [Table("Users")] - public class User : IdentityUser, IModel + public class User : IdentityUser, IUser { public string FirstName { get; set; } diff --git a/src/DevHive.Data/Repositories/LanguageRepository.cs b/src/DevHive.Data/Repositories/LanguageRepository.cs index b867a93..e644fc4 100644 --- a/src/DevHive.Data/Repositories/LanguageRepository.cs +++ b/src/DevHive.Data/Repositories/LanguageRepository.cs @@ -1,7 +1,7 @@ using System; using System.Threading.Tasks; using DevHive.Common.Models.Misc; -using DevHive.Data.Interfaces; +using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; using Microsoft.EntityFrameworkCore; diff --git a/src/DevHive.Data/Repositories/PostRepository.cs b/src/DevHive.Data/Repositories/PostRepository.cs index f5e9b7b..3be14e3 100644 --- a/src/DevHive.Data/Repositories/PostRepository.cs +++ b/src/DevHive.Data/Repositories/PostRepository.cs @@ -1,7 +1,7 @@ using System; using System.Threading.Tasks; using DevHive.Common.Models.Misc; -using DevHive.Data.Interfaces; +using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; using Microsoft.EntityFrameworkCore; @@ -107,4 +107,4 @@ namespace DevHive.Data.Repositories } #endregion } -} \ No newline at end of file +} diff --git a/src/DevHive.Data/Repositories/RoleRepository.cs b/src/DevHive.Data/Repositories/RoleRepository.cs index 4cd5b79..ca3fb8b 100644 --- a/src/DevHive.Data/Repositories/RoleRepository.cs +++ b/src/DevHive.Data/Repositories/RoleRepository.cs @@ -1,7 +1,7 @@ using System; using System.Threading.Tasks; using DevHive.Common.Models.Misc; -using DevHive.Data.Interfaces; +using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; using Microsoft.EntityFrameworkCore; diff --git a/src/DevHive.Data/Repositories/TechnologyRepository.cs b/src/DevHive.Data/Repositories/TechnologyRepository.cs index d81433c..1631972 100644 --- a/src/DevHive.Data/Repositories/TechnologyRepository.cs +++ b/src/DevHive.Data/Repositories/TechnologyRepository.cs @@ -1,7 +1,7 @@ using System; using System.Threading.Tasks; using DevHive.Common.Models.Misc; -using DevHive.Data.Interfaces; +using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; using Microsoft.EntityFrameworkCore; diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs index da08a5a..c06fef6 100644 --- a/src/DevHive.Data/Repositories/UserRepository.cs +++ b/src/DevHive.Data/Repositories/UserRepository.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using DevHive.Common.Models.Misc; -using DevHive.Data.Interfaces; +using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; using Microsoft.EntityFrameworkCore; diff --git a/src/DevHive.Services/Services/LanguageService.cs b/src/DevHive.Services/Services/LanguageService.cs index c34537f..be035c2 100644 --- a/src/DevHive.Services/Services/LanguageService.cs +++ b/src/DevHive.Services/Services/LanguageService.cs @@ -1,7 +1,7 @@ using System; using System.Threading.Tasks; using AutoMapper; -using DevHive.Data.Interfaces; +using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; using DevHive.Services.Interfaces; using DevHive.Services.Models.Language; diff --git a/src/DevHive.Services/Services/PostService.cs b/src/DevHive.Services/Services/PostService.cs index 24ca8f3..6e83ad4 100644 --- a/src/DevHive.Services/Services/PostService.cs +++ b/src/DevHive.Services/Services/PostService.cs @@ -8,7 +8,7 @@ using DevHive.Services.Models.Post.Post; using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using DevHive.Services.Interfaces; -using DevHive.Data.Interfaces; +using DevHive.Data.Interfaces.Repositories; namespace DevHive.Services.Services { diff --git a/src/DevHive.Services/Services/RoleService.cs b/src/DevHive.Services/Services/RoleService.cs index fd56c2c..c38ac74 100644 --- a/src/DevHive.Services/Services/RoleService.cs +++ b/src/DevHive.Services/Services/RoleService.cs @@ -2,7 +2,7 @@ using System; using System.Threading.Tasks; using AutoMapper; using DevHive.Common.Models.Identity; -using DevHive.Data.Interfaces; +using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; using DevHive.Services.Interfaces; diff --git a/src/DevHive.Services/Services/TechnologyService.cs b/src/DevHive.Services/Services/TechnologyService.cs index 7fd0b2f..d8b7262 100644 --- a/src/DevHive.Services/Services/TechnologyService.cs +++ b/src/DevHive.Services/Services/TechnologyService.cs @@ -1,7 +1,7 @@ using System; using System.Threading.Tasks; using AutoMapper; -using DevHive.Data.Interfaces; +using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; using DevHive.Services.Interfaces; using DevHive.Services.Models.Technology; diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs index 6619f60..ae657cc 100644 --- a/src/DevHive.Services/Services/UserService.cs +++ b/src/DevHive.Services/Services/UserService.cs @@ -15,7 +15,7 @@ using DevHive.Services.Models.Language; using DevHive.Services.Interfaces; using DevHive.Services.Models.Technology; using DevHive.Data.Repositories; -using DevHive.Data.Interfaces; +using DevHive.Data.Interfaces.Repositories; namespace DevHive.Services.Services { diff --git a/src/DevHive.Tests/DevHive.Data.Tests/DevHive.Data.Tests.csproj b/src/DevHive.Tests/DevHive.Data.Tests/DevHive.Data.Tests.csproj index 509ceef..81e7b2b 100644 --- a/src/DevHive.Tests/DevHive.Data.Tests/DevHive.Data.Tests.csproj +++ b/src/DevHive.Tests/DevHive.Data.Tests/DevHive.Data.Tests.csproj @@ -8,6 +8,7 @@ + diff --git a/src/DevHive.Tests/DevHive.Data.Tests/UserRepositoryTests.cs b/src/DevHive.Tests/DevHive.Data.Tests/UserRepositoryTests.cs index a88de7f..81f62db 100644 --- a/src/DevHive.Tests/DevHive.Data.Tests/UserRepositoryTests.cs +++ b/src/DevHive.Tests/DevHive.Data.Tests/UserRepositoryTests.cs @@ -1,5 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using DevHive.Data.Models; using DevHive.Data.Repositories; using Microsoft.EntityFrameworkCore; +using Moq; using NUnit.Framework; namespace DevHive.Data.Tests @@ -9,19 +14,29 @@ namespace DevHive.Data.Tests { private DevHiveContext _context; private UserRepository _userRepository; + private User _dummyUser; [SetUp] public void Setup() { + //Naming convention: MethodName_ExpectedBehavior_StateUnderTest var options = new DbContextOptionsBuilder() .UseInMemoryDatabase("DevHive_UserRepository_Database"); this._context = new DevHiveContext(options.Options); this._userRepository = new UserRepository(_context); + + this._dummyUser = new Mock().Object; + + foreach (var item in _dummyUser.Langauges) + System.Console.WriteLine(item); + + foreach (var item in _dummyUser.Technologies) + System.Console.WriteLine(item); } [Test] - public void Test() + public void AddAsync_ShouldAddUserToDatabase() { } diff --git a/src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs b/src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs index 1f0b01e..d028957 100644 --- a/src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs +++ b/src/DevHive.Tests/DevHive.Services.Tests/TechnologyServices.Tests.cs @@ -1,5 +1,5 @@ using AutoMapper; -using DevHive.Data.Interfaces; +using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; using DevHive.Services.Models.Technology; using DevHive.Services.Services; diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs index e1601e7..f93f801 100644 --- a/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs +++ b/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs @@ -1,4 +1,4 @@ -using DevHive.Data.Interfaces; +using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; using DevHive.Data.Repositories; using DevHive.Services.Interfaces; diff --git a/src/DevHive.Web/DevHive.Web.csproj b/src/DevHive.Web/DevHive.Web.csproj index 84cd92f..3bfa507 100644 --- a/src/DevHive.Web/DevHive.Web.csproj +++ b/src/DevHive.Web/DevHive.Web.csproj @@ -2,28 +2,27 @@ net5.0 + + true + latest + - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - - - - - - + + + + + + - - + + - - - true - latest - \ No newline at end of file -- cgit v1.2.3 From d67ee86eb3a0eae62163a0caebe07dfc02d53934 Mon Sep 17 00:00:00 2001 From: transtrike Date: Sat, 23 Jan 2021 15:29:50 +0200 Subject: Removal of unused package and configuration --- .../Extensions/ConfigureProblemDetails.cs | 19 ------------------- src/DevHive.Web/DevHive.Web.csproj | 3 +-- 2 files changed, 1 insertion(+), 21 deletions(-) delete mode 100644 src/DevHive.Web/Configurations/Extensions/ConfigureProblemDetails.cs (limited to 'src/DevHive.Web/DevHive.Web.csproj') diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureProblemDetails.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureProblemDetails.cs deleted file mode 100644 index f945f03..0000000 --- a/src/DevHive.Web/Configurations/Extensions/ConfigureProblemDetails.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Hellang.Middleware.ProblemDetails; -using Microsoft.AspNetCore.Builder; -using Microsoft.Extensions.DependencyInjection; - -namespace DevHive.Web.Configurations.Extensions -{ - public static class ConfigureProblemDetails - { - public static void ProblemDetailsConfiguration(this IServiceCollection services) - { - services.AddProblemDetails(); - } - - public static void UseProblemDetailsConfiguration(this IApplicationBuilder app) - { - app.UseProblemDetails(); - } - } -} \ No newline at end of file diff --git a/src/DevHive.Web/DevHive.Web.csproj b/src/DevHive.Web/DevHive.Web.csproj index 3bfa507..0aa2831 100644 --- a/src/DevHive.Web/DevHive.Web.csproj +++ b/src/DevHive.Web/DevHive.Web.csproj @@ -7,7 +7,6 @@ latest - @@ -25,4 +24,4 @@ - \ No newline at end of file + -- cgit v1.2.3