aboutsummaryrefslogtreecommitdiff
path: root/src/DevHive.Data
diff options
context:
space:
mode:
authortranstrike <transtrike@gmail.com>2021-01-12 13:16:39 +0200
committertranstrike <transtrike@gmail.com>2021-01-12 13:16:39 +0200
commit11bd1d9a9760c7bc6a601d78b3d89ec9028647a2 (patch)
tree4e74a8fc10a07f58e11d3612373b17a246ec2868 /src/DevHive.Data
parentb14dc0fe3e5ecfca3a7e780a17627f823d59246c (diff)
downloadDevHive-11bd1d9a9760c7bc6a601d78b3d89ec9028647a2.tar
DevHive-11bd1d9a9760c7bc6a601d78b3d89ec9028647a2.tar.gz
DevHive-11bd1d9a9760c7bc6a601d78b3d89ec9028647a2.zip
Language layers refactored; User implements adding & removing Languages; Migrations added
Diffstat (limited to 'src/DevHive.Data')
-rw-r--r--src/DevHive.Data/Migrations/20210112111416_User_Implements_Languages.Designer.cs405
-rw-r--r--src/DevHive.Data/Migrations/20210112111416_User_Implements_Languages.cs106
-rw-r--r--src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs38
-rw-r--r--src/DevHive.Data/Models/Technology.cs1
-rw-r--r--src/DevHive.Data/Models/User.cs12
-rw-r--r--src/DevHive.Data/Repositories/Contracts/ILanguageRepository.cs13
-rw-r--r--src/DevHive.Data/Repositories/Contracts/IPostRepository.cs21
-rw-r--r--src/DevHive.Data/Repositories/Contracts/IRoleRepository.cs15
-rw-r--r--src/DevHive.Data/Repositories/Contracts/ITechnologyRepository.cs13
-rw-r--r--src/DevHive.Data/Repositories/Contracts/IUserRepository.cs26
-rw-r--r--src/DevHive.Data/Repositories/IRepository.cs (renamed from src/DevHive.Data/Repositories/Contracts/IRepository.cs)2
-rw-r--r--src/DevHive.Data/Repositories/LanguageRepository.cs55
-rw-r--r--src/DevHive.Data/Repositories/PostRepository.cs6
-rw-r--r--src/DevHive.Data/Repositories/RoleRepository.cs3
-rw-r--r--src/DevHive.Data/Repositories/TechnologyRepository.cs5
-rw-r--r--src/DevHive.Data/Repositories/UserRepository.cs162
16 files changed, 722 insertions, 161 deletions
diff --git a/src/DevHive.Data/Migrations/20210112111416_User_Implements_Languages.Designer.cs b/src/DevHive.Data/Migrations/20210112111416_User_Implements_Languages.Designer.cs
new file mode 100644
index 0000000..0f1aa80
--- /dev/null
+++ b/src/DevHive.Data/Migrations/20210112111416_User_Implements_Languages.Designer.cs
@@ -0,0 +1,405 @@
+// <auto-generated />
+using System;
+using DevHive.Data;
+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("20210112111416_User_Implements_Languages")]
+ partial class User_Implements_Languages
+ {
+ 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.Comment", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<Guid>("IssuerId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("Message")
+ .HasColumnType("text");
+
+ b.Property<DateTime>("TimeCreated")
+ .HasColumnType("timestamp without time zone");
+
+ b.HasKey("Id");
+
+ b.ToTable("Comments");
+ });
+
+ modelBuilder.Entity("DevHive.Data.Models.Language", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<string>("Name")
+ .HasColumnType("text");
+
+ b.Property<Guid?>("UserId")
+ .HasColumnType("uuid");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("Languages");
+ });
+
+ modelBuilder.Entity("DevHive.Data.Models.Role", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<string>("ConcurrencyStamp")
+ .IsConcurrencyToken()
+ .HasColumnType("text");
+
+ b.Property<string>("Name")
+ .HasMaxLength(256)
+ .HasColumnType("character varying(256)");
+
+ b.Property<string>("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<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<string>("Name")
+ .HasColumnType("text");
+
+ b.Property<Guid?>("UserId")
+ .HasColumnType("uuid");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("Technologies");
+ });
+
+ modelBuilder.Entity("DevHive.Data.Models.User", b =>
+ {
+ b.Property<Guid>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("uuid");
+
+ b.Property<int>("AccessFailedCount")
+ .HasColumnType("integer");
+
+ b.Property<string>("ConcurrencyStamp")
+ .IsConcurrencyToken()
+ .HasColumnType("text");
+
+ b.Property<string>("Email")
+ .HasMaxLength(256)
+ .HasColumnType("character varying(256)");
+
+ b.Property<bool>("EmailConfirmed")
+ .HasColumnType("boolean");
+
+ b.Property<string>("FirstName")
+ .HasColumnType("text");
+
+ b.Property<string>("LastName")
+ .HasColumnType("text");
+
+ b.Property<bool>("LockoutEnabled")
+ .HasColumnType("boolean");
+
+ b.Property<DateTimeOffset?>("LockoutEnd")
+ .HasColumnType("timestamp with time zone");
+
+ b.Property<string>("NormalizedEmail")
+ .HasMaxLength(256)
+ .HasColumnType("character varying(256)");
+
+ b.Property<string>("NormalizedUserName")
+ .HasMaxLength(256)
+ .HasColumnType("character varying(256)");
+
+ b.Property<string>("PasswordHash")
+ .HasColumnType("text");
+
+ b.Property<string>("PhoneNumber")
+ .HasColumnType("text");
+
+ b.Property<bool>("PhoneNumberConfirmed")
+ .HasColumnType("boolean");
+
+ b.Property<string>("ProfilePictureUrl")
+ .HasColumnType("text");
+
+ b.Property<string>("SecurityStamp")
+ .HasColumnType("text");
+
+ b.Property<bool>("TwoFactorEnabled")
+ .HasColumnType("boolean");
+
+ b.Property<Guid?>("UserId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("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<System.Guid>", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer")
+ .UseIdentityByDefaultColumn();
+
+ b.Property<string>("ClaimType")
+ .HasColumnType("text");
+
+ b.Property<string>("ClaimValue")
+ .HasColumnType("text");
+
+ b.Property<Guid>("RoleId")
+ .HasColumnType("uuid");
+
+ b.HasKey("Id");
+
+ b.HasIndex("RoleId");
+
+ b.ToTable("AspNetRoleClaims");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<System.Guid>", b =>
+ {
+ b.Property<int>("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("integer")
+ .UseIdentityByDefaultColumn();
+
+ b.Property<string>("ClaimType")
+ .HasColumnType("text");
+
+ b.Property<string>("ClaimValue")
+ .HasColumnType("text");
+
+ b.Property<Guid>("UserId")
+ .HasColumnType("uuid");
+
+ b.HasKey("Id");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("AspNetUserClaims");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<System.Guid>", b =>
+ {
+ b.Property<string>("LoginProvider")
+ .HasColumnType("text");
+
+ b.Property<string>("ProviderKey")
+ .HasColumnType("text");
+
+ b.Property<string>("ProviderDisplayName")
+ .HasColumnType("text");
+
+ b.Property<Guid>("UserId")
+ .HasColumnType("uuid");
+
+ b.HasKey("LoginProvider", "ProviderKey");
+
+ b.HasIndex("UserId");
+
+ b.ToTable("AspNetUserLogins");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<System.Guid>", b =>
+ {
+ b.Property<Guid>("UserId")
+ .HasColumnType("uuid");
+
+ b.Property<Guid>("RoleId")
+ .HasColumnType("uuid");
+
+ b.HasKey("UserId", "RoleId");
+
+ b.HasIndex("RoleId");
+
+ b.ToTable("AspNetUserRoles");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<System.Guid>", b =>
+ {
+ b.Property<Guid>("UserId")
+ .HasColumnType("uuid");
+
+ b.Property<string>("LoginProvider")
+ .HasColumnType("text");
+
+ b.Property<string>("Name")
+ .HasColumnType("text");
+
+ b.Property<string>("Value")
+ .HasColumnType("text");
+
+ b.HasKey("UserId", "LoginProvider", "Name");
+
+ b.ToTable("AspNetUserTokens");
+ });
+
+ modelBuilder.Entity("RoleUser", b =>
+ {
+ b.Property<Guid>("RolesId")
+ .HasColumnType("uuid");
+
+ b.Property<Guid>("UsersId")
+ .HasColumnType("uuid");
+
+ b.HasKey("RolesId", "UsersId");
+
+ b.HasIndex("UsersId");
+
+ b.ToTable("RoleUser");
+ });
+
+ modelBuilder.Entity("DevHive.Data.Models.Language", b =>
+ {
+ b.HasOne("DevHive.Data.Models.User", null)
+ .WithMany("Langauges")
+ .HasForeignKey("UserId");
+ });
+
+ modelBuilder.Entity("DevHive.Data.Models.Technology", b =>
+ {
+ b.HasOne("DevHive.Data.Models.User", null)
+ .WithMany("Technologies")
+ .HasForeignKey("UserId");
+ });
+
+ modelBuilder.Entity("DevHive.Data.Models.User", b =>
+ {
+ b.HasOne("DevHive.Data.Models.User", null)
+ .WithMany("Friends")
+ .HasForeignKey("UserId");
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<System.Guid>", b =>
+ {
+ b.HasOne("DevHive.Data.Models.Role", null)
+ .WithMany()
+ .HasForeignKey("RoleId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<System.Guid>", b =>
+ {
+ b.HasOne("DevHive.Data.Models.User", null)
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<System.Guid>", b =>
+ {
+ b.HasOne("DevHive.Data.Models.User", null)
+ .WithMany()
+ .HasForeignKey("UserId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+ });
+
+ modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<System.Guid>", 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<System.Guid>", 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");
+
+ b.Navigation("Langauges");
+
+ b.Navigation("Technologies");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/src/DevHive.Data/Migrations/20210112111416_User_Implements_Languages.cs b/src/DevHive.Data/Migrations/20210112111416_User_Implements_Languages.cs
new file mode 100644
index 0000000..a51ad09
--- /dev/null
+++ b/src/DevHive.Data/Migrations/20210112111416_User_Implements_Languages.cs
@@ -0,0 +1,106 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+namespace DevHive.Data.Migrations
+{
+ public partial class User_Implements_Languages : Migration
+ {
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.RenameColumn(
+ name: "UserId",
+ table: "Comments",
+ newName: "IssuerId");
+
+ migrationBuilder.RenameColumn(
+ name: "Date",
+ table: "Comments",
+ newName: "TimeCreated");
+
+ migrationBuilder.RenameColumn(
+ name: "ProfilePicture",
+ table: "AspNetUsers",
+ newName: "ProfilePictureUrl");
+
+ migrationBuilder.AddColumn<Guid>(
+ name: "UserId",
+ table: "Technologies",
+ type: "uuid",
+ nullable: true);
+
+ migrationBuilder.AddColumn<Guid>(
+ name: "UserId",
+ table: "Languages",
+ type: "uuid",
+ nullable: true);
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Technologies_UserId",
+ table: "Technologies",
+ column: "UserId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Languages_UserId",
+ table: "Languages",
+ column: "UserId");
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_Languages_AspNetUsers_UserId",
+ table: "Languages",
+ column: "UserId",
+ principalTable: "AspNetUsers",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Restrict);
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_Technologies_AspNetUsers_UserId",
+ table: "Technologies",
+ column: "UserId",
+ principalTable: "AspNetUsers",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Restrict);
+ }
+
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropForeignKey(
+ name: "FK_Languages_AspNetUsers_UserId",
+ table: "Languages");
+
+ migrationBuilder.DropForeignKey(
+ name: "FK_Technologies_AspNetUsers_UserId",
+ table: "Technologies");
+
+ migrationBuilder.DropIndex(
+ name: "IX_Technologies_UserId",
+ table: "Technologies");
+
+ migrationBuilder.DropIndex(
+ name: "IX_Languages_UserId",
+ table: "Languages");
+
+ migrationBuilder.DropColumn(
+ name: "UserId",
+ table: "Technologies");
+
+ migrationBuilder.DropColumn(
+ name: "UserId",
+ table: "Languages");
+
+ migrationBuilder.RenameColumn(
+ name: "TimeCreated",
+ table: "Comments",
+ newName: "Date");
+
+ migrationBuilder.RenameColumn(
+ name: "IssuerId",
+ table: "Comments",
+ newName: "UserId");
+
+ migrationBuilder.RenameColumn(
+ name: "ProfilePictureUrl",
+ table: "AspNetUsers",
+ newName: "ProfilePicture");
+ }
+ }
+}
diff --git a/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs b/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs
index c7ff6c6..cc6d24d 100644
--- a/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs
+++ b/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs
@@ -25,14 +25,14 @@ namespace DevHive.Data.Migrations
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
- b.Property<DateTime>("Date")
- .HasColumnType("timestamp without time zone");
+ b.Property<Guid>("IssuerId")
+ .HasColumnType("uuid");
b.Property<string>("Message")
.HasColumnType("text");
- b.Property<Guid>("UserId")
- .HasColumnType("uuid");
+ b.Property<DateTime>("TimeCreated")
+ .HasColumnType("timestamp without time zone");
b.HasKey("Id");
@@ -48,8 +48,13 @@ namespace DevHive.Data.Migrations
b.Property<string>("Name")
.HasColumnType("text");
+ b.Property<Guid?>("UserId")
+ .HasColumnType("uuid");
+
b.HasKey("Id");
+ b.HasIndex("UserId");
+
b.ToTable("Languages");
});
@@ -89,8 +94,13 @@ namespace DevHive.Data.Migrations
b.Property<string>("Name")
.HasColumnType("text");
+ b.Property<Guid?>("UserId")
+ .HasColumnType("uuid");
+
b.HasKey("Id");
+ b.HasIndex("UserId");
+
b.ToTable("Technologies");
});
@@ -143,7 +153,7 @@ namespace DevHive.Data.Migrations
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean");
- b.Property<string>("ProfilePicture")
+ b.Property<string>("ProfilePictureUrl")
.HasColumnType("text");
b.Property<string>("SecurityStamp")
@@ -292,6 +302,20 @@ namespace DevHive.Data.Migrations
b.ToTable("RoleUser");
});
+ modelBuilder.Entity("DevHive.Data.Models.Language", b =>
+ {
+ b.HasOne("DevHive.Data.Models.User", null)
+ .WithMany("Langauges")
+ .HasForeignKey("UserId");
+ });
+
+ modelBuilder.Entity("DevHive.Data.Models.Technology", b =>
+ {
+ b.HasOne("DevHive.Data.Models.User", null)
+ .WithMany("Technologies")
+ .HasForeignKey("UserId");
+ });
+
modelBuilder.Entity("DevHive.Data.Models.User", b =>
{
b.HasOne("DevHive.Data.Models.User", null)
@@ -368,6 +392,10 @@ namespace DevHive.Data.Migrations
modelBuilder.Entity("DevHive.Data.Models.User", b =>
{
b.Navigation("Friends");
+
+ b.Navigation("Langauges");
+
+ b.Navigation("Technologies");
});
#pragma warning restore 612, 618
}
diff --git a/src/DevHive.Data/Models/Technology.cs b/src/DevHive.Data/Models/Technology.cs
index 2e0aeed..a462d20 100644
--- a/src/DevHive.Data/Models/Technology.cs
+++ b/src/DevHive.Data/Models/Technology.cs
@@ -5,7 +5,6 @@ namespace DevHive.Data.Models
public class Technology : IModel
{
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 eef0af2..fda4651 100644
--- a/src/DevHive.Data/Models/User.cs
+++ b/src/DevHive.Data/Models/User.cs
@@ -12,7 +12,17 @@ namespace DevHive.Data.Models
public string LastName { get; set; }
- public string ProfilePicture { get; set; }
+ public string ProfilePictureUrl { get; set; }
+
+ /// <summary>
+ /// Languages that the user uses or is familiar with
+ /// </summary>
+ public IList<Language> Langauges { get; set; }
+
+ /// <summary>
+ /// Technologies that the user uses or is familiar with
+ /// </summary>
+ public IList<Technology> Technologies { get; set; }
public virtual IList<Role> Roles { get; set; } = new List<Role>();
diff --git a/src/DevHive.Data/Repositories/Contracts/ILanguageRepository.cs b/src/DevHive.Data/Repositories/Contracts/ILanguageRepository.cs
deleted file mode 100644
index e44d27b..0000000
--- a/src/DevHive.Data/Repositories/Contracts/ILanguageRepository.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-using DevHive.Data.Models;
-using System;
-using System.Threading.Tasks;
-
-namespace DevHive.Data.Repositories.Contracts
-{
- public interface ILanguageRepository : IRepository<Language>
- {
- public Task<bool> DoesLanguageNameExist(string languageName);
-
- public Task<bool> DoesLanguageExist(Guid id);
- }
-}
diff --git a/src/DevHive.Data/Repositories/Contracts/IPostRepository.cs b/src/DevHive.Data/Repositories/Contracts/IPostRepository.cs
deleted file mode 100644
index 930138a..0000000
--- a/src/DevHive.Data/Repositories/Contracts/IPostRepository.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-using DevHive.Data.Models;
-using System;
-using System.Threading.Tasks;
-
-namespace DevHive.Data.Repositories.Contracts
-{
- public interface IPostRepository : IRepository<Post>
- {
- public Task<bool> AddCommentAsync(Comment entity);
-
- public Task<Comment> GetCommentByIdAsync(Guid id);
-
- public Task<bool> EditCommentAsync(Comment newEntity);
-
- public Task<bool> DeleteCommentAsync(Comment entity);
-
- public Task<bool> DoesPostExist(Guid postId);
-
- public Task<bool> DoesCommentExist(Guid id);
- }
-}
diff --git a/src/DevHive.Data/Repositories/Contracts/IRoleRepository.cs b/src/DevHive.Data/Repositories/Contracts/IRoleRepository.cs
deleted file mode 100644
index 6cb8a4e..0000000
--- a/src/DevHive.Data/Repositories/Contracts/IRoleRepository.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using DevHive.Data.Models;
-using System;
-using System.Threading.Tasks;
-
-namespace DevHive.Data.Repositories.Contracts
-{
- public interface IRoleRepository : IRepository<Role>
- {
- public Task<Role> GetByNameAsync(string name);
-
- public Task<bool> DoesNameExist(string name);
-
- public Task<bool> DoesRoleExist(Guid id);
- }
-}
diff --git a/src/DevHive.Data/Repositories/Contracts/ITechnologyRepository.cs b/src/DevHive.Data/Repositories/Contracts/ITechnologyRepository.cs
deleted file mode 100644
index 3c4a6b6..0000000
--- a/src/DevHive.Data/Repositories/Contracts/ITechnologyRepository.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-using DevHive.Data.Models;
-using System;
-using System.Threading.Tasks;
-
-namespace DevHive.Data.Repositories.Contracts
-{
- public interface ITechnologyRepository : IRepository<Technology>
- {
- public Task<bool> DoesTechnologyNameExist(string technologyName);
-
- public Task<bool> DoesTechnologyExist(Guid id);
- }
-}
diff --git a/src/DevHive.Data/Repositories/Contracts/IUserRepository.cs b/src/DevHive.Data/Repositories/Contracts/IUserRepository.cs
deleted file mode 100644
index 74c4486..0000000
--- a/src/DevHive.Data/Repositories/Contracts/IUserRepository.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-using DevHive.Data.Models;
-using System;
-using System.Collections.Generic;
-using System.Threading.Tasks;
-
-namespace DevHive.Data.Repositories.Contracts
-{
- public interface IUserRepository : IRepository<User>
- {
- public Task<bool> AddFriendAsync(User user, User friend);
-
- public IEnumerable<User> QueryAll();
-
- public Task<User> GetByUsername(string username);
-
- public Task<bool> RemoveFriendAsync(User user, User friend);
-
- public bool DoesUserExist(Guid id);
-
- public bool DoesUserHaveThisUsername(Guid id, string username);
-
- public Task<bool> DoesUsernameExist(string username);
-
- public Task<bool> DoesEmailExist(string email);
- }
-}
diff --git a/src/DevHive.Data/Repositories/Contracts/IRepository.cs b/src/DevHive.Data/Repositories/IRepository.cs
index 37c5170..920ba13 100644
--- a/src/DevHive.Data/Repositories/Contracts/IRepository.cs
+++ b/src/DevHive.Data/Repositories/IRepository.cs
@@ -1,7 +1,7 @@
using System;
using System.Threading.Tasks;
-namespace DevHive.Data.Repositories.Contracts
+namespace DevHive.Data.Repositories
{
public interface IRepository<TEntity>
where TEntity : class
diff --git a/src/DevHive.Data/Repositories/LanguageRepository.cs b/src/DevHive.Data/Repositories/LanguageRepository.cs
index 243192a..5d8217a 100644
--- a/src/DevHive.Data/Repositories/LanguageRepository.cs
+++ b/src/DevHive.Data/Repositories/LanguageRepository.cs
@@ -1,13 +1,13 @@
using System;
+using System.Linq;
using System.Threading.Tasks;
using DevHive.Common.Models.Misc;
using DevHive.Data.Models;
-using DevHive.Data.Repositories.Contracts;
using Microsoft.EntityFrameworkCore;
namespace DevHive.Data.Repositories
{
- public class LanguageRepository : ILanguageRepository
+ public class LanguageRepository : IRepository<Language>
{
private readonly DevHiveContext _context;
@@ -16,7 +16,8 @@ namespace DevHive.Data.Repositories
this._context = context;
}
- //Create
+ #region Create
+
public async Task<bool> AddAsync(Language entity)
{
await this._context
@@ -25,42 +26,32 @@ namespace DevHive.Data.Repositories
return await RepositoryMethods.SaveChangesAsync(this._context);
}
+ #endregion
+
+ #region Read
- //Read
public async Task<Language> GetByIdAsync(Guid id)
{
return await this._context
.Set<Language>()
.FindAsync(id);
}
+ #endregion
- public async Task<bool> DoesLanguageNameExist(string languageName)
- {
- return await this._context
- .Set<Language>()
- .AsNoTracking()
- .AnyAsync(r => r.Name == languageName);
- }
-
- public async Task<bool> DoesLanguageExist(Guid id)
- {
- return await this._context
- .Set<Language>()
- .AsNoTracking()
- .AnyAsync(r => r.Id == id);
- }
+ #region Update
- //Update
public async Task<bool> EditAsync(Language newEntity)
{
- this._context
- .Set<Language>()
- .Update(newEntity);
+ this._context
+ .Set<Language>()
+ .Update(newEntity);
return await RepositoryMethods.SaveChangesAsync(this._context);
}
+ #endregion
+
+ #region Delete
- //Delete
public async Task<bool> DeleteAsync(Language entity)
{
this._context
@@ -69,5 +60,21 @@ namespace DevHive.Data.Repositories
return await RepositoryMethods.SaveChangesAsync(this._context);
}
+ #endregion
+
+ #region Validations
+
+ public async Task<bool> DoesLanguageNameExistAsync(string languageName)
+ {
+ return await this._context.Languages
+ .AnyAsync(r => r.Name == languageName);
+ }
+
+ public async Task<bool> DoesLanguageExistAsync(Guid id)
+ {
+ return await this._context.Languages
+ .AnyAsync(r => r.Id == id);
+ }
+ #endregion
}
} \ No newline at end of file
diff --git a/src/DevHive.Data/Repositories/PostRepository.cs b/src/DevHive.Data/Repositories/PostRepository.cs
index 0acfc23..002fb17 100644
--- a/src/DevHive.Data/Repositories/PostRepository.cs
+++ b/src/DevHive.Data/Repositories/PostRepository.cs
@@ -2,12 +2,11 @@ using System;
using System.Threading.Tasks;
using DevHive.Common.Models.Misc;
using DevHive.Data.Models;
-using DevHive.Data.Repositories.Contracts;
using Microsoft.EntityFrameworkCore;
namespace DevHive.Data.Repositories
{
- public class PostRepository : IPostRepository
+ public class PostRepository : IRepository<Post>
{
private readonly DevHiveContext _context;
@@ -88,6 +87,8 @@ namespace DevHive.Data.Repositories
return await RepositoryMethods.SaveChangesAsync(this._context);
}
+ #region Validations
+
public async Task<bool> DoesPostExist(Guid postId)
{
return await this._context
@@ -103,5 +104,6 @@ namespace DevHive.Data.Repositories
.AsNoTracking()
.AnyAsync(r => r.Id == id);
}
+ #endregion
}
} \ No newline at end of file
diff --git a/src/DevHive.Data/Repositories/RoleRepository.cs b/src/DevHive.Data/Repositories/RoleRepository.cs
index d6f83a8..0ca1646 100644
--- a/src/DevHive.Data/Repositories/RoleRepository.cs
+++ b/src/DevHive.Data/Repositories/RoleRepository.cs
@@ -2,12 +2,11 @@ using System;
using System.Threading.Tasks;
using DevHive.Common.Models.Misc;
using DevHive.Data.Models;
-using DevHive.Data.Repositories.Contracts;
using Microsoft.EntityFrameworkCore;
namespace DevHive.Data.Repositories
{
- public class RoleRepository : IRoleRepository
+ public class RoleRepository : IRepository<Role>
{
private readonly DevHiveContext _context;
diff --git a/src/DevHive.Data/Repositories/TechnologyRepository.cs b/src/DevHive.Data/Repositories/TechnologyRepository.cs
index 27918ca..2ed3a23 100644
--- a/src/DevHive.Data/Repositories/TechnologyRepository.cs
+++ b/src/DevHive.Data/Repositories/TechnologyRepository.cs
@@ -2,13 +2,12 @@ using System;
using System.Threading.Tasks;
using DevHive.Common.Models.Misc;
using DevHive.Data.Models;
-using DevHive.Data.Repositories.Contracts;
using Microsoft.EntityFrameworkCore;
namespace DevHive.Data.Repositories
{
- public abstract class TechnologyRepository : ITechnologyRepository
+ public abstract class TechnologyRepository : IRepository<Technology>
{
private DevHiveContext _context;
@@ -27,7 +26,7 @@ namespace DevHive.Data.Repositories
return await RepositoryMethods.SaveChangesAsync(this._context);
}
- //Read
+ //Read
public async Task<Technology> GetByIdAsync(Guid id)
{
return await this._context
diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs
index 5142b82..e3c1304 100644
--- a/src/DevHive.Data/Repositories/UserRepository.cs
+++ b/src/DevHive.Data/Repositories/UserRepository.cs
@@ -4,12 +4,11 @@ using System.Linq;
using System.Threading.Tasks;
using DevHive.Common.Models.Misc;
using DevHive.Data.Models;
-using DevHive.Data.Repositories.Contracts;
using Microsoft.EntityFrameworkCore;
namespace DevHive.Data.Repositories
{
- public class UserRepository : IUserRepository
+ public class UserRepository : IRepository<User>
{
private readonly DevHiveContext _context;
@@ -18,11 +17,11 @@ namespace DevHive.Data.Repositories
this._context = context;
}
- //Create
+ #region Create
+
public async Task<bool> AddAsync(User entity)
{
- await this._context
- .Set<User>()
+ await this._context.Users
.AddAsync(entity);
return await RepositoryMethods.SaveChangesAsync(this._context);
@@ -35,12 +34,31 @@ namespace DevHive.Data.Repositories
return await RepositoryMethods.SaveChangesAsync(this._context);
}
-
- //Read
+
+ public async Task<bool> AddLanguageToUserAsync(User user, Language language)
+ {
+ this._context.Update(user);
+
+ user.Langauges.Add(language);
+
+ return await RepositoryMethods.SaveChangesAsync(this._context);
+ }
+
+ public async Task<bool> AddTechnologyToUserAsync(User user, Technology technology)
+ {
+ this._context.Update(user);
+
+ user.Technologies.Add(technology);
+
+ return await RepositoryMethods.SaveChangesAsync(this._context);
+ }
+ #endregion
+
+ #region Read
+
public IEnumerable<User> QueryAll()
{
- return this._context
- .Set<User>()
+ return this._context.Users
.Include(x => x.Roles)
.AsNoTracking()
.AsEnumerable();
@@ -48,8 +66,7 @@ namespace DevHive.Data.Repositories
public async Task<User> GetByIdAsync(Guid id)
{
- return await this._context
- .Set<User>()
+ return await this._context.Users
.Include(x => x.Roles)
.Include(x => x.Friends)
.FirstOrDefaultAsync(x => x.Id == id);
@@ -57,13 +74,36 @@ namespace DevHive.Data.Repositories
public async Task<User> GetByUsername(string username)
{
- return await this._context
- .Set<User>()
+ return await this._context.Users
.Include(u => u.Roles)
.FirstOrDefaultAsync(x => x.UserName == username);
}
- //Update
+ public IList<Language> GetUserLanguages(User user)
+ {
+ return user.Langauges;
+ }
+
+ public Language GetUserLanguage(User user, Language language)
+ {
+ return user.Langauges
+ .FirstOrDefault(x => x.Id == language.Id);
+ }
+
+ public IList<Technology> GetUserTechnologies(User user)
+ {
+ return user.Technologies;
+ }
+
+ public Technology GetUserTechnology(User user, Technology technology)
+ {
+ return user.Technologies
+ .FirstOrDefault(x => x.Id == technology.Id);
+ }
+ #endregion
+
+ #region Update
+
public async Task<bool> EditAsync(User newEntity)
{
User user = await this.GetByIdAsync(newEntity.Id);
@@ -76,11 +116,32 @@ namespace DevHive.Data.Repositories
return await RepositoryMethods.SaveChangesAsync(this._context);
}
- //Delete
+ public async Task<bool> EditUserLanguage(User user, Language oldLang, Language newLang)
+ {
+ this._context.Update(user);
+
+ user.Langauges.Remove(oldLang);
+ user.Langauges.Add(newLang);
+
+ return await RepositoryMethods.SaveChangesAsync(this._context);
+ }
+
+ public async Task<bool> EditUserTechnologies(User user, Technology oldTech, Technology newTech)
+ {
+ this._context.Update(user);
+
+ user.Technologies.Remove(oldTech);
+ user.Technologies.Add(newTech);
+
+ return await RepositoryMethods.SaveChangesAsync(this._context);
+ }
+ #endregion
+
+ #region Delete
+
public async Task<bool> DeleteAsync(User entity)
{
- this._context
- .Set<User>()
+ this._context.Users
.Remove(entity);
return await RepositoryMethods.SaveChangesAsync(this._context);
@@ -93,37 +154,70 @@ namespace DevHive.Data.Repositories
return await RepositoryMethods.SaveChangesAsync(this._context);
}
-
- //Validations
- public bool DoesUserExist(Guid id)
+
+ public async Task<bool> RemoveLanguageFromUserAsync(User user, Language language)
{
- return this._context
- .Set<User>()
- .Any(x => x.Id == id);
+ this._context.Update(user);
+
+ user.Langauges.Remove(language);
+
+ return await RepositoryMethods.SaveChangesAsync(this._context);
}
- public bool DoesUserHaveThisUsername(Guid id, string username)
+ public async Task<bool> RemoveTechnologyFromUserAsync(User user, Technology technology)
{
- return this._context
- .Set<User>()
- .Any(x => x.Id == id &&
- x.UserName == username);
+ this._context.Update(user);
+
+ user.Technologies.Remove(technology);
+
+ return await RepositoryMethods.SaveChangesAsync(this._context);
+ }
+ #endregion
+
+ #region Validations
+
+ public async Task<bool> DoesUserExistAsync(Guid id)
+ {
+ return await this._context.Users
+ .AnyAsync(x => x.Id == id);
}
- public async Task<bool> DoesUsernameExist(string username)
+ public async Task<bool> DoesUsernameExistAsync(string username)
{
- return await this._context
- .Set<User>()
+ return await this._context.Users
.AsNoTracking()
.AnyAsync(u => u.UserName == username);
}
- public async Task<bool> DoesEmailExist(string email)
+ public async Task<bool> DoesEmailExistAsync(string email)
{
- return await this._context
- .Set<User>()
+ return await this._context.Users
.AsNoTracking()
.AnyAsync(u => u.Email == email);
}
+
+ public async Task<bool> DoesUserHaveThisFriendAsync(Guid userId, Guid friendId)
+ {
+ User user = await this._context.Users
+ .FirstOrDefaultAsync(x => x.Id == userId);
+
+ User friend = await this._context.Users
+ .FirstOrDefaultAsync(x => x.Id == friendId);
+
+ return user.Friends.Contains(friend);
+ }
+
+ public bool DoesUserHaveThisUsername(Guid id, string username)
+ {
+ return this._context.Users
+ .Any(x => x.Id == id &&
+ x.UserName == username);
+ }
+
+ public bool DoesUserHaveFriends(User user)
+ {
+ return user.Friends.Count >= 1;
+ }
+ #endregion
}
}