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 --- .../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 ++++++++++++++++++++++ 6 files changed, 122 insertions(+) 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 (limited to 'src/DevHive.Data/Interfaces/Repositories') 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); + } +} -- cgit v1.2.3 From 64d29a657d7736fc970ae3ea2b0a9217cd406a64 Mon Sep 17 00:00:00 2001 From: transtrike Date: Fri, 15 Jan 2021 19:39:56 +0200 Subject: Renamed AddFriend to AddFriendToUser to clarify method --- src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs | 2 +- src/DevHive.Data/Repositories/UserRepository.cs | 2 +- src/DevHive.Services/Services/UserService.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/DevHive.Data/Interfaces/Repositories') diff --git a/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs index 3a22911..eca6adb 100644 --- a/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs +++ b/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs @@ -8,7 +8,7 @@ namespace DevHive.Data.Interfaces.Repositories { public interface IUserRepository : IRepository { - Task AddFriendAsync(User user, User friend); + Task AddFriendToUserAsync(User user, User friend); Task AddLanguageToUserAsync(User user, Language language); Task AddTechnologyToUserAsync(User user, Technology technology); diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs index c06fef6..17ca93b 100644 --- a/src/DevHive.Data/Repositories/UserRepository.cs +++ b/src/DevHive.Data/Repositories/UserRepository.cs @@ -28,7 +28,7 @@ namespace DevHive.Data.Repositories return await RepositoryMethods.SaveChangesAsync(this._context); } - public async Task AddFriendAsync(User user, User friend) + public async Task AddFriendToUserAsync(User user, User friend) { this._context.Update(user); user.Friends.Add(friend); diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs index ae657cc..37dbc7b 100644 --- a/src/DevHive.Services/Services/UserService.cs +++ b/src/DevHive.Services/Services/UserService.cs @@ -105,7 +105,7 @@ namespace DevHive.Services.Services User friend = await this._userRepository.GetByIdAsync(friendId); return user != default(User) && friend != default(User) ? - await this._userRepository.AddFriendAsync(user, friend) : + await this._userRepository.AddFriendToUserAsync(user, friend) : throw new ArgumentException("Invalid user!"); } -- cgit v1.2.3 From 83f63ad729d585d597bdcf0afc05b7d56344223e Mon Sep 17 00:00:00 2001 From: transtrike Date: Sun, 17 Jan 2021 13:38:24 +0200 Subject: Lang&Tech layers now return id on Create --- src/DevHive.Data/DevHiveContext.cs | 1 + .../Interfaces/Repositories/IPostRepository.cs | 4 ++++ src/DevHive.Data/Repositories/PostRepository.cs | 14 +++++++++++++ .../Interfaces/ILanguageService.cs | 2 +- src/DevHive.Services/Interfaces/IPostService.cs | 4 ++-- .../Interfaces/ITechnologyService.cs | 2 +- .../Models/Post/Comment/BaseCommentServiceModel.cs | 3 ++- src/DevHive.Services/Services/LanguageService.cs | 14 +++++++++---- src/DevHive.Services/Services/PostService.cs | 24 +++++++++++++++++----- src/DevHive.Services/Services/TechnologyService.cs | 14 +++++++++---- src/DevHive.Web/Controllers/LanguageController.cs | 9 ++++---- src/DevHive.Web/Controllers/PostController.cs | 18 ++++++++-------- .../Controllers/TechnologyController.cs | 13 ++++++------ .../Models/Post/Comment/CommentWebModel.cs | 3 ++- src/DevHive.code-workspace | 2 +- 15 files changed, 85 insertions(+), 42 deletions(-) (limited to 'src/DevHive.Data/Interfaces/Repositories') diff --git a/src/DevHive.Data/DevHiveContext.cs b/src/DevHive.Data/DevHiveContext.cs index 10fd004..c1bda49 100644 --- a/src/DevHive.Data/DevHiveContext.cs +++ b/src/DevHive.Data/DevHiveContext.cs @@ -12,6 +12,7 @@ namespace DevHive.Data public DbSet Technologies { get; set; } public DbSet Languages { get; set; } + public DbSet Posts { get; set; } public DbSet Comments { get; set; } protected override void OnModelCreating(ModelBuilder builder) diff --git a/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs index 913d8c4..7a9c02e 100644 --- a/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs +++ b/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs @@ -9,12 +9,16 @@ namespace DevHive.Data.Interfaces.Repositories { Task AddCommentAsync(Comment entity); + Task GetPostByIssuerAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated); + Task GetCommentByIdAsync(Guid id); + Task GetCommentByIssuerAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated); Task EditCommentAsync(Comment newEntity); Task DeleteCommentAsync(Comment entity); Task DoesCommentExist(Guid id); + Task DoesPostExist(Guid postId); } } diff --git a/src/DevHive.Data/Repositories/PostRepository.cs b/src/DevHive.Data/Repositories/PostRepository.cs index 3be14e3..c5e8569 100644 --- a/src/DevHive.Data/Repositories/PostRepository.cs +++ b/src/DevHive.Data/Repositories/PostRepository.cs @@ -43,6 +43,13 @@ namespace DevHive.Data.Repositories .FindAsync(id); } + public async Task GetPostByIssuerAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated) + { + return await this._context.Posts + .FirstOrDefaultAsync(p => p.IssuerId == issuerId && + p.TimeCreated == timeCreated); + } + public async Task GetCommentByIdAsync(Guid id) { return await this._context @@ -50,6 +57,13 @@ namespace DevHive.Data.Repositories .FindAsync(id); } + public async Task GetCommentByIssuerAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated) + { + return await this._context.Comments + .FirstOrDefaultAsync(p => p.IssuerId == issuerId && + p.TimeCreated == timeCreated); + } + //Update public async Task EditAsync(Post newPost) { diff --git a/src/DevHive.Services/Interfaces/ILanguageService.cs b/src/DevHive.Services/Interfaces/ILanguageService.cs index 4d16ea3..0df9a95 100644 --- a/src/DevHive.Services/Interfaces/ILanguageService.cs +++ b/src/DevHive.Services/Interfaces/ILanguageService.cs @@ -6,7 +6,7 @@ namespace DevHive.Services.Interfaces { public interface ILanguageService { - Task CreateLanguage(CreateLanguageServiceModel createLanguageServiceModel); + Task CreateLanguage(CreateLanguageServiceModel createLanguageServiceModel); Task GetLanguageById(Guid id); diff --git a/src/DevHive.Services/Interfaces/IPostService.cs b/src/DevHive.Services/Interfaces/IPostService.cs index dd886b4..4364c67 100644 --- a/src/DevHive.Services/Interfaces/IPostService.cs +++ b/src/DevHive.Services/Interfaces/IPostService.cs @@ -7,8 +7,8 @@ namespace DevHive.Services.Interfaces { public interface IPostService { - Task CreatePost(CreatePostServiceModel postServiceModel); - Task AddComment(CreateCommentServiceModel commentServiceModel); + Task CreatePost(CreatePostServiceModel postServiceModel); + Task AddComment(CreateCommentServiceModel commentServiceModel); Task GetCommentById(Guid id); Task GetPostById(Guid id); diff --git a/src/DevHive.Services/Interfaces/ITechnologyService.cs b/src/DevHive.Services/Interfaces/ITechnologyService.cs index 9e1e955..9c5661d 100644 --- a/src/DevHive.Services/Interfaces/ITechnologyService.cs +++ b/src/DevHive.Services/Interfaces/ITechnologyService.cs @@ -6,7 +6,7 @@ namespace DevHive.Services.Interfaces { public interface ITechnologyService { - Task Create(CreateTechnologyServiceModel technologyServiceModel); + Task Create(CreateTechnologyServiceModel technologyServiceModel); Task GetTechnologyById(Guid id); diff --git a/src/DevHive.Services/Models/Post/Comment/BaseCommentServiceModel.cs b/src/DevHive.Services/Models/Post/Comment/BaseCommentServiceModel.cs index 3aa92ee..54d6838 100644 --- a/src/DevHive.Services/Models/Post/Comment/BaseCommentServiceModel.cs +++ b/src/DevHive.Services/Models/Post/Comment/BaseCommentServiceModel.cs @@ -5,7 +5,8 @@ namespace DevHive.Services.Models.Post.Comment public class BaseCommentServiceModel { public Guid Id { get; set; } + public Guid PostId { get; set; } public Guid IssuerId { get; set; } public string Message { get; set; } } -} \ No newline at end of file +} diff --git a/src/DevHive.Services/Services/LanguageService.cs b/src/DevHive.Services/Services/LanguageService.cs index f457a31..e9c401e 100644 --- a/src/DevHive.Services/Services/LanguageService.cs +++ b/src/DevHive.Services/Services/LanguageService.cs @@ -21,15 +21,21 @@ namespace DevHive.Services.Services #region Create - public async Task CreateLanguage(CreateLanguageServiceModel createLanguageServiceModel) + public async Task CreateLanguage(CreateLanguageServiceModel createLanguageServiceModel) { if (await this._languageRepository.DoesLanguageNameExistAsync(createLanguageServiceModel.Name)) throw new ArgumentException("Language already exists!"); Language language = this._languageMapper.Map(createLanguageServiceModel); - bool result = await this._languageRepository.AddAsync(language); - - return result; + bool success = await this._languageRepository.AddAsync(language); + + if(success) + { + Language newLanguage = await this._languageRepository.GetByNameAsync(createLanguageServiceModel.Name); + return newLanguage.Id; + } + else + return Guid.Empty; } #endregion diff --git a/src/DevHive.Services/Services/PostService.cs b/src/DevHive.Services/Services/PostService.cs index 6e83ad4..f2f60d1 100644 --- a/src/DevHive.Services/Services/PostService.cs +++ b/src/DevHive.Services/Services/PostService.cs @@ -26,21 +26,35 @@ namespace DevHive.Services.Services } //Create - public async Task CreatePost(CreatePostServiceModel postServiceModel) + public async Task CreatePost(CreatePostServiceModel postServiceModel) { Post post = this._postMapper.Map(postServiceModel); - return await this._postRepository.AddAsync(post); + bool success = await this._postRepository.AddAsync(post); + + if(success) + { + Post newPost = await this._postRepository.GetPostByIssuerAndTimeCreatedAsync(postServiceModel.IssuerId, postServiceModel.TimeCreated); + return newPost.Id; + } + else + return Guid.Empty; } - public async Task AddComment(CreateCommentServiceModel commentServiceModel) + public async Task AddComment(CreateCommentServiceModel commentServiceModel) { commentServiceModel.TimeCreated = DateTime.Now; Comment comment = this._postMapper.Map(commentServiceModel); - bool result = await this._postRepository.AddCommentAsync(comment); + bool success = await this._postRepository.AddCommentAsync(comment); - return result; + if(success) + { + Comment newComment = await this._postRepository.GetCommentByIssuerAndTimeCreatedAsync(commentServiceModel.IssuerId, commentServiceModel.TimeCreated); + return newComment.Id; + } + else + return Guid.Empty; } //Read diff --git a/src/DevHive.Services/Services/TechnologyService.cs b/src/DevHive.Services/Services/TechnologyService.cs index 4e74c83..1b2f0ff 100644 --- a/src/DevHive.Services/Services/TechnologyService.cs +++ b/src/DevHive.Services/Services/TechnologyService.cs @@ -21,15 +21,21 @@ namespace DevHive.Services.Services #region Create - public async Task Create(CreateTechnologyServiceModel technologyServiceModel) + public async Task Create(CreateTechnologyServiceModel technologyServiceModel) { if (await this._technologyRepository.DoesTechnologyNameExistAsync(technologyServiceModel.Name)) throw new ArgumentException("Technology already exists!"); Technology technology = this._technologyMapper.Map(technologyServiceModel); - bool result = await this._technologyRepository.AddAsync(technology); - - return result; + bool success = await this._technologyRepository.AddAsync(technology); + + if(success) + { + Technology newTechnology = await this._technologyRepository.GetByNameAsync(technologyServiceModel.Name); + return newTechnology.Id; + } + else + return Guid.Empty; } #endregion diff --git a/src/DevHive.Web/Controllers/LanguageController.cs b/src/DevHive.Web/Controllers/LanguageController.cs index bbac409..e2d0dec 100644 --- a/src/DevHive.Web/Controllers/LanguageController.cs +++ b/src/DevHive.Web/Controllers/LanguageController.cs @@ -26,12 +26,11 @@ namespace DevHive.Web.Controllers { CreateLanguageServiceModel languageServiceModel = this._languageMapper.Map(createLanguageWebModel); - bool result = await this._languageService.CreateLanguage(languageServiceModel); + Guid id = await this._languageService.CreateLanguage(languageServiceModel); - if (!result) - return new BadRequestObjectResult("Could not create Language"); - - return new OkResult(); + return id == Guid.Empty ? + new BadRequestObjectResult($"Could not create language {createLanguageWebModel.Name}") : + new OkObjectResult(new { Id = id }); } [HttpGet] diff --git a/src/DevHive.Web/Controllers/PostController.cs b/src/DevHive.Web/Controllers/PostController.cs index 15adb1b..2a08605 100644 --- a/src/DevHive.Web/Controllers/PostController.cs +++ b/src/DevHive.Web/Controllers/PostController.cs @@ -32,12 +32,11 @@ namespace DevHive.Web.Controllers CreatePostServiceModel postServiceModel = this._postMapper.Map(createPostModel); - bool result = await this._postService.CreatePost(postServiceModel); + Guid id = await this._postService.CreatePost(postServiceModel); - if (!result) - return new BadRequestObjectResult("Could not create post!"); - - return new OkResult(); + return id == Guid.Empty ? + new BadRequestObjectResult("Could not create post") : + new OkObjectResult(new { Id = id }); } [HttpPost] @@ -46,12 +45,11 @@ namespace DevHive.Web.Controllers { CreateCommentServiceModel createCommentServiceModel = this._postMapper.Map(commentWebModel); - bool result = await this._postService.AddComment(createCommentServiceModel); + Guid id = await this._postService.AddComment(createCommentServiceModel); - if (!result) - return new BadRequestObjectResult("Could not create the Comment"); - - return new OkResult(); + return id == Guid.Empty ? + new BadRequestObjectResult("Could not create language") : + new OkObjectResult(new { Id = id }); } //Read diff --git a/src/DevHive.Web/Controllers/TechnologyController.cs b/src/DevHive.Web/Controllers/TechnologyController.cs index 104b96e..ba2ffdc 100644 --- a/src/DevHive.Web/Controllers/TechnologyController.cs +++ b/src/DevHive.Web/Controllers/TechnologyController.cs @@ -22,16 +22,15 @@ namespace DevHive.Web.Controllers } [HttpPost] - public async Task Create([FromBody] CreateTechnologyWebModel technologyWebModel) + public async Task Create([FromBody] CreateTechnologyWebModel createTechnologyWebModel) { - CreateTechnologyServiceModel technologyServiceModel = this._technologyMapper.Map(technologyWebModel); + CreateTechnologyServiceModel technologyServiceModel = this._technologyMapper.Map(createTechnologyWebModel); - bool result = await this._technologyService.Create(technologyServiceModel); + Guid id = await this._technologyService.Create(technologyServiceModel); - if (!result) - return new BadRequestObjectResult("Could not create the Technology"); - - return new OkResult(); + return id == Guid.Empty ? + new BadRequestObjectResult($"Could not create technology {createTechnologyWebModel.Name}") : + new OkObjectResult(new { Id = id }); } [HttpGet] diff --git a/src/DevHive.Web/Models/Post/Comment/CommentWebModel.cs b/src/DevHive.Web/Models/Post/Comment/CommentWebModel.cs index 3cdc7c4..d66e5c9 100644 --- a/src/DevHive.Web/Models/Post/Comment/CommentWebModel.cs +++ b/src/DevHive.Web/Models/Post/Comment/CommentWebModel.cs @@ -5,7 +5,8 @@ namespace DevHive.Web.Models.Post.Comment public class CommentWebModel { public Guid IssuerId { get; set; } + public Guid PostId { get; set; } public string Message { get; set; } public DateTime TimeCreated { get; set; } } -} \ No newline at end of file +} diff --git a/src/DevHive.code-workspace b/src/DevHive.code-workspace index 4f764c2..28b1e3c 100644 --- a/src/DevHive.code-workspace +++ b/src/DevHive.code-workspace @@ -62,7 +62,7 @@ "ASPNETCORE_ENVIRONMENT": "Development" }, "launchBrowser": { - "enabled": true + "enabled": false } }, ], -- cgit v1.2.3 From 8179af787a7bf375753a178b89111a91d84a8bb8 Mon Sep 17 00:00:00 2001 From: transtrike Date: Wed, 20 Jan 2021 18:07:58 +0200 Subject: Changed List to HashSet for "no duplicates" scenario --- src/DevHive.Data/Interfaces/Models/ILanguage.cs | 2 +- src/DevHive.Data/Interfaces/Models/IRole.cs | 2 +- src/DevHive.Data/Interfaces/Models/ITechnology.cs | 2 +- src/DevHive.Data/Interfaces/Models/IUser.cs | 8 ++++---- .../Interfaces/Repositories/IUserRepository.cs | 4 ++-- src/DevHive.Data/Models/Language.cs | 2 +- src/DevHive.Data/Models/Role.cs | 2 +- src/DevHive.Data/Models/Technology.cs | 2 +- src/DevHive.Data/Models/User.cs | 8 ++++---- src/DevHive.Data/Repositories/UserRepository.cs | 4 ++-- .../Models/Identity/User/RegisterServiceModel.cs | 4 ++-- .../Models/Identity/User/UpdateUserServiceModel.cs | 8 ++++---- .../Models/Identity/User/UserServiceModel.cs | 8 ++++---- src/DevHive.Services/Services/PostService.cs | 5 +++-- src/DevHive.Services/Services/UserService.cs | 12 ++++++------ .../DevHive.Data.Tests/UserRepositoryTests.cs | 18 +++++++++--------- .../Models/Identity/User/UpdateUserWebModel.cs | 6 +++--- src/DevHive.Web/Models/Identity/User/UserWebModel.cs | 8 ++++---- 18 files changed, 53 insertions(+), 52 deletions(-) (limited to 'src/DevHive.Data/Interfaces/Repositories') diff --git a/src/DevHive.Data/Interfaces/Models/ILanguage.cs b/src/DevHive.Data/Interfaces/Models/ILanguage.cs index 9549777..b77d5ae 100644 --- a/src/DevHive.Data/Interfaces/Models/ILanguage.cs +++ b/src/DevHive.Data/Interfaces/Models/ILanguage.cs @@ -6,7 +6,7 @@ namespace DevHive.Data.Interfaces.Models public interface ILanguage : IModel { string Name { get; set; } - List Users { get; set; } + HashSet Users { get; set; } } } diff --git a/src/DevHive.Data/Interfaces/Models/IRole.cs b/src/DevHive.Data/Interfaces/Models/IRole.cs index 0623f07..c8b7068 100644 --- a/src/DevHive.Data/Interfaces/Models/IRole.cs +++ b/src/DevHive.Data/Interfaces/Models/IRole.cs @@ -5,6 +5,6 @@ namespace DevHive.Data.Interfaces.Models { public interface IRole { - List Users { get; set; } + HashSet Users { get; set; } } } diff --git a/src/DevHive.Data/Interfaces/Models/ITechnology.cs b/src/DevHive.Data/Interfaces/Models/ITechnology.cs index 159a21a..153f75f 100644 --- a/src/DevHive.Data/Interfaces/Models/ITechnology.cs +++ b/src/DevHive.Data/Interfaces/Models/ITechnology.cs @@ -6,6 +6,6 @@ namespace DevHive.Data.Interfaces.Models public interface ITechnology : IModel { string Name { get; set; } - List Users { get; set; } + HashSet Users { get; set; } } } diff --git a/src/DevHive.Data/Interfaces/Models/IUser.cs b/src/DevHive.Data/Interfaces/Models/IUser.cs index ef8c927..08ce385 100644 --- a/src/DevHive.Data/Interfaces/Models/IUser.cs +++ b/src/DevHive.Data/Interfaces/Models/IUser.cs @@ -8,9 +8,9 @@ namespace DevHive.Data.Interfaces.Models string FirstName { get; set; } string LastName { get; set; } string ProfilePictureUrl { get; set; } - IList Languages { get; set; } - IList Technologies { get; set; } - IList Roles { get; set; } - IList Friends { get; set; } + HashSet Languages { get; set; } + HashSet Technologies { get; set; } + HashSet Roles { get; set; } + HashSet Friends { get; set; } } } diff --git a/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs index eca6adb..456eb94 100644 --- a/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs +++ b/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs @@ -14,8 +14,8 @@ namespace DevHive.Data.Interfaces.Repositories Task GetByUsernameAsync(string username); Language GetUserLanguage(User user, Language language); - IList GetUserLanguages(User user); - IList GetUserTechnologies(User user); + HashSet GetUserLanguages(User user); + HashSet GetUserTechnologies(User user); Technology GetUserTechnology(User user, Technology technology); IEnumerable QueryAll(); diff --git a/src/DevHive.Data/Models/Language.cs b/src/DevHive.Data/Models/Language.cs index 0db8cb6..f2b2786 100644 --- a/src/DevHive.Data/Models/Language.cs +++ b/src/DevHive.Data/Models/Language.cs @@ -8,6 +8,6 @@ namespace DevHive.Data.Models { public Guid Id { get; set; } public string Name { get; set; } - public List Users { get; set; } + public HashSet Users { get; set; } } } diff --git a/src/DevHive.Data/Models/Role.cs b/src/DevHive.Data/Models/Role.cs index e63f007..e0855aa 100644 --- a/src/DevHive.Data/Models/Role.cs +++ b/src/DevHive.Data/Models/Role.cs @@ -12,6 +12,6 @@ namespace DevHive.Data.Models public const string DefaultRole = "User"; public const string AdminRole = "Admin"; - public List Users { get; set; } + public HashSet Users { get; set; } } } diff --git a/src/DevHive.Data/Models/Technology.cs b/src/DevHive.Data/Models/Technology.cs index 9096cbe..a0728d5 100644 --- a/src/DevHive.Data/Models/Technology.cs +++ b/src/DevHive.Data/Models/Technology.cs @@ -8,6 +8,6 @@ namespace DevHive.Data.Models { public Guid Id { get; set; } public string Name { get; set; } - public List Users { get; set; } + public HashSet Users { get; set; } } } diff --git a/src/DevHive.Data/Models/User.cs b/src/DevHive.Data/Models/User.cs index cf779f5..2ac7adf 100644 --- a/src/DevHive.Data/Models/User.cs +++ b/src/DevHive.Data/Models/User.cs @@ -19,15 +19,15 @@ namespace DevHive.Data.Models /// Languages that the user uses or is familiar with /// // [Unique] - public IList Languages { get; set; } + public HashSet Languages { get; set; } /// /// Technologies that the user uses or is familiar with /// - public IList Technologies { get; set; } = new List(); + public HashSet Technologies { get; set; } = new HashSet(); - public IList Roles { get; set; } = new List(); + public HashSet Roles { get; set; } = new HashSet(); - public IList Friends { get; set; } = new List(); + public HashSet Friends { get; set; } = new HashSet(); } } diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs index 2ca8099..492d46b 100644 --- a/src/DevHive.Data/Repositories/UserRepository.cs +++ b/src/DevHive.Data/Repositories/UserRepository.cs @@ -82,7 +82,7 @@ namespace DevHive.Data.Repositories .FirstOrDefaultAsync(x => x.UserName == username); } - public IList GetUserLanguages(User user) + public HashSet GetUserLanguages(User user) { return user.Languages; } @@ -93,7 +93,7 @@ namespace DevHive.Data.Repositories .FirstOrDefault(x => x.Id == language.Id); } - public IList GetUserTechnologies(User user) + public HashSet GetUserTechnologies(User user) { return user.Technologies; } diff --git a/src/DevHive.Services/Models/Identity/User/RegisterServiceModel.cs b/src/DevHive.Services/Models/Identity/User/RegisterServiceModel.cs index 74f66b4..3171ea6 100644 --- a/src/DevHive.Services/Models/Identity/User/RegisterServiceModel.cs +++ b/src/DevHive.Services/Models/Identity/User/RegisterServiceModel.cs @@ -6,8 +6,8 @@ namespace DevHive.Services.Models.Identity.User { public class RegisterServiceModel : BaseUserServiceModel { - public IList Languages { get; set; } - public IList Technologies { get; set; } + public HashSet Languages { get; set; } + public HashSet Technologies { get; set; } public string Password { get; set; } } } diff --git a/src/DevHive.Services/Models/Identity/User/UpdateUserServiceModel.cs b/src/DevHive.Services/Models/Identity/User/UpdateUserServiceModel.cs index 5b5a178..87af43a 100644 --- a/src/DevHive.Services/Models/Identity/User/UpdateUserServiceModel.cs +++ b/src/DevHive.Services/Models/Identity/User/UpdateUserServiceModel.cs @@ -7,13 +7,13 @@ namespace DevHive.Services.Models.Identity.User { public Guid Id { get; set; } - public IList Roles { get; set; } = new List(); + public HashSet Roles { get; set; } = new HashSet(); - public IList Friends { get; set; } = new List(); + public HashSet Friends { get; set; } = new HashSet(); - public IList Languages { get; set; } = new List(); + public HashSet Languages { get; set; } = new HashSet(); - public IList Technologies { get; set; } = new List(); + public HashSet Technologies { get; set; } = new HashSet(); } } diff --git a/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs b/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs index 913b5c0..5fcd494 100644 --- a/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs +++ b/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs @@ -7,12 +7,12 @@ namespace DevHive.Services.Models.Identity.User { public class UserServiceModel : BaseUserServiceModel { - public IList Roles { get; set; } = new List(); + public HashSet Roles { get; set; } = new HashSet(); - public IList Friends { get; set; } = new List(); + public HashSet Friends { get; set; } = new HashSet(); - public IList Languages { get; set; } = new List(); + public HashSet Languages { get; set; } = new HashSet(); - public IList Technologies { get; set; } = new List(); + public HashSet Technologies { get; set; } = new HashSet(); } } diff --git a/src/DevHive.Services/Services/PostService.cs b/src/DevHive.Services/Services/PostService.cs index f2f60d1..9503b8a 100644 --- a/src/DevHive.Services/Services/PostService.cs +++ b/src/DevHive.Services/Services/PostService.cs @@ -9,6 +9,7 @@ using System.IdentityModel.Tokens.Jwt; using System.Security.Claims; using DevHive.Services.Interfaces; using DevHive.Data.Interfaces.Repositories; +using System.Linq; namespace DevHive.Services.Services { @@ -131,8 +132,8 @@ namespace DevHive.Services.Services { var jwt = new JwtSecurityTokenHandler().ReadJwtToken(rawTokenData.Remove(0, 7)); - string jwtUserName = this.GetClaimTypeValues("unique_name", jwt.Claims)[0]; - //List jwtRoleNames = this.GetClaimTypeValues("role", jwt.Claims); + string jwtUserName = this.GetClaimTypeValues("unique_name", jwt.Claims).First(); + //HashSet jwtRoleNames = this.GetClaimTypeValues("role", jwt.Claims); User user = await this._userRepository.GetByUsernameAsync(jwtUserName) ?? throw new ArgumentException("User does not exist!"); diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs index ee4b24d..51c4432 100644 --- a/src/DevHive.Services/Services/UserService.cs +++ b/src/DevHive.Services/Services/UserService.cs @@ -75,7 +75,7 @@ namespace DevHive.Services.Services // Set the default role to the user Role defaultRole = await this._roleRepository.GetByNameAsync(Role.DefaultRole); - user.Roles = new List() { defaultRole }; + user.Roles = new HashSet() { defaultRole }; await this._userRepository.AddAsync(user); @@ -144,12 +144,12 @@ namespace DevHive.Services.Services await this.ValidateUserCollections(updateUserServiceModel); - List languages = new(); + HashSet languages = new(); foreach (UpdateUserCollectionServiceModel lang in updateUserServiceModel.Languages) languages.Add(await this._languageRepository.GetByNameAsync(lang.Name) ?? throw new ArgumentException("Invalid language name!")); - List technologies = new(); + HashSet technologies = new(); foreach (UpdateUserCollectionServiceModel tech in updateUserServiceModel.Technologies) technologies.Add(await this._technologyRepository.GetByNameAsync(tech.Name) ?? throw new ArgumentException("Invalid technology name!")); @@ -257,7 +257,7 @@ namespace DevHive.Services.Services // There is authorization name in the beginning, i.e. "Bearer eyJh..." var jwt = new JwtSecurityTokenHandler().ReadJwtToken(rawTokenData.Remove(0, 7)); - Guid jwtUserID = new Guid(this.GetClaimTypeValues("ID", jwt.Claims)[0]); + Guid jwtUserID = new Guid(this.GetClaimTypeValues("ID", jwt.Claims).First()); List jwtRoleNames = this.GetClaimTypeValues("role", jwt.Claims); User user = await this._userRepository.GetByIdAsync(jwtUserID) @@ -326,11 +326,11 @@ namespace DevHive.Services.Services } } - private string WriteJWTSecurityToken(Guid userId, IList roles) + private string WriteJWTSecurityToken(Guid userId, HashSet roles) { byte[] signingKey = Encoding.ASCII.GetBytes(_jwtOptions.Secret); - List claims = new() + HashSet claims = new() { new Claim("ID", $"{userId}"), }; diff --git a/src/DevHive.Tests/DevHive.Data.Tests/UserRepositoryTests.cs b/src/DevHive.Tests/DevHive.Data.Tests/UserRepositoryTests.cs index b0a5b93..be116b0 100644 --- a/src/DevHive.Tests/DevHive.Data.Tests/UserRepositoryTests.cs +++ b/src/DevHive.Tests/DevHive.Data.Tests/UserRepositoryTests.cs @@ -165,10 +165,10 @@ namespace DevHive.Data.Tests //Arrange User dummyUser = CreateDummyUser(); await this._userRepository.AddAsync(dummyUser); - IList dummyUserLanguages = dummyUser.Languages; + HashSet dummyUserLanguages = dummyUser.Languages; //Act - IList languages = this._userRepository.GetUserLanguages(dummyUser); + HashSet languages = this._userRepository.GetUserLanguages(dummyUser); //Assert Assert.AreEqual(dummyUserLanguages, languages, "Method doesn't query languages properly"); @@ -185,7 +185,7 @@ namespace DevHive.Data.Tests // Language dummyLang = await this._languageRepository.GetByNameAsync("csharp"); // //Act - // IList languages = this._userRepository.GetUserLanguage(dummyUser, dummyLang); + // HashSet languages = this._userRepository.GetUserLanguage(dummyUser, dummyLang); // //Assert // Assert.AreEqual(dummyUserLanguages, languages, "Method doesn't query languages properly"); @@ -195,7 +195,7 @@ namespace DevHive.Data.Tests #region HelperMethods private User CreateDummyUser() { - List languages = new() + HashSet languages = new() { new Language() { @@ -204,7 +204,7 @@ namespace DevHive.Data.Tests }, }; - List technologies = new() + HashSet technologies = new() { new Technology() { @@ -213,7 +213,7 @@ namespace DevHive.Data.Tests }, }; - List roles = new() + HashSet roles = new() { new Role() { @@ -237,7 +237,7 @@ namespace DevHive.Data.Tests private User CreateAnotherDummyUser() { - List languages = new() + HashSet languages = new() { new Language() { @@ -246,7 +246,7 @@ namespace DevHive.Data.Tests }, }; - List technologies = new() + HashSet technologies = new() { new Technology() { @@ -255,7 +255,7 @@ namespace DevHive.Data.Tests }, }; - List roles = new() + HashSet roles = new() { new Role() { diff --git a/src/DevHive.Web/Models/Identity/User/UpdateUserWebModel.cs b/src/DevHive.Web/Models/Identity/User/UpdateUserWebModel.cs index 724930c..3c38ab6 100644 --- a/src/DevHive.Web/Models/Identity/User/UpdateUserWebModel.cs +++ b/src/DevHive.Web/Models/Identity/User/UpdateUserWebModel.cs @@ -16,14 +16,14 @@ namespace DevHive.Web.Models.Identity.User [NotNull] [Required] - public IList Friends { get; set; } + public HashSet Friends { get; set; } [NotNull] [Required] - public IList Languages { get; set; } + public HashSet Languages { get; set; } [NotNull] [Required] - public IList Technologies { get; set; } + public HashSet Technologies { get; set; } } } diff --git a/src/DevHive.Web/Models/Identity/User/UserWebModel.cs b/src/DevHive.Web/Models/Identity/User/UserWebModel.cs index 1d2d17b..5b80ba3 100644 --- a/src/DevHive.Web/Models/Identity/User/UserWebModel.cs +++ b/src/DevHive.Web/Models/Identity/User/UserWebModel.cs @@ -11,18 +11,18 @@ namespace DevHive.Web.Models.Identity.User { [NotNull] [Required] - public IList Roles { get; set; } = new List(); + public HashSet Roles { get; set; } = new HashSet(); [NotNull] [Required] - public IList Friends { get; set; } = new List(); + public HashSet Friends { get; set; } = new HashSet(); [NotNull] [Required] - public IList Languages { get; set; } = new List(); + public HashSet Languages { get; set; } = new HashSet(); [NotNull] [Required] - public IList Technologies { get; set; } = new List(); + public HashSet Technologies { get; set; } = new HashSet(); } } -- cgit v1.2.3 From f8f3727319a03eb9dd9a2ed8546810beb732cdab Mon Sep 17 00:00:00 2001 From: transtrike Date: Thu, 21 Jan 2021 19:21:46 +0200 Subject: Cleaning of UserRepo&UserService of unused methods --- .../Interfaces/Repositories/IUserRepository.cs | 13 +--- src/DevHive.Data/Repositories/UserRepository.cs | 74 ---------------------- src/DevHive.Services/Interfaces/IUserService.cs | 5 -- src/DevHive.Services/Services/UserService.cs | 51 --------------- 4 files changed, 2 insertions(+), 141 deletions(-) (limited to 'src/DevHive.Data/Interfaces/Repositories') diff --git a/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs index 456eb94..c29669d 100644 --- a/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs +++ b/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs @@ -8,10 +8,7 @@ namespace DevHive.Data.Interfaces.Repositories { public interface IUserRepository : IRepository { - Task AddFriendToUserAsync(User user, User friend); - Task AddLanguageToUserAsync(User user, Language language); - Task AddTechnologyToUserAsync(User user, Technology technology); - + //Read Task GetByUsernameAsync(string username); Language GetUserLanguage(User user, Language language); HashSet GetUserLanguages(User user); @@ -19,13 +16,7 @@ namespace DevHive.Data.Interfaces.Repositories 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); - + //Validations Task DoesEmailExistAsync(string email); Task DoesUserExistAsync(Guid id); Task DoesUserHaveThisFriendAsync(Guid userId, Guid friendId); diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs index c769f7e..f0c28f1 100644 --- a/src/DevHive.Data/Repositories/UserRepository.cs +++ b/src/DevHive.Data/Repositories/UserRepository.cs @@ -2,11 +2,9 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using DevHive.Common.Models.Misc; using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.ChangeTracking; namespace DevHive.Data.Repositories { @@ -28,32 +26,6 @@ namespace DevHive.Data.Repositories return await this.SaveChangesAsync(this._context); } - - public async Task AddFriendToUserAsync(User user, User friend) - { - this._context.Update(user); - user.Friends.Add(friend); - - return await this.SaveChangesAsync(this._context); - } - - public async Task AddLanguageToUserAsync(User user, Language language) - { - this._context.Update(user); - - user.Languages.Add(language); - - return await this.SaveChangesAsync(this._context); - } - - public async Task AddTechnologyToUserAsync(User user, Technology technology) - { - this._context.Update(user); - - user.Technologies.Add(technology); - - return await this.SaveChangesAsync(this._context); - } #endregion #region Read @@ -120,26 +92,6 @@ namespace DevHive.Data.Repositories return await this.SaveChangesAsync(this._context); } - - public async Task EditUserLanguageAsync(User user, Language oldLang, Language newLang) - { - this._context.Update(user); - - user.Languages.Remove(oldLang); - user.Languages.Add(newLang); - - return await this.SaveChangesAsync(this._context); - } - - public async Task EditUserTechnologyAsync(User user, Technology oldTech, Technology newTech) - { - this._context.Update(user); - - user.Technologies.Remove(oldTech); - user.Technologies.Add(newTech); - - return await this.SaveChangesAsync(this._context); - } #endregion #region Delete @@ -151,32 +103,6 @@ namespace DevHive.Data.Repositories return await this.SaveChangesAsync(this._context); } - - public async Task RemoveFriendAsync(User user, User friend) - { - this._context.Update(user); - user.Friends.Remove(friend); - - return await this.SaveChangesAsync(this._context); - } - - public async Task RemoveLanguageFromUserAsync(User user, Language language) - { - this._context.Update(user); - - user.Languages.Remove(language); - - return await this.SaveChangesAsync(this._context); - } - - public async Task RemoveTechnologyFromUserAsync(User user, Technology technology) - { - this._context.Update(user); - - user.Technologies.Remove(technology); - - return await this.SaveChangesAsync(this._context); - } #endregion #region Validations diff --git a/src/DevHive.Services/Interfaces/IUserService.cs b/src/DevHive.Services/Interfaces/IUserService.cs index 923e9bb..51e3cf9 100644 --- a/src/DevHive.Services/Interfaces/IUserService.cs +++ b/src/DevHive.Services/Interfaces/IUserService.cs @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; using System.Threading.Tasks; using DevHive.Common.Models.Identity; -using DevHive.Common.Models.Misc; using DevHive.Services.Models.Identity.User; namespace DevHive.Services.Interfaces @@ -12,15 +10,12 @@ namespace DevHive.Services.Interfaces Task LoginUser(LoginServiceModel loginModel); Task RegisterUser(RegisterServiceModel registerModel); - Task AddFriend(Guid userId, Guid friendId); - Task GetUserByUsername(string username); Task GetUserById(Guid id); Task UpdateUser(UpdateUserServiceModel updateModel); Task DeleteUser(Guid id); - Task RemoveFriend(Guid userId, Guid friendId); Task ValidJWT(Guid id, string rawTokenData); } diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs index a57fd23..217154e 100644 --- a/src/DevHive.Services/Services/UserService.cs +++ b/src/DevHive.Services/Services/UserService.cs @@ -84,35 +84,7 @@ namespace DevHive.Services.Services } #endregion - #region Create - - public async Task AddFriend(Guid userId, Guid friendId) - { - Task userExists = this._userRepository.DoesUserExistAsync(userId); - Task friendExists = this._userRepository.DoesUserExistAsync(friendId); - - await Task.WhenAll(userExists, friendExists); - - if (!userExists.Result) - throw new ArgumentException("User doesn't exist!"); - - if (!friendExists.Result) - throw new ArgumentException("Friend doesn't exist!"); - - if (await this._userRepository.DoesUserHaveThisFriendAsync(userId, friendId)) - throw new ArgumentException("Friend already exists in your friends list."); - - User user = await this._userRepository.GetByIdAsync(userId); - User friend = await this._userRepository.GetByIdAsync(friendId); - - return user != null && friend != null ? - await this._userRepository.AddFriendToUserAsync(user, friend) : - throw new ArgumentException("Invalid user!"); - } - #endregion - #region Read - public async Task GetUserById(Guid id) { User user = await this._userRepository.GetByIdAsync(id) @@ -133,7 +105,6 @@ namespace DevHive.Services.Services #endregion #region Update - public async Task UpdateUser(UpdateUserServiceModel updateUserServiceModel) { await this.ValidateUserOnUpdate(updateUserServiceModel); @@ -191,7 +162,6 @@ namespace DevHive.Services.Services #endregion #region Delete - public async Task DeleteUser(Guid id) { if (!await this._userRepository.DoesUserExistAsync(id)) @@ -203,30 +173,9 @@ namespace DevHive.Services.Services if (!result) throw new InvalidOperationException("Unable to delete user!"); } - - public async Task RemoveFriend(Guid userId, Guid friendId) - { - bool userExists = await this._userRepository.DoesUserExistAsync(userId); - bool friendExists = await this._userRepository.DoesUserExistAsync(friendId); - - if (!userExists) - throw new ArgumentException("User doesn't exist!"); - - if (!friendExists) - throw new ArgumentException("Friend doesn't exist!"); - - if (!await this._userRepository.DoesUserHaveThisFriendAsync(userId, friendId)) - throw new ArgumentException("This ain't your friend, amigo."); - - User user = await this._userRepository.GetByIdAsync(userId); - User homie = await this._userRepository.GetByIdAsync(friendId); - - return await this._userRepository.RemoveFriendAsync(user, homie); - } #endregion #region Validations - public async Task ValidJWT(Guid id, string rawTokenData) { // There is authorization name in the beginning, i.e. "Bearer eyJh..." -- cgit v1.2.3 From bda98b96433d7a9952524fab4ec65f96998b55de Mon Sep 17 00:00:00 2001 From: transtrike Date: Thu, 21 Jan 2021 22:08:50 +0200 Subject: Generic base repo class refactored; All repos inherit generic base repo --- .../Interfaces/Repositories/IRepository.cs | 2 +- src/DevHive.Data/Repositories/BaseRepository.cs | 54 +++++++++++++++++++++- .../Repositories/LanguageRepository.cs | 43 +---------------- src/DevHive.Data/Repositories/PostRepository.cs | 34 +------------- src/DevHive.Data/Repositories/RoleRepository.cs | 43 +---------------- .../Repositories/TechnologyRepository.cs | 39 +--------------- src/DevHive.Data/Repositories/UserRepository.cs | 41 ++-------------- 7 files changed, 64 insertions(+), 192 deletions(-) (limited to 'src/DevHive.Data/Interfaces/Repositories') diff --git a/src/DevHive.Data/Interfaces/Repositories/IRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IRepository.cs index 40a78de..d9f7c7a 100644 --- a/src/DevHive.Data/Interfaces/Repositories/IRepository.cs +++ b/src/DevHive.Data/Interfaces/Repositories/IRepository.cs @@ -18,4 +18,4 @@ namespace DevHive.Data.Repositories.Interfaces //Delete Entity from database Task DeleteAsync(TEntity entity); } -} \ No newline at end of file +} diff --git a/src/DevHive.Data/Repositories/BaseRepository.cs b/src/DevHive.Data/Repositories/BaseRepository.cs index b0f0f3e..dabb35b 100644 --- a/src/DevHive.Data/Repositories/BaseRepository.cs +++ b/src/DevHive.Data/Repositories/BaseRepository.cs @@ -1,11 +1,61 @@ +using System; using System.Threading.Tasks; +using DevHive.Data.Repositories.Interfaces; using Microsoft.EntityFrameworkCore; namespace DevHive.Data.Repositories { - public class BaseRepository + public class BaseRepository : IRepository + where TEntity : class { - public async Task SaveChangesAsync(DbContext context) + private readonly DbContext _context; + + public BaseRepository(DbContext context) + { + this._context = context; + this._context.ChangeTracker.AutoDetectChangesEnabled = false; + } + + public virtual async Task AddAsync(TEntity entity) + { + await this._context + .Set() + .AddAsync(entity); + + return await this.SaveChangesAsync(_context); + } + + public virtual async Task GetByIdAsync(Guid id) + { + return await this._context + .Set() + .FindAsync(id); + } + + public virtual async Task EditAsync(TEntity newEntity) + { + // Old way(backup) + // User user = await this._context.Users + // .FirstOrDefaultAsync(x => x.Id == entity.Id); + + // this._context.Update(user); + // this._context.Entry(entity).CurrentValues.SetValues(entity); + + this._context + .Set() + .Update(newEntity); + + return await this.SaveChangesAsync(_context); + } + + public virtual async Task DeleteAsync(TEntity entity) + { + this._context.Remove(entity); + + return await this.SaveChangesAsync(_context); + } + + public virtual async Task SaveChangesAsync(DbContext context) { int result = await context.SaveChangesAsync(); diff --git a/src/DevHive.Data/Repositories/LanguageRepository.cs b/src/DevHive.Data/Repositories/LanguageRepository.cs index 59c88a6..d7ee609 100644 --- a/src/DevHive.Data/Repositories/LanguageRepository.cs +++ b/src/DevHive.Data/Repositories/LanguageRepository.cs @@ -1,38 +1,22 @@ using System; using System.Threading.Tasks; -using DevHive.Common.Models.Misc; using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; using Microsoft.EntityFrameworkCore; namespace DevHive.Data.Repositories { - public class LanguageRepository : BaseRepository, ILanguageRepository + public class LanguageRepository : BaseRepository, ILanguageRepository { private readonly DevHiveContext _context; public LanguageRepository(DevHiveContext context) + :base(context) { this._context = context; } - #region Create - public async Task AddAsync(Language entity) - { - await this._context.Languages - .AddAsync(entity); - - return await this.SaveChangesAsync(this._context); - } - #endregion - #region Read - public async Task GetByIdAsync(Guid id) - { - return await this._context.Languages - .FindAsync(id); - } - public async Task GetByNameAsync(string languageName) { return await this._context.Languages @@ -41,29 +25,6 @@ namespace DevHive.Data.Repositories } #endregion - #region Update - - public async Task EditAsync(Language entity) - { - Language language = await this._context.Languages - .FirstOrDefaultAsync(x => x.Id == entity.Id); - - this._context.Update(language); - this._context.Entry(entity).CurrentValues.SetValues(entity); - - return await this.SaveChangesAsync(this._context); - } - #endregion - - #region Delete - public async Task DeleteAsync(Language entity) - { - this._context.Languages.Remove(entity); - - return await this.SaveChangesAsync(this._context); - } - #endregion - #region Validations public async Task DoesLanguageNameExistAsync(string languageName) { diff --git a/src/DevHive.Data/Repositories/PostRepository.cs b/src/DevHive.Data/Repositories/PostRepository.cs index 71602e7..9230a2e 100644 --- a/src/DevHive.Data/Repositories/PostRepository.cs +++ b/src/DevHive.Data/Repositories/PostRepository.cs @@ -1,30 +1,22 @@ using System; using System.Threading.Tasks; -using DevHive.Common.Models.Misc; using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; using Microsoft.EntityFrameworkCore; namespace DevHive.Data.Repositories { - public class PostRepository : BaseRepository, IPostRepository + public class PostRepository : BaseRepository, IPostRepository { private readonly DevHiveContext _context; public PostRepository(DevHiveContext context) + : base(context) { this._context = context; } #region Create - public async Task AddAsync(Post post) - { - await this._context.Posts - .AddAsync(post); - - return await this.SaveChangesAsync(this._context); - } - public async Task AddCommentAsync(Comment entity) { await this._context.Comments @@ -35,12 +27,6 @@ namespace DevHive.Data.Repositories #endregion #region Read - public async Task GetByIdAsync(Guid id) - { - return await this._context.Posts - .FindAsync(id); - } - public async Task GetPostByIssuerAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated) { return await this._context.Posts @@ -63,14 +49,6 @@ namespace DevHive.Data.Repositories #endregion #region Update - public async Task EditAsync(Post newPost) - { - this._context.Posts - .Update(newPost); - - return await this.SaveChangesAsync(this._context); - } - public async Task EditCommentAsync(Comment newEntity) { this._context.Comments @@ -81,14 +59,6 @@ namespace DevHive.Data.Repositories #endregion #region Delete - public async Task DeleteAsync(Post post) - { - this._context.Posts - .Remove(post); - - return await this.SaveChangesAsync(this._context); - } - public async Task DeleteCommentAsync(Comment entity) { this._context.Comments diff --git a/src/DevHive.Data/Repositories/RoleRepository.cs b/src/DevHive.Data/Repositories/RoleRepository.cs index 25549bf..156792d 100644 --- a/src/DevHive.Data/Repositories/RoleRepository.cs +++ b/src/DevHive.Data/Repositories/RoleRepository.cs @@ -6,32 +6,17 @@ using Microsoft.EntityFrameworkCore; namespace DevHive.Data.Repositories { - public class RoleRepository : BaseRepository, IRoleRepository + public class RoleRepository : BaseRepository, IRoleRepository { private readonly DevHiveContext _context; public RoleRepository(DevHiveContext context) + :base(context) { this._context = context; } - #region Create - public async Task AddAsync(Role entity) - { - await this._context.Roles - .AddAsync(entity); - - return await this.SaveChangesAsync(this._context); - } - #endregion - #region Read - public async Task GetByIdAsync(Guid id) - { - return await this._context.Roles - .FindAsync(id); - } - public async Task GetByNameAsync(string name) { return await this._context.Roles @@ -39,30 +24,6 @@ namespace DevHive.Data.Repositories } #endregion - #region Update - public async Task EditAsync(Role newEntity) - { - Role role = await this.GetByIdAsync(newEntity.Id); - - this._context - .Entry(role) - .CurrentValues - .SetValues(newEntity); - - return await this.SaveChangesAsync(this._context); - } - #endregion - - #region Delete - public async Task DeleteAsync(Role entity) - { - this._context.Roles - .Remove(entity); - - return await this.SaveChangesAsync(this._context); - } - #endregion - #region Validations public async Task DoesNameExist(string name) { diff --git a/src/DevHive.Data/Repositories/TechnologyRepository.cs b/src/DevHive.Data/Repositories/TechnologyRepository.cs index 35ee567..83cc7aa 100644 --- a/src/DevHive.Data/Repositories/TechnologyRepository.cs +++ b/src/DevHive.Data/Repositories/TechnologyRepository.cs @@ -1,38 +1,22 @@ using System; using System.Threading.Tasks; -using DevHive.Common.Models.Misc; using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; using Microsoft.EntityFrameworkCore; - namespace DevHive.Data.Repositories { - public class TechnologyRepository : BaseRepository, ITechnologyRepository + public class TechnologyRepository : BaseRepository, ITechnologyRepository { private readonly DevHiveContext _context; public TechnologyRepository(DevHiveContext context) + :base(context) { this._context = context; } - #region Create - public async Task AddAsync(Technology entity) - { - await this._context.Technologies - .AddAsync(entity); - - return await this.SaveChangesAsync(this._context); - } - #endregion - #region Read - public async Task GetByIdAsync(Guid id) - { - return await this._context.Technologies - .FindAsync(id); - } public async Task GetByNameAsync(string technologyName) { return await this._context.Technologies @@ -41,25 +25,6 @@ namespace DevHive.Data.Repositories } #endregion - #region Edit - public async Task EditAsync(Technology newEntity) - { - this._context.Technologies.Update(newEntity); - - return await this.SaveChangesAsync(this._context); - } - #endregion - - #region Delete - public async Task DeleteAsync(Technology entity) - { - this._context.Technologies - .Remove(entity); - - return await this.SaveChangesAsync(this._context); - } - #endregion - #region Validations public async Task DoesTechnologyNameExistAsync(string technologyName) { diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs index f0c28f1..1511c63 100644 --- a/src/DevHive.Data/Repositories/UserRepository.cs +++ b/src/DevHive.Data/Repositories/UserRepository.cs @@ -8,26 +8,16 @@ using Microsoft.EntityFrameworkCore; namespace DevHive.Data.Repositories { - public class UserRepository : BaseRepository, IUserRepository + public class UserRepository : BaseRepository, IUserRepository { private readonly DevHiveContext _context; public UserRepository(DevHiveContext context) + :base(context) { this._context = context; } - #region Create - - public async Task AddAsync(User entity) - { - await this._context.Users - .AddAsync(entity); - - return await this.SaveChangesAsync(this._context); - } - #endregion - #region Read public IEnumerable QueryAll() @@ -38,7 +28,7 @@ namespace DevHive.Data.Repositories .AsEnumerable(); } - public async Task GetByIdAsync(Guid id) + public override async Task GetByIdAsync(Guid id) { return await this._context.Users .Include(x => x.Friends) @@ -80,31 +70,6 @@ namespace DevHive.Data.Repositories } #endregion - #region Update - - public async Task EditAsync(User entity) - { - User user = await this._context.Users - .FirstOrDefaultAsync(x => x.Id == entity.Id); - - this._context.Update(user); - this._context.Entry(entity).CurrentValues.SetValues(entity); - - return await this.SaveChangesAsync(this._context); - } - #endregion - - #region Delete - - public async Task DeleteAsync(User entity) - { - this._context.Users - .Remove(entity); - - return await this.SaveChangesAsync(this._context); - } - #endregion - #region Validations public async Task DoesUserExistAsync(Guid id) -- cgit v1.2.3 From 1c91e52c91a1a94616eca632ffdd930ffeb616f4 Mon Sep 17 00:00:00 2001 From: transtrike Date: Fri, 22 Jan 2021 22:39:23 +0200 Subject: Kamen's proposal in Update() at BaseRepo merged --- src/DevHive.Data/Interfaces/Repositories/IRepository.cs | 2 +- src/DevHive.Data/Repositories/BaseRepository.cs | 15 +++++---------- 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 +- 7 files changed, 11 insertions(+), 16 deletions(-) (limited to 'src/DevHive.Data/Interfaces/Repositories') diff --git a/src/DevHive.Data/Interfaces/Repositories/IRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IRepository.cs index d9f7c7a..0d11cd3 100644 --- a/src/DevHive.Data/Interfaces/Repositories/IRepository.cs +++ b/src/DevHive.Data/Interfaces/Repositories/IRepository.cs @@ -13,7 +13,7 @@ namespace DevHive.Data.Repositories.Interfaces Task GetByIdAsync(Guid id); //Modify Entity from database - Task EditAsync(TEntity newEntity); + Task EditAsync(Guid id, TEntity newEntity); //Delete Entity from database Task DeleteAsync(TEntity entity); diff --git a/src/DevHive.Data/Repositories/BaseRepository.cs b/src/DevHive.Data/Repositories/BaseRepository.cs index dabb35b..0a97ac1 100644 --- a/src/DevHive.Data/Repositories/BaseRepository.cs +++ b/src/DevHive.Data/Repositories/BaseRepository.cs @@ -32,18 +32,13 @@ namespace DevHive.Data.Repositories .FindAsync(id); } - public virtual async Task EditAsync(TEntity newEntity) + public virtual async Task EditAsync(Guid id, TEntity newEntity) { - // Old way(backup) - // User user = await this._context.Users - // .FirstOrDefaultAsync(x => x.Id == entity.Id); - - // this._context.Update(user); - // this._context.Entry(entity).CurrentValues.SetValues(entity); - + TEntity currEnt = await this.GetByIdAsync(id); this._context - .Set() - .Update(newEntity); + .Entry(currEnt) + .CurrentValues + .SetValues(newEntity); return await this.SaveChangesAsync(_context); } diff --git a/src/DevHive.Services/Services/LanguageService.cs b/src/DevHive.Services/Services/LanguageService.cs index 89df654..a602d43 100644 --- a/src/DevHive.Services/Services/LanguageService.cs +++ b/src/DevHive.Services/Services/LanguageService.cs @@ -66,7 +66,7 @@ namespace DevHive.Services.Services throw new ArgumentException("Language name already exists in our data base!"); Language lang = this._languageMapper.Map(languageServiceModel); - return await this._languageRepository.EditAsync(lang); + return await this._languageRepository.EditAsync(languageServiceModel.Id, lang); } #endregion diff --git a/src/DevHive.Services/Services/PostService.cs b/src/DevHive.Services/Services/PostService.cs index 9503b8a..4757937 100644 --- a/src/DevHive.Services/Services/PostService.cs +++ b/src/DevHive.Services/Services/PostService.cs @@ -84,7 +84,7 @@ namespace DevHive.Services.Services throw new ArgumentException("Comment does not exist!"); Post post = this._postMapper.Map(postServiceModel); - return await this._postRepository.EditAsync(post); + return await this._postRepository.EditAsync(postServiceModel.Id, post); } public async Task UpdateComment(UpdateCommentServiceModel commentServiceModel) diff --git a/src/DevHive.Services/Services/RoleService.cs b/src/DevHive.Services/Services/RoleService.cs index 3ebb7c8..896946d 100644 --- a/src/DevHive.Services/Services/RoleService.cs +++ b/src/DevHive.Services/Services/RoleService.cs @@ -56,7 +56,7 @@ namespace DevHive.Services.Services throw new ArgumentException("Role name already exists!"); Role role = this._roleMapper.Map(updateRoleServiceModel); - return await this._roleRepository.EditAsync(role); + return await this._roleRepository.EditAsync(updateRoleServiceModel.Id, role); } public async Task DeleteRole(Guid id) diff --git a/src/DevHive.Services/Services/TechnologyService.cs b/src/DevHive.Services/Services/TechnologyService.cs index 88ed702..c879ad7 100644 --- a/src/DevHive.Services/Services/TechnologyService.cs +++ b/src/DevHive.Services/Services/TechnologyService.cs @@ -60,7 +60,7 @@ namespace DevHive.Services.Services throw new ArgumentException("Technology name already exists!"); Technology technology = this._technologyMapper.Map(updateTechnologyServiceModel); - bool result = await this._technologyRepository.EditAsync(technology); + bool result = await this._technologyRepository.EditAsync(updateTechnologyServiceModel.Id, technology); return result; } diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs index 217154e..533f422 100644 --- a/src/DevHive.Services/Services/UserService.cs +++ b/src/DevHive.Services/Services/UserService.cs @@ -152,7 +152,7 @@ namespace DevHive.Services.Services updateUserServiceModel.Technologies.RemoveWhere(x => x.Id == Guid.Empty); User user = this._userMapper.Map(updateUserServiceModel); - bool successful = await this._userRepository.EditAsync(user); + bool successful = await this._userRepository.EditAsync(updateUserServiceModel.Id, user); if (!successful) throw new InvalidOperationException("Unable to edit user!"); -- cgit v1.2.3 From e01a81954e0fba2c4521e03a76f48a970a87994f Mon Sep 17 00:00:00 2001 From: transtrike Date: Sat, 23 Jan 2021 22:34:43 +0200 Subject: All Post&Comment Implemented; Initializing testing... --- .../Interfaces/Repositories/ICommentRepository.cs | 13 +++ .../Interfaces/Repositories/IPostRepository.cs | 13 +-- src/DevHive.Data/Repositories/CommentRepository.cs | 37 +++++++ src/DevHive.Data/Repositories/PostRepository.cs | 54 +--------- src/DevHive.Services/Interfaces/IPostService.cs | 15 +-- src/DevHive.Services/Services/PostService.cs | 115 +++++++++++++-------- .../Extensions/ConfigureDependencyInjection.cs | 1 + src/DevHive.Web/Controllers/PostController.cs | 102 +++++++++--------- .../Controllers/TechnologyController.cs | 4 +- .../Models/Post/Comment/UpdateCommentWebModel.cs | 4 + .../Models/Post/Post/UpdatePostWebModel.cs | 4 + 11 files changed, 195 insertions(+), 167 deletions(-) create mode 100644 src/DevHive.Data/Interfaces/Repositories/ICommentRepository.cs create mode 100644 src/DevHive.Data/Repositories/CommentRepository.cs (limited to 'src/DevHive.Data/Interfaces/Repositories') diff --git a/src/DevHive.Data/Interfaces/Repositories/ICommentRepository.cs b/src/DevHive.Data/Interfaces/Repositories/ICommentRepository.cs new file mode 100644 index 0000000..b80c5a0 --- /dev/null +++ b/src/DevHive.Data/Interfaces/Repositories/ICommentRepository.cs @@ -0,0 +1,13 @@ +using System; +using System.Threading.Tasks; +using DevHive.Data.Models; +using DevHive.Data.Repositories.Interfaces; + +namespace DevHive.Data.Interfaces.Repositories +{ + public interface ICommentRepository : IRepository + { + Task DoesCommentExist(Guid id); + Task GetCommentByIssuerAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated); + } +} diff --git a/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs index 7a9c02e..aa0afc7 100644 --- a/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs +++ b/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs @@ -7,18 +7,7 @@ namespace DevHive.Data.Interfaces.Repositories { public interface IPostRepository : IRepository { - Task AddCommentAsync(Comment entity); - - Task GetPostByIssuerAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated); - - Task GetCommentByIdAsync(Guid id); - Task GetCommentByIssuerAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated); - - Task EditCommentAsync(Comment newEntity); - - Task DeleteCommentAsync(Comment entity); - Task DoesCommentExist(Guid id); - + Task GetPostByCreatorAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated); Task DoesPostExist(Guid postId); } } diff --git a/src/DevHive.Data/Repositories/CommentRepository.cs b/src/DevHive.Data/Repositories/CommentRepository.cs new file mode 100644 index 0000000..880631a --- /dev/null +++ b/src/DevHive.Data/Repositories/CommentRepository.cs @@ -0,0 +1,37 @@ +using System; +using System.Threading.Tasks; +using DevHive.Data.Interfaces.Repositories; +using DevHive.Data.Models; +using Microsoft.EntityFrameworkCore; + +namespace DevHive.Data.Repositories +{ + public class CommentRepository : BaseRepository, ICommentRepository + { + private readonly DevHiveContext _context; + + public CommentRepository(DevHiveContext context) + : base(context) + { + this._context = context; + } + + #region Read + public async Task GetCommentByIssuerAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated) + { + return await this._context.Comments + .FirstOrDefaultAsync(p => p.IssuerId == issuerId && + p.TimeCreated == timeCreated); + } + #endregion + + #region Validations + public async Task DoesCommentExist(Guid id) + { + return await this._context.Comments + .AsNoTracking() + .AnyAsync(r => r.Id == id); + } + #endregion + } +} diff --git a/src/DevHive.Data/Repositories/PostRepository.cs b/src/DevHive.Data/Repositories/PostRepository.cs index 9230a2e..a79eacf 100644 --- a/src/DevHive.Data/Repositories/PostRepository.cs +++ b/src/DevHive.Data/Repositories/PostRepository.cs @@ -16,56 +16,13 @@ namespace DevHive.Data.Repositories this._context = context; } - #region Create - public async Task AddCommentAsync(Comment entity) - { - await this._context.Comments - .AddAsync(entity); - - return await this.SaveChangesAsync(this._context); - } - #endregion - #region Read - public async Task GetPostByIssuerAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated) + public async Task GetPostByCreatorAndTimeCreatedAsync(Guid creatorId, DateTime timeCreated) { return await this._context.Posts - .FirstOrDefaultAsync(p => p.IssuerId == issuerId && + .FirstOrDefaultAsync(p => p.CreatorId == creatorId && p.TimeCreated == timeCreated); } - - public async Task GetCommentByIdAsync(Guid id) - { - return await this._context.Comments - .FindAsync(id); - } - - public async Task GetCommentByIssuerAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated) - { - return await this._context.Comments - .FirstOrDefaultAsync(p => p.IssuerId == issuerId && - p.TimeCreated == timeCreated); - } - #endregion - - #region Update - public async Task EditCommentAsync(Comment newEntity) - { - this._context.Comments - .Update(newEntity); - - return await this.SaveChangesAsync(this._context); - } - #endregion - - #region Delete - public async Task DeleteCommentAsync(Comment entity) - { - this._context.Comments - .Remove(entity); - - return await this.SaveChangesAsync(this._context); - } #endregion #region Validations @@ -75,13 +32,6 @@ namespace DevHive.Data.Repositories .AsNoTracking() .AnyAsync(r => r.Id == postId); } - - public async Task DoesCommentExist(Guid id) - { - return await this._context.Comments - .AsNoTracking() - .AnyAsync(r => r.Id == id); - } #endregion } } diff --git a/src/DevHive.Services/Interfaces/IPostService.cs b/src/DevHive.Services/Interfaces/IPostService.cs index 4364c67..37c3354 100644 --- a/src/DevHive.Services/Interfaces/IPostService.cs +++ b/src/DevHive.Services/Interfaces/IPostService.cs @@ -7,18 +7,19 @@ namespace DevHive.Services.Interfaces { public interface IPostService { - Task CreatePost(CreatePostServiceModel postServiceModel); - Task AddComment(CreateCommentServiceModel commentServiceModel); + Task CreatePost(CreatePostServiceModel createPostServiceModel); + Task AddComment(CreateCommentServiceModel createPostServiceModel); - Task GetCommentById(Guid id); - Task GetPostById(Guid id); + Task GetPostById(Guid id); + Task GetCommentById(Guid id); - Task UpdateComment(UpdateCommentServiceModel commentServiceModel); - Task UpdatePost(UpdatePostServiceModel postServiceModel); + Task UpdatePost(UpdatePostServiceModel updatePostServiceModel); + Task UpdateComment(UpdateCommentServiceModel updateCommentServiceModel); - Task DeleteComment(Guid id); Task DeletePost(Guid id); + Task DeleteComment(Guid id); + Task ValidateJwtForPost(Guid postId, string rawTokenData); Task ValidateJwtForComment(Guid commentId, string rawTokenData); } } diff --git a/src/DevHive.Services/Services/PostService.cs b/src/DevHive.Services/Services/PostService.cs index 2df3b41..377fe05 100644 --- a/src/DevHive.Services/Services/PostService.cs +++ b/src/DevHive.Services/Services/PostService.cs @@ -15,117 +15,141 @@ namespace DevHive.Services.Services { public class PostService : IPostService { - private readonly IPostRepository _postRepository; private readonly IUserRepository _userRepository; + private readonly IPostRepository _postRepository; + private readonly ICommentRepository _commentRepository; private readonly IMapper _postMapper; - public PostService(IPostRepository postRepository, IUserRepository userRepository, IMapper postMapper) + public PostService(IUserRepository userRepository, IPostRepository postRepository, ICommentRepository commentRepository, IMapper postMapper) { - this._postRepository = postRepository; this._userRepository = userRepository; + this._postRepository = postRepository; + this._commentRepository = commentRepository; this._postMapper = postMapper; } - //Create - public async Task CreatePost(CreatePostServiceModel postServiceModel) + #region Create + public async Task CreatePost(CreatePostServiceModel createPostServiceModel) { - Post post = this._postMapper.Map(postServiceModel); + Post post = this._postMapper.Map(createPostServiceModel); + post.TimeCreated = DateTime.Now; bool success = await this._postRepository.AddAsync(post); - if (success) { - Post newPost = await this._postRepository.GetPostByIssuerAndTimeCreatedAsync(postServiceModel.IssuerId, postServiceModel.TimeCreated); + Post newPost = await this._postRepository + .GetPostByCreatorAndTimeCreatedAsync(createPostServiceModel.IssuerId, createPostServiceModel.TimeCreated); + return newPost.Id; } else return Guid.Empty; } - public async Task AddComment(CreateCommentServiceModel commentServiceModel) + public async Task AddComment(CreateCommentServiceModel createCommentServiceModel) { - commentServiceModel.TimeCreated = DateTime.Now; - Comment comment = this._postMapper.Map(commentServiceModel); + if (!await this._postRepository.DoesPostExist(createCommentServiceModel.PostId)) + throw new ArgumentException("Post does not exist!"); - bool success = await this._postRepository.AddCommentAsync(comment); + Comment comment = this._postMapper.Map(createCommentServiceModel); + createCommentServiceModel.TimeCreated = DateTime.Now; + bool success = await this._commentRepository.AddAsync(comment); if (success) { - Comment newComment = await this._postRepository.GetCommentByIssuerAndTimeCreatedAsync(commentServiceModel.IssuerId, commentServiceModel.TimeCreated); + Comment newComment = await this._commentRepository + .GetCommentByIssuerAndTimeCreatedAsync(createCommentServiceModel.IssuerId, createCommentServiceModel.TimeCreated); + return newComment.Id; } else return Guid.Empty; } + #endregion - //Read - public async Task GetPostById(Guid id) + #region Read + public async Task GetPostById(Guid id) { - Post post = await this._postRepository.GetByIdAsync(id) - ?? throw new ArgumentException("Post does not exist!"); + Post post = await this._postRepository.GetByIdAsync(id) ?? + throw new ArgumentException("The post does not exist!"); - return this._postMapper.Map(post); + return this._postMapper.Map(post); } - public async Task GetCommentById(Guid id) + public async Task GetCommentById(Guid id) { - Comment comment = await this._postRepository.GetCommentByIdAsync(id); - - if (comment == null) + Comment comment = await this._commentRepository.GetByIdAsync(id) ?? throw new ArgumentException("The comment does not exist"); - return this._postMapper.Map(comment); + return this._postMapper.Map(comment); } + #endregion - //Update - public async Task UpdatePost(UpdatePostServiceModel postServiceModel) + #region Update + public async Task UpdatePost(UpdatePostServiceModel updatePostServiceModel) { - if (!await this._postRepository.DoesPostExist(postServiceModel.IssuerId)) - throw new ArgumentException("Comment does not exist!"); + if (!await this._postRepository.DoesPostExist(updatePostServiceModel.PostId)) + throw new ArgumentException("Post does not exist!"); + + Post post = this._postMapper.Map(updatePostServiceModel); + bool result = await this._postRepository.EditAsync(updatePostServiceModel.PostId, post); - Post post = this._postMapper.Map(postServiceModel); - return await this._postRepository.EditAsync(postServiceModel.Id, post); + if (result) + return (await this._postRepository.GetByIdAsync(updatePostServiceModel.PostId)).Id; + else + return Guid.Empty; } - public async Task UpdateComment(UpdateCommentServiceModel commentServiceModel) + public async Task UpdateComment(UpdateCommentServiceModel updateCommentServiceModel) { - if (!await this._postRepository.DoesCommentExist(commentServiceModel.Id)) + if (!await this._commentRepository.DoesCommentExist(updateCommentServiceModel.CommentId)) throw new ArgumentException("Comment does not exist!"); - Comment comment = this._postMapper.Map(commentServiceModel); - bool result = await this._postRepository.EditCommentAsync(comment); + Comment comment = this._postMapper.Map(updateCommentServiceModel); + bool result = await this._commentRepository.EditAsync(updateCommentServiceModel.CommentId, comment); - return result; + if (result) + return (await this._commentRepository.GetByIdAsync(updateCommentServiceModel.CommentId)).Id; + else + return Guid.Empty; } + #endregion - //Delete + #region Delete public async Task DeletePost(Guid id) { + if (!await this._postRepository.DoesPostExist(id)) + throw new ArgumentException("Post does not exist!"); + Post post = await this._postRepository.GetByIdAsync(id); return await this._postRepository.DeleteAsync(post); } public async Task DeleteComment(Guid id) { - if (!await this._postRepository.DoesCommentExist(id)) + if (!await this._commentRepository.DoesCommentExist(id)) throw new ArgumentException("Comment does not exist!"); - Comment comment = await this._postRepository.GetCommentByIdAsync(id); - bool result = await this._postRepository.DeleteCommentAsync(comment); + Comment comment = await this._commentRepository.GetByIdAsync(id); + return await this._commentRepository.DeleteAsync(comment); + } + #endregion - return result; + #region Validations + public async Task ValidateJwtForPost(Guid postId, string rawTokenData) + { + Post post = await this._postRepository.GetByIdAsync(postId); + User user = await this.GetUserForValidation(rawTokenData); + + return post.CreatorId == user.Id; } - //Validate public async Task ValidateJwtForComment(Guid commentId, string rawTokenData) { - Comment comment = await this._postRepository.GetCommentByIdAsync(commentId); + Comment comment = await this._commentRepository.GetByIdAsync(commentId); User user = await this.GetUserForValidation(rawTokenData); - if (comment.IssuerId != user.Id) - return false; - - return true; + return comment.IssuerId == user.Id; } private async Task GetUserForValidation(string rawTokenData) @@ -151,5 +175,6 @@ namespace DevHive.Services.Services return toReturn; } + #endregion } } diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs index f93f801..bcf16ac 100644 --- a/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs +++ b/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs @@ -16,6 +16,7 @@ namespace DevHive.Web.Configurations.Extensions services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/src/DevHive.Web/Controllers/PostController.cs b/src/DevHive.Web/Controllers/PostController.cs index 8b7344b..8b8b525 100644 --- a/src/DevHive.Web/Controllers/PostController.cs +++ b/src/DevHive.Web/Controllers/PostController.cs @@ -13,52 +13,56 @@ namespace DevHive.Web.Controllers { [ApiController] [Route("/api/[controller]")] + // [Authorize(Roles = "User")] public class PostController { private readonly IPostService _postService; private readonly IMapper _postMapper; - public PostController(IPostService postService, IMapper mapper) + public PostController(IPostService postService, IMapper postMapper) { this._postService = postService; - this._postMapper = mapper; + this._postMapper = postMapper; } - //Create + #region Create [HttpPost] - [Authorize(Roles = "User")] - public async Task Create([FromBody] CreatePostWebModel createPostModel) + public async Task Create(Guid userId, [FromBody] CreatePostWebModel createPostWebModel) { - CreatePostServiceModel postServiceModel = - this._postMapper.Map(createPostModel); + CreatePostServiceModel createPostServiceModel = + this._postMapper.Map(createPostWebModel); + createPostServiceModel.IssuerId = userId; - Guid id = await this._postService.CreatePost(postServiceModel); + Guid id = await this._postService.CreatePost(createPostServiceModel); return id == Guid.Empty ? - new BadRequestObjectResult("Could not create post") : + new BadRequestObjectResult("Could not create post!") : new OkObjectResult(new { Id = id }); } [HttpPost] [Route("Comment")] - public async Task AddComment([FromBody] CommentWebModel commentWebModel) + public async Task AddComment(Guid userId, [FromBody] CreateCommentWebModel createCommentWebModel) { - CreateCommentServiceModel createCommentServiceModel = this._postMapper.Map(commentWebModel); + CreateCommentServiceModel createCommentServiceModel = + this._postMapper.Map(createCommentWebModel); + createCommentServiceModel.IssuerId = userId; Guid id = await this._postService.AddComment(createCommentServiceModel); return id == Guid.Empty ? - new BadRequestObjectResult("Could not create comment") : + new BadRequestObjectResult("Could not create comment!") : new OkObjectResult(new { Id = id }); } + #endregion - //Read + #region Read [HttpGet] [AllowAnonymous] public async Task GetById(Guid id) { - PostServiceModel postServiceModel = await this._postService.GetPostById(id); - PostWebModel postWebModel = this._postMapper.Map(postServiceModel); + ReadPostServiceModel postServiceModel = await this._postService.GetPostById(id); + ReadPostWebModel postWebModel = this._postMapper.Map(postServiceModel); return new OkObjectResult(postWebModel); } @@ -68,56 +72,58 @@ namespace DevHive.Web.Controllers [AllowAnonymous] public async Task GetCommentById(Guid id) { - CommentServiceModel commentServiceModel = await this._postService.GetCommentById(id); - CommentWebModel commentWebModel = this._postMapper.Map(commentServiceModel); + ReadCommentServiceModel readCommentServiceModel = await this._postService.GetCommentById(id); + ReadCommentWebModel readCommentWebModel = this._postMapper.Map(readCommentServiceModel); - return new OkObjectResult(commentWebModel); + return new OkObjectResult(readCommentWebModel); } + #endregion - //Update + #region Update [HttpPut] - public async Task Update(Guid id, [FromBody] UpdatePostWebModel updatePostModel) + public async Task Update(Guid userId, [FromBody] UpdatePostWebModel updatePostWebModel, [FromHeader] string authorization) { - UpdatePostServiceModel postServiceModel = - this._postMapper.Map(updatePostModel); - postServiceModel.IssuerId = id; + if (!await this._postService.ValidateJwtForPost(userId, authorization)) + return new UnauthorizedResult(); - bool result = await this._postService.UpdatePost(postServiceModel); + UpdatePostServiceModel updatePostServiceModel = + this._postMapper.Map(updatePostWebModel); - if (!result) - return new BadRequestObjectResult("Could not update post!"); + Guid id = await this._postService.UpdatePost(updatePostServiceModel); - return new OkResult(); + return id == Guid.Empty ? + new BadRequestObjectResult("Unable to update post!") : + new OkObjectResult(new { Id = id }); } [HttpPut] [Route("Comment")] - public async Task UpdateComment(Guid id, [FromBody] CommentWebModel commentWebModel, [FromHeader] string authorization) + public async Task UpdateComment(Guid userId, [FromBody] UpdateCommentWebModel updateCommentWebModel, [FromHeader] string authorization) { - if (!await this._postService.ValidateJwtForComment(id, authorization)) + if (!await this._postService.ValidateJwtForComment(userId, authorization)) return new UnauthorizedResult(); - UpdateCommentServiceModel updateCommentServiceModel = this._postMapper.Map(commentWebModel); - updateCommentServiceModel.Id = id; - - bool result = await this._postService.UpdateComment(updateCommentServiceModel); + UpdateCommentServiceModel updateCommentServiceModel = + this._postMapper.Map(updateCommentWebModel); - if (!result) - return new BadRequestObjectResult("Could not update Comment"); + Guid id = await this._postService.UpdateComment(updateCommentServiceModel); - return new OkResult(); + return id == Guid.Empty ? + new BadRequestObjectResult("Unable to update comment!") : + new OkObjectResult(new { Id = id }); } + #endregion - //Delete + #region Delete [HttpDelete] - public async Task Delete(Guid id) + public async Task Delete(Guid id, [FromHeader] string authorization) { - bool result = await this._postService.DeletePost(id); - - if (!result) - return new BadRequestObjectResult("Could not delete post!"); + if (!await this._postService.ValidateJwtForPost(id, authorization)) + return new UnauthorizedResult(); - return new OkResult(); + return await this._postService.DeletePost(id) ? + new OkResult() : + new BadRequestObjectResult("Could not delete Comment"); } [HttpDelete] @@ -127,12 +133,10 @@ namespace DevHive.Web.Controllers if (!await this._postService.ValidateJwtForComment(id, authorization)) return new UnauthorizedResult(); - bool result = await this._postService.DeleteComment(id); - - if (!result) - return new BadRequestObjectResult("Could not delete Comment"); - - return new OkResult(); + return await this._postService.DeleteComment(id) ? + new OkResult() : + new BadRequestObjectResult("Could not delete Comment"); } + #endregion } } diff --git a/src/DevHive.Web/Controllers/TechnologyController.cs b/src/DevHive.Web/Controllers/TechnologyController.cs index 9c6c094..3d7568b 100644 --- a/src/DevHive.Web/Controllers/TechnologyController.cs +++ b/src/DevHive.Web/Controllers/TechnologyController.cs @@ -17,10 +17,10 @@ namespace DevHive.Web.Controllers private readonly ITechnologyService _technologyService; private readonly IMapper _technologyMapper; - public TechnologyController(ITechnologyService technologyService, IMapper mapper) + public TechnologyController(ITechnologyService technologyService, IMapper technologyMapper) { this._technologyService = technologyService; - this._technologyMapper = mapper; + this._technologyMapper = technologyMapper; } [HttpPost] diff --git a/src/DevHive.Web/Models/Post/Comment/UpdateCommentWebModel.cs b/src/DevHive.Web/Models/Post/Comment/UpdateCommentWebModel.cs index 8e78a48..6dff49e 100644 --- a/src/DevHive.Web/Models/Post/Comment/UpdateCommentWebModel.cs +++ b/src/DevHive.Web/Models/Post/Comment/UpdateCommentWebModel.cs @@ -1,7 +1,11 @@ +using System; + namespace DevHive.Web.Models.Post.Comment { public class UpdateCommentWebModel { + public Guid CommentId { get; set; } + public string NewMessage { get; set; } } } diff --git a/src/DevHive.Web/Models/Post/Post/UpdatePostWebModel.cs b/src/DevHive.Web/Models/Post/Post/UpdatePostWebModel.cs index 5b66436..fe42715 100644 --- a/src/DevHive.Web/Models/Post/Post/UpdatePostWebModel.cs +++ b/src/DevHive.Web/Models/Post/Post/UpdatePostWebModel.cs @@ -6,6 +6,10 @@ namespace DevHive.Web.Models.Post.Post { public class UpdatePostWebModel { + [Required] + [NotNull] + public Guid PostId { get; set; } + [NotNull] [Required] public string Message { get; set; } -- cgit v1.2.3 From d2bc08c0dcd6f0dc0822333bbb00c9fc851f49cb Mon Sep 17 00:00:00 2001 From: transtrike Date: Tue, 26 Jan 2021 10:55:25 +0200 Subject: Brief testing of GetPost --- .../Interfaces/Repositories/IFeedRepository.cs | 12 +++++ src/DevHive.Data/Repositories/FeedRepository.cs | 35 ++++++++++++++ .../Configurations/Mapping/FeedMappings.cs | 11 +++++ .../Configurations/Mapping/PostMappings.cs | 1 + .../Configurations/Mapping/RoleMapings.cs | 4 +- .../Configurations/Mapping/UserMappings.cs | 2 + src/DevHive.Services/Interfaces/IFeedService.cs | 10 ++++ src/DevHive.Services/Interfaces/IRoleService.cs | 2 +- src/DevHive.Services/Interfaces/IUserService.cs | 2 + .../Models/Feed/GetPageServiceModel.cs | 15 ++++++ .../Models/Feed/ReadPageServiceModel.cs | 10 ++++ .../Models/Identity/User/UserServiceModel.cs | 2 +- src/DevHive.Services/Services/FeedService.cs | 47 +++++++++++++++++++ src/DevHive.Services/Services/RoleService.cs | 4 +- src/DevHive.Services/Services/UserService.cs | 53 +++++++++++++++++++--- .../Extensions/ConfigureDependencyInjection.cs | 2 + .../Configurations/Mapping/FeedMappings.cs | 18 ++++++++ .../Configurations/Mapping/RoleMappings.cs | 4 +- .../Configurations/Mapping/UserMappings.cs | 3 ++ src/DevHive.Web/Controllers/FeedController.cs | 36 +++++++++++++++ src/DevHive.Web/Controllers/PostController.cs | 2 +- src/DevHive.Web/Controllers/RoleController.cs | 2 +- src/DevHive.Web/Controllers/UserController.cs | 15 +++++- src/DevHive.Web/Models/Feed/GetPageWebModel.cs | 19 ++++++++ src/DevHive.Web/Models/Feed/ReadPageWebModel.cs | 10 ++++ 25 files changed, 303 insertions(+), 18 deletions(-) create mode 100644 src/DevHive.Data/Interfaces/Repositories/IFeedRepository.cs create mode 100644 src/DevHive.Data/Repositories/FeedRepository.cs create mode 100644 src/DevHive.Services/Configurations/Mapping/FeedMappings.cs create mode 100644 src/DevHive.Services/Interfaces/IFeedService.cs create mode 100644 src/DevHive.Services/Models/Feed/GetPageServiceModel.cs create mode 100644 src/DevHive.Services/Models/Feed/ReadPageServiceModel.cs create mode 100644 src/DevHive.Services/Services/FeedService.cs create mode 100644 src/DevHive.Web/Configurations/Mapping/FeedMappings.cs create mode 100644 src/DevHive.Web/Controllers/FeedController.cs create mode 100644 src/DevHive.Web/Models/Feed/GetPageWebModel.cs create mode 100644 src/DevHive.Web/Models/Feed/ReadPageWebModel.cs (limited to 'src/DevHive.Data/Interfaces/Repositories') diff --git a/src/DevHive.Data/Interfaces/Repositories/IFeedRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IFeedRepository.cs new file mode 100644 index 0000000..e9fd48a --- /dev/null +++ b/src/DevHive.Data/Interfaces/Repositories/IFeedRepository.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using DevHive.Data.Models; + +namespace DevHive.Data.Interfaces.Repositories +{ + public interface IFeedRepository + { + Task> GetFriendsPosts(List friendsList, DateTime firstRequestIssued, int pageNumber, int pageSize); + } +} diff --git a/src/DevHive.Data/Repositories/FeedRepository.cs b/src/DevHive.Data/Repositories/FeedRepository.cs new file mode 100644 index 0000000..8bf1f9a --- /dev/null +++ b/src/DevHive.Data/Repositories/FeedRepository.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using AutoMapper.Internal; +using DevHive.Data.Interfaces.Repositories; +using DevHive.Data.Models; +using Microsoft.EntityFrameworkCore; + +namespace DevHive.Data.Repositories +{ + public class FeedRepository : IFeedRepository + { + private readonly DevHiveContext _context; + + public FeedRepository(DevHiveContext context) + { + this._context = context; + } + public async Task> GetFriendsPosts(List friendsList, DateTime firstRequestIssued, int pageNumber, int pageSize) + { + List friendsIds = friendsList.Select(f => f.Id).ToList(); + + List posts = await this._context.Posts + .Where(post => post.TimeCreated < firstRequestIssued) + .Where(p => friendsIds.Contains(p.CreatorId)) + .OrderByDescending(x => x.TimeCreated) + .Skip((pageNumber - 1) * pageSize) + .Take(pageSize) + .ToListAsync(); + + return posts; + } + } +} diff --git a/src/DevHive.Services/Configurations/Mapping/FeedMappings.cs b/src/DevHive.Services/Configurations/Mapping/FeedMappings.cs new file mode 100644 index 0000000..952e480 --- /dev/null +++ b/src/DevHive.Services/Configurations/Mapping/FeedMappings.cs @@ -0,0 +1,11 @@ +using AutoMapper; + +namespace DevHive.Services.Configurations.Mapping +{ + public class FeedMappings : Profile + { + public FeedMappings() + { + } + } +} diff --git a/src/DevHive.Services/Configurations/Mapping/PostMappings.cs b/src/DevHive.Services/Configurations/Mapping/PostMappings.cs index cea7b1c..d8dcc84 100644 --- a/src/DevHive.Services/Configurations/Mapping/PostMappings.cs +++ b/src/DevHive.Services/Configurations/Mapping/PostMappings.cs @@ -20,6 +20,7 @@ namespace DevHive.Services.Configurations.Mapping .ForMember(dest => dest.CreatorFirstName, src => src.Ignore()) .ForMember(dest => dest.CreatorLastName, src => src.Ignore()) .ForMember(dest => dest.CreatorUsername, src => src.Ignore()); + //TODO: Map those here /\ } } } diff --git a/src/DevHive.Services/Configurations/Mapping/RoleMapings.cs b/src/DevHive.Services/Configurations/Mapping/RoleMapings.cs index e61a107..23bd46f 100644 --- a/src/DevHive.Services/Configurations/Mapping/RoleMapings.cs +++ b/src/DevHive.Services/Configurations/Mapping/RoleMapings.cs @@ -9,10 +9,10 @@ namespace DevHive.Services.Configurations.Mapping public RoleMappings() { CreateMap(); - CreateMap(); + CreateMap(); CreateMap(); - CreateMap(); + CreateMap(); CreateMap(); } } diff --git a/src/DevHive.Services/Configurations/Mapping/UserMappings.cs b/src/DevHive.Services/Configurations/Mapping/UserMappings.cs index 5d9e41c..6797ce1 100644 --- a/src/DevHive.Services/Configurations/Mapping/UserMappings.cs +++ b/src/DevHive.Services/Configurations/Mapping/UserMappings.cs @@ -14,6 +14,8 @@ namespace DevHive.Services.Configurations.Mapping CreateMap() .AfterMap((src, dest) => dest.PasswordHash = PasswordModifications.GeneratePasswordHash(src.Password)); CreateMap(); + CreateMap() + .ForMember(dest => dest.UserName, src => src.MapFrom(p => p.Name)); CreateMap(); CreateMap() diff --git a/src/DevHive.Services/Interfaces/IFeedService.cs b/src/DevHive.Services/Interfaces/IFeedService.cs new file mode 100644 index 0000000..1edba5a --- /dev/null +++ b/src/DevHive.Services/Interfaces/IFeedService.cs @@ -0,0 +1,10 @@ +using System.Threading.Tasks; +using DevHive.Services.Models; + +namespace DevHive.Services.Interfaces +{ + public interface IFeedService + { + Task GetPage(GetPageServiceModel getPageServiceModel); + } +} diff --git a/src/DevHive.Services/Interfaces/IRoleService.cs b/src/DevHive.Services/Interfaces/IRoleService.cs index d47728c..d3a45e5 100644 --- a/src/DevHive.Services/Interfaces/IRoleService.cs +++ b/src/DevHive.Services/Interfaces/IRoleService.cs @@ -8,7 +8,7 @@ namespace DevHive.Services.Interfaces { Task CreateRole(CreateRoleServiceModel roleServiceModel); - Task GetRoleById(Guid id); + Task GetRoleById(Guid id); Task UpdateRole(UpdateRoleServiceModel roleServiceModel); diff --git a/src/DevHive.Services/Interfaces/IUserService.cs b/src/DevHive.Services/Interfaces/IUserService.cs index 51e3cf9..9372517 100644 --- a/src/DevHive.Services/Interfaces/IUserService.cs +++ b/src/DevHive.Services/Interfaces/IUserService.cs @@ -18,5 +18,7 @@ namespace DevHive.Services.Interfaces Task DeleteUser(Guid id); Task ValidJWT(Guid id, string rawTokenData); + + Task SuperSecretPromotionToAdmin(Guid userId); } } diff --git a/src/DevHive.Services/Models/Feed/GetPageServiceModel.cs b/src/DevHive.Services/Models/Feed/GetPageServiceModel.cs new file mode 100644 index 0000000..745039f --- /dev/null +++ b/src/DevHive.Services/Models/Feed/GetPageServiceModel.cs @@ -0,0 +1,15 @@ +using System; + +namespace DevHive.Services.Models +{ + public class GetPageServiceModel + { + public Guid UserId { get; set; } + + public int PageNumber { get; set; } + + public DateTime FirstRequestIssued { get; set; } + + public int PageSize { get; set; } + } +} diff --git a/src/DevHive.Services/Models/Feed/ReadPageServiceModel.cs b/src/DevHive.Services/Models/Feed/ReadPageServiceModel.cs new file mode 100644 index 0000000..f291de7 --- /dev/null +++ b/src/DevHive.Services/Models/Feed/ReadPageServiceModel.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; +using DevHive.Services.Models.Post.Post; + +namespace DevHive.Services.Models +{ + public class ReadPageServiceModel + { + public List Posts { get; set; } = new(); + } +} diff --git a/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs b/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs index 3aa0d44..3e41057 100644 --- a/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs +++ b/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs @@ -7,7 +7,7 @@ namespace DevHive.Services.Models.Identity.User { public class UserServiceModel : BaseUserServiceModel { - public HashSet Roles { get; set; } = new HashSet(); + public HashSet Roles { get; set; } = new HashSet(); public HashSet Friends { get; set; } = new HashSet(); diff --git a/src/DevHive.Services/Services/FeedService.cs b/src/DevHive.Services/Services/FeedService.cs new file mode 100644 index 0000000..cae986f --- /dev/null +++ b/src/DevHive.Services/Services/FeedService.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using AutoMapper; +using DevHive.Data.Interfaces.Repositories; +using DevHive.Data.Models; +using DevHive.Services.Interfaces; +using DevHive.Services.Models; +using DevHive.Services.Models.Post.Post; + +namespace DevHive.Services.Services +{ + public class FeedService : IFeedService + { + private readonly IMapper _mapper; + private readonly IFeedRepository _feedRepository; + private readonly IUserRepository _userRepository; + + public FeedService(IFeedRepository feedRepository, IUserRepository userRepository, IMapper mapper) + { + this._feedRepository = feedRepository; + this._userRepository = userRepository; + this._mapper = mapper; + } + + public async Task GetPage(GetPageServiceModel model) + { + User user = await this._userRepository.GetByIdAsync(model.UserId) ?? + throw new ArgumentException("User doesn't exist!"); + + List friendsList = user.Friends.ToList(); + // if(friendsList.Count == 0) + // throw new ArgumentException("This user does not have any friends!"); + + List posts = await this._feedRepository + .GetFriendsPosts(friendsList, model.FirstRequestIssued, model.PageNumber, model.PageSize) ?? + throw new ArgumentException("No posts to query."); + + ReadPageServiceModel readPageServiceModel = new(); + foreach (Post post in posts) + readPageServiceModel.Posts.Add(this._mapper.Map(post)); + + return readPageServiceModel; + } + } +} diff --git a/src/DevHive.Services/Services/RoleService.cs b/src/DevHive.Services/Services/RoleService.cs index a8b8e17..9f7a5ac 100644 --- a/src/DevHive.Services/Services/RoleService.cs +++ b/src/DevHive.Services/Services/RoleService.cs @@ -38,12 +38,12 @@ namespace DevHive.Services.Services } - public async Task GetRoleById(Guid id) + public async Task GetRoleById(Guid id) { Role role = await this._roleRepository.GetByIdAsync(id) ?? throw new ArgumentException("Role does not exist!"); - return this._roleMapper.Map(role); + return this._roleMapper.Map(role); } public async Task UpdateRole(UpdateRoleServiceModel updateRoleServiceModel) diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs index d7013e1..1beb07f 100644 --- a/src/DevHive.Services/Services/UserService.cs +++ b/src/DevHive.Services/Services/UserService.cs @@ -111,7 +111,7 @@ namespace DevHive.Services.Services await this.ValidateUserCollections(updateUserServiceModel); - //Preserve roles + /* Roles */ int roleCount = updateUserServiceModel.Roles.Count; for (int i = 0; i < roleCount; i++) { @@ -123,6 +123,7 @@ namespace DevHive.Services.Services updateUserServiceModel.Roles.Add(updateRoleServiceModel); } + /* Languages */ int langCount = updateUserServiceModel.Languages.Count; for (int i = 0; i < langCount; i++) { @@ -133,10 +134,10 @@ namespace DevHive.Services.Services updateUserServiceModel.Languages.Add(updateLanguageServiceModel); } - //Clean the already replaced languages updateUserServiceModel.Languages.RemoveWhere(x => x.Id == Guid.Empty); + /* Technologies */ int techCount = updateUserServiceModel.Technologies.Count; for (int i = 0; i < techCount; i++) { @@ -147,11 +148,25 @@ namespace DevHive.Services.Services updateUserServiceModel.Technologies.Add(updateTechnologyServiceModel); } - //Clean the already replaced technologies updateUserServiceModel.Technologies.RemoveWhere(x => x.Id == Guid.Empty); + /* Friends */ + HashSet friends = new(); + int friendsCount = updateUserServiceModel.Friends.Count; + for (int i = 0; i < friendsCount; i++) + { + User friend = await this._userRepository.GetByUsernameAsync(updateUserServiceModel.Friends.ElementAt(i).Name) ?? + throw new ArgumentException("Invalid friend's username!"); + + friends.Add(friend); + } + //Clean the already replaced technologies + updateUserServiceModel.Friends.RemoveWhere(x => x.Id == Guid.Empty); + User user = this._userMapper.Map(updateUserServiceModel); + user.Friends = friends; + bool successful = await this._userRepository.EditAsync(updateUserServiceModel.Id, user); if (!successful) @@ -189,14 +204,14 @@ namespace DevHive.Services.Services /* Check if user is trying to do something to himself, unless he's an admin */ - if (!jwtRoleNames.Contains(Role.AdminRole)) - if (user.Id != id) - return false; - /* Check roles */ if (jwtRoleNames.Contains(Role.AdminRole)) return true; + if (!jwtRoleNames.Contains(Role.AdminRole)) + if (user.Id != id) + return false; + // Check if jwt contains all user roles (if it doesn't, jwt is either old or tampered with) foreach (var role in user.Roles) { @@ -290,5 +305,29 @@ namespace DevHive.Services.Services return tokenHandler.WriteToken(token); } #endregion + + public async Task SuperSecretPromotionToAdmin(Guid userId) + { + User user = await this._userRepository.GetByIdAsync(userId) ?? + throw new ArgumentException("User does not exist! Can't promote shit in this country..."); + + if(!await this._roleRepository.DoesNameExist("Admin")) + { + Role adminRole = new() + { + Name = Role.AdminRole + }; + adminRole.Users.Add(user); + + await this._roleRepository.AddAsync(adminRole); + } + + Role admin = await this._roleRepository.GetByNameAsync(Role.AdminRole); + + user.Roles.Add(admin); + await this._userRepository.EditAsync(user.Id, user); + + return admin.Id; + } } } diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs index bcf16ac..d7c859e 100644 --- a/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs +++ b/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs @@ -17,12 +17,14 @@ namespace DevHive.Web.Configurations.Extensions services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } diff --git a/src/DevHive.Web/Configurations/Mapping/FeedMappings.cs b/src/DevHive.Web/Configurations/Mapping/FeedMappings.cs new file mode 100644 index 0000000..159582d --- /dev/null +++ b/src/DevHive.Web/Configurations/Mapping/FeedMappings.cs @@ -0,0 +1,18 @@ +using AutoMapper; +using DevHive.Services.Models; +using DevHive.Web.Controllers; +using DevHive.Web.Models.Feed; + +namespace DevHive.Web.Configurations.Mapping +{ + public class FeedMappings : Profile + { + public FeedMappings() + { + CreateMap() + .ForMember(dest => dest.FirstRequestIssued, src => src.MapFrom(p => p.FirstPageTimeIssued)); + + CreateMap(); + } + } +} diff --git a/src/DevHive.Web/Configurations/Mapping/RoleMappings.cs b/src/DevHive.Web/Configurations/Mapping/RoleMappings.cs index 2ea2742..2f01f77 100644 --- a/src/DevHive.Web/Configurations/Mapping/RoleMappings.cs +++ b/src/DevHive.Web/Configurations/Mapping/RoleMappings.cs @@ -11,11 +11,11 @@ namespace DevHive.Web.Configurations.Mapping CreateMap(); CreateMap() .ForMember(src => src.Id, dest => dest.Ignore()); - CreateMap(); + CreateMap(); CreateMap(); CreateMap(); - CreateMap(); + CreateMap(); } } } diff --git a/src/DevHive.Web/Configurations/Mapping/UserMappings.cs b/src/DevHive.Web/Configurations/Mapping/UserMappings.cs index 9dbf613..e80a69a 100644 --- a/src/DevHive.Web/Configurations/Mapping/UserMappings.cs +++ b/src/DevHive.Web/Configurations/Mapping/UserMappings.cs @@ -25,6 +25,9 @@ namespace DevHive.Web.Configurations.Mapping .ForMember(src => src.Id, dest => dest.Ignore()); CreateMap() .ForMember(src => src.Id, dest => dest.Ignore()); + CreateMap() + .ForMember(src => src.Id, dest => dest.Ignore()) + .ForMember(src => src.Name, dest => dest.MapFrom(p => p.UserName)); CreateMap(); CreateMap(); diff --git a/src/DevHive.Web/Controllers/FeedController.cs b/src/DevHive.Web/Controllers/FeedController.cs new file mode 100644 index 0000000..7d0269b --- /dev/null +++ b/src/DevHive.Web/Controllers/FeedController.cs @@ -0,0 +1,36 @@ +using System; +using System.Threading.Tasks; +using AutoMapper; +using DevHive.Services.Interfaces; +using DevHive.Services.Models; +using DevHive.Web.Models.Feed; +using Microsoft.AspNetCore.Mvc; + +namespace DevHive.Web.Controllers +{ + [ApiController] + [Route("/api/[controller]")] + public class FeedController + { + private readonly IFeedService _feedService; + private readonly IMapper _mapper; + + public FeedController(IFeedService feedService, IMapper mapper) + { + this._feedService = feedService; + this._mapper = mapper; + } + + [HttpGet] + public async Task GetPosts(Guid userId, [FromBody] GetPageWebModel getPageWebModel) + { + GetPageServiceModel getPageServiceModel = this._mapper.Map(getPageWebModel); + getPageServiceModel.UserId = userId; + + ReadPageServiceModel readPageServiceModel = await this._feedService.GetPage(getPageServiceModel); + ReadPageWebModel readPageWebModel = this._mapper.Map(readPageServiceModel); + + return new OkObjectResult(readPageWebModel); + } + } +} diff --git a/src/DevHive.Web/Controllers/PostController.cs b/src/DevHive.Web/Controllers/PostController.cs index b5e1c98..151c688 100644 --- a/src/DevHive.Web/Controllers/PostController.cs +++ b/src/DevHive.Web/Controllers/PostController.cs @@ -13,7 +13,7 @@ namespace DevHive.Web.Controllers { [ApiController] [Route("/api/[controller]")] - // [Authorize(Roles = "User")] + [Authorize(Roles = "User,Admin")] public class PostController { private readonly IPostService _postService; diff --git a/src/DevHive.Web/Controllers/RoleController.cs b/src/DevHive.Web/Controllers/RoleController.cs index c68a32b..d8bb60c 100644 --- a/src/DevHive.Web/Controllers/RoleController.cs +++ b/src/DevHive.Web/Controllers/RoleController.cs @@ -40,7 +40,7 @@ namespace DevHive.Web.Controllers [Authorize(Policy = "User")] public async Task GetById(Guid id) { - RoleServiceModel roleServiceModel = await this._roleService.GetRoleById(id); + ReadRoleServiceModel roleServiceModel = await this._roleService.GetRoleById(id); RoleWebModel roleWebModel = this._roleMapper.Map(roleServiceModel); return new OkObjectResult(roleWebModel); diff --git a/src/DevHive.Web/Controllers/UserController.cs b/src/DevHive.Web/Controllers/UserController.cs index dd94089..e409eea 100644 --- a/src/DevHive.Web/Controllers/UserController.cs +++ b/src/DevHive.Web/Controllers/UserController.cs @@ -12,7 +12,7 @@ namespace DevHive.Web.Controllers { [ApiController] [Route("/api/[controller]")] - [Authorize(Policy = "User")] + [Authorize(Roles = "User,Admin")] public class UserController : ControllerBase { private readonly IUserService _userService; @@ -104,5 +104,18 @@ namespace DevHive.Web.Controllers return new OkResult(); } #endregion + + [HttpPost] + [Route("SuperSecretPromotionToAdmin")] + public async Task SuperSecretPromotionToAdmin(Guid userId) + { + object obj = new + { + UserId = userId, + AdminRoleId = await this._userService.SuperSecretPromotionToAdmin(userId) + }; + + return new OkObjectResult(obj); + } } } diff --git a/src/DevHive.Web/Models/Feed/GetPageWebModel.cs b/src/DevHive.Web/Models/Feed/GetPageWebModel.cs new file mode 100644 index 0000000..4ea44cc --- /dev/null +++ b/src/DevHive.Web/Models/Feed/GetPageWebModel.cs @@ -0,0 +1,19 @@ +using System; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace DevHive.Web.Models.Feed +{ + public class GetPageWebModel + { + [Range(1, int.MaxValue)] + public int PageNumber { get; set; } + + [Required] + public DateTime FirstPageTimeIssued { get; set; } + + [DefaultValue(5)] + [Range(1, int.MaxValue)] + public int PageSize { get; set; } + } +} diff --git a/src/DevHive.Web/Models/Feed/ReadPageWebModel.cs b/src/DevHive.Web/Models/Feed/ReadPageWebModel.cs new file mode 100644 index 0000000..40d29c9 --- /dev/null +++ b/src/DevHive.Web/Models/Feed/ReadPageWebModel.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; +using DevHive.Web.Models.Post.Post; + +namespace DevHive.Web.Controllers +{ + public class ReadPageWebModel + { + public List Posts { get; set; } = new(); + } +} -- cgit v1.2.3 From f1515439c5fd26a96817723db5d48b77baa82fb6 Mon Sep 17 00:00:00 2001 From: transtrike Date: Tue, 26 Jan 2021 14:38:21 +0200 Subject: Working on Update User; Currently not updating user in UserRepo --- .../Interfaces/Repositories/IUserRepository.cs | 9 +--- src/DevHive.Data/Repositories/UserRepository.cs | 54 ++++++++----------- src/DevHive.Services/Services/UserService.cs | 62 ++++++++++++---------- 3 files changed, 57 insertions(+), 68 deletions(-) (limited to 'src/DevHive.Data/Interfaces/Repositories') diff --git a/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs index c29669d..4346e9c 100644 --- a/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs +++ b/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs @@ -10,20 +10,13 @@ namespace DevHive.Data.Interfaces.Repositories { //Read Task GetByUsernameAsync(string username); - Language GetUserLanguage(User user, Language language); - HashSet GetUserLanguages(User user); - HashSet GetUserTechnologies(User user); - Technology GetUserTechnology(User user, Technology technology); IEnumerable QueryAll(); //Validations 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); + Task DoesUsernameExistAsync(string username); } } diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs index a2298db..d319ce7 100644 --- a/src/DevHive.Data/Repositories/UserRepository.cs +++ b/src/DevHive.Data/Repositories/UserRepository.cs @@ -8,7 +8,20 @@ using Microsoft.EntityFrameworkCore; namespace DevHive.Data.Repositories { - public class UserRepository : BaseRepository, IUserRepository + public interface IUserRepository + { + Task DoesEmailExistAsync(string email); + Task DoesUserExistAsync(Guid id); + Task DoesUserHaveThisFriendAsync(Guid userId, Guid friendId); + bool DoesUserHaveThisUsername(Guid id, string username); + Task DoesUsernameExistAsync(string username); + Task EditAsync(Guid id, User newEntity); + Task GetByIdAsync(Guid id); + Task GetByUsernameAsync(string username); + IEnumerable QueryAll(); + } + + public class UserRepository : BaseRepository, IUserRepository, IUserRepository { private readonly DevHiveContext _context; @@ -48,27 +61,17 @@ namespace DevHive.Data.Repositories .Include(x => x.Technologies) .FirstOrDefaultAsync(x => x.UserName == username); } + #endregion - public HashSet GetUserLanguages(User user) - { - return user.Languages; - } - - public Language GetUserLanguage(User user, Language language) + #region Update + public override async Task EditAsync(Guid id, User newEntity) { - return user.Languages - .FirstOrDefault(x => x.Id == language.Id); - } + User user = await GetByIdAsync(id); - public HashSet GetUserTechnologies(User user) - { - return user.Technologies; - } + this._context.Update(user); + user = newEntity; - public Technology GetUserTechnology(User user, Technology technology) - { - return user.Technologies - .FirstOrDefault(x => x.Id == technology.Id); + return await this.SaveChangesAsync(this._context); } #endregion @@ -113,21 +116,6 @@ namespace DevHive.Data.Repositories .Any(x => x.Id == id && x.UserName == username); } - - public bool DoesUserHaveFriends(User user) - { - return user.Friends.Count >= 1; - } - - public bool DoesUserHaveThisLanguage(User user, Language language) - { - return user.Languages.Contains(language); - } - - public bool DoesUserHaveThisTechnology(User user, Technology technology) - { - return user.Technologies.Contains(technology); - } #endregion } } diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs index 960630e..0e3bf72 100644 --- a/src/DevHive.Services/Services/UserService.cs +++ b/src/DevHive.Services/Services/UserService.cs @@ -111,9 +111,7 @@ namespace DevHive.Services.Services await this.ValidateUserCollections(updateUserServiceModel); - updateUserServiceModel = await this.PopulateUpdateModelWithIds(updateUserServiceModel); - - User user = this._userMapper.Map(updateUserServiceModel); + User user = await this.PopulateModel(updateUserServiceModel); bool successful = await this._userRepository.EditAsync(updateUserServiceModel.Id, user); @@ -298,49 +296,59 @@ namespace DevHive.Services.Services return admin.Id; } - private async Task PopulateUpdateModelWithIds(UpdateUserServiceModel updateUserServiceModel) + private async Task PopulateModel(UpdateUserServiceModel updateUserServiceModel) { - /* Roles */ - int roleCount = updateUserServiceModel.Roles.Count; - for (int i = 0; i < roleCount; i++) + User user = this._userMapper.Map(updateUserServiceModel); + + /* Fetch Roles and replace model's*/ + HashSet roles = new(); + int rolesCount = updateUserServiceModel.Roles.Count; + for (int i = 0; i < rolesCount; i++) { Role role = await this._roleRepository.GetByNameAsync(updateUserServiceModel.Roles.ElementAt(i).Name) ?? throw new ArgumentException("Invalid role name!"); - updateUserServiceModel.Roles.ElementAt(i).Id = role.Id; + roles.Add(role); } + user.Roles = roles; - /* Languages */ - int langCount = updateUserServiceModel.Languages.Count; - for (int i = 0; i < langCount; i++) + /* Fetch Friends and replace model's*/ + HashSet friends = new(); + int friendsCount = updateUserServiceModel.Friends.Count; + for (int i = 0; i < friendsCount; i++) { - Language language = await this._languageRepository.GetByNameAsync(updateUserServiceModel.Languages.ElementAt(i).Name) ?? - throw new ArgumentException("Invalid language name!"); + User friend = await this._userRepository.GetByUsernameAsync(updateUserServiceModel.Friends.ElementAt(i).UserName) ?? + throw new ArgumentException("Invalid friend's username!"); - updateUserServiceModel.Languages.ElementAt(i).Id = language.Id; + friends.Add(friend); } + user.Friends = friends; - /* Technologies */ - int techCount = updateUserServiceModel.Technologies.Count; - for (int i = 0; i < techCount; i++) + /* Fetch Languages and replace model's*/ + HashSet languages = new(); + int languagesCount = updateUserServiceModel.Languages.Count; + for (int i = 0; i < languagesCount; i++) { - Technology technology = await this._technologyRepository.GetByNameAsync(updateUserServiceModel.Technologies.ElementAt(i).Name) ?? - throw new ArgumentException("Invalid technology name!"); + Language language = await this._languageRepository.GetByNameAsync(updateUserServiceModel.Languages.ElementAt(i).Name) ?? + throw new ArgumentException("Invalid language name!"); - updateUserServiceModel.Technologies.ElementAt(i).Id = technology.Id; + languages.Add(language); } + user.Languages = languages; - /* Friends */ - int friendsCount = updateUserServiceModel.Friends.Count; - for (int i = 0; i < friendsCount; i++) + /* Fetch Technologies and replace model's*/ + HashSet technologies = new(); + int technologiesCount = updateUserServiceModel.Technologies.Count; + for (int i = 0; i < technologiesCount; i++) { - User friend = await this._userRepository.GetByUsernameAsync(updateUserServiceModel.Friends.ElementAt(i).UserName) ?? - throw new ArgumentException("Invalid friend's username!"); + Technology technology = await this._technologyRepository.GetByNameAsync(updateUserServiceModel.Technologies.ElementAt(i).Name) ?? + throw new ArgumentException("Invalid technology name!"); - updateUserServiceModel.Friends.ElementAt(i).Id = friend.Id; + technologies.Add(technology); } + user.Technologies = technologies; - return updateUserServiceModel; + return user; } #endregion } -- cgit v1.2.3 From bddc0b0566bc19e936ccae9d3aa16b6e0116b186 Mon Sep 17 00:00:00 2001 From: transtrike Date: Tue, 26 Jan 2021 15:38:40 +0200 Subject: GetLanguages&GetTechnologies implmenented --- .../Interfaces/Repositories/ILanguageRepository.cs | 5 ++++- .../Interfaces/Repositories/ITechnologyRepository.cs | 5 ++++- src/DevHive.Data/Repositories/LanguageRepository.cs | 7 +++++++ src/DevHive.Data/Repositories/TechnologyRepository.cs | 7 +++++++ .../Configurations/Mapping/TechnologyMappings.cs | 1 + src/DevHive.Services/Interfaces/ILanguageService.cs | 2 ++ src/DevHive.Services/Interfaces/ITechnologyService.cs | 2 ++ src/DevHive.Services/Services/LanguageService.cs | 12 ++++++++---- src/DevHive.Services/Services/TechnologyService.cs | 7 +++++++ src/DevHive.Web/Controllers/LanguageController.cs | 12 ++++++++++++ src/DevHive.Web/Controllers/TechnologyController.cs | 12 ++++++++++++ 11 files changed, 66 insertions(+), 6 deletions(-) (limited to 'src/DevHive.Data/Interfaces/Repositories') diff --git a/src/DevHive.Data/Interfaces/Repositories/ILanguageRepository.cs b/src/DevHive.Data/Interfaces/Repositories/ILanguageRepository.cs index f1d7248..db2949a 100644 --- a/src/DevHive.Data/Interfaces/Repositories/ILanguageRepository.cs +++ b/src/DevHive.Data/Interfaces/Repositories/ILanguageRepository.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using DevHive.Data.Models; using DevHive.Data.Repositories.Interfaces; @@ -7,8 +8,10 @@ namespace DevHive.Data.Interfaces.Repositories { public interface ILanguageRepository : IRepository { + HashSet GetLanguages(); + Task GetByNameAsync(string name); + Task DoesLanguageExistAsync(Guid id); Task DoesLanguageNameExistAsync(string languageName); - Task GetByNameAsync(string name); } } diff --git a/src/DevHive.Data/Interfaces/Repositories/ITechnologyRepository.cs b/src/DevHive.Data/Interfaces/Repositories/ITechnologyRepository.cs index fb0ba20..9126bfc 100644 --- a/src/DevHive.Data/Interfaces/Repositories/ITechnologyRepository.cs +++ b/src/DevHive.Data/Interfaces/Repositories/ITechnologyRepository.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using DevHive.Data.Models; using DevHive.Data.Repositories.Interfaces; @@ -7,8 +8,10 @@ namespace DevHive.Data.Interfaces.Repositories { public interface ITechnologyRepository : IRepository { + Task GetByNameAsync(string name); + HashSet GetTechnologies(); + Task DoesTechnologyExistAsync(Guid id); Task DoesTechnologyNameExistAsync(string technologyName); - Task GetByNameAsync(string name); } } diff --git a/src/DevHive.Data/Repositories/LanguageRepository.cs b/src/DevHive.Data/Repositories/LanguageRepository.cs index c28ef31..f2cc67f 100644 --- a/src/DevHive.Data/Repositories/LanguageRepository.cs +++ b/src/DevHive.Data/Repositories/LanguageRepository.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; @@ -23,6 +25,11 @@ namespace DevHive.Data.Repositories .AsNoTracking() .FirstOrDefaultAsync(x => x.Name == languageName); } + + public HashSet GetLanguages() + { + return this._context.Languages.ToHashSet(); + } #endregion #region Validations diff --git a/src/DevHive.Data/Repositories/TechnologyRepository.cs b/src/DevHive.Data/Repositories/TechnologyRepository.cs index 87540fb..e03291d 100644 --- a/src/DevHive.Data/Repositories/TechnologyRepository.cs +++ b/src/DevHive.Data/Repositories/TechnologyRepository.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; @@ -23,6 +25,11 @@ namespace DevHive.Data.Repositories .AsNoTracking() .FirstOrDefaultAsync(x => x.Name == technologyName); } + + public HashSet GetTechnologies() + { + return this._context.Technologies.ToHashSet(); + } #endregion #region Validations diff --git a/src/DevHive.Services/Configurations/Mapping/TechnologyMappings.cs b/src/DevHive.Services/Configurations/Mapping/TechnologyMappings.cs index 0103ccf..85b57f1 100644 --- a/src/DevHive.Services/Configurations/Mapping/TechnologyMappings.cs +++ b/src/DevHive.Services/Configurations/Mapping/TechnologyMappings.cs @@ -14,6 +14,7 @@ namespace DevHive.Services.Configurations.Mapping CreateMap(); CreateMap(); + CreateMap(); CreateMap(); } } diff --git a/src/DevHive.Services/Interfaces/ILanguageService.cs b/src/DevHive.Services/Interfaces/ILanguageService.cs index 0df9a95..fabbec2 100644 --- a/src/DevHive.Services/Interfaces/ILanguageService.cs +++ b/src/DevHive.Services/Interfaces/ILanguageService.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using DevHive.Services.Models.Language; @@ -9,6 +10,7 @@ namespace DevHive.Services.Interfaces Task CreateLanguage(CreateLanguageServiceModel createLanguageServiceModel); Task GetLanguageById(Guid id); + HashSet GetLanguages(); Task UpdateLanguage(UpdateLanguageServiceModel languageServiceModel); diff --git a/src/DevHive.Services/Interfaces/ITechnologyService.cs b/src/DevHive.Services/Interfaces/ITechnologyService.cs index 9c5661d..1d4fa8b 100644 --- a/src/DevHive.Services/Interfaces/ITechnologyService.cs +++ b/src/DevHive.Services/Interfaces/ITechnologyService.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using DevHive.Services.Models.Technology; @@ -9,6 +10,7 @@ namespace DevHive.Services.Interfaces Task Create(CreateTechnologyServiceModel technologyServiceModel); Task GetTechnologyById(Guid id); + HashSet GetTechnologies(); Task UpdateTechnology(UpdateTechnologyServiceModel updateTechnologyServiceModel); diff --git a/src/DevHive.Services/Services/LanguageService.cs b/src/DevHive.Services/Services/LanguageService.cs index a602d43..a6364d8 100644 --- a/src/DevHive.Services/Services/LanguageService.cs +++ b/src/DevHive.Services/Services/LanguageService.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using AutoMapper; using DevHive.Data.Interfaces.Repositories; @@ -20,7 +21,6 @@ namespace DevHive.Services.Services } #region Create - public async Task CreateLanguage(CreateLanguageServiceModel createLanguageServiceModel) { if (await this._languageRepository.DoesLanguageNameExistAsync(createLanguageServiceModel.Name)) @@ -40,7 +40,6 @@ namespace DevHive.Services.Services #endregion #region Read - public async Task GetLanguageById(Guid id) { Language language = await this._languageRepository.GetByIdAsync(id); @@ -50,10 +49,16 @@ namespace DevHive.Services.Services return this._languageMapper.Map(language); } + + public HashSet GetLanguages() + { + HashSet languages = this._languageRepository.GetLanguages(); + + return this._languageMapper.Map>(languages); + } #endregion #region Update - public async Task UpdateLanguage(UpdateLanguageServiceModel languageServiceModel) { bool langExists = await this._languageRepository.DoesLanguageExistAsync(languageServiceModel.Id); @@ -71,7 +76,6 @@ namespace DevHive.Services.Services #endregion #region Delete - public async Task DeleteLanguage(Guid id) { if (!await this._languageRepository.DoesLanguageExistAsync(id)) diff --git a/src/DevHive.Services/Services/TechnologyService.cs b/src/DevHive.Services/Services/TechnologyService.cs index c879ad7..039cd8a 100644 --- a/src/DevHive.Services/Services/TechnologyService.cs +++ b/src/DevHive.Services/Services/TechnologyService.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using AutoMapper; using DevHive.Data.Interfaces.Repositories; @@ -48,6 +49,12 @@ namespace DevHive.Services.Services return this._technologyMapper.Map(technology); } + public HashSet GetTechnologies() + { + HashSet technologies = this._technologyRepository.GetTechnologies(); + + return this._technologyMapper.Map>(technologies); + } #endregion #region Update diff --git a/src/DevHive.Web/Controllers/LanguageController.cs b/src/DevHive.Web/Controllers/LanguageController.cs index de6bf15..85ec1e1 100644 --- a/src/DevHive.Web/Controllers/LanguageController.cs +++ b/src/DevHive.Web/Controllers/LanguageController.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using AutoMapper; using DevHive.Services.Interfaces; @@ -45,6 +46,17 @@ namespace DevHive.Web.Controllers return new OkObjectResult(languageWebModel); } + [HttpGet] + [Route("GetLanguages")] + [Authorize(Roles = "User,Admin")] + public IActionResult GetAllExistingLanguages() + { + HashSet languageServiceModels = this._languageService.GetLanguages(); + HashSet languageWebModels = this._languageMapper.Map>(languageServiceModels); + + return new OkObjectResult(languageWebModels); + } + [HttpPut] [Authorize(Roles = "Admin")] public async Task Update(Guid id, [FromBody] UpdateLanguageWebModel updateModel) diff --git a/src/DevHive.Web/Controllers/TechnologyController.cs b/src/DevHive.Web/Controllers/TechnologyController.cs index c107c6e..6453d12 100644 --- a/src/DevHive.Web/Controllers/TechnologyController.cs +++ b/src/DevHive.Web/Controllers/TechnologyController.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using AutoMapper; using DevHive.Services.Interfaces; @@ -45,6 +46,17 @@ namespace DevHive.Web.Controllers return new OkObjectResult(createTechnologyWebModel); } + [HttpGet] + [Route("GetTechnologies")] + [Authorize(Roles = "User,Admin")] + public IActionResult GetAllExistingTechnologies() + { + HashSet technologyServiceModels = this._technologyService.GetTechnologies(); + HashSet languageWebModels = this._technologyMapper.Map>(technologyServiceModels); + + return new OkObjectResult(languageWebModels); + } + [HttpPut] [Authorize(Roles = "Admin")] public async Task Update(Guid id, [FromBody] UpdateTechnologyWebModel updateModel) -- cgit v1.2.3 From b38d6693476917972345397298b534af2b8b8f78 Mon Sep 17 00:00:00 2001 From: transtrike Date: Fri, 29 Jan 2021 20:39:07 +0200 Subject: File Upload implemented; Post Layers adapted to File Uploading --- src/DevHive.Data/Interfaces/Models/IPost.cs | 2 +- .../Interfaces/Repositories/IPostRepository.cs | 4 ++ src/DevHive.Data/Models/Post.cs | 2 +- src/DevHive.Data/Repositories/BaseRepository.cs | 6 +-- src/DevHive.Data/Repositories/PostRepository.cs | 16 +++++++ .../Configurations/Mapping/PostMappings.cs | 4 +- src/DevHive.Services/DevHive.Services.csproj | 56 +++++++++++----------- src/DevHive.Services/Interfaces/ICloudService.cs | 13 +++++ .../Models/Cloud/CloudinaryService.cs | 55 +++++++++++++++++++++ .../Models/Post/Post/CreatePostServiceModel.cs | 4 +- .../Models/Post/Post/ReadPostServiceModel.cs | 3 +- .../Models/Post/Post/UpdatePostServiceModel.cs | 4 +- src/DevHive.Services/Services/PostService.cs | 34 +++++++++++-- .../Extensions/ConfigureDependencyInjection.cs | 8 +++- .../Models/Post/Post/CreatePostWebModel.cs | 4 +- .../Models/Post/Post/ReadPostWebModel.cs | 3 +- .../Models/Post/Post/UpdatePostWebModel.cs | 4 ++ src/DevHive.Web/Startup.cs | 2 +- src/DevHive.Web/appsettings.json | 7 ++- 19 files changed, 186 insertions(+), 45 deletions(-) create mode 100644 src/DevHive.Services/Interfaces/ICloudService.cs create mode 100644 src/DevHive.Services/Models/Cloud/CloudinaryService.cs (limited to 'src/DevHive.Data/Interfaces/Repositories') diff --git a/src/DevHive.Data/Interfaces/Models/IPost.cs b/src/DevHive.Data/Interfaces/Models/IPost.cs index 0902465..86469a7 100644 --- a/src/DevHive.Data/Interfaces/Models/IPost.cs +++ b/src/DevHive.Data/Interfaces/Models/IPost.cs @@ -14,6 +14,6 @@ namespace DevHive.Data.Interfaces.Models List Comments { get; set; } - //List Files + List FileUrls { get; set; } } } diff --git a/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs index aa0afc7..5022df5 100644 --- a/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs +++ b/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using DevHive.Data.Models; using DevHive.Data.Repositories.Interfaces; @@ -8,6 +9,9 @@ namespace DevHive.Data.Interfaces.Repositories public interface IPostRepository : IRepository { Task GetPostByCreatorAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated); + Task> GetFileUrls(Guid postId); + Task DoesPostExist(Guid postId); + Task DoesPostHaveFiles(Guid postId); } } diff --git a/src/DevHive.Data/Models/Post.cs b/src/DevHive.Data/Models/Post.cs index 0ea7142..c513eb4 100644 --- a/src/DevHive.Data/Models/Post.cs +++ b/src/DevHive.Data/Models/Post.cs @@ -18,6 +18,6 @@ namespace DevHive.Data.Models public List Comments { get; set; } = new(); - // public List Files { get; set; } = new(); + public List FileUrls { get; set; } = new(); } } diff --git a/src/DevHive.Data/Repositories/BaseRepository.cs b/src/DevHive.Data/Repositories/BaseRepository.cs index f1e6673..cac802e 100644 --- a/src/DevHive.Data/Repositories/BaseRepository.cs +++ b/src/DevHive.Data/Repositories/BaseRepository.cs @@ -34,10 +34,10 @@ namespace DevHive.Data.Repositories public virtual async Task EditAsync(Guid id, TEntity newEntity) { var entry = this._context.Entry(newEntity); - if (entry.State == EntityState.Detached) - this._context.Attach(newEntity); + if (entry.State == EntityState.Detached) + this._context.Attach(newEntity); - entry.State = EntityState.Modified; + entry.State = EntityState.Modified; return await this.SaveChangesAsync(_context); } diff --git a/src/DevHive.Data/Repositories/PostRepository.cs b/src/DevHive.Data/Repositories/PostRepository.cs index 67988f2..78b40cd 100644 --- a/src/DevHive.Data/Repositories/PostRepository.cs +++ b/src/DevHive.Data/Repositories/PostRepository.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; @@ -30,6 +32,11 @@ namespace DevHive.Data.Repositories .FirstOrDefaultAsync(p => p.Creator.Id == creatorId && p.TimeCreated == timeCreated); } + + public async Task> GetFileUrls(Guid postId) + { + return (await this.GetByIdAsync(postId)).FileUrls; + } #endregion #region Validations @@ -39,6 +46,15 @@ namespace DevHive.Data.Repositories .AsNoTracking() .AnyAsync(r => r.Id == postId); } + + public async Task DoesPostHaveFiles(Guid postId) + { + return await this._context.Posts + .AsNoTracking() + .Where(x => x.Id == postId) + .Select(x => x.FileUrls) + .AnyAsync(); + } #endregion } } diff --git a/src/DevHive.Services/Configurations/Mapping/PostMappings.cs b/src/DevHive.Services/Configurations/Mapping/PostMappings.cs index d8dcc84..c7466d9 100644 --- a/src/DevHive.Services/Configurations/Mapping/PostMappings.cs +++ b/src/DevHive.Services/Configurations/Mapping/PostMappings.cs @@ -9,7 +9,7 @@ namespace DevHive.Services.Configurations.Mapping public PostMappings() { CreateMap(); - // .ForMember(dest => dest.Files, src => src.Ignore()); + // .ForMember(dest => dest.Files, src => src.Ignore()); CreateMap() .ForMember(dest => dest.Id, src => src.MapFrom(p => p.PostId)) // .ForMember(dest => dest.Files, src => src.Ignore()) @@ -20,7 +20,7 @@ namespace DevHive.Services.Configurations.Mapping .ForMember(dest => dest.CreatorFirstName, src => src.Ignore()) .ForMember(dest => dest.CreatorLastName, src => src.Ignore()) .ForMember(dest => dest.CreatorUsername, src => src.Ignore()); - //TODO: Map those here /\ + //TODO: Map those here /\ } } } diff --git a/src/DevHive.Services/DevHive.Services.csproj b/src/DevHive.Services/DevHive.Services.csproj index 52f0323..66df209 100644 --- a/src/DevHive.Services/DevHive.Services.csproj +++ b/src/DevHive.Services/DevHive.Services.csproj @@ -1,27 +1,29 @@ - - - net5.0 - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - - - - - - - - - true - latest - - + + + net5.0 + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + + + + + + + true + latest + + diff --git a/src/DevHive.Services/Interfaces/ICloudService.cs b/src/DevHive.Services/Interfaces/ICloudService.cs new file mode 100644 index 0000000..6616444 --- /dev/null +++ b/src/DevHive.Services/Interfaces/ICloudService.cs @@ -0,0 +1,13 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; + +namespace DevHive.Services.Interfaces +{ + public interface ICloudService + { + Task> UploadFilesToCloud(List formFiles); + + Task RemoveFilesFromCloud(List fileUrls); + } +} diff --git a/src/DevHive.Services/Models/Cloud/CloudinaryService.cs b/src/DevHive.Services/Models/Cloud/CloudinaryService.cs new file mode 100644 index 0000000..a9bc9bd --- /dev/null +++ b/src/DevHive.Services/Models/Cloud/CloudinaryService.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Threading.Tasks; +using CloudinaryDotNet; +using CloudinaryDotNet.Actions; +using DevHive.Services.Interfaces; +using Microsoft.AspNetCore.Http; + +namespace DevHive.Services.Services +{ + public class CloudinaryService : ICloudService + { + private readonly Cloudinary _cloudinary; + + public CloudinaryService(string cloudName, string apiKey, string apiSecret) + { + this._cloudinary = new Cloudinary(new Account(cloudName, apiKey, apiSecret)); + } + + public async Task> UploadFilesToCloud(List formFiles) + { + List fileUrls = new(); + foreach (var formFile in formFiles) + { + string formFileId = Guid.NewGuid().ToString(); + + if (formFile.Length > 0) + { + using (var ms = new MemoryStream()) + { + formFile.CopyTo(ms); + byte[] formBytes = ms.ToArray(); + + ImageUploadParams imageUploadParams = new() + { + File = new FileDescription(formFileId, new MemoryStream(formBytes)), + PublicId = formFileId + }; + + ImageUploadResult uploadResult = await this._cloudinary.UploadAsync(imageUploadParams); + fileUrls.Add(uploadResult.Url.AbsoluteUri); + } + } + } + + return fileUrls; + } + + public async Task RemoveFilesFromCloud(List fileUrls) + { + return true; + } + } +} diff --git a/src/DevHive.Services/Models/Post/Post/CreatePostServiceModel.cs b/src/DevHive.Services/Models/Post/Post/CreatePostServiceModel.cs index 36f6351..8676f6c 100644 --- a/src/DevHive.Services/Models/Post/Post/CreatePostServiceModel.cs +++ b/src/DevHive.Services/Models/Post/Post/CreatePostServiceModel.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Http; namespace DevHive.Services.Models.Post.Post { @@ -8,6 +10,6 @@ namespace DevHive.Services.Models.Post.Post public string Message { get; set; } - // public List Files { get; set; } + public List Files { get; set; } } } diff --git a/src/DevHive.Services/Models/Post/Post/ReadPostServiceModel.cs b/src/DevHive.Services/Models/Post/Post/ReadPostServiceModel.cs index 3e673c1..f0a4fe5 100644 --- a/src/DevHive.Services/Models/Post/Post/ReadPostServiceModel.cs +++ b/src/DevHive.Services/Models/Post/Post/ReadPostServiceModel.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using DevHive.Services.Models.Post.Comment; +using Microsoft.Extensions.FileProviders; namespace DevHive.Services.Models.Post.Post { @@ -20,6 +21,6 @@ namespace DevHive.Services.Models.Post.Post public List Comments { get; set; } = new(); - //public List Files { get; set; } + public List Files { get; set; } } } diff --git a/src/DevHive.Services/Models/Post/Post/UpdatePostServiceModel.cs b/src/DevHive.Services/Models/Post/Post/UpdatePostServiceModel.cs index 8924b07..24b0b74 100644 --- a/src/DevHive.Services/Models/Post/Post/UpdatePostServiceModel.cs +++ b/src/DevHive.Services/Models/Post/Post/UpdatePostServiceModel.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using Microsoft.AspNetCore.Http; namespace DevHive.Services.Models.Post.Post { @@ -10,6 +12,6 @@ namespace DevHive.Services.Models.Post.Post public string NewMessage { get; set; } - // public List Files { get; set; } + public List Files { get; set; } } } diff --git a/src/DevHive.Services/Services/PostService.cs b/src/DevHive.Services/Services/PostService.cs index d80d815..7ce7b58 100644 --- a/src/DevHive.Services/Services/PostService.cs +++ b/src/DevHive.Services/Services/PostService.cs @@ -15,13 +15,15 @@ namespace DevHive.Services.Services { public class PostService : IPostService { + private readonly ICloudService _cloudService; private readonly IUserRepository _userRepository; private readonly IPostRepository _postRepository; private readonly ICommentRepository _commentRepository; private readonly IMapper _postMapper; - public PostService(IUserRepository userRepository, IPostRepository postRepository, ICommentRepository commentRepository, IMapper postMapper) + public PostService(ICloudService cloudService, IUserRepository userRepository, IPostRepository postRepository, ICommentRepository commentRepository, IMapper postMapper) { + this._cloudService = cloudService; this._userRepository = userRepository; this._postRepository = postRepository; this._commentRepository = commentRepository; @@ -35,9 +37,12 @@ namespace DevHive.Services.Services throw new ArgumentException("User does not exist!"); Post post = this._postMapper.Map(createPostServiceModel); - post.TimeCreated = DateTime.Now; + + if (createPostServiceModel.Files.Count != 0) + post.FileUrls = await _cloudService.UploadFilesToCloud(createPostServiceModel.Files); post.Creator = await this._userRepository.GetByIdAsync(createPostServiceModel.CreatorId); + post.TimeCreated = DateTime.Now; bool success = await this._postRepository.AddAsync(post); if (success) @@ -116,9 +121,23 @@ namespace DevHive.Services.Services throw new ArgumentException("Post does not exist!"); Post post = this._postMapper.Map(updatePostServiceModel); - post.TimeCreated = DateTime.Now; + + if (updatePostServiceModel.Files.Count != 0) + { + if (await this._postRepository.DoesPostHaveFiles(updatePostServiceModel.PostId)) + { + List fileUrls = await this._postRepository.GetFileUrls(updatePostServiceModel.PostId); + bool success = await _cloudService.RemoveFilesFromCloud(fileUrls); + if (!success) + throw new InvalidCastException("Could not delete files from the post!"); + } + + post.FileUrls = await _cloudService.UploadFilesToCloud(updatePostServiceModel.Files) ?? + throw new ArgumentNullException("Unable to upload images to cloud"); + } post.Creator = await this._userRepository.GetByIdAsync(updatePostServiceModel.CreatorId); + post.TimeCreated = DateTime.Now; bool result = await this._postRepository.EditAsync(updatePostServiceModel.PostId, post); @@ -155,6 +174,15 @@ namespace DevHive.Services.Services throw new ArgumentException("Post does not exist!"); Post post = await this._postRepository.GetByIdAsync(id); + + if (await this._postRepository.DoesPostHaveFiles(id)) + { + List fileUrls = await this._postRepository.GetFileUrls(id); + bool success = await _cloudService.RemoveFilesFromCloud(fileUrls); + if (!success) + throw new InvalidCastException("Could not delete files from the post. Please try again"); + } + return await this._postRepository.DeleteAsync(post); } diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs index d7c859e..fe2c788 100644 --- a/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs +++ b/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs @@ -3,13 +3,14 @@ using DevHive.Data.Models; using DevHive.Data.Repositories; using DevHive.Services.Interfaces; using DevHive.Services.Services; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; namespace DevHive.Web.Configurations.Extensions { public static class ConfigureDependencyInjection { - public static void DependencyInjectionConfiguration(this IServiceCollection services) + public static void DependencyInjectionConfiguration(this IServiceCollection services, IConfiguration configuration) { services.AddTransient(); services.AddTransient(); @@ -25,6 +26,11 @@ namespace DevHive.Web.Configurations.Extensions services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(options => + new CloudinaryService( + cloudName: configuration.GetSection("Cloud").GetSection("cloudName").Value, + apiKey: configuration.GetSection("Cloud").GetSection("apiKey").Value, + apiSecret: configuration.GetSection("Cloud").GetSection("apiSecret").Value)); } } } diff --git a/src/DevHive.Web/Models/Post/Post/CreatePostWebModel.cs b/src/DevHive.Web/Models/Post/Post/CreatePostWebModel.cs index b7b4cf4..e35a813 100644 --- a/src/DevHive.Web/Models/Post/Post/CreatePostWebModel.cs +++ b/src/DevHive.Web/Models/Post/Post/CreatePostWebModel.cs @@ -1,6 +1,8 @@ using System; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Diagnostics.CodeAnalysis; +using Microsoft.AspNetCore.Http; namespace DevHive.Web.Models.Post.Post { @@ -10,6 +12,6 @@ namespace DevHive.Web.Models.Post.Post [Required] public string Message { get; set; } - // public List Files { get; set; } + public List Files { get; set; } } } diff --git a/src/DevHive.Web/Models/Post/Post/ReadPostWebModel.cs b/src/DevHive.Web/Models/Post/Post/ReadPostWebModel.cs index 04c6275..5d4da31 100644 --- a/src/DevHive.Web/Models/Post/Post/ReadPostWebModel.cs +++ b/src/DevHive.Web/Models/Post/Post/ReadPostWebModel.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using DevHive.Web.Models.Post.Comment; +using Microsoft.AspNetCore.Http; namespace DevHive.Web.Models.Post.Post { @@ -20,6 +21,6 @@ namespace DevHive.Web.Models.Post.Post public List Comments { get; set; } - //public Files[] Files { get; set; } + public List Files { get; set; } } } diff --git a/src/DevHive.Web/Models/Post/Post/UpdatePostWebModel.cs b/src/DevHive.Web/Models/Post/Post/UpdatePostWebModel.cs index 685f08b..ac84d2c 100644 --- a/src/DevHive.Web/Models/Post/Post/UpdatePostWebModel.cs +++ b/src/DevHive.Web/Models/Post/Post/UpdatePostWebModel.cs @@ -1,6 +1,8 @@ using System; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Diagnostics.CodeAnalysis; +using Microsoft.AspNetCore.Http; namespace DevHive.Web.Models.Post.Post { @@ -13,5 +15,7 @@ namespace DevHive.Web.Models.Post.Post [NotNull] [Required] public string NewMessage { get; set; } + + public List Files { get; set; } = new(); } } diff --git a/src/DevHive.Web/Startup.cs b/src/DevHive.Web/Startup.cs index 92d4359..dd7e852 100644 --- a/src/DevHive.Web/Startup.cs +++ b/src/DevHive.Web/Startup.cs @@ -32,7 +32,7 @@ namespace DevHive.Web services.SwaggerConfiguration(); services.JWTConfiguration(Configuration); services.AutoMapperConfiguration(); - services.DependencyInjectionConfiguration(); + services.DependencyInjectionConfiguration(this.Configuration); services.ExceptionHandlerMiddlewareConfiguration(); } diff --git a/src/DevHive.Web/appsettings.json b/src/DevHive.Web/appsettings.json index 83932a7..bcdcae7 100644 --- a/src/DevHive.Web/appsettings.json +++ b/src/DevHive.Web/appsettings.json @@ -4,7 +4,12 @@ }, "ConnectionStrings": { "DEV": "Server=localhost;Port=5432;Database=API;User Id=postgres;Password=;" - }, + }, + "Cloud": { + "cloudName": "devhive", + "apiKey": "488664116365813", + "apiSecret": "" + }, "Logging": { "LogLevel": { "Default": "Information", -- cgit v1.2.3 From 498af41f38b14372bd2f5eb9a0add7af95c40168 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 30 Jan 2021 13:07:54 +0200 Subject: Fixed GetUserPosts implementation --- .../Interfaces/Repositories/IFeedRepository.cs | 1 + src/DevHive.Data/Repositories/FeedRepository.cs | 13 ++++++++++++ src/DevHive.Services/Interfaces/IFeedService.cs | 1 + src/DevHive.Services/Services/FeedService.cs | 24 ++++++++++++++++++++++ src/DevHive.Web/Controllers/FeedController.cs | 2 +- 5 files changed, 40 insertions(+), 1 deletion(-) (limited to 'src/DevHive.Data/Interfaces/Repositories') diff --git a/src/DevHive.Data/Interfaces/Repositories/IFeedRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IFeedRepository.cs index e9fd48a..7262510 100644 --- a/src/DevHive.Data/Interfaces/Repositories/IFeedRepository.cs +++ b/src/DevHive.Data/Interfaces/Repositories/IFeedRepository.cs @@ -8,5 +8,6 @@ namespace DevHive.Data.Interfaces.Repositories public interface IFeedRepository { Task> GetFriendsPosts(List friendsList, DateTime firstRequestIssued, int pageNumber, int pageSize); + Task> GetUsersPosts(User user, DateTime firstRequestIssued, int pageNumber, int pageSize); } } diff --git a/src/DevHive.Data/Repositories/FeedRepository.cs b/src/DevHive.Data/Repositories/FeedRepository.cs index efcb8e0..7ab9a91 100644 --- a/src/DevHive.Data/Repositories/FeedRepository.cs +++ b/src/DevHive.Data/Repositories/FeedRepository.cs @@ -32,5 +32,18 @@ namespace DevHive.Data.Repositories return posts; } + + public async Task> GetUsersPosts(User user, DateTime firstRequestIssued, int pageNumber, int pageSize) + { + List posts = await this._context.Posts + .Where(post => post.TimeCreated < firstRequestIssued) + .Where(p => p.Creator.Id == user.Id) + .OrderByDescending(x => x.TimeCreated) + .Skip((pageNumber - 1) * pageSize) + .Take(pageSize) + .ToListAsync(); + + return posts; + } } } diff --git a/src/DevHive.Services/Interfaces/IFeedService.cs b/src/DevHive.Services/Interfaces/IFeedService.cs index 1edba5a..b507b3b 100644 --- a/src/DevHive.Services/Interfaces/IFeedService.cs +++ b/src/DevHive.Services/Interfaces/IFeedService.cs @@ -6,5 +6,6 @@ namespace DevHive.Services.Interfaces public interface IFeedService { Task GetPage(GetPageServiceModel getPageServiceModel); + Task GetUserPage(GetPageServiceModel model); } } diff --git a/src/DevHive.Services/Services/FeedService.cs b/src/DevHive.Services/Services/FeedService.cs index 269471e..ceb5ebf 100644 --- a/src/DevHive.Services/Services/FeedService.cs +++ b/src/DevHive.Services/Services/FeedService.cs @@ -54,5 +54,29 @@ namespace DevHive.Services.Services return readPageServiceModel; } + + public async Task GetUserPage(GetPageServiceModel model) { + User user = null; + + if (!string.IsNullOrEmpty(model.Username)) + user = await this._userRepository.GetByUsernameAsync(model.Username); + else + throw new ArgumentException("Invalid given data!"); + + if (user == null) + throw new ArgumentException("User doesn't exist!"); + + List posts = await this._feedRepository + .GetUsersPosts(user, model.FirstRequestIssued, model.PageNumber, model.PageSize); + + if (posts.Count <= 0) + throw new ArgumentException("User hasn't posted anything yet!"); + + ReadPageServiceModel readPageServiceModel = new(); + foreach (Post post in posts) + readPageServiceModel.Posts.Add(this._mapper.Map(post)); + + return readPageServiceModel; + } } } diff --git a/src/DevHive.Web/Controllers/FeedController.cs b/src/DevHive.Web/Controllers/FeedController.cs index 4fd3ae9..b04c37a 100644 --- a/src/DevHive.Web/Controllers/FeedController.cs +++ b/src/DevHive.Web/Controllers/FeedController.cs @@ -43,7 +43,7 @@ namespace DevHive.Web.Controllers GetPageServiceModel getPageServiceModel = this._mapper.Map(getPageWebModel); getPageServiceModel.Username = username; - ReadPageServiceModel readPageServiceModel = await this._feedService.GetPage(getPageServiceModel); + ReadPageServiceModel readPageServiceModel = await this._feedService.GetUserPage(getPageServiceModel); ReadPageWebModel readPageWebModel = this._mapper.Map(readPageServiceModel); return new OkObjectResult(readPageWebModel); -- cgit v1.2.3 From 866a5a15b8b722bc78d065f73adc0c465f264f55 Mon Sep 17 00:00:00 2001 From: transtrike Date: Sat, 30 Jan 2021 18:45:18 +0200 Subject: IDFK --- src/DevHive.Data/DevHiveContext.cs | 19 +- src/DevHive.Data/Interfaces/Models/IRating.cs | 14 + src/DevHive.Data/Interfaces/Models/IUser.cs | 1 + .../Interfaces/Repositories/IRatingRepository.cs | 15 + ...23215634_PostAndComment_Implemented.Designer.cs | 476 ------------------- .../20210123215634_PostAndComment_Implemented.cs | 411 ----------------- ...7110304_RelationsManuallyConfigured.Designer.cs | 478 ------------------- .../20210127110304_RelationsManuallyConfigured.cs | 69 --- ...3238_RelationsManuallyConfiguredTwo.Designer.cs | 510 --------------------- ...0210127213238_RelationsManuallyConfiguredTwo.cs | 121 ----- ...0210127222937_UserFriends_Implement.Designer.cs | 510 --------------------- .../20210127222937_UserFriends_Implement.cs | 78 ---- .../Migrations/DevHiveContextModelSnapshot.cs | 508 -------------------- src/DevHive.Data/Models/Rating.cs | 16 + src/DevHive.Data/Models/User.cs | 1 + src/DevHive.Data/RelationModels/UserFriends.cs | 3 + src/DevHive.Data/Repositories/RatingRepository.cs | 37 ++ .../Configurations/Mapping/RatingMappings.cs | 12 + .../Models/Post/Rating/RatePostServiceModel.cs | 13 + .../Models/Post/Rating/ReadRatingServiceModel.cs | 13 + src/DevHive.Services/Services/RatingService.cs | 54 +++ src/DevHive.Web/Controllers/UserController.cs | 1 + 22 files changed, 189 insertions(+), 3171 deletions(-) create mode 100644 src/DevHive.Data/Interfaces/Models/IRating.cs create mode 100644 src/DevHive.Data/Interfaces/Repositories/IRatingRepository.cs delete mode 100644 src/DevHive.Data/Migrations/20210123215634_PostAndComment_Implemented.Designer.cs delete mode 100644 src/DevHive.Data/Migrations/20210123215634_PostAndComment_Implemented.cs delete mode 100644 src/DevHive.Data/Migrations/20210127110304_RelationsManuallyConfigured.Designer.cs delete mode 100644 src/DevHive.Data/Migrations/20210127110304_RelationsManuallyConfigured.cs delete mode 100644 src/DevHive.Data/Migrations/20210127213238_RelationsManuallyConfiguredTwo.Designer.cs delete mode 100644 src/DevHive.Data/Migrations/20210127213238_RelationsManuallyConfiguredTwo.cs delete mode 100644 src/DevHive.Data/Migrations/20210127222937_UserFriends_Implement.Designer.cs delete mode 100644 src/DevHive.Data/Migrations/20210127222937_UserFriends_Implement.cs delete mode 100644 src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs create mode 100644 src/DevHive.Data/Models/Rating.cs create mode 100644 src/DevHive.Data/Repositories/RatingRepository.cs create mode 100644 src/DevHive.Services/Configurations/Mapping/RatingMappings.cs create mode 100644 src/DevHive.Services/Models/Post/Rating/RatePostServiceModel.cs create mode 100644 src/DevHive.Services/Models/Post/Rating/ReadRatingServiceModel.cs create mode 100644 src/DevHive.Services/Services/RatingService.cs (limited to 'src/DevHive.Data/Interfaces/Repositories') diff --git a/src/DevHive.Data/DevHiveContext.cs b/src/DevHive.Data/DevHiveContext.cs index e391882..7eb90de 100644 --- a/src/DevHive.Data/DevHiveContext.cs +++ b/src/DevHive.Data/DevHiveContext.cs @@ -15,6 +15,7 @@ namespace DevHive.Data public DbSet Languages { get; set; } public DbSet Posts { get; set; } public DbSet Comments { get; set; } + public DbSet Rating { get; set; } protected override void OnModelCreating(ModelBuilder builder) { @@ -29,9 +30,10 @@ namespace DevHive.Data .WithMany(x => x.Users); /* Friends */ - //TODO: Look into the User - User - builder.Entity() - .HasKey(uu => new { uu.UserId, uu.FriendId }); + builder.Entity() + .HasMany(x => x.Friends) + .WithMany(x => x.Friends) + .UsingEntity(x => x.ToTable("UserFriends")); /* Languages */ builder.Entity() @@ -45,9 +47,6 @@ namespace DevHive.Data .UsingEntity(x => x.ToTable("LanguageUser")); /* Technologies */ - builder.Entity() - .HasKey(x => x.Id); - builder.Entity() .HasMany(x => x.Technologies) .WithMany(x => x.Users) @@ -59,14 +58,14 @@ namespace DevHive.Data .UsingEntity(x => x.ToTable("TechnologyUser")); /* Post */ - builder.Entity() - .HasMany(x => x.Comments) - .WithOne(x => x.Post); - builder.Entity() .HasOne(x => x.Creator) .WithMany(x => x.Posts); + builder.Entity() + .HasMany(x => x.Comments) + .WithOne(x => x.Post); + /* Comment */ builder.Entity() .HasOne(x => x.Post) diff --git a/src/DevHive.Data/Interfaces/Models/IRating.cs b/src/DevHive.Data/Interfaces/Models/IRating.cs new file mode 100644 index 0000000..4604a75 --- /dev/null +++ b/src/DevHive.Data/Interfaces/Models/IRating.cs @@ -0,0 +1,14 @@ +using DevHive.Data.Interfaces.Models; +using DevHive.Data.Models; + +namespace DevHive.Data.Interfaces.Models +{ + public interface IRating : IModel + { + Post Post { get; set; } + + int Likes { get; set; } + + int Dislikes { get; set; } + } +} diff --git a/src/DevHive.Data/Interfaces/Models/IUser.cs b/src/DevHive.Data/Interfaces/Models/IUser.cs index 08ce385..3e3ee7d 100644 --- a/src/DevHive.Data/Interfaces/Models/IUser.cs +++ b/src/DevHive.Data/Interfaces/Models/IUser.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using DevHive.Data.Models; +using DevHive.Data.RelationModels; namespace DevHive.Data.Interfaces.Models { diff --git a/src/DevHive.Data/Interfaces/Repositories/IRatingRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IRatingRepository.cs new file mode 100644 index 0000000..de4e3f2 --- /dev/null +++ b/src/DevHive.Data/Interfaces/Repositories/IRatingRepository.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 IRatingRepository : IRepository + { + Task GetByPostId(Guid postId); + Task> GetRating(Guid postId); + + Task HasUserRatedThisPost(Guid userId, Guid postId); + } +} diff --git a/src/DevHive.Data/Migrations/20210123215634_PostAndComment_Implemented.Designer.cs b/src/DevHive.Data/Migrations/20210123215634_PostAndComment_Implemented.Designer.cs deleted file mode 100644 index 0e4b103..0000000 --- a/src/DevHive.Data/Migrations/20210123215634_PostAndComment_Implemented.Designer.cs +++ /dev/null @@ -1,476 +0,0 @@ -// -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("20210123215634_PostAndComment_Implemented")] - partial class PostAndComment_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.Comment", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatorId") - .HasColumnType("uuid"); - - b.Property("Message") - .HasColumnType("text"); - - b.Property("PostId") - .HasColumnType("uuid"); - - b.Property("TimeCreated") - .HasColumnType("timestamp without time zone"); - - b.HasKey("Id"); - - b.HasIndex("PostId"); - - b.ToTable("Comments"); - }); - - 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.Post", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatorId") - .HasColumnType("uuid"); - - b.Property("Message") - .HasColumnType("text"); - - b.Property("TimeCreated") - .HasColumnType("timestamp without time zone"); - - b.HasKey("Id"); - - b.ToTable("Posts"); - }); - - 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.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("ProfilePictureUrl") - .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("LanguageUser", b => - { - b.Property("LanguagesId") - .HasColumnType("uuid"); - - b.Property("UsersId") - .HasColumnType("uuid"); - - b.HasKey("LanguagesId", "UsersId"); - - b.HasIndex("UsersId"); - - b.ToTable("LanguageUser"); - }); - - 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") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - 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") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - 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("TechnologyUser", b => - { - b.Property("TechnologiesId") - .HasColumnType("uuid"); - - b.Property("UsersId") - .HasColumnType("uuid"); - - b.HasKey("TechnologiesId", "UsersId"); - - b.HasIndex("UsersId"); - - b.ToTable("TechnologyUser"); - }); - - modelBuilder.Entity("DevHive.Data.Models.Comment", b => - { - b.HasOne("DevHive.Data.Models.Post", null) - .WithMany("Comments") - .HasForeignKey("PostId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("DevHive.Data.Models.User", b => - { - b.HasOne("DevHive.Data.Models.User", null) - .WithMany("Friends") - .HasForeignKey("UserId"); - }); - - modelBuilder.Entity("LanguageUser", b => - { - b.HasOne("DevHive.Data.Models.Language", null) - .WithMany() - .HasForeignKey("LanguagesId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("DevHive.Data.Models.User", null) - .WithMany() - .HasForeignKey("UsersId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - 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("TechnologyUser", b => - { - b.HasOne("DevHive.Data.Models.Technology", null) - .WithMany() - .HasForeignKey("TechnologiesId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("DevHive.Data.Models.User", null) - .WithMany() - .HasForeignKey("UsersId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("DevHive.Data.Models.Post", b => - { - b.Navigation("Comments"); - }); - - modelBuilder.Entity("DevHive.Data.Models.User", b => - { - b.Navigation("Friends"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/DevHive.Data/Migrations/20210123215634_PostAndComment_Implemented.cs b/src/DevHive.Data/Migrations/20210123215634_PostAndComment_Implemented.cs deleted file mode 100644 index 4c9f3bd..0000000 --- a/src/DevHive.Data/Migrations/20210123215634_PostAndComment_Implemented.cs +++ /dev/null @@ -1,411 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; -using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; - -namespace DevHive.Data.Migrations -{ - public partial class PostAndComment_Implemented : 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), - FirstName = table.Column(type: "text", nullable: true), - LastName = table.Column(type: "text", nullable: true), - ProfilePictureUrl = table.Column(type: "text", nullable: true), - UserId = table.Column(type: "uuid", nullable: true), - UserName = table.Column(type: "character varying(256)", maxLength: 256, 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); - table.ForeignKey( - name: "FK_AspNetUsers_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Restrict); - }); - - 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: "Posts", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - CreatorId = table.Column(type: "uuid", nullable: false), - Message = table.Column(type: "text", nullable: true), - TimeCreated = table.Column(type: "timestamp without time zone", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Posts", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Technologies", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - Name = table.Column(type: "text", nullable: true) - }, - 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: "text", nullable: false), - ProviderKey = table.Column(type: "text", 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: "text", nullable: false), - Name = table.Column(type: "text", 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.CreateTable( - name: "RoleUser", - columns: table => new - { - RolesId = table.Column(type: "uuid", nullable: false), - UsersId = table.Column(type: "uuid", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_RoleUser", x => new { x.RolesId, x.UsersId }); - table.ForeignKey( - name: "FK_RoleUser_AspNetRoles_RolesId", - column: x => x.RolesId, - principalTable: "AspNetRoles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_RoleUser_AspNetUsers_UsersId", - column: x => x.UsersId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "LanguageUser", - columns: table => new - { - LanguagesId = table.Column(type: "uuid", nullable: false), - UsersId = table.Column(type: "uuid", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_LanguageUser", x => new { x.LanguagesId, x.UsersId }); - table.ForeignKey( - name: "FK_LanguageUser_AspNetUsers_UsersId", - column: x => x.UsersId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_LanguageUser_Languages_LanguagesId", - column: x => x.LanguagesId, - principalTable: "Languages", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Comments", - columns: table => new - { - Id = table.Column(type: "uuid", nullable: false), - PostId = table.Column(type: "uuid", nullable: false), - CreatorId = table.Column(type: "uuid", nullable: false), - Message = table.Column(type: "text", nullable: true), - TimeCreated = table.Column(type: "timestamp without time zone", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Comments", x => x.Id); - table.ForeignKey( - name: "FK_Comments_Posts_PostId", - column: x => x.PostId, - principalTable: "Posts", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "TechnologyUser", - columns: table => new - { - TechnologiesId = table.Column(type: "uuid", nullable: false), - UsersId = table.Column(type: "uuid", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_TechnologyUser", x => new { x.TechnologiesId, x.UsersId }); - table.ForeignKey( - name: "FK_TechnologyUser_AspNetUsers_UsersId", - column: x => x.UsersId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_TechnologyUser_Technologies_TechnologiesId", - column: x => x.TechnologiesId, - principalTable: "Technologies", - 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_UserId", - table: "AspNetUsers", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUsers_UserName", - table: "AspNetUsers", - column: "UserName", - unique: true); - - migrationBuilder.CreateIndex( - name: "UserNameIndex", - table: "AspNetUsers", - column: "NormalizedUserName", - unique: true); - - migrationBuilder.CreateIndex( - name: "IX_Comments_PostId", - table: "Comments", - column: "PostId"); - - migrationBuilder.CreateIndex( - name: "IX_LanguageUser_UsersId", - table: "LanguageUser", - column: "UsersId"); - - migrationBuilder.CreateIndex( - name: "IX_RoleUser_UsersId", - table: "RoleUser", - column: "UsersId"); - - migrationBuilder.CreateIndex( - name: "IX_TechnologyUser_UsersId", - table: "TechnologyUser", - column: "UsersId"); - } - - 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: "Comments"); - - migrationBuilder.DropTable( - name: "LanguageUser"); - - migrationBuilder.DropTable( - name: "RoleUser"); - - migrationBuilder.DropTable( - name: "TechnologyUser"); - - migrationBuilder.DropTable( - name: "Posts"); - - migrationBuilder.DropTable( - name: "Languages"); - - migrationBuilder.DropTable( - name: "AspNetRoles"); - - migrationBuilder.DropTable( - name: "AspNetUsers"); - - migrationBuilder.DropTable( - name: "Technologies"); - } - } -} diff --git a/src/DevHive.Data/Migrations/20210127110304_RelationsManuallyConfigured.Designer.cs b/src/DevHive.Data/Migrations/20210127110304_RelationsManuallyConfigured.Designer.cs deleted file mode 100644 index 4fb21a7..0000000 --- a/src/DevHive.Data/Migrations/20210127110304_RelationsManuallyConfigured.Designer.cs +++ /dev/null @@ -1,478 +0,0 @@ -// -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("20210127110304_RelationsManuallyConfigured")] - partial class RelationsManuallyConfigured - { - 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("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatorId") - .HasColumnType("uuid"); - - b.Property("Message") - .HasColumnType("text"); - - b.Property("PostId") - .HasColumnType("uuid"); - - b.Property("TimeCreated") - .HasColumnType("timestamp without time zone"); - - b.HasKey("Id"); - - b.HasIndex("PostId"); - - b.ToTable("Comments"); - }); - - 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.Post", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatorId") - .HasColumnType("uuid"); - - b.Property("Message") - .HasColumnType("text"); - - b.Property("TimeCreated") - .HasColumnType("timestamp without time zone"); - - b.HasKey("Id"); - - b.ToTable("Posts"); - }); - - 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.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("ProfilePictureUrl") - .HasColumnType("text"); - - b.Property("SecurityStamp") - .HasColumnType("text"); - - b.Property("TwoFactorEnabled") - .HasColumnType("boolean"); - - 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("UserName") - .IsUnique(); - - b.ToTable("AspNetUsers"); - }); - - modelBuilder.Entity("LanguageUser", b => - { - b.Property("LanguagesId") - .HasColumnType("uuid"); - - b.Property("UsersId") - .HasColumnType("uuid"); - - b.HasKey("LanguagesId", "UsersId"); - - b.HasIndex("UsersId"); - - b.ToTable("LanguageUser"); - }); - - 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") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - 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") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - 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("TechnologyUser", b => - { - b.Property("TechnologiesId") - .HasColumnType("uuid"); - - b.Property("UsersId") - .HasColumnType("uuid"); - - b.HasKey("TechnologiesId", "UsersId"); - - b.HasIndex("UsersId"); - - b.ToTable("TechnologyUser"); - }); - - modelBuilder.Entity("UserUser", b => - { - b.Property("FriendsId") - .HasColumnType("uuid"); - - b.HasIndex("FriendsId"); - - b.ToTable("UserUser"); - }); - - modelBuilder.Entity("DevHive.Data.Models.Comment", b => - { - b.HasOne("DevHive.Data.Models.Post", null) - .WithMany("Comments") - .HasForeignKey("PostId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("LanguageUser", b => - { - b.HasOne("DevHive.Data.Models.Language", null) - .WithMany() - .HasForeignKey("LanguagesId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("DevHive.Data.Models.User", null) - .WithMany() - .HasForeignKey("UsersId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - 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("TechnologyUser", b => - { - b.HasOne("DevHive.Data.Models.Technology", null) - .WithMany() - .HasForeignKey("TechnologiesId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("DevHive.Data.Models.User", null) - .WithMany() - .HasForeignKey("UsersId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("UserUser", b => - { - b.HasOne("DevHive.Data.Models.User", null) - .WithMany() - .HasForeignKey("FriendsId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("DevHive.Data.Models.Post", b => - { - b.Navigation("Comments"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/DevHive.Data/Migrations/20210127110304_RelationsManuallyConfigured.cs b/src/DevHive.Data/Migrations/20210127110304_RelationsManuallyConfigured.cs deleted file mode 100644 index d52546d..0000000 --- a/src/DevHive.Data/Migrations/20210127110304_RelationsManuallyConfigured.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace DevHive.Data.Migrations -{ - public partial class RelationsManuallyConfigured : Migration - { - protected override void Up(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"); - - migrationBuilder.CreateTable( - name: "UserUser", - columns: table => new - { - FriendsId = table.Column(type: "uuid", nullable: false) - }, - constraints: table => - { - table.ForeignKey( - name: "FK_UserUser_AspNetUsers_FriendsId", - column: x => x.FriendsId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_UserUser_FriendsId", - table: "UserUser", - column: "FriendsId"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "UserUser"); - - 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); - } - } -} diff --git a/src/DevHive.Data/Migrations/20210127213238_RelationsManuallyConfiguredTwo.Designer.cs b/src/DevHive.Data/Migrations/20210127213238_RelationsManuallyConfiguredTwo.Designer.cs deleted file mode 100644 index de63d70..0000000 --- a/src/DevHive.Data/Migrations/20210127213238_RelationsManuallyConfiguredTwo.Designer.cs +++ /dev/null @@ -1,510 +0,0 @@ -// -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("20210127213238_RelationsManuallyConfiguredTwo")] - partial class RelationsManuallyConfiguredTwo - { - 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("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatorId") - .HasColumnType("uuid"); - - b.Property("Message") - .HasColumnType("text"); - - b.Property("PostId") - .HasColumnType("uuid"); - - b.Property("TimeCreated") - .HasColumnType("timestamp without time zone"); - - b.HasKey("Id"); - - b.HasIndex("PostId"); - - b.ToTable("Comments"); - }); - - 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.Post", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatorId") - .HasColumnType("uuid"); - - b.Property("Message") - .HasColumnType("text"); - - b.Property("TimeCreated") - .HasColumnType("timestamp without time zone"); - - b.HasKey("Id"); - - b.ToTable("Posts"); - }); - - 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.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("ProfilePictureUrl") - .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("DevHive.Data.RelationModels.UserUser", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("FriendId") - .HasColumnType("uuid"); - - b.HasKey("UserId", "FriendId"); - - b.HasIndex("FriendId"); - - b.ToTable("UserUser"); - }); - - modelBuilder.Entity("LanguageUser", b => - { - b.Property("LanguagesId") - .HasColumnType("uuid"); - - b.Property("UsersId") - .HasColumnType("uuid"); - - b.HasKey("LanguagesId", "UsersId"); - - b.HasIndex("UsersId"); - - b.ToTable("LanguageUser"); - }); - - 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") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - 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") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - 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("TechnologyUser", b => - { - b.Property("TechnologiesId") - .HasColumnType("uuid"); - - b.Property("UsersId") - .HasColumnType("uuid"); - - b.HasKey("TechnologiesId", "UsersId"); - - b.HasIndex("UsersId"); - - b.ToTable("TechnologyUser"); - }); - - modelBuilder.Entity("DevHive.Data.Models.Comment", b => - { - b.HasOne("DevHive.Data.Models.Post", null) - .WithMany("Comments") - .HasForeignKey("PostId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("DevHive.Data.Models.User", b => - { - b.HasOne("DevHive.Data.Models.User", null) - .WithMany("Friends") - .HasForeignKey("UserId"); - }); - - modelBuilder.Entity("DevHive.Data.RelationModels.UserUser", b => - { - b.HasOne("DevHive.Data.Models.User", "Friend") - .WithMany() - .HasForeignKey("FriendId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("DevHive.Data.Models.User", "User") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Friend"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("LanguageUser", b => - { - b.HasOne("DevHive.Data.Models.Language", null) - .WithMany() - .HasForeignKey("LanguagesId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("DevHive.Data.Models.User", null) - .WithMany() - .HasForeignKey("UsersId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - 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("TechnologyUser", b => - { - b.HasOne("DevHive.Data.Models.Technology", null) - .WithMany() - .HasForeignKey("TechnologiesId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("DevHive.Data.Models.User", null) - .WithMany() - .HasForeignKey("UsersId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("DevHive.Data.Models.Post", b => - { - b.Navigation("Comments"); - }); - - modelBuilder.Entity("DevHive.Data.Models.User", b => - { - b.Navigation("Friends"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/DevHive.Data/Migrations/20210127213238_RelationsManuallyConfiguredTwo.cs b/src/DevHive.Data/Migrations/20210127213238_RelationsManuallyConfiguredTwo.cs deleted file mode 100644 index ad1649c..0000000 --- a/src/DevHive.Data/Migrations/20210127213238_RelationsManuallyConfiguredTwo.cs +++ /dev/null @@ -1,121 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace DevHive.Data.Migrations -{ - public partial class RelationsManuallyConfiguredTwo : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_UserUser_AspNetUsers_FriendsId", - table: "UserUser"); - - migrationBuilder.RenameColumn( - name: "FriendsId", - table: "UserUser", - newName: "FriendId"); - - migrationBuilder.RenameIndex( - name: "IX_UserUser_FriendsId", - table: "UserUser", - newName: "IX_UserUser_FriendId"); - - migrationBuilder.AddColumn( - name: "UserId", - table: "UserUser", - type: "uuid", - nullable: false, - defaultValue: new Guid("00000000-0000-0000-0000-000000000000")); - - migrationBuilder.AddColumn( - name: "UserId", - table: "AspNetUsers", - type: "uuid", - nullable: true); - - migrationBuilder.AddPrimaryKey( - name: "PK_UserUser", - table: "UserUser", - columns: new[] { "UserId", "FriendId" }); - - 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); - - migrationBuilder.AddForeignKey( - name: "FK_UserUser_AspNetUsers_FriendId", - table: "UserUser", - column: "FriendId", - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - - migrationBuilder.AddForeignKey( - name: "FK_UserUser_AspNetUsers_UserId", - table: "UserUser", - column: "UserId", - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_AspNetUsers_AspNetUsers_UserId", - table: "AspNetUsers"); - - migrationBuilder.DropForeignKey( - name: "FK_UserUser_AspNetUsers_FriendId", - table: "UserUser"); - - migrationBuilder.DropForeignKey( - name: "FK_UserUser_AspNetUsers_UserId", - table: "UserUser"); - - migrationBuilder.DropPrimaryKey( - name: "PK_UserUser", - table: "UserUser"); - - migrationBuilder.DropIndex( - name: "IX_AspNetUsers_UserId", - table: "AspNetUsers"); - - migrationBuilder.DropColumn( - name: "UserId", - table: "UserUser"); - - migrationBuilder.DropColumn( - name: "UserId", - table: "AspNetUsers"); - - migrationBuilder.RenameColumn( - name: "FriendId", - table: "UserUser", - newName: "FriendsId"); - - migrationBuilder.RenameIndex( - name: "IX_UserUser_FriendId", - table: "UserUser", - newName: "IX_UserUser_FriendsId"); - - migrationBuilder.AddForeignKey( - name: "FK_UserUser_AspNetUsers_FriendsId", - table: "UserUser", - column: "FriendsId", - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - } - } -} diff --git a/src/DevHive.Data/Migrations/20210127222937_UserFriends_Implement.Designer.cs b/src/DevHive.Data/Migrations/20210127222937_UserFriends_Implement.Designer.cs deleted file mode 100644 index 84b6453..0000000 --- a/src/DevHive.Data/Migrations/20210127222937_UserFriends_Implement.Designer.cs +++ /dev/null @@ -1,510 +0,0 @@ -// -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("20210127222937_UserFriends_Implement")] - partial class UserFriends_Implement - { - 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("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatorId") - .HasColumnType("uuid"); - - b.Property("Message") - .HasColumnType("text"); - - b.Property("PostId") - .HasColumnType("uuid"); - - b.Property("TimeCreated") - .HasColumnType("timestamp without time zone"); - - b.HasKey("Id"); - - b.HasIndex("PostId"); - - b.ToTable("Comments"); - }); - - 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.Post", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatorId") - .HasColumnType("uuid"); - - b.Property("Message") - .HasColumnType("text"); - - b.Property("TimeCreated") - .HasColumnType("timestamp without time zone"); - - b.HasKey("Id"); - - b.ToTable("Posts"); - }); - - 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.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("ProfilePictureUrl") - .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("DevHive.Data.RelationModels.UserFriends", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("FriendId") - .HasColumnType("uuid"); - - b.HasKey("UserId", "FriendId"); - - b.HasIndex("FriendId"); - - b.ToTable("UserFriends"); - }); - - modelBuilder.Entity("LanguageUser", b => - { - b.Property("LanguagesId") - .HasColumnType("uuid"); - - b.Property("UsersId") - .HasColumnType("uuid"); - - b.HasKey("LanguagesId", "UsersId"); - - b.HasIndex("UsersId"); - - b.ToTable("LanguageUser"); - }); - - 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") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - 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") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - 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("TechnologyUser", b => - { - b.Property("TechnologiesId") - .HasColumnType("uuid"); - - b.Property("UsersId") - .HasColumnType("uuid"); - - b.HasKey("TechnologiesId", "UsersId"); - - b.HasIndex("UsersId"); - - b.ToTable("TechnologyUser"); - }); - - modelBuilder.Entity("DevHive.Data.Models.Comment", b => - { - b.HasOne("DevHive.Data.Models.Post", null) - .WithMany("Comments") - .HasForeignKey("PostId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("DevHive.Data.Models.User", b => - { - b.HasOne("DevHive.Data.Models.User", null) - .WithMany("Friends") - .HasForeignKey("UserId"); - }); - - modelBuilder.Entity("DevHive.Data.RelationModels.UserFriends", b => - { - b.HasOne("DevHive.Data.Models.User", "Friend") - .WithMany() - .HasForeignKey("FriendId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("DevHive.Data.Models.User", "User") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Friend"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("LanguageUser", b => - { - b.HasOne("DevHive.Data.Models.Language", null) - .WithMany() - .HasForeignKey("LanguagesId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("DevHive.Data.Models.User", null) - .WithMany() - .HasForeignKey("UsersId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - 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("TechnologyUser", b => - { - b.HasOne("DevHive.Data.Models.Technology", null) - .WithMany() - .HasForeignKey("TechnologiesId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("DevHive.Data.Models.User", null) - .WithMany() - .HasForeignKey("UsersId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("DevHive.Data.Models.Post", b => - { - b.Navigation("Comments"); - }); - - modelBuilder.Entity("DevHive.Data.Models.User", b => - { - b.Navigation("Friends"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/DevHive.Data/Migrations/20210127222937_UserFriends_Implement.cs b/src/DevHive.Data/Migrations/20210127222937_UserFriends_Implement.cs deleted file mode 100644 index e891b9f..0000000 --- a/src/DevHive.Data/Migrations/20210127222937_UserFriends_Implement.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace DevHive.Data.Migrations -{ - public partial class UserFriends_Implement : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "UserUser"); - - migrationBuilder.CreateTable( - name: "UserFriends", - columns: table => new - { - UserId = table.Column(type: "uuid", nullable: false), - FriendId = table.Column(type: "uuid", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_UserFriends", x => new { x.UserId, x.FriendId }); - table.ForeignKey( - name: "FK_UserFriends_AspNetUsers_FriendId", - column: x => x.FriendId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_UserFriends_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_UserFriends_FriendId", - table: "UserFriends", - column: "FriendId"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "UserFriends"); - - migrationBuilder.CreateTable( - name: "UserUser", - columns: table => new - { - UserId = table.Column(type: "uuid", nullable: false), - FriendId = table.Column(type: "uuid", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_UserUser", x => new { x.UserId, x.FriendId }); - table.ForeignKey( - name: "FK_UserUser_AspNetUsers_FriendId", - column: x => x.FriendId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_UserUser_AspNetUsers_UserId", - column: x => x.UserId, - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_UserUser_FriendId", - table: "UserUser", - column: "FriendId"); - } - } -} diff --git a/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs b/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs deleted file mode 100644 index cf0a82b..0000000 --- a/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs +++ /dev/null @@ -1,508 +0,0 @@ -// -using System; -using DevHive.Data; -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.Comment", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatorId") - .HasColumnType("uuid"); - - b.Property("Message") - .HasColumnType("text"); - - b.Property("PostId") - .HasColumnType("uuid"); - - b.Property("TimeCreated") - .HasColumnType("timestamp without time zone"); - - b.HasKey("Id"); - - b.HasIndex("PostId"); - - b.ToTable("Comments"); - }); - - 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.Post", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("uuid"); - - b.Property("CreatorId") - .HasColumnType("uuid"); - - b.Property("Message") - .HasColumnType("text"); - - b.Property("TimeCreated") - .HasColumnType("timestamp without time zone"); - - b.HasKey("Id"); - - b.ToTable("Posts"); - }); - - 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.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("ProfilePictureUrl") - .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("DevHive.Data.RelationModels.UserFriends", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("FriendId") - .HasColumnType("uuid"); - - b.HasKey("UserId", "FriendId"); - - b.HasIndex("FriendId"); - - b.ToTable("UserFriends"); - }); - - modelBuilder.Entity("LanguageUser", b => - { - b.Property("LanguagesId") - .HasColumnType("uuid"); - - b.Property("UsersId") - .HasColumnType("uuid"); - - b.HasKey("LanguagesId", "UsersId"); - - b.HasIndex("UsersId"); - - b.ToTable("LanguageUser"); - }); - - 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") - .HasColumnType("text"); - - b.Property("ProviderKey") - .HasColumnType("text"); - - 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") - .HasColumnType("text"); - - b.Property("Name") - .HasColumnType("text"); - - 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("TechnologyUser", b => - { - b.Property("TechnologiesId") - .HasColumnType("uuid"); - - b.Property("UsersId") - .HasColumnType("uuid"); - - b.HasKey("TechnologiesId", "UsersId"); - - b.HasIndex("UsersId"); - - b.ToTable("TechnologyUser"); - }); - - modelBuilder.Entity("DevHive.Data.Models.Comment", b => - { - b.HasOne("DevHive.Data.Models.Post", null) - .WithMany("Comments") - .HasForeignKey("PostId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("DevHive.Data.Models.User", b => - { - b.HasOne("DevHive.Data.Models.User", null) - .WithMany("Friends") - .HasForeignKey("UserId"); - }); - - modelBuilder.Entity("DevHive.Data.RelationModels.UserFriends", b => - { - b.HasOne("DevHive.Data.Models.User", "Friend") - .WithMany() - .HasForeignKey("FriendId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("DevHive.Data.Models.User", "User") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Friend"); - - b.Navigation("User"); - }); - - modelBuilder.Entity("LanguageUser", b => - { - b.HasOne("DevHive.Data.Models.Language", null) - .WithMany() - .HasForeignKey("LanguagesId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("DevHive.Data.Models.User", null) - .WithMany() - .HasForeignKey("UsersId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - 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("TechnologyUser", b => - { - b.HasOne("DevHive.Data.Models.Technology", null) - .WithMany() - .HasForeignKey("TechnologiesId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("DevHive.Data.Models.User", null) - .WithMany() - .HasForeignKey("UsersId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("DevHive.Data.Models.Post", b => - { - b.Navigation("Comments"); - }); - - modelBuilder.Entity("DevHive.Data.Models.User", b => - { - b.Navigation("Friends"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/DevHive.Data/Models/Rating.cs b/src/DevHive.Data/Models/Rating.cs new file mode 100644 index 0000000..8ebde9a --- /dev/null +++ b/src/DevHive.Data/Models/Rating.cs @@ -0,0 +1,16 @@ +using System; +using DevHive.Data.Interfaces.Models; + +namespace DevHive.Data.Models +{ + public class Rating : IRating + { + public Guid Id { get; set; } + + public Post Post { get; set; } + + public int Likes { get; set; } + + public int Dislikes { get; set; } + } +} diff --git a/src/DevHive.Data/Models/User.cs b/src/DevHive.Data/Models/User.cs index 8f66b35..504d841 100644 --- a/src/DevHive.Data/Models/User.cs +++ b/src/DevHive.Data/Models/User.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using DevHive.Data.Interfaces.Models; +using DevHive.Data.RelationModels; using Microsoft.AspNetCore.Identity; namespace DevHive.Data.Models diff --git a/src/DevHive.Data/RelationModels/UserFriends.cs b/src/DevHive.Data/RelationModels/UserFriends.cs index aad3083..dec366d 100644 --- a/src/DevHive.Data/RelationModels/UserFriends.cs +++ b/src/DevHive.Data/RelationModels/UserFriends.cs @@ -1,13 +1,16 @@ using System; +using System.ComponentModel.DataAnnotations; using DevHive.Data.Models; namespace DevHive.Data.RelationModels { public class UserFriends { + [Key] public Guid UserId { get; set; } public User User { get; set; } + [Key] public Guid FriendId { get; set; } public User Friend { get; set; } } diff --git a/src/DevHive.Data/Repositories/RatingRepository.cs b/src/DevHive.Data/Repositories/RatingRepository.cs new file mode 100644 index 0000000..43fe90d --- /dev/null +++ b/src/DevHive.Data/Repositories/RatingRepository.cs @@ -0,0 +1,37 @@ +using System; +using System.Threading.Tasks; +using DevHive.Data.Interfaces.Repositories; +using DevHive.Data.Models; +using Microsoft.EntityFrameworkCore; + +namespace DevHive.Data.Repositories +{ + public class RatingRepository : BaseRepository, IRatingRepository + { + private readonly DevHiveContext _context; + + public RatingRepository(DevHiveContext context) + : base(context) + { + this._context = context; + } + + public async Task GetByPostId(Guid postId) + { + return await this._context.Rating + .FirstOrDefaultAsync(x => x.Post.Id == postId); + } + + public async Task> GetRating(Guid postId) + { + Rating rating = await this.GetByPostId(postId); + + return new Tuple(rating.Likes, rating.Dislikes); + } + + public async Task HasUserRatedThisPost(Guid userId, Guid postId) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/DevHive.Services/Configurations/Mapping/RatingMappings.cs b/src/DevHive.Services/Configurations/Mapping/RatingMappings.cs new file mode 100644 index 0000000..5da1b0d --- /dev/null +++ b/src/DevHive.Services/Configurations/Mapping/RatingMappings.cs @@ -0,0 +1,12 @@ +using AutoMapper; + +namespace DevHive.Services.Configurations.Mapping +{ + public class RatingMappings : Profile + { + public RatingMappings() + { + + } + } +} diff --git a/src/DevHive.Services/Models/Post/Rating/RatePostServiceModel.cs b/src/DevHive.Services/Models/Post/Rating/RatePostServiceModel.cs new file mode 100644 index 0000000..d4eb7bd --- /dev/null +++ b/src/DevHive.Services/Models/Post/Rating/RatePostServiceModel.cs @@ -0,0 +1,13 @@ +using System; + +namespace DevHive.Services.Models.Post.Rating +{ + public class RatePostServiceModel + { + public Guid UserId { get; set; } + + public Guid PostId { get; set; } + + public bool Liked { get; set; } + } +} diff --git a/src/DevHive.Services/Models/Post/Rating/ReadRatingServiceModel.cs b/src/DevHive.Services/Models/Post/Rating/ReadRatingServiceModel.cs new file mode 100644 index 0000000..b071e74 --- /dev/null +++ b/src/DevHive.Services/Models/Post/Rating/ReadRatingServiceModel.cs @@ -0,0 +1,13 @@ +using System; + +namespace DevHive.Services.Models.Post.Rating +{ + public class ReadRatingServiceModel + { + public Guid PostId { get; set; } + + public int Likes { get; set; } + + public int Dislikes { get; set; } + } +} diff --git a/src/DevHive.Services/Services/RatingService.cs b/src/DevHive.Services/Services/RatingService.cs new file mode 100644 index 0000000..2c5a6b6 --- /dev/null +++ b/src/DevHive.Services/Services/RatingService.cs @@ -0,0 +1,54 @@ +using System; +using System.Diagnostics; +using System.Threading.Tasks; +using AutoMapper; +using DevHive.Data.Interfaces.Repositories; +using DevHive.Data.Models; +using DevHive.Services.Models.Post.Rating; +using Microsoft.CodeAnalysis.CSharp.Syntax; + +namespace DevHive.Services.Services +{ + public class RatingService + { + private readonly IPostRepository _postRepository; + private readonly IRatingRepository _ratingRepository; + private readonly IMapper _mapper; + + public RatingService(IPostRepository postRepository, IRatingRepository ratingRepository, IMapper mapper) + { + this._postRepository = postRepository; + this._ratingRepository = ratingRepository; + this._mapper = mapper; + } + + public async Task RatePost(RatePostServiceModel ratePostServiceModel) + { + if (!await this._postRepository.DoesPostExist(ratePostServiceModel.PostId)) + throw new ArgumentNullException("Post does not exist!"); + + if (!await this._ratingRepository.HasUserRatedThisPost(ratePostServiceModel.UserId, ratePostServiceModel.PostId)) + throw new ArgumentException("You can't rate the same post more then one(duh, amigo)"); + + Post post = await this._postRepository.GetByIdAsync(ratePostServiceModel.PostId); + + Rating rating = post.Rating; + if (ratePostServiceModel.Liked) + rating.Likes++; + else + rating.Dislikes++; + + bool success = await this._ratingRepository.EditAsync(rating.Id, rating); + if (!success) + throw new InvalidOperationException("Unable to rate the post!"); + + Rating newRating = await this._ratingRepository.GetByIdAsync(rating.Id); + return this._mapper.Map(newRating); + } + + public async Task RemoveUserRateFromPost(Guid userId, Guid postId) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/DevHive.Web/Controllers/UserController.cs b/src/DevHive.Web/Controllers/UserController.cs index 332868d..2fe9c2f 100644 --- a/src/DevHive.Web/Controllers/UserController.cs +++ b/src/DevHive.Web/Controllers/UserController.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using DevHive.Common.Models.Identity; using DevHive.Services.Interfaces; +using Microsoft.Extensions.Hosting; namespace DevHive.Web.Controllers { -- cgit v1.2.3 From b41f887712ef8f2f0b602da3042261a78c5f492a Mon Sep 17 00:00:00 2001 From: transtrike Date: Mon, 1 Feb 2021 16:03:38 +0200 Subject: Commented out implementation of Rating; Bug fixes --- src/DevHive.Data/DevHiveContext.cs | 36 +- src/DevHive.Data/Interfaces/Models/IPost.cs | 2 +- src/DevHive.Data/Interfaces/Models/IRating.cs | 8 +- .../Interfaces/Repositories/IRatingRepository.cs | 4 +- .../20210201105546_Rating_Implemented.Designer.cs | 575 +++++++++++++++++++ .../20210201105546_Rating_Implemented.cs | 45 ++ ...201110523_Rating_Init_Configuration.Designer.cs | 597 ++++++++++++++++++++ .../20210201110523_Rating_Init_Configuration.cs | 77 +++ .../20210201112614_Rating_Rename.Designer.cs | 597 ++++++++++++++++++++ .../Migrations/20210201112614_Rating_Rename.cs | 78 +++ .../20210201113039_Rating_Rename_2.Designer.cs | 597 ++++++++++++++++++++ .../Migrations/20210201113039_Rating_Rename_2.cs | 97 ++++ .../20210201113809_Rating_Many-To-Many.Designer.cs | 611 ++++++++++++++++++++ .../20210201113809_Rating_Many-To-Many.cs | 45 ++ ...0913_Rating_Many-To-Many_Configured.Designer.cs | 614 +++++++++++++++++++++ ...0210201120913_Rating_Many-To-Many_Configured.cs | 25 + .../20210201140246_Rating_Frozen.Designer.cs | 601 ++++++++++++++++++++ .../Migrations/20210201140246_Rating_Frozen.cs | 137 +++++ .../Migrations/DevHiveContextModelSnapshot.cs | 80 ++- src/DevHive.Data/Models/Post.cs | 4 +- src/DevHive.Data/Models/Rating.cs | 9 +- src/DevHive.Data/Models/User.cs | 2 + src/DevHive.Data/RelationModels/RatedPosts.cs | 18 + src/DevHive.Data/RelationModels/UserFriends.cs | 2 + src/DevHive.Data/RelationModels/UserRate.cs | 16 + src/DevHive.Data/Repositories/BaseRepository.cs | 10 +- src/DevHive.Data/Repositories/CommentRepository.cs | 2 +- src/DevHive.Data/Repositories/PostRepository.cs | 8 +- src/DevHive.Data/Repositories/RatingRepository.cs | 19 +- src/DevHive.Data/Repositories/RoleRepository.cs | 2 +- src/DevHive.Data/Repositories/UserRepository.cs | 2 +- .../Configurations/Mapping/RatingMappings.cs | 5 +- src/DevHive.Services/Interfaces/IRateService.cs | 14 + .../Post/Rating/ReadPostRatingServiceModel.cs | 15 + .../Models/Post/Rating/ReadRatingServiceModel.cs | 13 - src/DevHive.Services/Services/RateService.cs | 80 +++ src/DevHive.Services/Services/RatingService.cs | 54 -- .../Extensions/ConfigureDependencyInjection.cs | 1 + .../Configurations/Mapping/RatingMappings.cs | 16 + src/DevHive.Web/Controllers/RateController.cs | 40 ++ .../Models/Post/Rating/RatePostWebModel.cs | 11 + .../Models/Post/Rating/ReadPostRatingWebModel.cs | 15 + 42 files changed, 5056 insertions(+), 128 deletions(-) create mode 100644 src/DevHive.Data/Migrations/20210201105546_Rating_Implemented.Designer.cs create mode 100644 src/DevHive.Data/Migrations/20210201105546_Rating_Implemented.cs create mode 100644 src/DevHive.Data/Migrations/20210201110523_Rating_Init_Configuration.Designer.cs create mode 100644 src/DevHive.Data/Migrations/20210201110523_Rating_Init_Configuration.cs create mode 100644 src/DevHive.Data/Migrations/20210201112614_Rating_Rename.Designer.cs create mode 100644 src/DevHive.Data/Migrations/20210201112614_Rating_Rename.cs create mode 100644 src/DevHive.Data/Migrations/20210201113039_Rating_Rename_2.Designer.cs create mode 100644 src/DevHive.Data/Migrations/20210201113039_Rating_Rename_2.cs create mode 100644 src/DevHive.Data/Migrations/20210201113809_Rating_Many-To-Many.Designer.cs create mode 100644 src/DevHive.Data/Migrations/20210201113809_Rating_Many-To-Many.cs create mode 100644 src/DevHive.Data/Migrations/20210201120913_Rating_Many-To-Many_Configured.Designer.cs create mode 100644 src/DevHive.Data/Migrations/20210201120913_Rating_Many-To-Many_Configured.cs create mode 100644 src/DevHive.Data/Migrations/20210201140246_Rating_Frozen.Designer.cs create mode 100644 src/DevHive.Data/Migrations/20210201140246_Rating_Frozen.cs create mode 100644 src/DevHive.Data/RelationModels/RatedPosts.cs create mode 100644 src/DevHive.Data/RelationModels/UserRate.cs create mode 100644 src/DevHive.Services/Interfaces/IRateService.cs create mode 100644 src/DevHive.Services/Models/Post/Rating/ReadPostRatingServiceModel.cs delete mode 100644 src/DevHive.Services/Models/Post/Rating/ReadRatingServiceModel.cs create mode 100644 src/DevHive.Services/Services/RateService.cs delete mode 100644 src/DevHive.Services/Services/RatingService.cs create mode 100644 src/DevHive.Web/Configurations/Mapping/RatingMappings.cs create mode 100644 src/DevHive.Web/Controllers/RateController.cs create mode 100644 src/DevHive.Web/Models/Post/Rating/RatePostWebModel.cs create mode 100644 src/DevHive.Web/Models/Post/Rating/ReadPostRatingWebModel.cs (limited to 'src/DevHive.Data/Interfaces/Repositories') diff --git a/src/DevHive.Data/DevHiveContext.cs b/src/DevHive.Data/DevHiveContext.cs index e7c606f..993ddb6 100644 --- a/src/DevHive.Data/DevHiveContext.cs +++ b/src/DevHive.Data/DevHiveContext.cs @@ -17,6 +17,8 @@ namespace DevHive.Data public DbSet Comments { get; set; } public DbSet UserFriends { get; set; } public DbSet Rating { get; set; } + public DbSet RatedPost { get; set; } + public DbSet UserRate { get; set; } protected override void OnModelCreating(ModelBuilder builder) { @@ -73,10 +75,6 @@ namespace DevHive.Data .HasMany(x => x.Comments) .WithOne(x => x.Post); - builder.Entity() - .HasOne(x => x.Rating) - .WithOne(x => x.Post); - /* Comment */ builder.Entity() .HasOne(x => x.Post) @@ -86,6 +84,36 @@ namespace DevHive.Data .HasOne(x => x.Creator) .WithMany(x => x.Comments); + /* Rating */ + builder.Entity() + .HasKey(x => x.Id); + + // builder.Entity() + // .HasOne(x => x.Post) + // .WithOne(x => x.Rating) + // .HasForeignKey(x => x.RatingId); + + // builder.Entity() + // .HasOne(x => x.Rating) + // .WithOne(x => x.Post); + + // builder.Entity() + // .HasMany(x => x.UsersThatRated); + + // /* User Rated Posts */ + builder.Entity() + .HasKey(x => new { x.UserId, x.PostId }); + + // builder.Entity() + // .HasOne(x => x.User) + // .WithMany(x => x.RatedPosts); + + // builder.Entity() + // .HasOne(x => x.Post); + + // builder.Entity() + // .HasMany(x => x.RatedPosts); + base.OnModelCreating(builder); } } diff --git a/src/DevHive.Data/Interfaces/Models/IPost.cs b/src/DevHive.Data/Interfaces/Models/IPost.cs index 65c0fb4..5031a05 100644 --- a/src/DevHive.Data/Interfaces/Models/IPost.cs +++ b/src/DevHive.Data/Interfaces/Models/IPost.cs @@ -14,7 +14,7 @@ namespace DevHive.Data.Interfaces.Models List Comments { get; set; } - Rating Rating { get; set; } + // Rating Rating { get; set; } List FileUrls { get; set; } } diff --git a/src/DevHive.Data/Interfaces/Models/IRating.cs b/src/DevHive.Data/Interfaces/Models/IRating.cs index 4604a75..d1b968f 100644 --- a/src/DevHive.Data/Interfaces/Models/IRating.cs +++ b/src/DevHive.Data/Interfaces/Models/IRating.cs @@ -1,14 +1,14 @@ -using DevHive.Data.Interfaces.Models; +using System.Collections.Generic; using DevHive.Data.Models; namespace DevHive.Data.Interfaces.Models { public interface IRating : IModel { - Post Post { get; set; } + // Post Post { get; set; } - int Likes { get; set; } + int Rate { get; set; } - int Dislikes { get; set; } + // HashSet UsersThatRated { get; set; } } } diff --git a/src/DevHive.Data/Interfaces/Repositories/IRatingRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IRatingRepository.cs index de4e3f2..7b99e0e 100644 --- a/src/DevHive.Data/Interfaces/Repositories/IRatingRepository.cs +++ b/src/DevHive.Data/Interfaces/Repositories/IRatingRepository.cs @@ -8,8 +8,6 @@ namespace DevHive.Data.Interfaces.Repositories public interface IRatingRepository : IRepository { Task GetByPostId(Guid postId); - Task> GetRating(Guid postId); - - Task HasUserRatedThisPost(Guid userId, Guid postId); + Task GetRating(Guid postId); } } diff --git a/src/DevHive.Data/Migrations/20210201105546_Rating_Implemented.Designer.cs b/src/DevHive.Data/Migrations/20210201105546_Rating_Implemented.Designer.cs new file mode 100644 index 0000000..00e4fbd --- /dev/null +++ b/src/DevHive.Data/Migrations/20210201105546_Rating_Implemented.Designer.cs @@ -0,0 +1,575 @@ +// +using System; +using System.Collections.Generic; +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("20210201105546_Rating_Implemented")] + partial class Rating_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.Comment", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("PostId") + .HasColumnType("uuid"); + + b.Property("TimeCreated") + .HasColumnType("timestamp without time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("PostId"); + + b.ToTable("Comments"); + }); + + 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.Post", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property>("FileUrls") + .HasColumnType("text[]"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("RatingId") + .HasColumnType("uuid"); + + b.Property("TimeCreated") + .HasColumnType("timestamp without time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("RatingId") + .IsUnique(); + + b.ToTable("Posts"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Rating", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Dislikes") + .HasColumnType("integer"); + + b.Property("Likes") + .HasColumnType("integer"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Rating"); + }); + + 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.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("ProfilePictureUrl") + .HasColumnType("text"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + 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("UserName") + .IsUnique(); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserFriends", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("FriendId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "FriendId"); + + b.HasIndex("FriendId"); + + b.ToTable("UserFriends"); + }); + + modelBuilder.Entity("LanguageUser", b => + { + b.Property("LanguagesId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("LanguagesId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("LanguageUser"); + }); + + 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") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + 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") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + 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("TechnologyUser", b => + { + b.Property("TechnologiesId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("TechnologiesId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("TechnologyUser"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Comment", b => + { + b.HasOne("DevHive.Data.Models.User", "Creator") + .WithMany("Comments") + .HasForeignKey("CreatorId"); + + b.HasOne("DevHive.Data.Models.Post", "Post") + .WithMany("Comments") + .HasForeignKey("PostId"); + + b.Navigation("Creator"); + + b.Navigation("Post"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Post", b => + { + b.HasOne("DevHive.Data.Models.User", "Creator") + .WithMany("Posts") + .HasForeignKey("CreatorId"); + + b.HasOne("DevHive.Data.Models.Rating", "Rating") + .WithOne("Post") + .HasForeignKey("DevHive.Data.Models.Post", "RatingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Creator"); + + b.Navigation("Rating"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Rating", b => + { + b.HasOne("DevHive.Data.Models.User", null) + .WithMany("RatedPosts") + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserFriends", b => + { + b.HasOne("DevHive.Data.Models.User", "Friend") + .WithMany() + .HasForeignKey("FriendId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany("Friends") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Friend"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("LanguageUser", b => + { + b.HasOne("DevHive.Data.Models.Language", null) + .WithMany() + .HasForeignKey("LanguagesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + 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("TechnologyUser", b => + { + b.HasOne("DevHive.Data.Models.Technology", null) + .WithMany() + .HasForeignKey("TechnologiesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("DevHive.Data.Models.Post", b => + { + b.Navigation("Comments"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Rating", b => + { + b.Navigation("Post"); + }); + + modelBuilder.Entity("DevHive.Data.Models.User", b => + { + b.Navigation("Comments"); + + b.Navigation("Friends"); + + b.Navigation("Posts"); + + b.Navigation("RatedPosts"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/DevHive.Data/Migrations/20210201105546_Rating_Implemented.cs b/src/DevHive.Data/Migrations/20210201105546_Rating_Implemented.cs new file mode 100644 index 0000000..ae7ef8e --- /dev/null +++ b/src/DevHive.Data/Migrations/20210201105546_Rating_Implemented.cs @@ -0,0 +1,45 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace DevHive.Data.Migrations +{ + public partial class Rating_Implemented : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "UserId", + table: "Rating", + type: "uuid", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_Rating_UserId", + table: "Rating", + column: "UserId"); + + migrationBuilder.AddForeignKey( + name: "FK_Rating_AspNetUsers_UserId", + table: "Rating", + column: "UserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Rating_AspNetUsers_UserId", + table: "Rating"); + + migrationBuilder.DropIndex( + name: "IX_Rating_UserId", + table: "Rating"); + + migrationBuilder.DropColumn( + name: "UserId", + table: "Rating"); + } + } +} diff --git a/src/DevHive.Data/Migrations/20210201110523_Rating_Init_Configuration.Designer.cs b/src/DevHive.Data/Migrations/20210201110523_Rating_Init_Configuration.Designer.cs new file mode 100644 index 0000000..0aea5ce --- /dev/null +++ b/src/DevHive.Data/Migrations/20210201110523_Rating_Init_Configuration.Designer.cs @@ -0,0 +1,597 @@ +// +using System; +using System.Collections.Generic; +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("20210201110523_Rating_Init_Configuration")] + partial class Rating_Init_Configuration + { + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("PostId") + .HasColumnType("uuid"); + + b.Property("TimeCreated") + .HasColumnType("timestamp without time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("PostId"); + + b.ToTable("Comments"); + }); + + 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.Post", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property>("FileUrls") + .HasColumnType("text[]"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("RatingId") + .HasColumnType("uuid"); + + b.Property("TimeCreated") + .HasColumnType("timestamp without time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("RatingId") + .IsUnique(); + + b.ToTable("Posts"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Rating", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Dislikes") + .HasColumnType("integer"); + + b.Property("Likes") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Rating"); + }); + + 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.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("ProfilePictureUrl") + .HasColumnType("text"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + 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("UserName") + .IsUnique(); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.RatedPosts", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("PostId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "PostId"); + + b.HasIndex("PostId"); + + b.ToTable("RatedPosts"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserFriends", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("FriendId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "FriendId"); + + b.HasIndex("FriendId"); + + b.ToTable("UserFriends"); + }); + + modelBuilder.Entity("LanguageUser", b => + { + b.Property("LanguagesId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("LanguagesId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("LanguageUser"); + }); + + 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") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + 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") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + 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("TechnologyUser", b => + { + b.Property("TechnologiesId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("TechnologiesId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("TechnologyUser"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Comment", b => + { + b.HasOne("DevHive.Data.Models.User", "Creator") + .WithMany("Comments") + .HasForeignKey("CreatorId"); + + b.HasOne("DevHive.Data.Models.Post", "Post") + .WithMany("Comments") + .HasForeignKey("PostId"); + + b.Navigation("Creator"); + + b.Navigation("Post"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Post", b => + { + b.HasOne("DevHive.Data.Models.User", "Creator") + .WithMany("Posts") + .HasForeignKey("CreatorId"); + + b.HasOne("DevHive.Data.Models.Rating", "Rating") + .WithOne("Post") + .HasForeignKey("DevHive.Data.Models.Post", "RatingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Creator"); + + b.Navigation("Rating"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.RatedPosts", b => + { + b.HasOne("DevHive.Data.Models.Post", "Post") + .WithMany() + .HasForeignKey("PostId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany("RatedPosts") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Post"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserFriends", b => + { + b.HasOne("DevHive.Data.Models.User", "Friend") + .WithMany() + .HasForeignKey("FriendId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany("Friends") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Friend"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("LanguageUser", b => + { + b.HasOne("DevHive.Data.Models.Language", null) + .WithMany() + .HasForeignKey("LanguagesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + 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("TechnologyUser", b => + { + b.HasOne("DevHive.Data.Models.Technology", null) + .WithMany() + .HasForeignKey("TechnologiesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("DevHive.Data.Models.Post", b => + { + b.Navigation("Comments"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Rating", b => + { + b.Navigation("Post"); + }); + + modelBuilder.Entity("DevHive.Data.Models.User", b => + { + b.Navigation("Comments"); + + b.Navigation("Friends"); + + b.Navigation("Posts"); + + b.Navigation("RatedPosts"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/DevHive.Data/Migrations/20210201110523_Rating_Init_Configuration.cs b/src/DevHive.Data/Migrations/20210201110523_Rating_Init_Configuration.cs new file mode 100644 index 0000000..a5a4a72 --- /dev/null +++ b/src/DevHive.Data/Migrations/20210201110523_Rating_Init_Configuration.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace DevHive.Data.Migrations +{ + public partial class Rating_Init_Configuration : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Rating_AspNetUsers_UserId", + table: "Rating"); + + migrationBuilder.DropIndex( + name: "IX_Rating_UserId", + table: "Rating"); + + migrationBuilder.DropColumn( + name: "UserId", + table: "Rating"); + + migrationBuilder.CreateTable( + name: "RatedPosts", + columns: table => new + { + UserId = table.Column(type: "uuid", nullable: false), + PostId = table.Column(type: "uuid", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_RatedPosts", x => new { x.UserId, x.PostId }); + table.ForeignKey( + name: "FK_RatedPosts_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_RatedPosts_Posts_PostId", + column: x => x.PostId, + principalTable: "Posts", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_RatedPosts_PostId", + table: "RatedPosts", + column: "PostId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "RatedPosts"); + + migrationBuilder.AddColumn( + name: "UserId", + table: "Rating", + type: "uuid", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_Rating_UserId", + table: "Rating", + column: "UserId"); + + migrationBuilder.AddForeignKey( + name: "FK_Rating_AspNetUsers_UserId", + table: "Rating", + column: "UserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + } + } +} diff --git a/src/DevHive.Data/Migrations/20210201112614_Rating_Rename.Designer.cs b/src/DevHive.Data/Migrations/20210201112614_Rating_Rename.Designer.cs new file mode 100644 index 0000000..a64baa1 --- /dev/null +++ b/src/DevHive.Data/Migrations/20210201112614_Rating_Rename.Designer.cs @@ -0,0 +1,597 @@ +// +using System; +using System.Collections.Generic; +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("20210201112614_Rating_Rename")] + partial class Rating_Rename + { + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("PostId") + .HasColumnType("uuid"); + + b.Property("TimeCreated") + .HasColumnType("timestamp without time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("PostId"); + + b.ToTable("Comments"); + }); + + 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.Post", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property>("FileUrls") + .HasColumnType("text[]"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("RatingId") + .HasColumnType("uuid"); + + b.Property("TimeCreated") + .HasColumnType("timestamp without time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("RatingId") + .IsUnique(); + + b.ToTable("Posts"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Rating", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Dislikes") + .HasColumnType("integer"); + + b.Property("Likes") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Rating"); + }); + + 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.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("ProfilePictureUrl") + .HasColumnType("text"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + 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("UserName") + .IsUnique(); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.RatedPost", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("PostId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "PostId"); + + b.HasIndex("PostId"); + + b.ToTable("RatedPost"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserFriends", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("FriendId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "FriendId"); + + b.HasIndex("FriendId"); + + b.ToTable("UserFriends"); + }); + + modelBuilder.Entity("LanguageUser", b => + { + b.Property("LanguagesId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("LanguagesId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("LanguageUser"); + }); + + 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") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + 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") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + 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("TechnologyUser", b => + { + b.Property("TechnologiesId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("TechnologiesId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("TechnologyUser"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Comment", b => + { + b.HasOne("DevHive.Data.Models.User", "Creator") + .WithMany("Comments") + .HasForeignKey("CreatorId"); + + b.HasOne("DevHive.Data.Models.Post", "Post") + .WithMany("Comments") + .HasForeignKey("PostId"); + + b.Navigation("Creator"); + + b.Navigation("Post"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Post", b => + { + b.HasOne("DevHive.Data.Models.User", "Creator") + .WithMany("Posts") + .HasForeignKey("CreatorId"); + + b.HasOne("DevHive.Data.Models.Rating", "Rating") + .WithOne("Post") + .HasForeignKey("DevHive.Data.Models.Post", "RatingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Creator"); + + b.Navigation("Rating"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.RatedPost", b => + { + b.HasOne("DevHive.Data.Models.Post", "Post") + .WithMany() + .HasForeignKey("PostId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany("RatedPosts") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Post"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserFriends", b => + { + b.HasOne("DevHive.Data.Models.User", "Friend") + .WithMany() + .HasForeignKey("FriendId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany("Friends") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Friend"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("LanguageUser", b => + { + b.HasOne("DevHive.Data.Models.Language", null) + .WithMany() + .HasForeignKey("LanguagesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + 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("TechnologyUser", b => + { + b.HasOne("DevHive.Data.Models.Technology", null) + .WithMany() + .HasForeignKey("TechnologiesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("DevHive.Data.Models.Post", b => + { + b.Navigation("Comments"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Rating", b => + { + b.Navigation("Post"); + }); + + modelBuilder.Entity("DevHive.Data.Models.User", b => + { + b.Navigation("Comments"); + + b.Navigation("Friends"); + + b.Navigation("Posts"); + + b.Navigation("RatedPosts"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/DevHive.Data/Migrations/20210201112614_Rating_Rename.cs b/src/DevHive.Data/Migrations/20210201112614_Rating_Rename.cs new file mode 100644 index 0000000..1fb4743 --- /dev/null +++ b/src/DevHive.Data/Migrations/20210201112614_Rating_Rename.cs @@ -0,0 +1,78 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace DevHive.Data.Migrations +{ + public partial class Rating_Rename : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "RatedPosts"); + + migrationBuilder.CreateTable( + name: "RatedPost", + columns: table => new + { + UserId = table.Column(type: "uuid", nullable: false), + PostId = table.Column(type: "uuid", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_RatedPost", x => new { x.UserId, x.PostId }); + table.ForeignKey( + name: "FK_RatedPost_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_RatedPost_Posts_PostId", + column: x => x.PostId, + principalTable: "Posts", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_RatedPost_PostId", + table: "RatedPost", + column: "PostId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "RatedPost"); + + migrationBuilder.CreateTable( + name: "RatedPosts", + columns: table => new + { + UserId = table.Column(type: "uuid", nullable: false), + PostId = table.Column(type: "uuid", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_RatedPosts", x => new { x.UserId, x.PostId }); + table.ForeignKey( + name: "FK_RatedPosts_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_RatedPosts_Posts_PostId", + column: x => x.PostId, + principalTable: "Posts", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_RatedPosts_PostId", + table: "RatedPosts", + column: "PostId"); + } + } +} diff --git a/src/DevHive.Data/Migrations/20210201113039_Rating_Rename_2.Designer.cs b/src/DevHive.Data/Migrations/20210201113039_Rating_Rename_2.Designer.cs new file mode 100644 index 0000000..82e08a5 --- /dev/null +++ b/src/DevHive.Data/Migrations/20210201113039_Rating_Rename_2.Designer.cs @@ -0,0 +1,597 @@ +// +using System; +using System.Collections.Generic; +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("20210201113039_Rating_Rename_2")] + partial class Rating_Rename_2 + { + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("PostId") + .HasColumnType("uuid"); + + b.Property("TimeCreated") + .HasColumnType("timestamp without time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("PostId"); + + b.ToTable("Comments"); + }); + + 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.Post", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property>("FileUrls") + .HasColumnType("text[]"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("RatingId") + .HasColumnType("uuid"); + + b.Property("TimeCreated") + .HasColumnType("timestamp without time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("RatingId") + .IsUnique(); + + b.ToTable("Posts"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Rating", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Dislikes") + .HasColumnType("integer"); + + b.Property("Likes") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Rating"); + }); + + 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.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("ProfilePictureUrl") + .HasColumnType("text"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + 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("UserName") + .IsUnique(); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.RatedPost", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("PostId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "PostId"); + + b.HasIndex("PostId"); + + b.ToTable("RatedPosts"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserFriends", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("FriendId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "FriendId"); + + b.HasIndex("FriendId"); + + b.ToTable("UserFriends"); + }); + + modelBuilder.Entity("LanguageUser", b => + { + b.Property("LanguagesId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("LanguagesId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("LanguageUser"); + }); + + 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") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + 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") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + 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("TechnologyUser", b => + { + b.Property("TechnologiesId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("TechnologiesId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("TechnologyUser"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Comment", b => + { + b.HasOne("DevHive.Data.Models.User", "Creator") + .WithMany("Comments") + .HasForeignKey("CreatorId"); + + b.HasOne("DevHive.Data.Models.Post", "Post") + .WithMany("Comments") + .HasForeignKey("PostId"); + + b.Navigation("Creator"); + + b.Navigation("Post"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Post", b => + { + b.HasOne("DevHive.Data.Models.User", "Creator") + .WithMany("Posts") + .HasForeignKey("CreatorId"); + + b.HasOne("DevHive.Data.Models.Rating", "Rating") + .WithOne("Post") + .HasForeignKey("DevHive.Data.Models.Post", "RatingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Creator"); + + b.Navigation("Rating"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.RatedPost", b => + { + b.HasOne("DevHive.Data.Models.Post", "Post") + .WithMany() + .HasForeignKey("PostId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany("RatedPosts") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Post"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserFriends", b => + { + b.HasOne("DevHive.Data.Models.User", "Friend") + .WithMany() + .HasForeignKey("FriendId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany("Friends") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Friend"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("LanguageUser", b => + { + b.HasOne("DevHive.Data.Models.Language", null) + .WithMany() + .HasForeignKey("LanguagesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + 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("TechnologyUser", b => + { + b.HasOne("DevHive.Data.Models.Technology", null) + .WithMany() + .HasForeignKey("TechnologiesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("DevHive.Data.Models.Post", b => + { + b.Navigation("Comments"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Rating", b => + { + b.Navigation("Post"); + }); + + modelBuilder.Entity("DevHive.Data.Models.User", b => + { + b.Navigation("Comments"); + + b.Navigation("Friends"); + + b.Navigation("Posts"); + + b.Navigation("RatedPosts"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/DevHive.Data/Migrations/20210201113039_Rating_Rename_2.cs b/src/DevHive.Data/Migrations/20210201113039_Rating_Rename_2.cs new file mode 100644 index 0000000..9dc87cf --- /dev/null +++ b/src/DevHive.Data/Migrations/20210201113039_Rating_Rename_2.cs @@ -0,0 +1,97 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace DevHive.Data.Migrations +{ + public partial class Rating_Rename_2 : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_RatedPost_AspNetUsers_UserId", + table: "RatedPost"); + + migrationBuilder.DropForeignKey( + name: "FK_RatedPost_Posts_PostId", + table: "RatedPost"); + + migrationBuilder.DropPrimaryKey( + name: "PK_RatedPost", + table: "RatedPost"); + + migrationBuilder.RenameTable( + name: "RatedPost", + newName: "RatedPosts"); + + migrationBuilder.RenameIndex( + name: "IX_RatedPost_PostId", + table: "RatedPosts", + newName: "IX_RatedPosts_PostId"); + + migrationBuilder.AddPrimaryKey( + name: "PK_RatedPosts", + table: "RatedPosts", + columns: new[] { "UserId", "PostId" }); + + migrationBuilder.AddForeignKey( + name: "FK_RatedPosts_AspNetUsers_UserId", + table: "RatedPosts", + column: "UserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_RatedPosts_Posts_PostId", + table: "RatedPosts", + column: "PostId", + principalTable: "Posts", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_RatedPosts_AspNetUsers_UserId", + table: "RatedPosts"); + + migrationBuilder.DropForeignKey( + name: "FK_RatedPosts_Posts_PostId", + table: "RatedPosts"); + + migrationBuilder.DropPrimaryKey( + name: "PK_RatedPosts", + table: "RatedPosts"); + + migrationBuilder.RenameTable( + name: "RatedPosts", + newName: "RatedPost"); + + migrationBuilder.RenameIndex( + name: "IX_RatedPosts_PostId", + table: "RatedPost", + newName: "IX_RatedPost_PostId"); + + migrationBuilder.AddPrimaryKey( + name: "PK_RatedPost", + table: "RatedPost", + columns: new[] { "UserId", "PostId" }); + + migrationBuilder.AddForeignKey( + name: "FK_RatedPost_AspNetUsers_UserId", + table: "RatedPost", + column: "UserId", + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + + migrationBuilder.AddForeignKey( + name: "FK_RatedPost_Posts_PostId", + table: "RatedPost", + column: "PostId", + principalTable: "Posts", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/src/DevHive.Data/Migrations/20210201113809_Rating_Many-To-Many.Designer.cs b/src/DevHive.Data/Migrations/20210201113809_Rating_Many-To-Many.Designer.cs new file mode 100644 index 0000000..849715a --- /dev/null +++ b/src/DevHive.Data/Migrations/20210201113809_Rating_Many-To-Many.Designer.cs @@ -0,0 +1,611 @@ +// +using System; +using System.Collections.Generic; +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("20210201113809_Rating_Many-To-Many")] + partial class Rating_ManyToMany + { + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("PostId") + .HasColumnType("uuid"); + + b.Property("TimeCreated") + .HasColumnType("timestamp without time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("PostId"); + + b.ToTable("Comments"); + }); + + 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.Post", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property>("FileUrls") + .HasColumnType("text[]"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("RatingId") + .HasColumnType("uuid"); + + b.Property("TimeCreated") + .HasColumnType("timestamp without time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("RatingId") + .IsUnique(); + + b.ToTable("Posts"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Rating", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Dislikes") + .HasColumnType("integer"); + + b.Property("Likes") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Rating"); + }); + + 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.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("ProfilePictureUrl") + .HasColumnType("text"); + + b.Property("RatingId") + .HasColumnType("uuid"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + 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("RatingId"); + + b.HasIndex("UserName") + .IsUnique(); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.RatedPost", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("PostId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "PostId"); + + b.HasIndex("PostId"); + + b.ToTable("RatedPosts"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserFriends", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("FriendId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "FriendId"); + + b.HasIndex("FriendId"); + + b.ToTable("UserFriends"); + }); + + modelBuilder.Entity("LanguageUser", b => + { + b.Property("LanguagesId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("LanguagesId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("LanguageUser"); + }); + + 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") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + 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") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + 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("TechnologyUser", b => + { + b.Property("TechnologiesId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("TechnologiesId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("TechnologyUser"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Comment", b => + { + b.HasOne("DevHive.Data.Models.User", "Creator") + .WithMany("Comments") + .HasForeignKey("CreatorId"); + + b.HasOne("DevHive.Data.Models.Post", "Post") + .WithMany("Comments") + .HasForeignKey("PostId"); + + b.Navigation("Creator"); + + b.Navigation("Post"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Post", b => + { + b.HasOne("DevHive.Data.Models.User", "Creator") + .WithMany("Posts") + .HasForeignKey("CreatorId"); + + b.HasOne("DevHive.Data.Models.Rating", "Rating") + .WithOne("Post") + .HasForeignKey("DevHive.Data.Models.Post", "RatingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Creator"); + + b.Navigation("Rating"); + }); + + modelBuilder.Entity("DevHive.Data.Models.User", b => + { + b.HasOne("DevHive.Data.Models.Rating", null) + .WithMany("UsersThatRated") + .HasForeignKey("RatingId"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.RatedPost", b => + { + b.HasOne("DevHive.Data.Models.Post", "Post") + .WithMany() + .HasForeignKey("PostId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany("RatedPosts") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Post"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserFriends", b => + { + b.HasOne("DevHive.Data.Models.User", "Friend") + .WithMany() + .HasForeignKey("FriendId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany("Friends") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Friend"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("LanguageUser", b => + { + b.HasOne("DevHive.Data.Models.Language", null) + .WithMany() + .HasForeignKey("LanguagesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + 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("TechnologyUser", b => + { + b.HasOne("DevHive.Data.Models.Technology", null) + .WithMany() + .HasForeignKey("TechnologiesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("DevHive.Data.Models.Post", b => + { + b.Navigation("Comments"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Rating", b => + { + b.Navigation("Post"); + + b.Navigation("UsersThatRated"); + }); + + modelBuilder.Entity("DevHive.Data.Models.User", b => + { + b.Navigation("Comments"); + + b.Navigation("Friends"); + + b.Navigation("Posts"); + + b.Navigation("RatedPosts"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/DevHive.Data/Migrations/20210201113809_Rating_Many-To-Many.cs b/src/DevHive.Data/Migrations/20210201113809_Rating_Many-To-Many.cs new file mode 100644 index 0000000..4ec0bd7 --- /dev/null +++ b/src/DevHive.Data/Migrations/20210201113809_Rating_Many-To-Many.cs @@ -0,0 +1,45 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace DevHive.Data.Migrations +{ + public partial class Rating_ManyToMany : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "RatingId", + table: "AspNetUsers", + type: "uuid", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUsers_RatingId", + table: "AspNetUsers", + column: "RatingId"); + + migrationBuilder.AddForeignKey( + name: "FK_AspNetUsers_Rating_RatingId", + table: "AspNetUsers", + column: "RatingId", + principalTable: "Rating", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_AspNetUsers_Rating_RatingId", + table: "AspNetUsers"); + + migrationBuilder.DropIndex( + name: "IX_AspNetUsers_RatingId", + table: "AspNetUsers"); + + migrationBuilder.DropColumn( + name: "RatingId", + table: "AspNetUsers"); + } + } +} diff --git a/src/DevHive.Data/Migrations/20210201120913_Rating_Many-To-Many_Configured.Designer.cs b/src/DevHive.Data/Migrations/20210201120913_Rating_Many-To-Many_Configured.Designer.cs new file mode 100644 index 0000000..e31576f --- /dev/null +++ b/src/DevHive.Data/Migrations/20210201120913_Rating_Many-To-Many_Configured.Designer.cs @@ -0,0 +1,614 @@ +// +using System; +using System.Collections.Generic; +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("20210201120913_Rating_Many-To-Many_Configured")] + partial class Rating_ManyToMany_Configured + { + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("PostId") + .HasColumnType("uuid"); + + b.Property("TimeCreated") + .HasColumnType("timestamp without time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("PostId"); + + b.ToTable("Comments"); + }); + + 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.Post", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property>("FileUrls") + .HasColumnType("text[]"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("RatingId") + .HasColumnType("uuid"); + + b.Property("TimeCreated") + .HasColumnType("timestamp without time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("RatingId") + .IsUnique(); + + b.ToTable("Posts"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Rating", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Dislikes") + .HasColumnType("integer"); + + b.Property("Likes") + .HasColumnType("integer"); + + b.Property("PostId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.ToTable("Rating"); + }); + + 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.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("ProfilePictureUrl") + .HasColumnType("text"); + + b.Property("RatingId") + .HasColumnType("uuid"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + 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("RatingId"); + + b.HasIndex("UserName") + .IsUnique(); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.RatedPost", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("PostId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "PostId"); + + b.HasIndex("PostId"); + + b.ToTable("RatedPosts"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserFriends", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("FriendId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "FriendId"); + + b.HasIndex("FriendId"); + + b.ToTable("UserFriends"); + }); + + modelBuilder.Entity("LanguageUser", b => + { + b.Property("LanguagesId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("LanguagesId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("LanguageUser"); + }); + + 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") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + 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") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + 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("TechnologyUser", b => + { + b.Property("TechnologiesId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("TechnologiesId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("TechnologyUser"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Comment", b => + { + b.HasOne("DevHive.Data.Models.User", "Creator") + .WithMany("Comments") + .HasForeignKey("CreatorId"); + + b.HasOne("DevHive.Data.Models.Post", "Post") + .WithMany("Comments") + .HasForeignKey("PostId"); + + b.Navigation("Creator"); + + b.Navigation("Post"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Post", b => + { + b.HasOne("DevHive.Data.Models.User", "Creator") + .WithMany("Posts") + .HasForeignKey("CreatorId"); + + b.HasOne("DevHive.Data.Models.Rating", "Rating") + .WithOne("Post") + .HasForeignKey("DevHive.Data.Models.Post", "RatingId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Creator"); + + b.Navigation("Rating"); + }); + + modelBuilder.Entity("DevHive.Data.Models.User", b => + { + b.HasOne("DevHive.Data.Models.Rating", null) + .WithMany("UsersThatRated") + .HasForeignKey("RatingId"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.RatedPost", b => + { + b.HasOne("DevHive.Data.Models.Post", "Post") + .WithMany() + .HasForeignKey("PostId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany("RatedPosts") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Post"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserFriends", b => + { + b.HasOne("DevHive.Data.Models.User", "Friend") + .WithMany() + .HasForeignKey("FriendId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany("Friends") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Friend"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("LanguageUser", b => + { + b.HasOne("DevHive.Data.Models.Language", null) + .WithMany() + .HasForeignKey("LanguagesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + 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("TechnologyUser", b => + { + b.HasOne("DevHive.Data.Models.Technology", null) + .WithMany() + .HasForeignKey("TechnologiesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("DevHive.Data.Models.Post", b => + { + b.Navigation("Comments"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Rating", b => + { + b.Navigation("Post"); + + b.Navigation("UsersThatRated"); + }); + + modelBuilder.Entity("DevHive.Data.Models.User", b => + { + b.Navigation("Comments"); + + b.Navigation("Friends"); + + b.Navigation("Posts"); + + b.Navigation("RatedPosts"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/DevHive.Data/Migrations/20210201120913_Rating_Many-To-Many_Configured.cs b/src/DevHive.Data/Migrations/20210201120913_Rating_Many-To-Many_Configured.cs new file mode 100644 index 0000000..7800d3a --- /dev/null +++ b/src/DevHive.Data/Migrations/20210201120913_Rating_Many-To-Many_Configured.cs @@ -0,0 +1,25 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace DevHive.Data.Migrations +{ + public partial class Rating_ManyToMany_Configured : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "PostId", + table: "Rating", + type: "uuid", + nullable: false, + defaultValue: new Guid("00000000-0000-0000-0000-000000000000")); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "PostId", + table: "Rating"); + } + } +} diff --git a/src/DevHive.Data/Migrations/20210201140246_Rating_Frozen.Designer.cs b/src/DevHive.Data/Migrations/20210201140246_Rating_Frozen.Designer.cs new file mode 100644 index 0000000..17c80e0 --- /dev/null +++ b/src/DevHive.Data/Migrations/20210201140246_Rating_Frozen.Designer.cs @@ -0,0 +1,601 @@ +// +using System; +using System.Collections.Generic; +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("20210201140246_Rating_Frozen")] + partial class Rating_Frozen + { + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("PostId") + .HasColumnType("uuid"); + + b.Property("TimeCreated") + .HasColumnType("timestamp without time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("PostId"); + + b.ToTable("Comments"); + }); + + 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.Post", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property>("FileUrls") + .HasColumnType("text[]"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("TimeCreated") + .HasColumnType("timestamp without time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.ToTable("Posts"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Rating", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Rate") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Rating"); + }); + + 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.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("ProfilePictureUrl") + .HasColumnType("text"); + + b.Property("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + 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("UserName") + .IsUnique(); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.RatedPost", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("PostId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "PostId"); + + b.HasIndex("PostId"); + + b.ToTable("RatedPosts"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserFriends", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("FriendId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "FriendId"); + + b.HasIndex("FriendId"); + + b.ToTable("UserFriends"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserRate", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Rate") + .HasColumnType("boolean"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("UserRates"); + }); + + modelBuilder.Entity("LanguageUser", b => + { + b.Property("LanguagesId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("LanguagesId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("LanguageUser"); + }); + + 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") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + 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") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + 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("TechnologyUser", b => + { + b.Property("TechnologiesId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("TechnologiesId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("TechnologyUser"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Comment", b => + { + b.HasOne("DevHive.Data.Models.User", "Creator") + .WithMany("Comments") + .HasForeignKey("CreatorId"); + + b.HasOne("DevHive.Data.Models.Post", "Post") + .WithMany("Comments") + .HasForeignKey("PostId"); + + b.Navigation("Creator"); + + b.Navigation("Post"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Post", b => + { + b.HasOne("DevHive.Data.Models.User", "Creator") + .WithMany("Posts") + .HasForeignKey("CreatorId"); + + b.Navigation("Creator"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.RatedPost", b => + { + b.HasOne("DevHive.Data.Models.Post", "Post") + .WithMany() + .HasForeignKey("PostId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Post"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserFriends", b => + { + b.HasOne("DevHive.Data.Models.User", "Friend") + .WithMany() + .HasForeignKey("FriendId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany("Friends") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Friend"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserRate", b => + { + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany() + .HasForeignKey("UserId"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("LanguageUser", b => + { + b.HasOne("DevHive.Data.Models.Language", null) + .WithMany() + .HasForeignKey("LanguagesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + 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("TechnologyUser", b => + { + b.HasOne("DevHive.Data.Models.Technology", null) + .WithMany() + .HasForeignKey("TechnologiesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("DevHive.Data.Models.Post", b => + { + b.Navigation("Comments"); + }); + + modelBuilder.Entity("DevHive.Data.Models.User", b => + { + b.Navigation("Comments"); + + b.Navigation("Friends"); + + b.Navigation("Posts"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/DevHive.Data/Migrations/20210201140246_Rating_Frozen.cs b/src/DevHive.Data/Migrations/20210201140246_Rating_Frozen.cs new file mode 100644 index 0000000..49b0809 --- /dev/null +++ b/src/DevHive.Data/Migrations/20210201140246_Rating_Frozen.cs @@ -0,0 +1,137 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace DevHive.Data.Migrations +{ + public partial class Rating_Frozen : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_AspNetUsers_Rating_RatingId", + table: "AspNetUsers"); + + migrationBuilder.DropForeignKey( + name: "FK_Posts_Rating_RatingId", + table: "Posts"); + + migrationBuilder.DropIndex( + name: "IX_Posts_RatingId", + table: "Posts"); + + migrationBuilder.DropIndex( + name: "IX_AspNetUsers_RatingId", + table: "AspNetUsers"); + + migrationBuilder.DropColumn( + name: "Dislikes", + table: "Rating"); + + migrationBuilder.DropColumn( + name: "PostId", + table: "Rating"); + + migrationBuilder.DropColumn( + name: "RatingId", + table: "Posts"); + + migrationBuilder.DropColumn( + name: "RatingId", + table: "AspNetUsers"); + + migrationBuilder.RenameColumn( + name: "Likes", + table: "Rating", + newName: "Rate"); + + migrationBuilder.CreateTable( + name: "UserRates", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + UserId = table.Column(type: "uuid", nullable: true), + Rate = table.Column(type: "boolean", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_UserRates", x => x.Id); + table.ForeignKey( + name: "FK_UserRates_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateIndex( + name: "IX_UserRates_UserId", + table: "UserRates", + column: "UserId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "UserRates"); + + migrationBuilder.RenameColumn( + name: "Rate", + table: "Rating", + newName: "Likes"); + + migrationBuilder.AddColumn( + name: "Dislikes", + table: "Rating", + type: "integer", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "PostId", + table: "Rating", + type: "uuid", + nullable: false, + defaultValue: new Guid("00000000-0000-0000-0000-000000000000")); + + migrationBuilder.AddColumn( + name: "RatingId", + table: "Posts", + type: "uuid", + nullable: false, + defaultValue: new Guid("00000000-0000-0000-0000-000000000000")); + + migrationBuilder.AddColumn( + name: "RatingId", + table: "AspNetUsers", + type: "uuid", + nullable: true); + + migrationBuilder.CreateIndex( + name: "IX_Posts_RatingId", + table: "Posts", + column: "RatingId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUsers_RatingId", + table: "AspNetUsers", + column: "RatingId"); + + migrationBuilder.AddForeignKey( + name: "FK_AspNetUsers_Rating_RatingId", + table: "AspNetUsers", + column: "RatingId", + principalTable: "Rating", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + + migrationBuilder.AddForeignKey( + name: "FK_Posts_Rating_RatingId", + table: "Posts", + column: "RatingId", + principalTable: "Rating", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs b/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs index 064fb26..435adb4 100644 --- a/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs +++ b/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs @@ -76,9 +76,6 @@ namespace DevHive.Data.Migrations b.Property("Message") .HasColumnType("text"); - b.Property("RatingId") - .HasColumnType("uuid"); - b.Property("TimeCreated") .HasColumnType("timestamp without time zone"); @@ -86,9 +83,6 @@ namespace DevHive.Data.Migrations b.HasIndex("CreatorId"); - b.HasIndex("RatingId") - .IsUnique(); - b.ToTable("Posts"); }); @@ -98,10 +92,7 @@ namespace DevHive.Data.Migrations .ValueGeneratedOnAdd() .HasColumnType("uuid"); - b.Property("Dislikes") - .HasColumnType("integer"); - - b.Property("Likes") + b.Property("Rate") .HasColumnType("integer"); b.HasKey("Id"); @@ -227,6 +218,21 @@ namespace DevHive.Data.Migrations b.ToTable("AspNetUsers"); }); + modelBuilder.Entity("DevHive.Data.RelationModels.RatedPost", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("PostId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "PostId"); + + b.HasIndex("PostId"); + + b.ToTable("RatedPosts"); + }); + modelBuilder.Entity("DevHive.Data.RelationModels.UserFriends", b => { b.Property("UserId") @@ -242,6 +248,25 @@ namespace DevHive.Data.Migrations b.ToTable("UserFriends"); }); + modelBuilder.Entity("DevHive.Data.RelationModels.UserRate", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Rate") + .HasColumnType("boolean"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("UserRates"); + }); + modelBuilder.Entity("LanguageUser", b => { b.Property("LanguagesId") @@ -409,15 +434,26 @@ namespace DevHive.Data.Migrations .WithMany("Posts") .HasForeignKey("CreatorId"); - b.HasOne("DevHive.Data.Models.Rating", "Rating") - .WithOne("Post") - .HasForeignKey("DevHive.Data.Models.Post", "RatingId") + b.Navigation("Creator"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.RatedPost", b => + { + b.HasOne("DevHive.Data.Models.Post", "Post") + .WithMany() + .HasForeignKey("PostId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); - b.Navigation("Creator"); + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); - b.Navigation("Rating"); + b.Navigation("Post"); + + b.Navigation("User"); }); modelBuilder.Entity("DevHive.Data.RelationModels.UserFriends", b => @@ -439,6 +475,15 @@ namespace DevHive.Data.Migrations b.Navigation("User"); }); + modelBuilder.Entity("DevHive.Data.RelationModels.UserRate", b => + { + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany() + .HasForeignKey("UserId"); + + b.Navigation("User"); + }); + modelBuilder.Entity("LanguageUser", b => { b.HasOne("DevHive.Data.Models.Language", null) @@ -540,11 +585,6 @@ namespace DevHive.Data.Migrations b.Navigation("Comments"); }); - modelBuilder.Entity("DevHive.Data.Models.Rating", b => - { - b.Navigation("Post"); - }); - modelBuilder.Entity("DevHive.Data.Models.User", b => { b.Navigation("Comments"); diff --git a/src/DevHive.Data/Models/Post.cs b/src/DevHive.Data/Models/Post.cs index bb22576..8fb3e91 100644 --- a/src/DevHive.Data/Models/Post.cs +++ b/src/DevHive.Data/Models/Post.cs @@ -18,8 +18,8 @@ namespace DevHive.Data.Models public List Comments { get; set; } = new(); - public Guid RatingId { get; set; } - public Rating Rating { get; set; } = new(); + // public Guid RatingId { get; set; } + // public Rating Rating { get; set; } = new(); public List FileUrls { get; set; } = new(); } diff --git a/src/DevHive.Data/Models/Rating.cs b/src/DevHive.Data/Models/Rating.cs index 8ebde9a..d07692d 100644 --- a/src/DevHive.Data/Models/Rating.cs +++ b/src/DevHive.Data/Models/Rating.cs @@ -1,5 +1,7 @@ using System; +using System.Collections.Generic; using DevHive.Data.Interfaces.Models; +using DevHive.Data.RelationModels; namespace DevHive.Data.Models { @@ -7,10 +9,11 @@ namespace DevHive.Data.Models { public Guid Id { get; set; } - public Post Post { get; set; } + // public Guid PostId { get; set; } + // public Post Post { get; set; } - public int Likes { get; set; } + public int Rate { get; set; } - public int Dislikes { get; set; } + // public HashSet UsersThatRated { get; set; } = new(); } } diff --git a/src/DevHive.Data/Models/User.cs b/src/DevHive.Data/Models/User.cs index da18c2f..44f3612 100644 --- a/src/DevHive.Data/Models/User.cs +++ b/src/DevHive.Data/Models/User.cs @@ -27,5 +27,7 @@ namespace DevHive.Data.Models public HashSet Posts { get; set; } = new(); public HashSet Comments { get; set; } = new(); + + // public HashSet RatedPosts { get; set; } = new(); } } diff --git a/src/DevHive.Data/RelationModels/RatedPosts.cs b/src/DevHive.Data/RelationModels/RatedPosts.cs new file mode 100644 index 0000000..7001d92 --- /dev/null +++ b/src/DevHive.Data/RelationModels/RatedPosts.cs @@ -0,0 +1,18 @@ +using System; +using System.ComponentModel.DataAnnotations.Schema; +using System.Reflection.Metadata.Ecma335; +using DevHive.Data.Models; +using Microsoft.EntityFrameworkCore; + +namespace DevHive.Data.RelationModels +{ + [Table("RatedPosts")] + public class RatedPost + { + public Guid UserId { get; set; } + public User User { get; set; } + + public Guid PostId { get; set; } + public Post Post { get; set; } + } +} diff --git a/src/DevHive.Data/RelationModels/UserFriends.cs b/src/DevHive.Data/RelationModels/UserFriends.cs index 485d6ec..31bdee2 100644 --- a/src/DevHive.Data/RelationModels/UserFriends.cs +++ b/src/DevHive.Data/RelationModels/UserFriends.cs @@ -1,9 +1,11 @@ using System; using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; using DevHive.Data.Models; namespace DevHive.Data.RelationModels { + [Table("UserFriends")] public class UserFriends { public Guid UserId { get; set; } diff --git a/src/DevHive.Data/RelationModels/UserRate.cs b/src/DevHive.Data/RelationModels/UserRate.cs new file mode 100644 index 0000000..06e9ab5 --- /dev/null +++ b/src/DevHive.Data/RelationModels/UserRate.cs @@ -0,0 +1,16 @@ +using System; +using System.ComponentModel.DataAnnotations.Schema; +using DevHive.Data.Models; + +namespace DevHive.Data.RelationModels +{ + [Table("UserRates")] + public class UserRate + { + public Guid Id { get; set; } + + public User User { get; set; } + + public bool Rate { get; set; } + } +} diff --git a/src/DevHive.Data/Repositories/BaseRepository.cs b/src/DevHive.Data/Repositories/BaseRepository.cs index cac802e..ece372e 100644 --- a/src/DevHive.Data/Repositories/BaseRepository.cs +++ b/src/DevHive.Data/Repositories/BaseRepository.cs @@ -21,7 +21,7 @@ namespace DevHive.Data.Repositories .Set() .AddAsync(entity); - return await this.SaveChangesAsync(_context); + return await this.SaveChangesAsync(); } public virtual async Task GetByIdAsync(Guid id) @@ -39,19 +39,19 @@ namespace DevHive.Data.Repositories entry.State = EntityState.Modified; - return await this.SaveChangesAsync(_context); + return await this.SaveChangesAsync(); } public virtual async Task DeleteAsync(TEntity entity) { this._context.Remove(entity); - return await this.SaveChangesAsync(_context); + return await this.SaveChangesAsync(); } - public virtual async Task SaveChangesAsync(DbContext context) + public virtual async Task SaveChangesAsync() { - int result = await context.SaveChangesAsync(); + int result = await _context.SaveChangesAsync(); return result >= 1; } diff --git a/src/DevHive.Data/Repositories/CommentRepository.cs b/src/DevHive.Data/Repositories/CommentRepository.cs index 8ddc628..1560c97 100644 --- a/src/DevHive.Data/Repositories/CommentRepository.cs +++ b/src/DevHive.Data/Repositories/CommentRepository.cs @@ -43,7 +43,7 @@ namespace DevHive.Data.Repositories .CurrentValues .SetValues(newEntity); - return await this.SaveChangesAsync(this._context); + return await this.SaveChangesAsync(); } #endregion diff --git a/src/DevHive.Data/Repositories/PostRepository.cs b/src/DevHive.Data/Repositories/PostRepository.cs index f9f2475..31eb7d0 100644 --- a/src/DevHive.Data/Repositories/PostRepository.cs +++ b/src/DevHive.Data/Repositories/PostRepository.cs @@ -24,7 +24,7 @@ namespace DevHive.Data.Repositories return await this._context.Posts .Include(x => x.Comments) .Include(x => x.Creator) - .Include(x => x.Rating) + // .Include(x => x.Rating) .FirstOrDefaultAsync(x => x.Id == id); } @@ -45,7 +45,7 @@ namespace DevHive.Data.Repositories public override async Task EditAsync(Guid id, Post newEntity) { Post post = await this.GetByIdAsync(id); - var ratingId = post.RatingId; + // var ratingId = post.Rating.Id; this._context .Entry(post) @@ -60,11 +60,11 @@ namespace DevHive.Data.Repositories foreach(var comment in newEntity.Comments) post.Comments.Add(comment); - post.RatingId = ratingId; + // post.Rating.Id = ratingId; this._context.Entry(post).State = EntityState.Modified; - return await this.SaveChangesAsync(this._context); + return await this.SaveChangesAsync(); } #endregion diff --git a/src/DevHive.Data/Repositories/RatingRepository.cs b/src/DevHive.Data/Repositories/RatingRepository.cs index 43fe90d..d676f27 100644 --- a/src/DevHive.Data/Repositories/RatingRepository.cs +++ b/src/DevHive.Data/Repositories/RatingRepository.cs @@ -9,29 +9,26 @@ namespace DevHive.Data.Repositories public class RatingRepository : BaseRepository, IRatingRepository { private readonly DevHiveContext _context; + private readonly IPostRepository _postRepository; - public RatingRepository(DevHiveContext context) + public RatingRepository(DevHiveContext context, IPostRepository postRepository) : base(context) { this._context = context; + this._postRepository = postRepository; } public async Task GetByPostId(Guid postId) { - return await this._context.Rating - .FirstOrDefaultAsync(x => x.Post.Id == postId); - } - - public async Task> GetRating(Guid postId) - { - Rating rating = await this.GetByPostId(postId); - - return new Tuple(rating.Likes, rating.Dislikes); + throw new NotImplementedException(); + // return await this._context.Rating + // .FirstOrDefaultAsync(x => x.Post.Id == postId); } - public async Task HasUserRatedThisPost(Guid userId, Guid postId) + public async Task GetRating(Guid postId) { throw new NotImplementedException(); + // return (await this.GetByPostId(postId)).Rate; } } } diff --git a/src/DevHive.Data/Repositories/RoleRepository.cs b/src/DevHive.Data/Repositories/RoleRepository.cs index 2eeb382..441efef 100644 --- a/src/DevHive.Data/Repositories/RoleRepository.cs +++ b/src/DevHive.Data/Repositories/RoleRepository.cs @@ -33,7 +33,7 @@ namespace DevHive.Data.Repositories .CurrentValues .SetValues(newEntity); - return await this.SaveChangesAsync(this._context); + return await this.SaveChangesAsync(); } #region Validations diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs index 6ff2ffa..4bf919e 100644 --- a/src/DevHive.Data/Repositories/UserRepository.cs +++ b/src/DevHive.Data/Repositories/UserRepository.cs @@ -95,7 +95,7 @@ namespace DevHive.Data.Repositories this._context.Entry(user).State = EntityState.Modified; - return await this.SaveChangesAsync(this._context); + return await this.SaveChangesAsync(); } #endregion diff --git a/src/DevHive.Services/Configurations/Mapping/RatingMappings.cs b/src/DevHive.Services/Configurations/Mapping/RatingMappings.cs index 5da1b0d..1dbb7b4 100644 --- a/src/DevHive.Services/Configurations/Mapping/RatingMappings.cs +++ b/src/DevHive.Services/Configurations/Mapping/RatingMappings.cs @@ -1,4 +1,6 @@ using AutoMapper; +using DevHive.Data.Models; +using DevHive.Services.Models.Post.Rating; namespace DevHive.Services.Configurations.Mapping { @@ -6,7 +8,8 @@ namespace DevHive.Services.Configurations.Mapping { public RatingMappings() { - + // CreateMap() + // .ForMember(dest => dest.PostId, src => src.MapFrom(p => p.Post.Id)); } } } diff --git a/src/DevHive.Services/Interfaces/IRateService.cs b/src/DevHive.Services/Interfaces/IRateService.cs new file mode 100644 index 0000000..359ef55 --- /dev/null +++ b/src/DevHive.Services/Interfaces/IRateService.cs @@ -0,0 +1,14 @@ +using System; +using System.Threading.Tasks; +using DevHive.Data.Models; +using DevHive.Services.Models.Post.Rating; + +namespace DevHive.Services.Interfaces +{ + public interface IRateService + { + Task RatePost(RatePostServiceModel ratePostServiceModel); + + bool HasUserRatedThisPost(User user, Post post); + } +} diff --git a/src/DevHive.Services/Models/Post/Rating/ReadPostRatingServiceModel.cs b/src/DevHive.Services/Models/Post/Rating/ReadPostRatingServiceModel.cs new file mode 100644 index 0000000..8c73aaf --- /dev/null +++ b/src/DevHive.Services/Models/Post/Rating/ReadPostRatingServiceModel.cs @@ -0,0 +1,15 @@ +using System; + +namespace DevHive.Services.Models.Post.Rating +{ + public class ReadPostRatingServiceModel + { + public Guid Id { get; set; } + + public Guid PostId { get; set; } + + public int Likes { get; set; } + + public int Dislikes { get; set; } + } +} diff --git a/src/DevHive.Services/Models/Post/Rating/ReadRatingServiceModel.cs b/src/DevHive.Services/Models/Post/Rating/ReadRatingServiceModel.cs deleted file mode 100644 index b071e74..0000000 --- a/src/DevHive.Services/Models/Post/Rating/ReadRatingServiceModel.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; - -namespace DevHive.Services.Models.Post.Rating -{ - public class ReadRatingServiceModel - { - public Guid PostId { get; set; } - - public int Likes { get; set; } - - public int Dislikes { get; set; } - } -} diff --git a/src/DevHive.Services/Services/RateService.cs b/src/DevHive.Services/Services/RateService.cs new file mode 100644 index 0000000..204c550 --- /dev/null +++ b/src/DevHive.Services/Services/RateService.cs @@ -0,0 +1,80 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using AutoMapper; +using DevHive.Data.Interfaces.Repositories; +using DevHive.Data.Models; +using DevHive.Services.Interfaces; +using DevHive.Services.Models.Post.Rating; + +namespace DevHive.Services.Services +{ + public class RateService : IRateService + { + private readonly IPostRepository _postRepository; + private readonly IUserRepository _userRepository; + private readonly IRatingRepository _ratingRepository; + private readonly IMapper _mapper; + + public RateService(IPostRepository postRepository, IRatingRepository ratingRepository, IUserRepository userRepository, IMapper mapper) + { + this._postRepository = postRepository; + this._ratingRepository = ratingRepository; + this._userRepository = userRepository; + this._mapper = mapper; + } + + public async Task RatePost(RatePostServiceModel ratePostServiceModel) + { + throw new NotImplementedException(); + // if (!await this._postRepository.DoesPostExist(ratePostServiceModel.PostId)) + // throw new ArgumentException("Post does not exist!"); + + // if (!await this._userRepository.DoesUserExistAsync(ratePostServiceModel.UserId)) + // throw new ArgumentException("User does not exist!"); + + // Post post = await this._postRepository.GetByIdAsync(ratePostServiceModel.PostId); + // User user = await this._userRepository.GetByIdAsync(ratePostServiceModel.UserId); + + // if (this.HasUserRatedThisPost(user, post)) + // throw new ArgumentException("You can't rate the same post more then one(duh, amigo)"); + + // this.Rate(user, post, ratePostServiceModel.Liked); + + // bool success = await this._ratingRepository.EditAsync(post.Rating.Id, post.Rating); + // if (!success) + // throw new InvalidOperationException("Unable to rate the post!"); + + // Rating newRating = await this._ratingRepository.GetByIdAsync(post.Rating.Id); + // return this._mapper.Map(newRating); + } + + public async Task RemoveUserRateFromPost(Guid userId, Guid postId) + { + throw new NotImplementedException(); + // Post post = await this._postRepository.GetByIdAsync(postId); + // User user = await this._userRepository.GetByIdAsync(userId); + + // if (!this.HasUserRatedThisPost(user, post)) + // throw new ArgumentException("You haven't rated this post, lmao!"); + } + + public bool HasUserRatedThisPost(User user, Post post) + { + throw new NotImplementedException(); + // return post.Rating.UsersThatRated + // .Any(x => x.Id == user.Id); + } + + private void Rate(User user, Post post, bool liked) + { + throw new NotImplementedException(); + // if (liked) + // post.Rating.Rate++; + // else + // post.Rating.Rate--; + + // post.Rating.UsersThatRated.Add(user); + } + } +} diff --git a/src/DevHive.Services/Services/RatingService.cs b/src/DevHive.Services/Services/RatingService.cs deleted file mode 100644 index 2c5a6b6..0000000 --- a/src/DevHive.Services/Services/RatingService.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using System.Diagnostics; -using System.Threading.Tasks; -using AutoMapper; -using DevHive.Data.Interfaces.Repositories; -using DevHive.Data.Models; -using DevHive.Services.Models.Post.Rating; -using Microsoft.CodeAnalysis.CSharp.Syntax; - -namespace DevHive.Services.Services -{ - public class RatingService - { - private readonly IPostRepository _postRepository; - private readonly IRatingRepository _ratingRepository; - private readonly IMapper _mapper; - - public RatingService(IPostRepository postRepository, IRatingRepository ratingRepository, IMapper mapper) - { - this._postRepository = postRepository; - this._ratingRepository = ratingRepository; - this._mapper = mapper; - } - - public async Task RatePost(RatePostServiceModel ratePostServiceModel) - { - if (!await this._postRepository.DoesPostExist(ratePostServiceModel.PostId)) - throw new ArgumentNullException("Post does not exist!"); - - if (!await this._ratingRepository.HasUserRatedThisPost(ratePostServiceModel.UserId, ratePostServiceModel.PostId)) - throw new ArgumentException("You can't rate the same post more then one(duh, amigo)"); - - Post post = await this._postRepository.GetByIdAsync(ratePostServiceModel.PostId); - - Rating rating = post.Rating; - if (ratePostServiceModel.Liked) - rating.Likes++; - else - rating.Dislikes++; - - bool success = await this._ratingRepository.EditAsync(rating.Id, rating); - if (!success) - throw new InvalidOperationException("Unable to rate the post!"); - - Rating newRating = await this._ratingRepository.GetByIdAsync(rating.Id); - return this._mapper.Map(newRating); - } - - public async Task RemoveUserRateFromPost(Guid userId, Guid postId) - { - throw new NotImplementedException(); - } - } -} diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs index 5c0d378..88f21d4 100644 --- a/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs +++ b/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs @@ -32,6 +32,7 @@ namespace DevHive.Web.Configurations.Extensions cloudName: configuration.GetSection("Cloud").GetSection("cloudName").Value, apiKey: configuration.GetSection("Cloud").GetSection("apiKey").Value, apiSecret: configuration.GetSection("Cloud").GetSection("apiSecret").Value)); + services.AddTransient(); } } } diff --git a/src/DevHive.Web/Configurations/Mapping/RatingMappings.cs b/src/DevHive.Web/Configurations/Mapping/RatingMappings.cs new file mode 100644 index 0000000..4e071de --- /dev/null +++ b/src/DevHive.Web/Configurations/Mapping/RatingMappings.cs @@ -0,0 +1,16 @@ +using AutoMapper; +using DevHive.Services.Models.Post.Rating; +using DevHive.Web.Models.Post.Rating; + +namespace DevHive.Web.Configurations.Mapping +{ + public class RatingMappings : Profile + { + public RatingMappings() + { + CreateMap(); + + CreateMap(); + } + } +} diff --git a/src/DevHive.Web/Controllers/RateController.cs b/src/DevHive.Web/Controllers/RateController.cs new file mode 100644 index 0000000..68b859b --- /dev/null +++ b/src/DevHive.Web/Controllers/RateController.cs @@ -0,0 +1,40 @@ +using System; +using System.Threading.Tasks; +using AutoMapper; +using DevHive.Services.Interfaces; +using DevHive.Services.Models.Post.Rating; +using DevHive.Web.Models.Post.Rating; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; + +namespace DevHive.Web.Controllers +{ + [ApiController] + [Route("api/[controller]")] + public class RateController + { + private readonly IRateService _rateService; + private readonly IUserService _userService; + private readonly IMapper _mapper; + + public RateController(IRateService rateService, IUserService userService, IMapper mapper) + { + this._rateService = rateService; + this._userService = userService; + this._mapper = mapper; + } + + [HttpPost] + [Authorize(Roles = "Admin,User")] + public async Task RatePost(Guid userId, [FromBody] RatePostWebModel ratePostWebModel, [FromHeader] string authorization) + { + RatePostServiceModel ratePostServiceModel = this._mapper.Map(ratePostWebModel); + ratePostServiceModel.UserId = userId; + + ReadPostRatingServiceModel readPostRatingServiceModel = await this._rateService.RatePost(ratePostServiceModel); + ReadPostRatingWebModel readPostRatingWebModel = this._mapper.Map(readPostRatingServiceModel); + + return new OkObjectResult(readPostRatingWebModel); + } + } +} diff --git a/src/DevHive.Web/Models/Post/Rating/RatePostWebModel.cs b/src/DevHive.Web/Models/Post/Rating/RatePostWebModel.cs new file mode 100644 index 0000000..5f0e58f --- /dev/null +++ b/src/DevHive.Web/Models/Post/Rating/RatePostWebModel.cs @@ -0,0 +1,11 @@ +using System; + +namespace DevHive.Web.Models.Post.Rating +{ + public class RatePostWebModel + { + public Guid PostId { get; set; } + + public bool Liked { get; set; } + } +} diff --git a/src/DevHive.Web/Models/Post/Rating/ReadPostRatingWebModel.cs b/src/DevHive.Web/Models/Post/Rating/ReadPostRatingWebModel.cs new file mode 100644 index 0000000..a551fb8 --- /dev/null +++ b/src/DevHive.Web/Models/Post/Rating/ReadPostRatingWebModel.cs @@ -0,0 +1,15 @@ +using System; + +namespace DevHive.Web.Models.Post.Rating +{ + public class ReadPostRatingWebModel + { + public Guid Id { get; set; } + + public Guid PostId { get; set; } + + public int Likes { get; set; } + + public int Dislikes { get; set; } + } +} -- cgit v1.2.3 From 6f7c7adced972944f5648b3714baa053037a4160 Mon Sep 17 00:00:00 2001 From: transtrike Date: Mon, 1 Feb 2021 18:28:55 +0200 Subject: GetByUsername & GetById return post Ids; Read POst returns URLs --- src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs | 2 ++ src/DevHive.Data/Repositories/PostRepository.cs | 13 ++++++++++++- src/DevHive.Data/Repositories/UserRepository.cs | 2 ++ src/DevHive.Services/Configurations/Mapping/PostMappings.cs | 4 ++++ .../Models/Identity/User/UserServiceModel.cs | 3 +++ src/DevHive.Services/Services/PostService.cs | 4 +++- src/DevHive.Web/Models/Identity/User/UserWebModel.cs | 11 +++++++---- 7 files changed, 33 insertions(+), 6 deletions(-) (limited to 'src/DevHive.Data/Interfaces/Repositories') diff --git a/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs index 5022df5..9f7cf85 100644 --- a/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs +++ b/src/DevHive.Data/Interfaces/Repositories/IPostRepository.cs @@ -8,6 +8,8 @@ namespace DevHive.Data.Interfaces.Repositories { public interface IPostRepository : IRepository { + Task AddNewPostToCreator(Guid userId, Post post); + Task GetPostByCreatorAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated); Task> GetFileUrls(Guid postId); diff --git a/src/DevHive.Data/Repositories/PostRepository.cs b/src/DevHive.Data/Repositories/PostRepository.cs index 31eb7d0..623a8f8 100644 --- a/src/DevHive.Data/Repositories/PostRepository.cs +++ b/src/DevHive.Data/Repositories/PostRepository.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using DevHive.Data.Interfaces.Models; using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; using Microsoft.EntityFrameworkCore; @@ -11,11 +12,21 @@ namespace DevHive.Data.Repositories public class PostRepository : BaseRepository, IPostRepository { private readonly DevHiveContext _context; + private readonly IUserRepository _userRepository; - public PostRepository(DevHiveContext context) + public PostRepository(DevHiveContext context, IUserRepository userRepository) : base(context) { this._context = context; + this._userRepository = userRepository; + } + + public async Task AddNewPostToCreator(Guid userId, Post post) + { + User user = await this._userRepository.GetByIdAsync(userId); + user.Posts.Add(post); + + return await this.SaveChangesAsync(); } #region Read diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs index 4bf919e..6f33570 100644 --- a/src/DevHive.Data/Repositories/UserRepository.cs +++ b/src/DevHive.Data/Repositories/UserRepository.cs @@ -38,6 +38,7 @@ namespace DevHive.Data.Repositories .Include(x => x.Roles) .Include(x => x.Languages) .Include(x => x.Technologies) + .Include(x => x.Posts) .FirstOrDefaultAsync(x => x.Id == id); } @@ -48,6 +49,7 @@ namespace DevHive.Data.Repositories .Include(x => x.Roles) .Include(x => x.Languages) .Include(x => x.Technologies) + .Include(x => x.Posts) .FirstOrDefaultAsync(x => x.UserName == username); } #endregion diff --git a/src/DevHive.Services/Configurations/Mapping/PostMappings.cs b/src/DevHive.Services/Configurations/Mapping/PostMappings.cs index d36dbdd..13c9736 100644 --- a/src/DevHive.Services/Configurations/Mapping/PostMappings.cs +++ b/src/DevHive.Services/Configurations/Mapping/PostMappings.cs @@ -1,6 +1,7 @@ using DevHive.Data.Models; using AutoMapper; using DevHive.Services.Models.Post; +using DevHive.Common.Models.Misc; namespace DevHive.Services.Configurations.Mapping { @@ -20,6 +21,9 @@ namespace DevHive.Services.Configurations.Mapping .ForMember(dest => dest.CreatorFirstName, src => src.MapFrom(p => p.Creator.FirstName)) .ForMember(dest => dest.CreatorLastName, src => src.MapFrom(p => p.Creator.LastName)) .ForMember(dest => dest.CreatorUsername, src => src.MapFrom(p => p.Creator.UserName)); + + CreateMap() + .ForMember(dest => dest.Id, src => src.MapFrom(x => x.Id)); } } } diff --git a/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs b/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs index 7da54b8..5bf58ec 100644 --- a/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs +++ b/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using DevHive.Common.Models.Misc; using DevHive.Services.Models.Identity.Role; using DevHive.Services.Models.Language; using DevHive.Services.Models.Technology; @@ -14,5 +15,7 @@ namespace DevHive.Services.Models.Identity.User public HashSet Languages { get; set; } = new(); public HashSet Technologies { get; set; } = new(); + + public List Posts { get; set; } = new(); } } diff --git a/src/DevHive.Services/Services/PostService.cs b/src/DevHive.Services/Services/PostService.cs index 8a37acd..3206479 100644 --- a/src/DevHive.Services/Services/PostService.cs +++ b/src/DevHive.Services/Services/PostService.cs @@ -9,6 +9,7 @@ using System.Security.Claims; using DevHive.Services.Interfaces; using DevHive.Data.Interfaces.Repositories; using System.Linq; +using Microsoft.CodeAnalysis.CSharp; namespace DevHive.Services.Services { @@ -49,6 +50,8 @@ namespace DevHive.Services.Services Post newPost = await this._postRepository .GetPostByCreatorAndTimeCreatedAsync(post.Creator.Id, post.TimeCreated); + await this._postRepository.AddNewPostToCreator(createPostServiceModel.CreatorId, newPost); + return newPost.Id; } else @@ -69,7 +72,6 @@ namespace DevHive.Services.Services readPostServiceModel.CreatorFirstName = user.FirstName; readPostServiceModel.CreatorLastName = user.LastName; readPostServiceModel.CreatorUsername = user.UserName; - // readPostServiceModel.Files = await this._cloudService.GetFilesFromCloud(post.FileUrls); return readPostServiceModel; } diff --git a/src/DevHive.Web/Models/Identity/User/UserWebModel.cs b/src/DevHive.Web/Models/Identity/User/UserWebModel.cs index 4097901..1a5484a 100644 --- a/src/DevHive.Web/Models/Identity/User/UserWebModel.cs +++ b/src/DevHive.Web/Models/Identity/User/UserWebModel.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Diagnostics.CodeAnalysis; +using DevHive.Common.Models.Misc; using DevHive.Web.Models.Identity.Role; using DevHive.Web.Models.Language; using DevHive.Web.Models.Technology; @@ -11,18 +12,20 @@ namespace DevHive.Web.Models.Identity.User { [NotNull] [Required] - public HashSet Roles { get; set; } = new HashSet(); + public HashSet Roles { get; set; } = new(); [NotNull] [Required] - public HashSet Friends { get; set; } = new HashSet(); + public HashSet Friends { get; set; } = new(); [NotNull] [Required] - public HashSet Languages { get; set; } = new HashSet(); + public HashSet Languages { get; set; } = new(); [NotNull] [Required] - public HashSet Technologies { get; set; } = new HashSet(); + public HashSet Technologies { get; set; } = new(); + + public List Posts { get; set; } = new(); } } -- cgit v1.2.3 From 01ad75fa5a871a0c9f8cd0c5291312286ae4d52d Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 3 Feb 2021 10:22:37 +0200 Subject: Implemented profile picture table functionality; added models and interfaces for profile picture; added ability for user layers to update the profile picture; added migrations; updated mappings --- src/DevHive.Data/DevHiveContext.cs | 5 + .../Interfaces/Models/IProfilePicture.cs | 13 + src/DevHive.Data/Interfaces/Models/IUser.cs | 2 +- .../Interfaces/Repositories/IUserRepository.cs | 1 + .../20210203071720_ProfilePicture.Designer.cs | 633 +++++++++++++++++++++ .../Migrations/20210203071720_ProfilePicture.cs | 52 ++ .../Migrations/DevHiveContextModelSnapshot.cs | 36 +- src/DevHive.Data/Models/ProfilePicture.cs | 14 + src/DevHive.Data/Models/User.cs | 2 +- src/DevHive.Data/Repositories/UserRepository.cs | 10 + .../Configurations/Mapping/UserMappings.cs | 6 +- src/DevHive.Services/Interfaces/IUserService.cs | 1 + .../Identity/User/ProfilePictureServiceModel.cs | 7 + .../User/UpdateProfilePictureServiceModel.cs | 12 + .../Models/Identity/User/UpdateUserServiceModel.cs | 2 + .../Models/Identity/User/UserServiceModel.cs | 2 + src/DevHive.Services/Services/UserService.cs | 29 +- .../Configurations/Mapping/UserMappings.cs | 3 + src/DevHive.Web/Controllers/UserController.cs | 17 + .../Models/Identity/User/ProfilePictureWebModel.cs | 7 + .../Identity/User/UpdateProfilePictureWebModel.cs | 9 + .../Models/Identity/User/UserWebModel.cs | 2 + 22 files changed, 857 insertions(+), 8 deletions(-) create mode 100644 src/DevHive.Data/Interfaces/Models/IProfilePicture.cs create mode 100644 src/DevHive.Data/Migrations/20210203071720_ProfilePicture.Designer.cs create mode 100644 src/DevHive.Data/Migrations/20210203071720_ProfilePicture.cs create mode 100644 src/DevHive.Data/Models/ProfilePicture.cs create mode 100644 src/DevHive.Services/Models/Identity/User/ProfilePictureServiceModel.cs create mode 100644 src/DevHive.Services/Models/Identity/User/UpdateProfilePictureServiceModel.cs create mode 100644 src/DevHive.Web/Models/Identity/User/ProfilePictureWebModel.cs create mode 100644 src/DevHive.Web/Models/Identity/User/UpdateProfilePictureWebModel.cs (limited to 'src/DevHive.Data/Interfaces/Repositories') diff --git a/src/DevHive.Data/DevHiveContext.cs b/src/DevHive.Data/DevHiveContext.cs index 417de7f..b3ebd73 100644 --- a/src/DevHive.Data/DevHiveContext.cs +++ b/src/DevHive.Data/DevHiveContext.cs @@ -27,6 +27,11 @@ namespace DevHive.Data .HasIndex(x => x.UserName) .IsUnique(); + builder.Entity() + .HasOne(x => x.ProfilePicture) + .WithOne(x => x.User) + .HasForeignKey(x => x.UserId); + /* Roles */ builder.Entity() .HasMany(x => x.Roles) diff --git a/src/DevHive.Data/Interfaces/Models/IProfilePicture.cs b/src/DevHive.Data/Interfaces/Models/IProfilePicture.cs new file mode 100644 index 0000000..c3fcbea --- /dev/null +++ b/src/DevHive.Data/Interfaces/Models/IProfilePicture.cs @@ -0,0 +1,13 @@ +using System; +using DevHive.Data.Models; + +namespace DevHive.Data.Interfaces.Models +{ + public interface IProfilePicture : IModel + { + Guid UserId { get; set; } + User User { get; set; } + + string PictureURL { get; set; } + } +} diff --git a/src/DevHive.Data/Interfaces/Models/IUser.cs b/src/DevHive.Data/Interfaces/Models/IUser.cs index eb262fd..fcd741c 100644 --- a/src/DevHive.Data/Interfaces/Models/IUser.cs +++ b/src/DevHive.Data/Interfaces/Models/IUser.cs @@ -10,7 +10,7 @@ namespace DevHive.Data.Interfaces.Models string LastName { get; set; } - string ProfilePictureUrl { get; set; } + ProfilePicture ProfilePicture { get; set; } HashSet Languages { get; set; } diff --git a/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs index 4346e9c..5b6ab9e 100644 --- a/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs +++ b/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs @@ -11,6 +11,7 @@ namespace DevHive.Data.Interfaces.Repositories //Read Task GetByUsernameAsync(string username); IEnumerable QueryAll(); + Task UpdateProfilePicture(Guid userId, string pictureUrl); //Validations Task DoesEmailExistAsync(string email); diff --git a/src/DevHive.Data/Migrations/20210203071720_ProfilePicture.Designer.cs b/src/DevHive.Data/Migrations/20210203071720_ProfilePicture.Designer.cs new file mode 100644 index 0000000..b8dbd8e --- /dev/null +++ b/src/DevHive.Data/Migrations/20210203071720_ProfilePicture.Designer.cs @@ -0,0 +1,633 @@ +// +using System; +using System.Collections.Generic; +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("20210203071720_ProfilePicture")] + partial class ProfilePicture + { + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("PostId") + .HasColumnType("uuid"); + + b.Property("TimeCreated") + .HasColumnType("timestamp without time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("PostId"); + + b.ToTable("Comments"); + }); + + 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.Post", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property>("FileUrls") + .HasColumnType("text[]"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("TimeCreated") + .HasColumnType("timestamp without time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.ToTable("Posts"); + }); + + modelBuilder.Entity("DevHive.Data.Models.ProfilePicture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("PictureURL") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("ProfilePicture"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Rating", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Rate") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Rating"); + }); + + 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.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("SecurityStamp") + .HasColumnType("text"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean"); + + 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("UserName") + .IsUnique(); + + b.ToTable("AspNetUsers"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.RatedPost", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("PostId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "PostId"); + + b.HasIndex("PostId"); + + b.ToTable("RatedPosts"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserFriend", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("FriendId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "FriendId"); + + b.HasIndex("FriendId"); + + b.ToTable("UserFriends"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserRate", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Rate") + .HasColumnType("boolean"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("UserRates"); + }); + + modelBuilder.Entity("LanguageUser", b => + { + b.Property("LanguagesId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("LanguagesId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("LanguageUser"); + }); + + 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") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + 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") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + 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("TechnologyUser", b => + { + b.Property("TechnologiesId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("TechnologiesId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("TechnologyUser"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Comment", b => + { + b.HasOne("DevHive.Data.Models.User", "Creator") + .WithMany("Comments") + .HasForeignKey("CreatorId"); + + b.HasOne("DevHive.Data.Models.Post", "Post") + .WithMany("Comments") + .HasForeignKey("PostId"); + + b.Navigation("Creator"); + + b.Navigation("Post"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Post", b => + { + b.HasOne("DevHive.Data.Models.User", "Creator") + .WithMany("Posts") + .HasForeignKey("CreatorId"); + + b.Navigation("Creator"); + }); + + modelBuilder.Entity("DevHive.Data.Models.ProfilePicture", b => + { + b.HasOne("DevHive.Data.Models.User", "User") + .WithOne("ProfilePicture") + .HasForeignKey("DevHive.Data.Models.ProfilePicture", "UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.RatedPost", b => + { + b.HasOne("DevHive.Data.Models.Post", "Post") + .WithMany() + .HasForeignKey("PostId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Post"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserFriend", b => + { + b.HasOne("DevHive.Data.Models.User", "Friend") + .WithMany("FriendsOf") + .HasForeignKey("FriendId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany("MyFriends") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Friend"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserRate", b => + { + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany() + .HasForeignKey("UserId"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("LanguageUser", b => + { + b.HasOne("DevHive.Data.Models.Language", null) + .WithMany() + .HasForeignKey("LanguagesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + 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("TechnologyUser", b => + { + b.HasOne("DevHive.Data.Models.Technology", null) + .WithMany() + .HasForeignKey("TechnologiesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("DevHive.Data.Models.Post", b => + { + b.Navigation("Comments"); + }); + + modelBuilder.Entity("DevHive.Data.Models.User", b => + { + b.Navigation("Comments"); + + b.Navigation("FriendsOf"); + + b.Navigation("MyFriends"); + + b.Navigation("Posts"); + + b.Navigation("ProfilePicture"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/DevHive.Data/Migrations/20210203071720_ProfilePicture.cs b/src/DevHive.Data/Migrations/20210203071720_ProfilePicture.cs new file mode 100644 index 0000000..1b0c2c6 --- /dev/null +++ b/src/DevHive.Data/Migrations/20210203071720_ProfilePicture.cs @@ -0,0 +1,52 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace DevHive.Data.Migrations +{ + public partial class ProfilePicture : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "ProfilePictureUrl", + table: "AspNetUsers"); + + migrationBuilder.CreateTable( + name: "ProfilePicture", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + UserId = table.Column(type: "uuid", nullable: false), + PictureURL = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ProfilePicture", x => x.Id); + table.ForeignKey( + name: "FK_ProfilePicture_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_ProfilePicture_UserId", + table: "ProfilePicture", + column: "UserId", + unique: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ProfilePicture"); + + migrationBuilder.AddColumn( + name: "ProfilePictureUrl", + table: "AspNetUsers", + type: "text", + nullable: true); + } + } +} diff --git a/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs b/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs index 96cabad..0450670 100644 --- a/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs +++ b/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs @@ -86,6 +86,26 @@ namespace DevHive.Data.Migrations b.ToTable("Posts"); }); + modelBuilder.Entity("DevHive.Data.Models.ProfilePicture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("PictureURL") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("ProfilePicture"); + }); + modelBuilder.Entity("DevHive.Data.Models.Rating", b => { b.Property("Id") @@ -190,9 +210,6 @@ namespace DevHive.Data.Migrations b.Property("PhoneNumberConfirmed") .HasColumnType("boolean"); - b.Property("ProfilePictureUrl") - .HasColumnType("text"); - b.Property("SecurityStamp") .HasColumnType("text"); @@ -437,6 +454,17 @@ namespace DevHive.Data.Migrations b.Navigation("Creator"); }); + modelBuilder.Entity("DevHive.Data.Models.ProfilePicture", b => + { + b.HasOne("DevHive.Data.Models.User", "User") + .WithOne("ProfilePicture") + .HasForeignKey("DevHive.Data.Models.ProfilePicture", "UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + modelBuilder.Entity("DevHive.Data.RelationModels.RatedPost", b => { b.HasOne("DevHive.Data.Models.Post", "Post") @@ -594,6 +622,8 @@ namespace DevHive.Data.Migrations b.Navigation("MyFriends"); b.Navigation("Posts"); + + b.Navigation("ProfilePicture"); }); #pragma warning restore 612, 618 } diff --git a/src/DevHive.Data/Models/ProfilePicture.cs b/src/DevHive.Data/Models/ProfilePicture.cs new file mode 100644 index 0000000..e2ef04b --- /dev/null +++ b/src/DevHive.Data/Models/ProfilePicture.cs @@ -0,0 +1,14 @@ +using System; + +namespace DevHive.Data.Models +{ + public class ProfilePicture + { + public Guid Id { get; set; } + + public Guid UserId { get; set; } + public User User { get; set; } + + public string PictureURL { get; set; } + } +} diff --git a/src/DevHive.Data/Models/User.cs b/src/DevHive.Data/Models/User.cs index 1c365e4..d73f989 100644 --- a/src/DevHive.Data/Models/User.cs +++ b/src/DevHive.Data/Models/User.cs @@ -14,7 +14,7 @@ namespace DevHive.Data.Models public string LastName { get; set; } - public string ProfilePictureUrl { get; set; } + public ProfilePicture ProfilePicture { get; set; } public HashSet Languages { get; set; } = new(); diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs index b46198c..466b123 100644 --- a/src/DevHive.Data/Repositories/UserRepository.cs +++ b/src/DevHive.Data/Repositories/UserRepository.cs @@ -38,6 +38,7 @@ namespace DevHive.Data.Repositories .Include(x => x.Languages) .Include(x => x.Technologies) .Include(x => x.Posts) + .Include(x => x.ProfilePicture) .FirstOrDefaultAsync(x => x.Id == id); } @@ -48,6 +49,7 @@ namespace DevHive.Data.Repositories .Include(x => x.Languages) .Include(x => x.Technologies) .Include(x => x.Posts) + .Include(x => x.ProfilePicture) .FirstOrDefaultAsync(x => x.UserName == username); } #endregion @@ -93,6 +95,14 @@ namespace DevHive.Data.Repositories return await this.SaveChangesAsync(); } + + public async Task UpdateProfilePicture(Guid userId, string pictureUrl) { + User user = await this.GetByIdAsync(userId); + + user.ProfilePicture.PictureURL = pictureUrl; + + return await this.SaveChangesAsync(); + } #endregion #region Validations diff --git a/src/DevHive.Services/Configurations/Mapping/UserMappings.cs b/src/DevHive.Services/Configurations/Mapping/UserMappings.cs index 5223d84..6922cd7 100644 --- a/src/DevHive.Services/Configurations/Mapping/UserMappings.cs +++ b/src/DevHive.Services/Configurations/Mapping/UserMappings.cs @@ -22,10 +22,12 @@ namespace DevHive.Services.Configurations.Mapping CreateMap(); CreateMap() - .ForMember(dest => dest.Friends, src => src.MapFrom(p => p.MyFriends)); + .ForMember(dest => dest.Friends, src => src.MapFrom(p => p.MyFriends)) + .ForMember(dest => dest.ProfilePictureURL, src => src.MapFrom(p => p.ProfilePicture.PictureURL)); // .ForMember(dest => dest.Friends, src => src.MapFrom(p => p.Friends)); CreateMap() - .ForMember(x => x.Password, opt => opt.Ignore()); + .ForMember(x => x.Password, opt => opt.Ignore()) + .ForMember(dest => dest.ProfilePictureURL, src => src.MapFrom(p => p.ProfilePicture.PictureURL)); CreateMap(); CreateMap() diff --git a/src/DevHive.Services/Interfaces/IUserService.cs b/src/DevHive.Services/Interfaces/IUserService.cs index b701e4a..9e2b4e3 100644 --- a/src/DevHive.Services/Interfaces/IUserService.cs +++ b/src/DevHive.Services/Interfaces/IUserService.cs @@ -14,6 +14,7 @@ namespace DevHive.Services.Interfaces Task GetUserById(Guid id); Task UpdateUser(UpdateUserServiceModel updateModel); + Task UpdateProfilePicture(UpdateProfilePictureServiceModel updateProfilePictureServiceModel); Task DeleteUser(Guid id); diff --git a/src/DevHive.Services/Models/Identity/User/ProfilePictureServiceModel.cs b/src/DevHive.Services/Models/Identity/User/ProfilePictureServiceModel.cs new file mode 100644 index 0000000..ad81057 --- /dev/null +++ b/src/DevHive.Services/Models/Identity/User/ProfilePictureServiceModel.cs @@ -0,0 +1,7 @@ +namespace DevHive.Services.Models.Identity.User +{ + public class ProfilePictureServiceModel + { + public string ProfilePictureURL { get; set; } + } +} diff --git a/src/DevHive.Services/Models/Identity/User/UpdateProfilePictureServiceModel.cs b/src/DevHive.Services/Models/Identity/User/UpdateProfilePictureServiceModel.cs new file mode 100644 index 0000000..8563953 --- /dev/null +++ b/src/DevHive.Services/Models/Identity/User/UpdateProfilePictureServiceModel.cs @@ -0,0 +1,12 @@ +using System; +using Microsoft.AspNetCore.Http; + +namespace DevHive.Services.Models.Identity.User +{ + public class UpdateProfilePictureServiceModel + { + public Guid UserId { get; set; } + + public IFormFile Picture { get; set; } + } +} diff --git a/src/DevHive.Services/Models/Identity/User/UpdateUserServiceModel.cs b/src/DevHive.Services/Models/Identity/User/UpdateUserServiceModel.cs index 5b197e4..b4e4400 100644 --- a/src/DevHive.Services/Models/Identity/User/UpdateUserServiceModel.cs +++ b/src/DevHive.Services/Models/Identity/User/UpdateUserServiceModel.cs @@ -12,6 +12,8 @@ namespace DevHive.Services.Models.Identity.User public string Password { get; set; } + public string ProfilePictureURL { get; set; } + public HashSet Roles { get; set; } = new HashSet(); public HashSet Friends { get; set; } = new HashSet(); diff --git a/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs b/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs index 5bf58ec..ac7bba2 100644 --- a/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs +++ b/src/DevHive.Services/Models/Identity/User/UserServiceModel.cs @@ -8,6 +8,8 @@ namespace DevHive.Services.Models.Identity.User { public class UserServiceModel : BaseUserServiceModel { + public string ProfilePictureURL { get; set; } + public HashSet Roles { get; set; } = new(); public HashSet Friends { get; set; } = new(); diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs index 09b56c1..d8c4ee5 100644 --- a/src/DevHive.Services/Services/UserService.cs +++ b/src/DevHive.Services/Services/UserService.cs @@ -15,6 +15,7 @@ using DevHive.Data.Interfaces.Repositories; using System.Linq; using DevHive.Common.Models.Misc; using DevHive.Data.RelationModels; +using Microsoft.AspNetCore.Http; namespace DevHive.Services.Services { @@ -26,13 +27,15 @@ namespace DevHive.Services.Services private readonly ITechnologyRepository _technologyRepository; private readonly IMapper _userMapper; private readonly JWTOptions _jwtOptions; + private readonly ICloudService _cloudService; public UserService(IUserRepository userRepository, ILanguageRepository languageRepository, IRoleRepository roleRepository, ITechnologyRepository technologyRepository, IMapper mapper, - JWTOptions jwtOptions) + JWTOptions jwtOptions, + ICloudService cloudService) { this._userRepository = userRepository; this._roleRepository = roleRepository; @@ -40,6 +43,7 @@ namespace DevHive.Services.Services this._jwtOptions = jwtOptions; this._languageRepository = languageRepository; this._technologyRepository = technologyRepository; + this._cloudService = cloudService; } #region Authentication @@ -66,6 +70,7 @@ namespace DevHive.Services.Services User user = this._userMapper.Map(registerModel); user.PasswordHash = PasswordModifications.GeneratePasswordHash(registerModel.Password); + user.ProfilePicture = new ProfilePicture() { PictureURL = String.Empty }; // Make sure the default role exists //TODO: Move when project starts @@ -119,6 +124,28 @@ namespace DevHive.Services.Services return this._userMapper.Map( await this._userRepository.GetByIdAsync(user.Id)); } + + public async Task UpdateProfilePicture(UpdateProfilePictureServiceModel updateProfilePictureServiceModel) + { + User user = await this._userRepository.GetByIdAsync(updateProfilePictureServiceModel.UserId); + + if (!String.IsNullOrEmpty(user.ProfilePicture.PictureURL)) + { + bool success = await _cloudService.RemoveFilesFromCloud(new List { user.ProfilePicture.PictureURL }); + if (!success) + throw new InvalidCastException("Could not delete old profile picture!"); + } + + string fileUrl = (await this._cloudService.UploadFilesToCloud(new List { updateProfilePictureServiceModel.Picture }))[0] ?? + throw new ArgumentNullException("Unable to upload profile picture to cloud"); + + bool successful = await this._userRepository.UpdateProfilePicture(updateProfilePictureServiceModel.UserId, fileUrl); + + if (!successful) + throw new InvalidOperationException("Unable to change profile picture!"); + + return new ProfilePictureServiceModel() { ProfilePictureURL = fileUrl }; + } #endregion #region Delete diff --git a/src/DevHive.Web/Configurations/Mapping/UserMappings.cs b/src/DevHive.Web/Configurations/Mapping/UserMappings.cs index 1b26cc9..f58e7ca 100644 --- a/src/DevHive.Web/Configurations/Mapping/UserMappings.cs +++ b/src/DevHive.Web/Configurations/Mapping/UserMappings.cs @@ -23,6 +23,9 @@ namespace DevHive.Web.Configurations.Mapping CreateMap(); CreateMap(); + CreateMap(); + CreateMap(); + CreateMap(); CreateMap(); } diff --git a/src/DevHive.Web/Controllers/UserController.cs b/src/DevHive.Web/Controllers/UserController.cs index fdf317c..109bbaa 100644 --- a/src/DevHive.Web/Controllers/UserController.cs +++ b/src/DevHive.Web/Controllers/UserController.cs @@ -94,6 +94,23 @@ namespace DevHive.Web.Controllers return new AcceptedResult("UpdateUser", userWebModel); } + + [HttpPut] + [Route("ProfilePicture")] + [Authorize(Roles = "User,Admin")] + public async Task UpdateProfilePicture(Guid userId, [FromForm] UpdateProfilePictureWebModel updateProfilePictureWebModel, [FromHeader] string authorization) + { + if (!await this._userService.ValidJWT(userId, authorization)) + return new UnauthorizedResult(); + + UpdateProfilePictureServiceModel updateProfilePictureServiceModel = this._userMapper.Map(updateProfilePictureWebModel); + updateProfilePictureServiceModel.UserId = userId; + + ProfilePictureServiceModel profilePictureServiceModel = await this._userService.UpdateProfilePicture(updateProfilePictureServiceModel); + ProfilePictureWebModel profilePictureWebModel = this._userMapper.Map(profilePictureServiceModel); + + return new AcceptedResult("UpdateProfilePicture", profilePictureWebModel); + } #endregion #region Delete diff --git a/src/DevHive.Web/Models/Identity/User/ProfilePictureWebModel.cs b/src/DevHive.Web/Models/Identity/User/ProfilePictureWebModel.cs new file mode 100644 index 0000000..9fb1516 --- /dev/null +++ b/src/DevHive.Web/Models/Identity/User/ProfilePictureWebModel.cs @@ -0,0 +1,7 @@ +namespace DevHive.Web.Models.Identity.User +{ + public class ProfilePictureWebModel + { + public string ProfilePictureURL { get; set; } + } +} diff --git a/src/DevHive.Web/Models/Identity/User/UpdateProfilePictureWebModel.cs b/src/DevHive.Web/Models/Identity/User/UpdateProfilePictureWebModel.cs new file mode 100644 index 0000000..6efe968 --- /dev/null +++ b/src/DevHive.Web/Models/Identity/User/UpdateProfilePictureWebModel.cs @@ -0,0 +1,9 @@ +using Microsoft.AspNetCore.Http; + +namespace DevHive.Web.Models.Identity.User +{ + public class UpdateProfilePictureWebModel + { + public IFormFile Picture { get; set; } + } +} diff --git a/src/DevHive.Web/Models/Identity/User/UserWebModel.cs b/src/DevHive.Web/Models/Identity/User/UserWebModel.cs index 1a5484a..7ab8cca 100644 --- a/src/DevHive.Web/Models/Identity/User/UserWebModel.cs +++ b/src/DevHive.Web/Models/Identity/User/UserWebModel.cs @@ -10,6 +10,8 @@ namespace DevHive.Web.Models.Identity.User { public class UserWebModel : BaseUserWebModel { + public string ProfilePictureURL { get; set; } + [NotNull] [Required] public HashSet Roles { get; set; } = new(); -- cgit v1.2.3 From 5446e356a9783645f5599fb2b4f7fe8f4d05e30e Mon Sep 17 00:00:00 2001 From: transtrike Date: Wed, 3 Feb 2021 20:54:49 +0200 Subject: Post Editing preserves Post's comments --- .../Interfaces/Repositories/ICommentRepository.cs | 3 +++ src/DevHive.Data/Repositories/CommentRepository.cs | 11 +++++++++++ src/DevHive.Services/Services/PostService.cs | 1 + 3 files changed, 15 insertions(+) (limited to 'src/DevHive.Data/Interfaces/Repositories') diff --git a/src/DevHive.Data/Interfaces/Repositories/ICommentRepository.cs b/src/DevHive.Data/Interfaces/Repositories/ICommentRepository.cs index b80c5a0..267f251 100644 --- a/src/DevHive.Data/Interfaces/Repositories/ICommentRepository.cs +++ b/src/DevHive.Data/Interfaces/Repositories/ICommentRepository.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using DevHive.Data.Models; using DevHive.Data.Repositories.Interfaces; @@ -7,6 +8,8 @@ namespace DevHive.Data.Interfaces.Repositories { public interface ICommentRepository : IRepository { + Task> GetPostComments(Guid postId); + Task DoesCommentExist(Guid id); Task GetCommentByIssuerAndTimeCreatedAsync(Guid issuerId, DateTime timeCreated); } diff --git a/src/DevHive.Data/Repositories/CommentRepository.cs b/src/DevHive.Data/Repositories/CommentRepository.cs index 1560c97..382c666 100644 --- a/src/DevHive.Data/Repositories/CommentRepository.cs +++ b/src/DevHive.Data/Repositories/CommentRepository.cs @@ -1,4 +1,7 @@ using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; using System.Threading.Tasks; using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; @@ -31,6 +34,14 @@ namespace DevHive.Data.Repositories .FirstOrDefaultAsync(p => p.Creator.Id == issuerId && p.TimeCreated == timeCreated); } + + public async Task> GetPostComments(Guid postId) + { + return await this._context.Posts + .SelectMany(x => x.Comments) + .Where(x => x.Post.Id == postId) + .ToListAsync(); + } #endregion #region Update diff --git a/src/DevHive.Services/Services/PostService.cs b/src/DevHive.Services/Services/PostService.cs index 8002468..6dbb272 100644 --- a/src/DevHive.Services/Services/PostService.cs +++ b/src/DevHive.Services/Services/PostService.cs @@ -105,6 +105,7 @@ namespace DevHive.Services.Services } post.Creator = await this._userRepository.GetByIdAsync(updatePostServiceModel.CreatorId); + post.Comments = await this._commentRepository.GetPostComments(updatePostServiceModel.PostId); post.TimeCreated = DateTime.Now; bool result = await this._postRepository.EditAsync(updatePostServiceModel.PostId, post); -- cgit v1.2.3 From a0a048d1fc6672a6478169f3c9139d9e5a6ff474 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 5 Feb 2021 17:46:59 +0200 Subject: Implemented post attachments, which move post file urls to their own table; updated post repository and post service to work with them (but didn't update service or web models) --- src/DevHive.Data/DevHiveContext.cs | 6 +++++ src/DevHive.Data/Interfaces/Models/IPost.cs | 3 ++- .../Interfaces/Repositories/IRatingRepository.cs | 4 ++-- src/DevHive.Data/Models/Post.cs | 3 ++- src/DevHive.Data/RelationModels/PostAttachments.cs | 16 +++++++++++++ src/DevHive.Data/Repositories/PostRepository.cs | 17 +++++++------- src/DevHive.Services/Services/PostService.cs | 27 +++++++++++++++++----- 7 files changed, 58 insertions(+), 18 deletions(-) create mode 100644 src/DevHive.Data/RelationModels/PostAttachments.cs (limited to 'src/DevHive.Data/Interfaces/Repositories') diff --git a/src/DevHive.Data/DevHiveContext.cs b/src/DevHive.Data/DevHiveContext.cs index 0cc28bb..0b81f92 100644 --- a/src/DevHive.Data/DevHiveContext.cs +++ b/src/DevHive.Data/DevHiveContext.cs @@ -14,6 +14,7 @@ namespace DevHive.Data public DbSet Technologies { get; set; } public DbSet Languages { get; set; } public DbSet Posts { get; set; } + public DbSet PostAttachments { get; set; } public DbSet Comments { get; set; } public DbSet UserFriends { get; set; } public DbSet Rating { get; set; } @@ -82,6 +83,11 @@ namespace DevHive.Data .HasMany(x => x.Comments) .WithOne(x => x.Post); + /* Post attachments */ + builder.Entity() + .HasOne(x => x.Post) + .WithMany(x => x.Attachments); + /* Comment */ builder.Entity() .HasOne(x => x.Post) diff --git a/src/DevHive.Data/Interfaces/Models/IPost.cs b/src/DevHive.Data/Interfaces/Models/IPost.cs index 5031a05..712d955 100644 --- a/src/DevHive.Data/Interfaces/Models/IPost.cs +++ b/src/DevHive.Data/Interfaces/Models/IPost.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using DevHive.Data.Models; +using DevHive.Data.RelationModels; namespace DevHive.Data.Interfaces.Models { @@ -16,6 +17,6 @@ namespace DevHive.Data.Interfaces.Models // Rating Rating { get; set; } - List FileUrls { get; set; } + List Attachments { get; set; } } } diff --git a/src/DevHive.Data/Interfaces/Repositories/IRatingRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IRatingRepository.cs index 7b99e0e..f77f301 100644 --- a/src/DevHive.Data/Interfaces/Repositories/IRatingRepository.cs +++ b/src/DevHive.Data/Interfaces/Repositories/IRatingRepository.cs @@ -7,7 +7,7 @@ namespace DevHive.Data.Interfaces.Repositories { public interface IRatingRepository : IRepository { - Task GetByPostId(Guid postId); - Task GetRating(Guid postId); + Task GetRatingByPostId(Guid postId); + Task UserRatedPost(Guid userId, Guid postId); } } diff --git a/src/DevHive.Data/Models/Post.cs b/src/DevHive.Data/Models/Post.cs index 95d7ac8..3f3d8c9 100644 --- a/src/DevHive.Data/Models/Post.cs +++ b/src/DevHive.Data/Models/Post.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using DevHive.Data.Interfaces.Models; +using DevHive.Data.RelationModels; namespace DevHive.Data.Models { @@ -20,6 +21,6 @@ namespace DevHive.Data.Models public Rating Rating { get; set; } = new(); - public List FileUrls { get; set; } = new(); + public List Attachments { get; set; } = new(); } } diff --git a/src/DevHive.Data/RelationModels/PostAttachments.cs b/src/DevHive.Data/RelationModels/PostAttachments.cs new file mode 100644 index 0000000..48aa8ff --- /dev/null +++ b/src/DevHive.Data/RelationModels/PostAttachments.cs @@ -0,0 +1,16 @@ +using System; +using System.ComponentModel.DataAnnotations.Schema; +using DevHive.Data.Models; + +namespace DevHive.Data.RelationModels +{ + [Table("PostAttachments")] + public class PostAttachments + { + public Guid Id { get; set; } + + public Post Post { get; set; } + + public string FileUrl { get; set; } + } +} diff --git a/src/DevHive.Data/Repositories/PostRepository.cs b/src/DevHive.Data/Repositories/PostRepository.cs index ed2fa1b..52c5b4e 100644 --- a/src/DevHive.Data/Repositories/PostRepository.cs +++ b/src/DevHive.Data/Repositories/PostRepository.cs @@ -2,14 +2,14 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using DevHive.Data.Interfaces.Models; using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; +using DevHive.Data.RelationModels; using Microsoft.EntityFrameworkCore; namespace DevHive.Data.Repositories { - public class PostRepository : BaseRepository, IPostRepository + public class PostRepository : BaseRepository, IPostRepository { private readonly DevHiveContext _context; private readonly IUserRepository _userRepository; @@ -35,6 +35,7 @@ namespace DevHive.Data.Repositories return await this._context.Posts .Include(x => x.Comments) .Include(x => x.Creator) + .Include(x => x.Attachments) // .Include(x => x.Rating) .FirstOrDefaultAsync(x => x.Id == id); } @@ -51,7 +52,7 @@ namespace DevHive.Data.Repositories public async Task> GetFileUrls(Guid postId) { - return (await this.GetByIdAsync(postId)).FileUrls; + return (await this.GetByIdAsync(postId)).Attachments.Select(x => x.FileUrl).ToList(); } #endregion @@ -66,10 +67,10 @@ namespace DevHive.Data.Repositories .CurrentValues .SetValues(newEntity); - List fileUrls = new(); - foreach(var fileUrl in newEntity.FileUrls) - fileUrls.Add(fileUrl); - post.FileUrls = fileUrls; + List postAttachments = new(); + foreach(var attachment in newEntity.Attachments) + postAttachments.Add(attachment); + post.Attachments = postAttachments; post.Comments.Clear(); foreach(var comment in newEntity.Comments) @@ -96,7 +97,7 @@ namespace DevHive.Data.Repositories return await this._context.Posts .AsNoTracking() .Where(x => x.Id == postId) - .Select(x => x.FileUrls) + .Select(x => x.Attachments) .AnyAsync(); } #endregion diff --git a/src/DevHive.Services/Services/PostService.cs b/src/DevHive.Services/Services/PostService.cs index 51f4d00..fe91f23 100644 --- a/src/DevHive.Services/Services/PostService.cs +++ b/src/DevHive.Services/Services/PostService.cs @@ -9,11 +9,11 @@ using System.Security.Claims; using DevHive.Services.Interfaces; using DevHive.Data.Interfaces.Repositories; using System.Linq; -using Microsoft.CodeAnalysis.CSharp; +using DevHive.Data.RelationModels; namespace DevHive.Services.Services { - public class PostService : IPostService + public class PostService : IPostService { private readonly ICloudService _cloudService; private readonly IUserRepository _userRepository; @@ -39,7 +39,10 @@ namespace DevHive.Services.Services Post post = this._postMapper.Map(createPostServiceModel); if (createPostServiceModel.Files.Count != 0) - post.FileUrls = await _cloudService.UploadFilesToCloud(createPostServiceModel.Files); + { + List fileUrls = await _cloudService.UploadFilesToCloud(createPostServiceModel.Files); + post.Attachments = this.GetPostAttachmentsFromUrls(post, fileUrls); + } post.Creator = await this._userRepository.GetByIdAsync(createPostServiceModel.CreatorId); post.TimeCreated = DateTime.Now; @@ -77,6 +80,7 @@ namespace DevHive.Services.Services readPostServiceModel.CreatorFirstName = user.FirstName; readPostServiceModel.CreatorLastName = user.LastName; readPostServiceModel.CreatorUsername = user.UserName; + readPostServiceModel.FileUrls = post.Attachments.Select(x => x.FileUrl).ToList(); return readPostServiceModel; } @@ -94,14 +98,15 @@ namespace DevHive.Services.Services { if (await this._postRepository.DoesPostHaveFiles(updatePostServiceModel.PostId)) { - List fileUrls = await this._postRepository.GetFileUrls(updatePostServiceModel.PostId); - bool success = await _cloudService.RemoveFilesFromCloud(fileUrls); + List fileUrlsToRemove = await this._postRepository.GetFileUrls(updatePostServiceModel.PostId); + bool success = await _cloudService.RemoveFilesFromCloud(fileUrlsToRemove); if (!success) throw new InvalidCastException("Could not delete files from the post!"); } - post.FileUrls = await _cloudService.UploadFilesToCloud(updatePostServiceModel.Files) ?? + List fileUrls = await _cloudService.UploadFilesToCloud(updatePostServiceModel.Files) ?? throw new ArgumentNullException("Unable to upload images to cloud"); + post.Attachments = this.GetPostAttachmentsFromUrls(post, fileUrls); } post.Creator = await this._userRepository.GetByIdAsync(updatePostServiceModel.CreatorId); @@ -220,5 +225,15 @@ namespace DevHive.Services.Services return toReturn; } #endregion + + #region Misc + private List GetPostAttachmentsFromUrls(Post post, List fileUrls) + { + List postAttachments = new List(); + foreach (string url in fileUrls) + postAttachments.Add(new PostAttachments { Post = post, FileUrl = url }); + return postAttachments; + } + #endregion } } -- cgit v1.2.3 From 8b62011960ce88d722c64b72af6837c2e2dbcda5 Mon Sep 17 00:00:00 2001 From: transtrike Date: Fri, 5 Feb 2021 19:02:35 +0200 Subject: Friends relation FUCKING FINALLY FIXED, NIGGA --- src/DevHive.Data/DevHiveContext.cs | 15 - .../Interfaces/Repositories/IUserRepository.cs | 5 +- .../20210205150447_Friends_Init_Config.Designer.cs | 643 +++++++++++++++++++++ .../20210205150447_Friends_Init_Config.cs | 45 ++ .../20210205160520_Friends_First_Tweek.Designer.cs | 609 +++++++++++++++++++ .../20210205160520_Friends_First_Tweek.cs | 46 ++ .../Migrations/DevHiveContextModelSnapshot.cs | 43 +- src/DevHive.Data/Models/User.cs | 4 +- src/DevHive.Data/RelationModels/UserFriend.cs | 17 - src/DevHive.Data/Repositories/UserRepository.cs | 73 +-- .../Configurations/Mapping/UserMappings.cs | 17 +- src/DevHive.Services/Services/UserService.cs | 102 ++-- .../Configurations/Extensions/ConfigureDatabase.cs | 3 - src/DevHive.Web/Startup.cs | 1 - 14 files changed, 1415 insertions(+), 208 deletions(-) create mode 100644 src/DevHive.Data/Migrations/20210205150447_Friends_Init_Config.Designer.cs create mode 100644 src/DevHive.Data/Migrations/20210205150447_Friends_Init_Config.cs create mode 100644 src/DevHive.Data/Migrations/20210205160520_Friends_First_Tweek.Designer.cs create mode 100644 src/DevHive.Data/Migrations/20210205160520_Friends_First_Tweek.cs delete mode 100644 src/DevHive.Data/RelationModels/UserFriend.cs (limited to 'src/DevHive.Data/Interfaces/Repositories') diff --git a/src/DevHive.Data/DevHiveContext.cs b/src/DevHive.Data/DevHiveContext.cs index 0b81f92..9de33c3 100644 --- a/src/DevHive.Data/DevHiveContext.cs +++ b/src/DevHive.Data/DevHiveContext.cs @@ -16,7 +16,6 @@ namespace DevHive.Data public DbSet Posts { get; set; } public DbSet PostAttachments { get; set; } public DbSet Comments { get; set; } - public DbSet UserFriends { get; set; } public DbSet Rating { get; set; } public DbSet RatedPost { get; set; } public DbSet UserRate { get; set; } @@ -38,20 +37,6 @@ namespace DevHive.Data .HasMany(x => x.Roles) .WithMany(x => x.Users); - /* Friends */ - builder.Entity() - .HasKey(x => new { x.UserId, x.FriendId }); - - builder.Entity() - .HasOne(x => x.User) - .WithMany(x => x.MyFriends) - .HasForeignKey(x => x.UserId); - - builder.Entity() - .HasOne(x => x.Friend) - .WithMany(x => x.FriendsOf) - .HasForeignKey(x => x.FriendId); - /* Languages */ builder.Entity() .HasMany(x => x.Languages) diff --git a/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs b/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs index 5b6ab9e..5ebe3d3 100644 --- a/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs +++ b/src/DevHive.Data/Interfaces/Repositories/IUserRepository.cs @@ -10,14 +10,13 @@ namespace DevHive.Data.Interfaces.Repositories { //Read Task GetByUsernameAsync(string username); - IEnumerable QueryAll(); Task UpdateProfilePicture(Guid userId, string pictureUrl); //Validations + Task ValidateFriendsCollectionAsync(List usernames); Task DoesEmailExistAsync(string email); Task DoesUserExistAsync(Guid id); - Task DoesUserHaveThisFriendAsync(Guid userId, Guid friendId); - bool DoesUserHaveThisUsername(Guid id, string username); Task DoesUsernameExistAsync(string username); + bool DoesUserHaveThisUsername(Guid id, string username); } } diff --git a/src/DevHive.Data/Migrations/20210205150447_Friends_Init_Config.Designer.cs b/src/DevHive.Data/Migrations/20210205150447_Friends_Init_Config.Designer.cs new file mode 100644 index 0000000..c11374a --- /dev/null +++ b/src/DevHive.Data/Migrations/20210205150447_Friends_Init_Config.Designer.cs @@ -0,0 +1,643 @@ +// +using System; +using System.Collections.Generic; +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("20210205150447_Friends_Init_Config")] + partial class Friends_Init_Config + { + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("PostId") + .HasColumnType("uuid"); + + b.Property("TimeCreated") + .HasColumnType("timestamp without time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("PostId"); + + b.ToTable("Comments"); + }); + + 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.Post", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property>("FileUrls") + .HasColumnType("text[]"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("TimeCreated") + .HasColumnType("timestamp without time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.ToTable("Posts"); + }); + + modelBuilder.Entity("DevHive.Data.Models.ProfilePicture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("PictureURL") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("ProfilePicture"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Rating", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Rate") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Rating"); + }); + + 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.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("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("DevHive.Data.RelationModels.RatedPost", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("PostId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "PostId"); + + b.HasIndex("PostId"); + + b.ToTable("RatedPosts"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserFriend", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("FriendId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "FriendId"); + + b.HasIndex("FriendId"); + + b.ToTable("UserFriends"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserRate", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Rate") + .HasColumnType("boolean"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("UserRates"); + }); + + modelBuilder.Entity("LanguageUser", b => + { + b.Property("LanguagesId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("LanguagesId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("LanguageUser"); + }); + + 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") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + 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") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + 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("TechnologyUser", b => + { + b.Property("TechnologiesId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("TechnologiesId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("TechnologyUser"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Comment", b => + { + b.HasOne("DevHive.Data.Models.User", "Creator") + .WithMany("Comments") + .HasForeignKey("CreatorId"); + + b.HasOne("DevHive.Data.Models.Post", "Post") + .WithMany("Comments") + .HasForeignKey("PostId"); + + b.Navigation("Creator"); + + b.Navigation("Post"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Post", b => + { + b.HasOne("DevHive.Data.Models.User", "Creator") + .WithMany("Posts") + .HasForeignKey("CreatorId"); + + b.Navigation("Creator"); + }); + + modelBuilder.Entity("DevHive.Data.Models.ProfilePicture", b => + { + b.HasOne("DevHive.Data.Models.User", "User") + .WithOne("ProfilePicture") + .HasForeignKey("DevHive.Data.Models.ProfilePicture", "UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DevHive.Data.Models.User", b => + { + b.HasOne("DevHive.Data.Models.User", null) + .WithMany("Friends") + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.RatedPost", b => + { + b.HasOne("DevHive.Data.Models.Post", "Post") + .WithMany() + .HasForeignKey("PostId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Post"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserFriend", b => + { + b.HasOne("DevHive.Data.Models.User", "Friend") + .WithMany() + .HasForeignKey("FriendId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Friend"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserRate", b => + { + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany() + .HasForeignKey("UserId"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("LanguageUser", b => + { + b.HasOne("DevHive.Data.Models.Language", null) + .WithMany() + .HasForeignKey("LanguagesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + 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("TechnologyUser", b => + { + b.HasOne("DevHive.Data.Models.Technology", null) + .WithMany() + .HasForeignKey("TechnologiesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("DevHive.Data.Models.Post", b => + { + b.Navigation("Comments"); + }); + + modelBuilder.Entity("DevHive.Data.Models.User", b => + { + b.Navigation("Comments"); + + b.Navigation("Friends"); + + b.Navigation("Posts"); + + b.Navigation("ProfilePicture"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/DevHive.Data/Migrations/20210205150447_Friends_Init_Config.cs b/src/DevHive.Data/Migrations/20210205150447_Friends_Init_Config.cs new file mode 100644 index 0000000..1fc970d --- /dev/null +++ b/src/DevHive.Data/Migrations/20210205150447_Friends_Init_Config.cs @@ -0,0 +1,45 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace DevHive.Data.Migrations +{ + public partial class Friends_Init_Config : 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.Data/Migrations/20210205160520_Friends_First_Tweek.Designer.cs b/src/DevHive.Data/Migrations/20210205160520_Friends_First_Tweek.Designer.cs new file mode 100644 index 0000000..3ad3ec8 --- /dev/null +++ b/src/DevHive.Data/Migrations/20210205160520_Friends_First_Tweek.Designer.cs @@ -0,0 +1,609 @@ +// +using System; +using System.Collections.Generic; +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("20210205160520_Friends_First_Tweek")] + partial class Friends_First_Tweek + { + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("PostId") + .HasColumnType("uuid"); + + b.Property("TimeCreated") + .HasColumnType("timestamp without time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.HasIndex("PostId"); + + b.ToTable("Comments"); + }); + + 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.Post", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("CreatorId") + .HasColumnType("uuid"); + + b.Property>("FileUrls") + .HasColumnType("text[]"); + + b.Property("Message") + .HasColumnType("text"); + + b.Property("TimeCreated") + .HasColumnType("timestamp without time zone"); + + b.HasKey("Id"); + + b.HasIndex("CreatorId"); + + b.ToTable("Posts"); + }); + + modelBuilder.Entity("DevHive.Data.Models.ProfilePicture", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("PictureURL") + .HasColumnType("text"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId") + .IsUnique(); + + b.ToTable("ProfilePicture"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Rating", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Rate") + .HasColumnType("integer"); + + b.HasKey("Id"); + + b.ToTable("Rating"); + }); + + 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.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("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("DevHive.Data.RelationModels.RatedPost", b => + { + b.Property("UserId") + .HasColumnType("uuid"); + + b.Property("PostId") + .HasColumnType("uuid"); + + b.HasKey("UserId", "PostId"); + + b.HasIndex("PostId"); + + b.ToTable("RatedPosts"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserRate", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("uuid"); + + b.Property("Rate") + .HasColumnType("boolean"); + + b.Property("UserId") + .HasColumnType("uuid"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("UserRates"); + }); + + modelBuilder.Entity("LanguageUser", b => + { + b.Property("LanguagesId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("LanguagesId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("LanguageUser"); + }); + + 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") + .HasColumnType("text"); + + b.Property("ProviderKey") + .HasColumnType("text"); + + 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") + .HasColumnType("text"); + + b.Property("Name") + .HasColumnType("text"); + + 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("TechnologyUser", b => + { + b.Property("TechnologiesId") + .HasColumnType("uuid"); + + b.Property("UsersId") + .HasColumnType("uuid"); + + b.HasKey("TechnologiesId", "UsersId"); + + b.HasIndex("UsersId"); + + b.ToTable("TechnologyUser"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Comment", b => + { + b.HasOne("DevHive.Data.Models.User", "Creator") + .WithMany("Comments") + .HasForeignKey("CreatorId"); + + b.HasOne("DevHive.Data.Models.Post", "Post") + .WithMany("Comments") + .HasForeignKey("PostId"); + + b.Navigation("Creator"); + + b.Navigation("Post"); + }); + + modelBuilder.Entity("DevHive.Data.Models.Post", b => + { + b.HasOne("DevHive.Data.Models.User", "Creator") + .WithMany("Posts") + .HasForeignKey("CreatorId"); + + b.Navigation("Creator"); + }); + + modelBuilder.Entity("DevHive.Data.Models.ProfilePicture", b => + { + b.HasOne("DevHive.Data.Models.User", "User") + .WithOne("ProfilePicture") + .HasForeignKey("DevHive.Data.Models.ProfilePicture", "UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DevHive.Data.Models.User", b => + { + b.HasOne("DevHive.Data.Models.User", null) + .WithMany("Friends") + .HasForeignKey("UserId"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.RatedPost", b => + { + b.HasOne("DevHive.Data.Models.Post", "Post") + .WithMany() + .HasForeignKey("PostId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Post"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DevHive.Data.RelationModels.UserRate", b => + { + b.HasOne("DevHive.Data.Models.User", "User") + .WithMany() + .HasForeignKey("UserId"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("LanguageUser", b => + { + b.HasOne("DevHive.Data.Models.Language", null) + .WithMany() + .HasForeignKey("LanguagesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + 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("TechnologyUser", b => + { + b.HasOne("DevHive.Data.Models.Technology", null) + .WithMany() + .HasForeignKey("TechnologiesId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DevHive.Data.Models.User", null) + .WithMany() + .HasForeignKey("UsersId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("DevHive.Data.Models.Post", b => + { + b.Navigation("Comments"); + }); + + modelBuilder.Entity("DevHive.Data.Models.User", b => + { + b.Navigation("Comments"); + + b.Navigation("Friends"); + + b.Navigation("Posts"); + + b.Navigation("ProfilePicture"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/DevHive.Data/Migrations/20210205160520_Friends_First_Tweek.cs b/src/DevHive.Data/Migrations/20210205160520_Friends_First_Tweek.cs new file mode 100644 index 0000000..565f863 --- /dev/null +++ b/src/DevHive.Data/Migrations/20210205160520_Friends_First_Tweek.cs @@ -0,0 +1,46 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace DevHive.Data.Migrations +{ + public partial class Friends_First_Tweek : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "UserFriends"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "UserFriends", + columns: table => new + { + UserId = table.Column(type: "uuid", nullable: false), + FriendId = table.Column(type: "uuid", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_UserFriends", x => new { x.UserId, x.FriendId }); + table.ForeignKey( + name: "FK_UserFriends_AspNetUsers_FriendId", + column: x => x.FriendId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_UserFriends_AspNetUsers_UserId", + column: x => x.UserId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_UserFriends_FriendId", + table: "UserFriends", + column: "FriendId"); + } + } +} diff --git a/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs b/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs index 6e0a03a..dc5739c 100644 --- a/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs +++ b/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs @@ -218,6 +218,9 @@ namespace DevHive.Data.Migrations b.Property("TwoFactorEnabled") .HasColumnType("boolean"); + b.Property("UserId") + .HasColumnType("uuid"); + b.Property("UserName") .HasMaxLength(256) .HasColumnType("character varying(256)"); @@ -231,6 +234,8 @@ namespace DevHive.Data.Migrations .IsUnique() .HasDatabaseName("UserNameIndex"); + b.HasIndex("UserId"); + b.HasIndex("UserName") .IsUnique(); @@ -271,21 +276,6 @@ namespace DevHive.Data.Migrations b.ToTable("RatedPosts"); }); - modelBuilder.Entity("DevHive.Data.RelationModels.UserFriend", b => - { - b.Property("UserId") - .HasColumnType("uuid"); - - b.Property("FriendId") - .HasColumnType("uuid"); - - b.HasKey("UserId", "FriendId"); - - b.HasIndex("FriendId"); - - b.ToTable("UserFriends"); - }); - modelBuilder.Entity("DevHive.Data.RelationModels.UserRate", b => { b.Property("Id") @@ -530,25 +520,6 @@ namespace DevHive.Data.Migrations b.Navigation("User"); }); - modelBuilder.Entity("DevHive.Data.RelationModels.UserFriend", b => - { - b.HasOne("DevHive.Data.Models.User", "Friend") - .WithMany("FriendsOf") - .HasForeignKey("FriendId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("DevHive.Data.Models.User", "User") - .WithMany("MyFriends") - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.Navigation("Friend"); - - b.Navigation("User"); - }); - modelBuilder.Entity("DevHive.Data.RelationModels.UserRate", b => { b.HasOne("DevHive.Data.Models.Post", "Post") @@ -673,9 +644,7 @@ namespace DevHive.Data.Migrations { b.Navigation("Comments"); - b.Navigation("FriendsOf"); - - b.Navigation("MyFriends"); + b.Navigation("Friends"); b.Navigation("Posts"); diff --git a/src/DevHive.Data/Models/User.cs b/src/DevHive.Data/Models/User.cs index f666677..983d073 100644 --- a/src/DevHive.Data/Models/User.cs +++ b/src/DevHive.Data/Models/User.cs @@ -24,9 +24,7 @@ namespace DevHive.Data.Models public HashSet Posts { get; set; } = new(); - public HashSet MyFriends { get; set; } = new(); - - public HashSet FriendsOf { get; set; } = new(); + public HashSet Friends { get; set; } = new(); public HashSet Comments { get; set; } = new(); diff --git a/src/DevHive.Data/RelationModels/UserFriend.cs b/src/DevHive.Data/RelationModels/UserFriend.cs deleted file mode 100644 index 32a00d4..0000000 --- a/src/DevHive.Data/RelationModels/UserFriend.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.ComponentModel.DataAnnotations; -using System.ComponentModel.DataAnnotations.Schema; -using DevHive.Data.Models; - -namespace DevHive.Data.RelationModels -{ - [Table("UserFriends")] - public class UserFriend - { - public Guid UserId { get; set; } - public User User { get; set; } - - public Guid FriendId { get; set; } - public User Friend { get; set; } - } -} diff --git a/src/DevHive.Data/Repositories/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs index ed8db49..6e97e60 100644 --- a/src/DevHive.Data/Repositories/UserRepository.cs +++ b/src/DevHive.Data/Repositories/UserRepository.cs @@ -23,14 +23,6 @@ namespace DevHive.Data.Repositories } #region Read - public IEnumerable QueryAll() - { - return this._context.Users - .Include(x => x.Roles) - .AsNoTracking() - .AsEnumerable(); - } - public override async Task GetByIdAsync(Guid id) { return await this._context.Users @@ -38,8 +30,7 @@ namespace DevHive.Data.Repositories .Include(x => x.Languages) .Include(x => x.Technologies) .Include(x => x.Posts) - .Include(x => x.MyFriends) - .Include(x => x.FriendsOf) + .Include(x => x.Friends) .Include(x => x.ProfilePicture) .FirstOrDefaultAsync(x => x.Id == id); } @@ -51,56 +42,15 @@ namespace DevHive.Data.Repositories .Include(x => x.Languages) .Include(x => x.Technologies) .Include(x => x.Posts) - .Include(x => x.MyFriends) - .Include(x => x.FriendsOf) + .Include(x => x.Friends) .Include(x => x.ProfilePicture) .FirstOrDefaultAsync(x => x.UserName == username); } #endregion #region Update - public override async Task EditAsync(Guid id, User newEntity) + public async Task UpdateProfilePicture(Guid userId, string pictureUrl) { - User user = await this.GetByIdAsync(id); - - this._context - .Entry(user) - .CurrentValues - .SetValues(newEntity); - - HashSet languages = new(); - foreach (var lang in newEntity.Languages) - languages.Add(lang); - user.Languages = languages; - - HashSet roles = new(); - foreach (var role in newEntity.Roles) - roles.Add(role); - user.Roles = roles; - - foreach (var friend in newEntity.MyFriends) - { - user.MyFriends.Add(friend); - this._context.Entry(friend).State = EntityState.Modified; - } - - foreach (var friend in newEntity.FriendsOf) - { - user.FriendsOf.Add(friend); - this._context.Entry(friend).State = EntityState.Modified; - } - - HashSet technologies = new(); - foreach (var tech in newEntity.Technologies) - technologies.Add(tech); - user.Technologies = technologies; - - this._context.Entry(user).State = EntityState.Modified; - - return await this.SaveChangesAsync(); - } - - public async Task UpdateProfilePicture(Guid userId, string pictureUrl) { User user = await this.GetByIdAsync(userId); user.ProfilePicture.PictureURL = pictureUrl; @@ -131,14 +81,19 @@ namespace DevHive.Data.Repositories .AnyAsync(u => u.Email == email); } - public async Task DoesUserHaveThisFriendAsync(Guid userId, Guid friendId) + public async Task ValidateFriendsCollectionAsync(List usernames) { - return true; - // User user = await this.GetByIdAsync(userId); + bool valid = true; - // User friend = await this.GetByIdAsync(friendId); - - // return user.Friends.Any(x => x.Friend.Id == friendId); + foreach (var username in usernames) + { + if (!await this._context.Users.AnyAsync(x => x.UserName == username)) + { + valid = false; + break; + } + } + return valid; } public bool DoesUserHaveThisUsername(Guid id, string username) diff --git a/src/DevHive.Services/Configurations/Mapping/UserMappings.cs b/src/DevHive.Services/Configurations/Mapping/UserMappings.cs index 6922cd7..2b0f4ed 100644 --- a/src/DevHive.Services/Configurations/Mapping/UserMappings.cs +++ b/src/DevHive.Services/Configurations/Mapping/UserMappings.cs @@ -12,27 +12,20 @@ namespace DevHive.Services.Configurations.Mapping { CreateMap(); CreateMap(); - CreateMap(); - // .ForMember(dest => dest.Friends, src => src.Ignore()); - CreateMap() - .ForMember(dest => dest.UserName, src => src.MapFrom(p => p.Friend.UserName)); + CreateMap() + .ForMember(dest => dest.Friends, src => src.Ignore()); CreateMap() - // .ForMember(dest => dest.Friends, src => src.Ignore()) + .ForMember(dest => dest.Friends, src => src.Ignore()) .AfterMap((src, dest) => dest.PasswordHash = PasswordModifications.GeneratePasswordHash(src.Password)); CreateMap(); CreateMap() - .ForMember(dest => dest.Friends, src => src.MapFrom(p => p.MyFriends)) - .ForMember(dest => dest.ProfilePictureURL, src => src.MapFrom(p => p.ProfilePicture.PictureURL)); - // .ForMember(dest => dest.Friends, src => src.MapFrom(p => p.Friends)); + .ForMember(dest => dest.ProfilePictureURL, src => src.MapFrom(p => p.ProfilePicture.PictureURL)) + .ForMember(dest => dest.Friends, src => src.MapFrom(p => p.Friends)); CreateMap() .ForMember(x => x.Password, opt => opt.Ignore()) .ForMember(dest => dest.ProfilePictureURL, src => src.MapFrom(p => p.ProfilePicture.PictureURL)); CreateMap(); - - CreateMap() - .ForMember(dest => dest.UserName, src => src.MapFrom(p => p.Friend.UserName)) - .ForMember(dest => dest.Id, src => src.MapFrom(p => p.FriendId)); } } } diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs index 9cc4a8e..8f9ebc4 100644 --- a/src/DevHive.Services/Services/UserService.cs +++ b/src/DevHive.Services/Services/UserService.cs @@ -14,8 +14,8 @@ using DevHive.Services.Interfaces; using DevHive.Data.Interfaces.Repositories; using System.Linq; using DevHive.Common.Models.Misc; -using DevHive.Data.RelationModels; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Identity; namespace DevHive.Services.Services { @@ -25,6 +25,8 @@ namespace DevHive.Services.Services private readonly IRoleRepository _roleRepository; private readonly ILanguageRepository _languageRepository; private readonly ITechnologyRepository _technologyRepository; + private readonly UserManager _userManager; + private readonly RoleManager _roleManager; private readonly IMapper _userMapper; private readonly JWTOptions _jwtOptions; private readonly ICloudService _cloudService; @@ -33,6 +35,8 @@ namespace DevHive.Services.Services ILanguageRepository languageRepository, IRoleRepository roleRepository, ITechnologyRepository technologyRepository, + UserManager userManager, + RoleManager roleManager, IMapper mapper, JWTOptions jwtOptions, ICloudService cloudService) @@ -43,6 +47,8 @@ namespace DevHive.Services.Services this._jwtOptions = jwtOptions; this._languageRepository = languageRepository; this._technologyRepository = technologyRepository; + this._userManager = userManager; + this._roleManager = roleManager; this._cloudService = cloudService; } @@ -77,20 +83,22 @@ namespace DevHive.Services.Services User user = this._userMapper.Map(registerModel); user.PasswordHash = PasswordModifications.GeneratePasswordHash(registerModel.Password); - user.ProfilePicture = new ProfilePicture() { PictureURL = "/assets/images/feed/profile-pic.png" }; + user.ProfilePicture = new ProfilePicture() { PictureURL = string.Empty }; // Make sure the default role exists //TODO: Move when project starts if (!await this._roleRepository.DoesNameExist(Role.DefaultRole)) await this._roleRepository.AddAsync(new Role { Name = Role.DefaultRole }); - // Set the default role to the user - Role defaultRole = await this._roleRepository.GetByNameAsync(Role.DefaultRole); - user.Roles.Add(defaultRole); + user.Roles.Add(await this._roleRepository.GetByNameAsync(Role.DefaultRole)); - await this._userRepository.AddAsync(user); + IdentityResult userResult = await this._userManager.CreateAsync(user); + User createdUser = await this._userRepository.GetByUsernameAsync(registerModel.UserName); - return new TokenModel(WriteJWTSecurityToken(user.Id, user.UserName, user.Roles)); + if (!userResult.Succeeded) + throw new ArgumentException("Unable to create a user"); + + return new TokenModel(WriteJWTSecurityToken(createdUser.Id, createdUser.UserName, createdUser.Roles)); } #endregion @@ -105,9 +113,7 @@ namespace DevHive.Services.Services public async Task GetUserByUsername(string username) { - User user = await this._userRepository.GetByUsernameAsync(username); - - if (user == null) + User user = await this._userRepository.GetByUsernameAsync(username) ?? throw new ArgumentException("User does not exist!"); return this._userMapper.Map(user); @@ -119,16 +125,17 @@ namespace DevHive.Services.Services { await this.ValidateUserOnUpdate(updateUserServiceModel); - User user = await this.PopulateModel(updateUserServiceModel); + User currentUser = await this._userRepository.GetByIdAsync(updateUserServiceModel.Id); + await this.PopulateUserModel(currentUser, updateUserServiceModel); - await this.CreateRelationToFriends(user, updateUserServiceModel.Friends.ToList()); + await this.CreateRelationToFriends(currentUser, updateUserServiceModel.Friends.ToList()); - bool successful = await this._userRepository.EditAsync(updateUserServiceModel.Id, user); + IdentityResult result = await this._userManager.UpdateAsync(currentUser); - if (!successful) + if (!result.Succeeded) throw new InvalidOperationException("Unable to edit user!"); - User newUser = await this._userRepository.GetByIdAsync(user.Id); + User newUser = await this._userRepository.GetByIdAsync(currentUser.Id); return this._userMapper.Map(newUser); } @@ -139,7 +146,7 @@ namespace DevHive.Services.Services { User user = await this._userRepository.GetByIdAsync(updateProfilePictureServiceModel.UserId); - if (!String.IsNullOrEmpty(user.ProfilePicture.PictureURL)) + if (!string.IsNullOrEmpty(user.ProfilePicture.PictureURL)) { bool success = await _cloudService.RemoveFilesFromCloud(new List { user.ProfilePicture.PictureURL }); if (!success) @@ -165,9 +172,9 @@ namespace DevHive.Services.Services throw new ArgumentException("User does not exist!"); User user = await this._userRepository.GetByIdAsync(id); - bool result = await this._userRepository.DeleteAsync(user); + IdentityResult result = await this._userManager.DeleteAsync(user); - return result; + return result.Succeeded; } #endregion @@ -233,9 +240,19 @@ namespace DevHive.Services.Services if (!await this._userRepository.DoesUserExistAsync(updateUserServiceModel.Id)) throw new ArgumentException("User does not exist!"); + if (updateUserServiceModel.Friends.Any(x => x.UserName == updateUserServiceModel.UserName)) + throw new ArgumentException("You cant add yourself as a friend(sry, bro)!"); + if (!this._userRepository.DoesUserHaveThisUsername(updateUserServiceModel.Id, updateUserServiceModel.UserName) && await this._userRepository.DoesUsernameExistAsync(updateUserServiceModel.UserName)) throw new ArgumentException("Username already exists!"); + + List usernames = new(); + foreach (var friend in updateUserServiceModel.Friends) + usernames.Add(friend.UserName); + + if (!await this._userRepository.ValidateFriendsCollectionAsync(usernames)) + throw new ArgumentException("One or more friends do not exist!"); } /// @@ -288,29 +305,20 @@ namespace DevHive.Services.Services await this._roleRepository.AddAsync(adminRole); } - Role admin = await this._roleRepository.GetByNameAsync(Role.AdminRole); + Role admin = await this._roleManager.FindByNameAsync(Role.AdminRole); user.Roles.Add(admin); - await this._userRepository.EditAsync(user.Id, user); + await this._userManager.UpdateAsync(user); User newUser = await this._userRepository.GetByIdAsync(userId); return new TokenModel(WriteJWTSecurityToken(newUser.Id, newUser.UserName, newUser.Roles)); } - /// - /// Returns the user with the Id in the model, adding to him the roles, languages and technologies, specified by the parameter model. - /// This practically maps HashSet to HashSet (and the equvalent HashSets for Languages and Technologies) - /// and assigns the latter to the returned user. - /// - private async Task PopulateModel(UpdateUserServiceModel updateUserServiceModel) + private async Task PopulateUserModel(User user, UpdateUserServiceModel updateUserServiceModel) { - User user = this._userMapper.Map(updateUserServiceModel); - - /* Fetch Roles and replace model's*/ //Do NOT allow a user to change his roles, unless he is an Admin - bool isAdmin = (await this._userRepository.GetByIdAsync(updateUserServiceModel.Id)) - .Roles.Any(r => r.Name == Role.AdminRole); + bool isAdmin = await this._userManager.IsInRoleAsync(user, Role.AdminRole); if (isAdmin) { @@ -324,11 +332,7 @@ namespace DevHive.Services.Services } user.Roles = roles; } - //Preserve original user roles - else - user.Roles = (await this._userRepository.GetByIdAsync(updateUserServiceModel.Id)).Roles; - /* Fetch Languages and replace model's*/ HashSet languages = new(); int languagesCount = updateUserServiceModel.Languages.Count; for (int i = 0; i < languagesCount; i++) @@ -351,37 +355,19 @@ namespace DevHive.Services.Services technologies.Add(technology); } user.Technologies = technologies; - - return user; } - private async Task CreateRelationToFriends(User user, List friends) + private async Task CreateRelationToFriends(User user, List friends) { foreach (var friend in friends) { - User amigo = await this._userRepository.GetByUsernameAsync(friend.UserName) ?? - throw new ArgumentException("No amigo, bro!"); - - UserFriend relation = new() - { - UserId = user.Id, - User = user, - FriendId = amigo.Id, - Friend = amigo - }; + User amigo = await this._userRepository.GetByUsernameAsync(friend.UserName); - UserFriend theOtherRelation = new() - { - UserId = amigo.Id, - User = amigo, - FriendId = user.Id, - Friend = user - }; + user.Friends.Add(amigo); + amigo.Friends.Add(user); - user.MyFriends.Add(relation); - user.FriendsOf.Add(theOtherRelation); + await this._userManager.UpdateAsync(amigo); } - return true; } #endregion } diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureDatabase.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureDatabase.cs index 3748edf..9f02dd7 100644 --- a/src/DevHive.Web/Configurations/Extensions/ConfigureDatabase.cs +++ b/src/DevHive.Web/Configurations/Extensions/ConfigureDatabase.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.DependencyInjection; -using DevHive.Data.Repositories; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using DevHive.Data.Models; @@ -8,8 +7,6 @@ using Microsoft.AspNetCore.Builder; using System; using Microsoft.AspNetCore.Authentication.JwtBearer; using DevHive.Data; -using Microsoft.AspNetCore.Authorization; -using System.Collections.Generic; namespace DevHive.Web.Configurations.Extensions { diff --git a/src/DevHive.Web/Startup.cs b/src/DevHive.Web/Startup.cs index dd7e852..46521cf 100644 --- a/src/DevHive.Web/Startup.cs +++ b/src/DevHive.Web/Startup.cs @@ -33,7 +33,6 @@ namespace DevHive.Web services.JWTConfiguration(Configuration); services.AutoMapperConfiguration(); services.DependencyInjectionConfiguration(this.Configuration); - services.ExceptionHandlerMiddlewareConfiguration(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. -- cgit v1.2.3