From 5514f1109cb3689fa81b29bb2d7dcf84cc05f65f Mon Sep 17 00:00:00 2001 From: transtrike Date: Fri, 15 Jan 2021 16:45:30 +0200 Subject: Extracted Interfaces from every DevHive.Data class; Tidied up the DevHive.Interfaces --- src/DevHive.Data/Interfaces/Models/IPost.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 src/DevHive.Data/Interfaces/Models/IPost.cs (limited to 'src/DevHive.Data/Interfaces/Models/IPost.cs') diff --git a/src/DevHive.Data/Interfaces/Models/IPost.cs b/src/DevHive.Data/Interfaces/Models/IPost.cs new file mode 100644 index 0000000..117d859 --- /dev/null +++ b/src/DevHive.Data/Interfaces/Models/IPost.cs @@ -0,0 +1,13 @@ +using System; +using DevHive.Data.Models; + +namespace DevHive.Data.Interfaces.Models +{ + public interface IPost : IModel + { + Guid IssuerId { get; set; } + DateTime TimeCreated { get; set; } + string Message { get; set; } + Comment[] Comments { get; set; } + } +} -- cgit v1.2.3 From fac1bf2d1772e60cbecc1cf0381c6063a0e97ffd Mon Sep 17 00:00:00 2001 From: transtrike Date: Sat, 23 Jan 2021 20:59:12 +0200 Subject: Post&Comment Models implemented; Mappings Configured --- src/DevHive.Data/Interfaces/Models/IPost.cs | 12 +++++-- src/DevHive.Data/Models/Post.cs | 11 +++--- .../Configurations/Mapping/PostMappings.cs | 12 +++++-- .../Models/Post/Comment/BaseCommentServiceModel.cs | 15 --------- .../Models/Post/Comment/CommentServiceModel.cs | 9 ----- .../Models/Post/Post/BasePostServiceModel.cs | 11 ------ .../Models/Post/Post/CreatePostServiceModel.cs | 8 ++++- .../Models/Post/Post/PostServiceModel.cs | 12 ------- .../Models/Post/Post/ReadPostServiceModel.cs | 21 ++++++++++++ .../Models/Post/Post/UpdatePostServiceModel.cs | 12 +++++-- .../Configurations/Mapping/PostMappings.cs | 20 +++++++++++ .../Models/Post/Comment/BaseCommentWebModel.cs | 21 ------------ .../Models/Post/Comment/CommentWebModel.cs | 25 -------------- .../Models/Post/Post/BasePostWebModel.cs | 17 ---------- .../Models/Post/Post/CreatePostWebModel.cs | 15 ++++++++- src/DevHive.Web/Models/Post/Post/PostWebModel.cs | 39 ---------------------- .../Models/Post/Post/ReadPostWebModel.cs | 25 ++++++++++++++ .../Models/Post/Post/UpdatePostModel.cs | 7 ---- .../Models/Post/Post/UpdatePostWebModel.cs | 13 ++++++++ 19 files changed, 134 insertions(+), 171 deletions(-) delete mode 100644 src/DevHive.Services/Models/Post/Comment/BaseCommentServiceModel.cs delete mode 100644 src/DevHive.Services/Models/Post/Comment/CommentServiceModel.cs delete mode 100644 src/DevHive.Services/Models/Post/Post/BasePostServiceModel.cs delete mode 100644 src/DevHive.Services/Models/Post/Post/PostServiceModel.cs create mode 100644 src/DevHive.Services/Models/Post/Post/ReadPostServiceModel.cs create mode 100644 src/DevHive.Web/Configurations/Mapping/PostMappings.cs delete mode 100644 src/DevHive.Web/Models/Post/Comment/BaseCommentWebModel.cs delete mode 100644 src/DevHive.Web/Models/Post/Comment/CommentWebModel.cs delete mode 100644 src/DevHive.Web/Models/Post/Post/BasePostWebModel.cs delete mode 100644 src/DevHive.Web/Models/Post/Post/PostWebModel.cs create mode 100644 src/DevHive.Web/Models/Post/Post/ReadPostWebModel.cs delete mode 100644 src/DevHive.Web/Models/Post/Post/UpdatePostModel.cs create mode 100644 src/DevHive.Web/Models/Post/Post/UpdatePostWebModel.cs (limited to 'src/DevHive.Data/Interfaces/Models/IPost.cs') diff --git a/src/DevHive.Data/Interfaces/Models/IPost.cs b/src/DevHive.Data/Interfaces/Models/IPost.cs index 117d859..e68407d 100644 --- a/src/DevHive.Data/Interfaces/Models/IPost.cs +++ b/src/DevHive.Data/Interfaces/Models/IPost.cs @@ -1,13 +1,19 @@ using System; +using System.Collections.Generic; using DevHive.Data.Models; namespace DevHive.Data.Interfaces.Models { public interface IPost : IModel { - Guid IssuerId { get; set; } - DateTime TimeCreated { get; set; } + Guid CreatorId { get; set; } + string Message { get; set; } - Comment[] Comments { get; set; } + + DateTime TimeCreated { get; set; } + + List Comments { get; set; } + + //List Files } } diff --git a/src/DevHive.Data/Models/Post.cs b/src/DevHive.Data/Models/Post.cs index 54576b7..f7bca43 100644 --- a/src/DevHive.Data/Models/Post.cs +++ b/src/DevHive.Data/Models/Post.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using DevHive.Data.Interfaces.Models; @@ -9,14 +10,14 @@ namespace DevHive.Data.Models { public Guid Id { get; set; } - public Guid IssuerId { get; set; } - - public DateTime TimeCreated { get; set; } + public Guid CreatorId { get; set; } public string Message { get; set; } - //public File[] Files { get; set; } + public DateTime TimeCreated { get; set; } + + public List Comments { get; set; } - public Comment[] Comments { get; set; } + // public List Files { get; set; } } } diff --git a/src/DevHive.Services/Configurations/Mapping/PostMappings.cs b/src/DevHive.Services/Configurations/Mapping/PostMappings.cs index 7f99c66..e4924a5 100644 --- a/src/DevHive.Services/Configurations/Mapping/PostMappings.cs +++ b/src/DevHive.Services/Configurations/Mapping/PostMappings.cs @@ -1,6 +1,5 @@ using DevHive.Data.Models; using AutoMapper; -using DevHive.Services.Models.Post; using DevHive.Services.Models.Post.Post; namespace DevHive.Services.Configurations.Mapping @@ -9,8 +8,15 @@ namespace DevHive.Services.Configurations.Mapping { public PostMappings() { - CreateMap(); - CreateMap(); + CreateMap(); + // .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()) + .ForMember(dest => dest.Message, src => src.MapFrom(p => p.NewMessage)); + + CreateMap() + .ForMember(dest => dest.PostId, src => src.MapFrom(p => p.Id)); } } } diff --git a/src/DevHive.Services/Models/Post/Comment/BaseCommentServiceModel.cs b/src/DevHive.Services/Models/Post/Comment/BaseCommentServiceModel.cs deleted file mode 100644 index dae7ec3..0000000 --- a/src/DevHive.Services/Models/Post/Comment/BaseCommentServiceModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -namespace DevHive.Services.Models.Post.Comment -{ - public class BaseCommentServiceModel - { - public Guid PostId { get; set; } - - public Guid IssuerId { get; set; } - - public string Message { get; set; } - - public DateTime TimeCreated { get; set; } - } -} diff --git a/src/DevHive.Services/Models/Post/Comment/CommentServiceModel.cs b/src/DevHive.Services/Models/Post/Comment/CommentServiceModel.cs deleted file mode 100644 index a0fa53e..0000000 --- a/src/DevHive.Services/Models/Post/Comment/CommentServiceModel.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System; - -namespace DevHive.Services.Models.Post.Comment -{ - public class CommentServiceModel : CreateCommentServiceModel - { - - } -} \ No newline at end of file diff --git a/src/DevHive.Services/Models/Post/Post/BasePostServiceModel.cs b/src/DevHive.Services/Models/Post/Post/BasePostServiceModel.cs deleted file mode 100644 index 45a677c..0000000 --- a/src/DevHive.Services/Models/Post/Post/BasePostServiceModel.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; - -namespace DevHive.Services.Models.Post.Post -{ - public class BasePostServiceModel - { - public Guid Id { get; set; } - public Guid IssuerId { get; set; } - public string Message { get; set; } - } -} \ No newline at end of file diff --git a/src/DevHive.Services/Models/Post/Post/CreatePostServiceModel.cs b/src/DevHive.Services/Models/Post/Post/CreatePostServiceModel.cs index 1bf60ae..6b83f3e 100644 --- a/src/DevHive.Services/Models/Post/Post/CreatePostServiceModel.cs +++ b/src/DevHive.Services/Models/Post/Post/CreatePostServiceModel.cs @@ -2,8 +2,14 @@ using System; namespace DevHive.Services.Models.Post.Post { - public class CreatePostServiceModel : BasePostServiceModel + public class CreatePostServiceModel { + public Guid IssuerId { get; set; } + + public string Message { get; set; } + public DateTime TimeCreated { get; set; } + + // public List Files { get; set; } } } diff --git a/src/DevHive.Services/Models/Post/Post/PostServiceModel.cs b/src/DevHive.Services/Models/Post/Post/PostServiceModel.cs deleted file mode 100644 index b9c2128..0000000 --- a/src/DevHive.Services/Models/Post/Post/PostServiceModel.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; - -namespace DevHive.Services.Models.Post.Post -{ - public class PostServiceModel : CreatePostServiceModel - { - - //public File[] Files { get; set; } - - //public Comment[] Comments { get; set; } - } -} \ No newline at end of file diff --git a/src/DevHive.Services/Models/Post/Post/ReadPostServiceModel.cs b/src/DevHive.Services/Models/Post/Post/ReadPostServiceModel.cs new file mode 100644 index 0000000..52b9232 --- /dev/null +++ b/src/DevHive.Services/Models/Post/Post/ReadPostServiceModel.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using DevHive.Services.Models.Post.Comment; + +namespace DevHive.Services.Models.Post.Post +{ + public class ReadPostServiceModel + { + public Guid PostId { get; set; } + + public Guid CreatorId { get; set; } + + public string Message { get; set; } + + public DateTime TimeCreated { get; set; } + + public List Comments { 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 5a4f621..67ee711 100644 --- a/src/DevHive.Services/Models/Post/Post/UpdatePostServiceModel.cs +++ b/src/DevHive.Services/Models/Post/Post/UpdatePostServiceModel.cs @@ -1,5 +1,13 @@ +using System; + namespace DevHive.Services.Models.Post.Post { - public class UpdatePostServiceModel : BasePostServiceModel - { } + public class UpdatePostServiceModel + { + public Guid PostId { get; set; } + + public string NewMessage { get; set; } + + // public List Files { get; set; } + } } diff --git a/src/DevHive.Web/Configurations/Mapping/PostMappings.cs b/src/DevHive.Web/Configurations/Mapping/PostMappings.cs new file mode 100644 index 0000000..0e966cc --- /dev/null +++ b/src/DevHive.Web/Configurations/Mapping/PostMappings.cs @@ -0,0 +1,20 @@ +using AutoMapper; +using DevHive.Services.Models.Post.Post; +using DevHive.Web.Models.Post.Post; + +namespace DevHive.Web.Configurations.Mapping +{ + public class PostMappings : Profile + { + public PostMappings() + { + CreateMap(); + CreateMap(); + + CreateMap() + .ForMember(dest => dest.CreatorFirstName, src => src.Ignore()) + .ForMember(dest => dest.CreatorLastName, src => src.Ignore()) + .ForMember(dest => dest.CreatorUsername, src => src.Ignore()); + } + } +} diff --git a/src/DevHive.Web/Models/Post/Comment/BaseCommentWebModel.cs b/src/DevHive.Web/Models/Post/Comment/BaseCommentWebModel.cs deleted file mode 100644 index 9ba0b87..0000000 --- a/src/DevHive.Web/Models/Post/Comment/BaseCommentWebModel.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.ComponentModel.DataAnnotations; -using System.Diagnostics.CodeAnalysis; - -namespace DevHive.Web.Models.Post.Comment -{ - public class BaseCommentWebModel - { - [NotNull] - [Required] - public Guid PostId { get; set; } - - [NotNull] - [Required] - public Guid CommentId { get; set; } - - [NotNull] - [Required] - public string Message { get; set; } - } -} diff --git a/src/DevHive.Web/Models/Post/Comment/CommentWebModel.cs b/src/DevHive.Web/Models/Post/Comment/CommentWebModel.cs deleted file mode 100644 index 590851d..0000000 --- a/src/DevHive.Web/Models/Post/Comment/CommentWebModel.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System; -using System.ComponentModel.DataAnnotations; -using System.Diagnostics.CodeAnalysis; - -namespace DevHive.Web.Models.Post.Comment -{ - public class CommentWebModel - { - [NotNull] - [Required] - public Guid IssuerId { get; set; } - - [NotNull] - [Required] - public Guid PostId { get; set; } - - [NotNull] - [Required] - public string Message { get; set; } - - [NotNull] - [Required] - public DateTime TimeCreated { get; set; } - } -} diff --git a/src/DevHive.Web/Models/Post/Post/BasePostWebModel.cs b/src/DevHive.Web/Models/Post/Post/BasePostWebModel.cs deleted file mode 100644 index 35ddd34..0000000 --- a/src/DevHive.Web/Models/Post/Post/BasePostWebModel.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.ComponentModel.DataAnnotations; -using System.Diagnostics.CodeAnalysis; - -namespace DevHive.Web.Models.Post.Post -{ - public class BasePostWebModel - { - [NotNull] - [Required] - public Guid IssuerId { get; set; } - - [NotNull] - [Required] - public string Message { get; set; } - } -} diff --git a/src/DevHive.Web/Models/Post/Post/CreatePostWebModel.cs b/src/DevHive.Web/Models/Post/Post/CreatePostWebModel.cs index 389ff9e..647b30e 100644 --- a/src/DevHive.Web/Models/Post/Post/CreatePostWebModel.cs +++ b/src/DevHive.Web/Models/Post/Post/CreatePostWebModel.cs @@ -1,6 +1,19 @@ using System; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics.CodeAnalysis; namespace DevHive.Web.Models.Post.Post { - public class CreatePostWebModel : BasePostWebModel { } + public class CreatePostWebModel + { + [NotNull] + [Required] + public Guid CreatorId { get; set; } + + [NotNull] + [Required] + public string Message { get; set; } + + // public List Files { get; set; } + } } diff --git a/src/DevHive.Web/Models/Post/Post/PostWebModel.cs b/src/DevHive.Web/Models/Post/Post/PostWebModel.cs deleted file mode 100644 index fe35cee..0000000 --- a/src/DevHive.Web/Models/Post/Post/PostWebModel.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Diagnostics.CodeAnalysis; -using DevHive.Web.Attributes; -using DevHive.Web.Models.Post.Comment; - -namespace DevHive.Web.Models.Post.Post -{ - public class PostWebModel - { - //public string Picture { get; set; } - - [NotNull] - [Required] - [MinLength(3)] - [MaxLength(50)] - public string IssuerFirstName { get; set; } - - [NotNull] - [Required] - [MinLength(3)] - [MaxLength(50)] - public string IssuerLastName { get; set; } - - [NotNull] - [Required] - [MinLength(3)] - [MaxLength(50)] - [OnlyAlphanumerics(ErrorMessage = "Username can only contain letters and digits!")] - public string IssuerUsername { get; set; } - - [NotNull] - [Required] - public string Message { get; set; } - - //public Files[] Files { get; set; } - - public CommentWebModel[] Comments { get; set; } - } -} diff --git a/src/DevHive.Web/Models/Post/Post/ReadPostWebModel.cs b/src/DevHive.Web/Models/Post/Post/ReadPostWebModel.cs new file mode 100644 index 0000000..04c6275 --- /dev/null +++ b/src/DevHive.Web/Models/Post/Post/ReadPostWebModel.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using DevHive.Web.Models.Post.Comment; + +namespace DevHive.Web.Models.Post.Post +{ + public class ReadPostWebModel + { + public Guid PostId { get; set; } + + public string CreatorFirstName { get; set; } + + public string CreatorLastName { get; set; } + + public string CreatorUsername { get; set; } + + public string Message { get; set; } + + public DateTime TimeCreated { get; set; } + + public List Comments { get; set; } + + //public Files[] Files { get; set; } + } +} diff --git a/src/DevHive.Web/Models/Post/Post/UpdatePostModel.cs b/src/DevHive.Web/Models/Post/Post/UpdatePostModel.cs deleted file mode 100644 index c774900..0000000 --- a/src/DevHive.Web/Models/Post/Post/UpdatePostModel.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace DevHive.Web.Models.Post.Post -{ - public class UpdatePostWebModel : BasePostWebModel - { - //public Files[] Files { get; set; } - } -} \ No newline at end of file diff --git a/src/DevHive.Web/Models/Post/Post/UpdatePostWebModel.cs b/src/DevHive.Web/Models/Post/Post/UpdatePostWebModel.cs new file mode 100644 index 0000000..5b66436 --- /dev/null +++ b/src/DevHive.Web/Models/Post/Post/UpdatePostWebModel.cs @@ -0,0 +1,13 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.Diagnostics.CodeAnalysis; + +namespace DevHive.Web.Models.Post.Post +{ + public class UpdatePostWebModel + { + [NotNull] + [Required] + public string Message { get; set; } + } +} -- cgit v1.2.3 From 63e29a43bf276b1f02626d0bb35acec14f051fc3 Mon Sep 17 00:00:00 2001 From: transtrike Date: Thu, 28 Jan 2021 20:05:16 +0200 Subject: Comment and Post models refactored --- src/DevHive.Data/Interfaces/Models/IComment.cs | 5 +++-- src/DevHive.Data/Interfaces/Models/IPost.cs | 2 +- src/DevHive.Data/Models/Comment.cs | 6 ++++-- src/DevHive.Data/Models/Post.cs | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) (limited to 'src/DevHive.Data/Interfaces/Models/IPost.cs') diff --git a/src/DevHive.Data/Interfaces/Models/IComment.cs b/src/DevHive.Data/Interfaces/Models/IComment.cs index 9a72da4..e7b5ad5 100644 --- a/src/DevHive.Data/Interfaces/Models/IComment.cs +++ b/src/DevHive.Data/Interfaces/Models/IComment.cs @@ -1,12 +1,13 @@ using System; +using DevHive.Data.Models; namespace DevHive.Data.Interfaces.Models { public interface IComment : IModel { - Guid PostId { get; set; } + Post Parrent { get; set; } - Guid CreatorId { get; set; } + User Creator { get; set; } string Message { get; set; } diff --git a/src/DevHive.Data/Interfaces/Models/IPost.cs b/src/DevHive.Data/Interfaces/Models/IPost.cs index e68407d..0902465 100644 --- a/src/DevHive.Data/Interfaces/Models/IPost.cs +++ b/src/DevHive.Data/Interfaces/Models/IPost.cs @@ -6,7 +6,7 @@ namespace DevHive.Data.Interfaces.Models { public interface IPost : IModel { - Guid CreatorId { get; set; } + User Creator { get; set; } string Message { get; set; } diff --git a/src/DevHive.Data/Models/Comment.cs b/src/DevHive.Data/Models/Comment.cs index c953355..e2bb21d 100644 --- a/src/DevHive.Data/Models/Comment.cs +++ b/src/DevHive.Data/Models/Comment.cs @@ -7,9 +7,11 @@ namespace DevHive.Data.Models { public Guid Id { get; set; } - public Guid PostId { get; set; } + // public Guid PostId { get; set; } + public Post Post { get; set; } - public Guid CreatorId { get; set; } + // public Guid CreatorId { get; set; } + public User Creator { get; set; } public string Message { get; set; } diff --git a/src/DevHive.Data/Models/Post.cs b/src/DevHive.Data/Models/Post.cs index 1b1ec4d..0ea7142 100644 --- a/src/DevHive.Data/Models/Post.cs +++ b/src/DevHive.Data/Models/Post.cs @@ -10,7 +10,7 @@ namespace DevHive.Data.Models { public Guid Id { get; set; } - public Guid CreatorId { get; set; } + public User Creator { get; set; } public string Message { get; set; } -- 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/Models/IPost.cs') 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 9d5f4628a3a75871b47ac6a9f9c0419748d9dfb8 Mon Sep 17 00:00:00 2001 From: transtrike Date: Sat, 30 Jan 2021 19:28:06 +0200 Subject: User - Friend relation inital fix --- src/DevHive.Data/DevHiveContext.cs | 15 +- src/DevHive.Data/Interfaces/Models/IPost.cs | 2 + src/DevHive.Data/Interfaces/Models/IUser.cs | 2 +- ...0210130171705_User_Friends_Relation.Designer.cs | 561 +++++++++++++++++++++ .../20210130171705_User_Friends_Relation.cs | 484 ++++++++++++++++++ .../Migrations/DevHiveContextModelSnapshot.cs | 559 ++++++++++++++++++++ src/DevHive.Data/Models/Post.cs | 3 + src/DevHive.Data/Models/User.cs | 2 +- src/DevHive.Data/RelationModels/UserFriends.cs | 2 - src/DevHive.Data/Repositories/UserRepository.cs | 30 +- src/DevHive.Services/Services/FeedService.cs | 2 +- src/DevHive.Services/Services/UserService.cs | 12 +- .../Extensions/ConfigureDependencyInjection.cs | 2 +- 13 files changed, 1654 insertions(+), 22 deletions(-) create mode 100644 src/DevHive.Data/Migrations/20210130171705_User_Friends_Relation.Designer.cs create mode 100644 src/DevHive.Data/Migrations/20210130171705_User_Friends_Relation.cs create mode 100644 src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs (limited to 'src/DevHive.Data/Interfaces/Models/IPost.cs') diff --git a/src/DevHive.Data/DevHiveContext.cs b/src/DevHive.Data/DevHiveContext.cs index 7eb90de..e7c606f 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 UserFriends { get; set; } public DbSet Rating { get; set; } protected override void OnModelCreating(ModelBuilder builder) @@ -30,10 +31,16 @@ namespace DevHive.Data .WithMany(x => x.Users); /* Friends */ + builder.Entity() + .HasKey(x => new { x.UserId, x.FriendId }); + + // builder.Entity() + // .HasOne(x => x.Friend) + // .WithMany(x => x.Friends); + builder.Entity() .HasMany(x => x.Friends) - .WithMany(x => x.Friends) - .UsingEntity(x => x.ToTable("UserFriends")); + .WithOne(x => x.User); /* Languages */ builder.Entity() @@ -66,6 +73,10 @@ 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) diff --git a/src/DevHive.Data/Interfaces/Models/IPost.cs b/src/DevHive.Data/Interfaces/Models/IPost.cs index 86469a7..65c0fb4 100644 --- a/src/DevHive.Data/Interfaces/Models/IPost.cs +++ b/src/DevHive.Data/Interfaces/Models/IPost.cs @@ -14,6 +14,8 @@ namespace DevHive.Data.Interfaces.Models List Comments { get; set; } + Rating Rating { get; set; } + List FileUrls { get; set; } } } diff --git a/src/DevHive.Data/Interfaces/Models/IUser.cs b/src/DevHive.Data/Interfaces/Models/IUser.cs index 3e3ee7d..90923fa 100644 --- a/src/DevHive.Data/Interfaces/Models/IUser.cs +++ b/src/DevHive.Data/Interfaces/Models/IUser.cs @@ -12,6 +12,6 @@ namespace DevHive.Data.Interfaces.Models HashSet Languages { get; set; } HashSet Technologies { get; set; } HashSet Roles { get; set; } - HashSet Friends { get; set; } + HashSet Friends { get; set; } } } diff --git a/src/DevHive.Data/Migrations/20210130171705_User_Friends_Relation.Designer.cs b/src/DevHive.Data/Migrations/20210130171705_User_Friends_Relation.Designer.cs new file mode 100644 index 0000000..fc0af18 --- /dev/null +++ b/src/DevHive.Data/Migrations/20210130171705_User_Friends_Relation.Designer.cs @@ -0,0 +1,561 @@ +// +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("20210130171705_User_Friends_Relation")] + partial class User_Friends_Relation + { + 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.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.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"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/DevHive.Data/Migrations/20210130171705_User_Friends_Relation.cs b/src/DevHive.Data/Migrations/20210130171705_User_Friends_Relation.cs new file mode 100644 index 0000000..2c3b75b --- /dev/null +++ b/src/DevHive.Data/Migrations/20210130171705_User_Friends_Relation.cs @@ -0,0 +1,484 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +namespace DevHive.Data.Migrations +{ + public partial class User_Friends_Relation : 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), + 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); + }); + + 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: "Rating", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + Likes = table.Column(type: "integer", nullable: false), + Dislikes = table.Column(type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Rating", 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: "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.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: "Posts", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + CreatorId = table.Column(type: "uuid", nullable: true), + Message = table.Column(type: "text", nullable: true), + TimeCreated = table.Column(type: "timestamp without time zone", nullable: false), + RatingId = table.Column(type: "uuid", nullable: false), + FileUrls = table.Column>(type: "text[]", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Posts", x => x.Id); + table.ForeignKey( + name: "FK_Posts_AspNetUsers_CreatorId", + column: x => x.CreatorId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_Posts_Rating_RatingId", + column: x => x.RatingId, + principalTable: "Rating", + 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.CreateTable( + name: "Comments", + columns: table => new + { + Id = table.Column(type: "uuid", nullable: false), + PostId = table.Column(type: "uuid", nullable: true), + CreatorId = table.Column(type: "uuid", nullable: true), + 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_AspNetUsers_CreatorId", + column: x => x.CreatorId, + principalTable: "AspNetUsers", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + table.ForeignKey( + name: "FK_Comments_Posts_PostId", + column: x => x.PostId, + principalTable: "Posts", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + }); + + migrationBuilder.CreateIndex( + name: "IX_AspNetRoleClaims_RoleId", + table: "AspNetRoleClaims", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "RoleNameIndex", + table: "AspNetRoles", + column: "NormalizedName", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserClaims_UserId", + table: "AspNetUserClaims", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserLogins_UserId", + table: "AspNetUserLogins", + column: "UserId"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUserRoles_RoleId", + table: "AspNetUserRoles", + column: "RoleId"); + + migrationBuilder.CreateIndex( + name: "EmailIndex", + table: "AspNetUsers", + column: "NormalizedEmail"); + + migrationBuilder.CreateIndex( + name: "IX_AspNetUsers_UserName", + table: "AspNetUsers", + column: "UserName", + unique: true); + + migrationBuilder.CreateIndex( + name: "UserNameIndex", + table: "AspNetUsers", + column: "NormalizedUserName", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_Comments_CreatorId", + table: "Comments", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Comments_PostId", + table: "Comments", + column: "PostId"); + + migrationBuilder.CreateIndex( + name: "IX_LanguageUser_UsersId", + table: "LanguageUser", + column: "UsersId"); + + migrationBuilder.CreateIndex( + name: "IX_Posts_CreatorId", + table: "Posts", + column: "CreatorId"); + + migrationBuilder.CreateIndex( + name: "IX_Posts_RatingId", + table: "Posts", + column: "RatingId", + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_RoleUser_UsersId", + table: "RoleUser", + column: "UsersId"); + + migrationBuilder.CreateIndex( + name: "IX_TechnologyUser_UsersId", + table: "TechnologyUser", + column: "UsersId"); + + migrationBuilder.CreateIndex( + name: "IX_UserFriends_FriendId", + table: "UserFriends", + column: "FriendId"); + } + + 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: "UserFriends"); + + migrationBuilder.DropTable( + name: "Posts"); + + migrationBuilder.DropTable( + name: "Languages"); + + migrationBuilder.DropTable( + name: "AspNetRoles"); + + migrationBuilder.DropTable( + name: "Technologies"); + + migrationBuilder.DropTable( + name: "AspNetUsers"); + + migrationBuilder.DropTable( + name: "Rating"); + } + } +} diff --git a/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs b/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs new file mode 100644 index 0000000..064fb26 --- /dev/null +++ b/src/DevHive.Data/Migrations/DevHiveContextModelSnapshot.cs @@ -0,0 +1,559 @@ +// +using System; +using System.Collections.Generic; +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("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.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.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"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/DevHive.Data/Models/Post.cs b/src/DevHive.Data/Models/Post.cs index c513eb4..2d144d3 100644 --- a/src/DevHive.Data/Models/Post.cs +++ b/src/DevHive.Data/Models/Post.cs @@ -18,6 +18,9 @@ namespace DevHive.Data.Models public List Comments { get; set; } = new(); + public Guid RatingId { get; set; } + public Rating Rating { get; set; } + public List FileUrls { get; set; } = new(); } } diff --git a/src/DevHive.Data/Models/User.cs b/src/DevHive.Data/Models/User.cs index 504d841..2203554 100644 --- a/src/DevHive.Data/Models/User.cs +++ b/src/DevHive.Data/Models/User.cs @@ -29,7 +29,7 @@ namespace DevHive.Data.Models public HashSet Roles { get; set; } = new(); - public HashSet Friends { get; set; } = new(); + public HashSet Friends { get; set; } = new(); public HashSet Posts { get; set; } = new(); diff --git a/src/DevHive.Data/RelationModels/UserFriends.cs b/src/DevHive.Data/RelationModels/UserFriends.cs index dec366d..485d6ec 100644 --- a/src/DevHive.Data/RelationModels/UserFriends.cs +++ b/src/DevHive.Data/RelationModels/UserFriends.cs @@ -6,11 +6,9 @@ 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/UserRepository.cs b/src/DevHive.Data/Repositories/UserRepository.cs index 6512c42..6c63244 100644 --- a/src/DevHive.Data/Repositories/UserRepository.cs +++ b/src/DevHive.Data/Repositories/UserRepository.cs @@ -3,8 +3,10 @@ using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Threading.Tasks; +using AutoMapper.Mappers; using DevHive.Data.Interfaces.Repositories; using DevHive.Data.Models; +using DevHive.Data.RelationModels; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; @@ -68,17 +70,21 @@ namespace DevHive.Data.Repositories foreach (var role in newEntity.Roles) user.Roles.Add(role); - foreach (var friend in user.Friends) - { - friend.Friends.Remove(user); - this._context.Entry(friend).State = EntityState.Modified; - } - user.Friends.Clear(); - foreach (var friend in newEntity.Friends) - { - friend.Friends.Add(user); - user.Friends.Add(friend); - } + // foreach (var friend in user.Friends) + // { + // friend.Friends.Remove(user); + // this._context.Entry(friend).State = EntityState.Modified; + // } + // user.Friends.Clear(); + // foreach (var friend in newEntity.Friends) + // { + // friend.Friends.Add(user); + // user.Friends.Add(friend); + // } + this._context.UserFriends.RemoveRange( + this._context.UserFriends + .Where(x => x.FriendId == user.Id && + x.UserId == user.Id)); user.Technologies.Clear(); foreach (var tech in newEntity.Technologies) @@ -118,7 +124,7 @@ namespace DevHive.Data.Repositories User friend = await this.GetByIdAsync(friendId); - return user.Friends.Contains(friend); + return user.Friends.Any(x => x.Friend.Id == friendId); } public bool DoesUserHaveThisUsername(Guid id, string username) diff --git a/src/DevHive.Services/Services/FeedService.cs b/src/DevHive.Services/Services/FeedService.cs index 1bddac4..c17861d 100644 --- a/src/DevHive.Services/Services/FeedService.cs +++ b/src/DevHive.Services/Services/FeedService.cs @@ -38,7 +38,7 @@ namespace DevHive.Services.Services if (user == null) throw new ArgumentException("User doesn't exist!"); - List friendsList = user.Friends.ToList(); + List friendsList = user.Friends.Select(x => x.Friend).ToList(); if (friendsList.Count == 0) throw new ArgumentException("User has no friends to get feed from!"); diff --git a/src/DevHive.Services/Services/UserService.cs b/src/DevHive.Services/Services/UserService.cs index ec74b5f..ea53f1a 100644 --- a/src/DevHive.Services/Services/UserService.cs +++ b/src/DevHive.Services/Services/UserService.cs @@ -14,6 +14,7 @@ using DevHive.Services.Interfaces; using DevHive.Data.Interfaces.Repositories; using System.Linq; using DevHive.Common.Models.Misc; +using DevHive.Data.RelationModels; namespace DevHive.Services.Services { @@ -309,14 +310,21 @@ namespace DevHive.Services.Services user.Roles = roles; /* Fetch Friends and replace model's*/ - HashSet friends = new(); + 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).UserName) ?? throw new ArgumentException("Invalid friend's username!"); - friends.Add(friend); + UserFriends relation = new() + { + UserId = user.Id, + User = user, + FriendId = friend.Id, + Friend = friend + }; + friends.Add(relation); } user.Friends = friends; diff --git a/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs b/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs index fe2c788..46e67ee 100644 --- a/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs +++ b/src/DevHive.Web/Configurations/Extensions/ConfigureDependencyInjection.cs @@ -1,5 +1,4 @@ using DevHive.Data.Interfaces.Repositories; -using DevHive.Data.Models; using DevHive.Data.Repositories; using DevHive.Services.Interfaces; using DevHive.Services.Services; @@ -19,6 +18,7 @@ namespace DevHive.Web.Configurations.Extensions services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); -- 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/Models/IPost.cs') 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 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/Models/IPost.cs') 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