From 728b07eddc5c91e4ef6303f0b62685f10d3c74bc Mon Sep 17 00:00:00 2001 From: Fergal Moran Date: Fri, 11 May 2018 17:43:41 +0100 Subject: [PATCH] Broken but need to create generic repository! --- .../chat-widget/chat-widget.component.css | 2 +- .../chat-widget/chat-widget.component.html | 6 +- server/Controllers/ChatController.cs | 21 +- server/Controllers/DebugController.cs | 10 +- .../20170717195629_Initial.Designer.cs | 2 +- .../20170717210912_SlugInUser.Designer.cs | 2 +- ...170718193205_AddedUserSlugKeys.Designer.cs | 2 +- ...720194622_CreatedDate defaults.Designer.cs | 2 +- ..._UidInPodcastAndRemoveImageUrl.Designer.cs | 2 +- ...171016143832_PodcastUniqueSlug.Designer.cs | 2 +- ...1023212048_RemoveSlugFromEntry.Designer.cs | 2 +- ...20171028164700_PodcastImageUrl.Designer.cs | 2 +- ...0171218202137_UserRefreshToken.Designer.cs | 2 +- ...313232409_Added playlist model.Designer.cs | 2 +- .../20180316223756_UidToUser.Designer.cs | 2 +- .../20180317002411_UidLenIncrease.Designer.cs | 2 +- ...20180421161830_AddedAuthTables.Designer.cs | 2 +- ...180421162833_ChangeContextType.Designer.cs | 2 +- ...20180421215724_RenameUserTable.Designer.cs | 2 +- ...20180422013049_JiggleUserModel.Designer.cs | 2 +- .../20180425154651_SlugUser.Designer.cs | 2 +- ...20180427010607_ImageUrlUpdates.Designer.cs | 2 +- ...507153433_ParsedPlaylistVideos.Designer.cs | 2 +- ...36_Rename_ParsedPlaylistVideos.Designer.cs | 2 +- ...159_AddVideoTypeToPlaylistItem.Designer.cs | 2 +- ...1151301_AddedSeenToChatMessage.Designer.cs | 439 ------------------ .../20180511151301_AddedSeenToChatMessage.cs | 23 - ...=> 20180511161156_AddedChatDb.Designer.cs} | 20 +- ...hatDb.cs => 20180511161156_AddedChatDb.cs} | 23 +- ...ot.cs => PodNomsDbContextModelSnapshot.cs} | 22 +- server/Models/Chat.cs | 6 +- server/Models/Playlist.cs | 1 + server/Persistence/ChatRepository.cs | 47 +- server/Persistence/EntryRepository.cs | 4 +- server/Persistence/IChatRepository.cs | 3 +- server/Persistence/PlaylistRepository.cs | 4 +- server/Persistence/PodcastRepository.cs | 4 +- server/Persistence/PodnomsContext.cs | 4 +- server/Persistence/UnitOfWork.cs | 4 +- server/Providers/MappingProvider.cs | 8 + .../Services/Processor/UrlProcessService.cs | 10 +- server/Services/Realtime/SignalRUpdater.cs | 4 +- server/Services/SupportChatService.cs | 8 +- server/Startup.cs | 18 +- 44 files changed, 154 insertions(+), 579 deletions(-) delete mode 100644 server/Migrations/20180511151301_AddedSeenToChatMessage.Designer.cs delete mode 100644 server/Migrations/20180511151301_AddedSeenToChatMessage.cs rename server/Migrations/{20180509115328_AddedChatDb.Designer.cs => 20180511161156_AddedChatDb.Designer.cs} (96%) rename server/Migrations/{20180509115328_AddedChatDb.cs => 20180511161156_AddedChatDb.cs} (75%) rename server/Migrations/{PodnomsDbContextModelSnapshot.cs => PodNomsDbContextModelSnapshot.cs} (96%) diff --git a/client/src/app/components/chat-widget/chat-widget.component.css b/client/src/app/components/chat-widget/chat-widget.component.css index de7d1a5..c1617c0 100644 --- a/client/src/app/components/chat-widget/chat-widget.component.css +++ b/client/src/app/components/chat-widget/chat-widget.component.css @@ -44,7 +44,7 @@ .floated-chat-w { z-index: 9999; position: fixed; - bottom: 70px; + bottom: 10px; right: 10px; visibility: hidden; opacity: 0; diff --git a/client/src/app/components/chat-widget/chat-widget.component.html b/client/src/app/components/chat-widget/chat-widget.component.html index ac217f0..44ef7ec 100644 --- a/client/src/app/components/chat-widget/chat-widget.component.html +++ b/client/src/app/components/chat-widget/chat-widget.component.html @@ -1,7 +1,7 @@
-
- +
+
@@ -45,7 +45,7 @@
-
+
Talk to us!
diff --git a/server/Controllers/ChatController.cs b/server/Controllers/ChatController.cs index 5abba7b..6daaca1 100644 --- a/server/Controllers/ChatController.cs +++ b/server/Controllers/ChatController.cs @@ -1,4 +1,5 @@ using System.Threading.Tasks; +using AutoMapper; using Lib.Net.Http.WebPush; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; @@ -6,8 +7,10 @@ using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Options; +using PodNoms.Api.Models; using PodNoms.Api.Models.Settings; using PodNoms.Api.Models.ViewModels; +using PodNoms.Api.Persistence; using PodNoms.Api.Services; using PodNoms.Api.Services.Auth; using PodNoms.Api.Services.Hubs; @@ -19,18 +22,34 @@ namespace PodNoms.Api.Controllers { [Authorize] public class ChatController : BaseAuthController { private readonly ISupportChatService _supportChatService; + private readonly IChatRepository _chatRepository; + private readonly IUnitOfWork _unitOfWork; + private readonly IMapper _mapper; public ChatController(IHttpContextAccessor contextAccessor, UserManager userManager, - ISupportChatService supportChatService) : + IMapper mapper, IUnitOfWork unitOfWork, IChatRepository chatRepository, ISupportChatService supportChatService) : base(contextAccessor, userManager) { + this._chatRepository = chatRepository; + this._unitOfWork = unitOfWork; + this._mapper = mapper; this._supportChatService = supportChatService; } + [HttpGet] + public async Task> Get() { + var chats = await _chatRepository.GetAllChats(_userId); + var response = _mapper.Map(chats); + return Ok(response); + } [HttpPost] public async Task> Post([FromBody]ChatViewModel message) { //need to lookup the current support host and notify them message.FromUserName = _applicationUser.FullName; message.FromUserId = _applicationUser.Id; + var chat = _mapper.Map(message); + await _chatRepository.AddOrUpdateChat(chat); + await this._unitOfWork.CompleteAsync(); + if (await _supportChatService.InitiateSupportRequest(_userId, message)) { return Ok(message); } diff --git a/server/Controllers/DebugController.cs b/server/Controllers/DebugController.cs index be1cfa3..4bc4678 100644 --- a/server/Controllers/DebugController.cs +++ b/server/Controllers/DebugController.cs @@ -27,14 +27,14 @@ namespace PodNoms.Api.Controllers { private readonly AudioFileStorageSettings _audioFileStorageSettings; private readonly HelpersSettings _helpersSettings; private readonly ImageFileStorageSettings _imageFileStorageSettings; - private readonly HubLifetimeManager _hubManager; + private readonly HubLifetimeManager _hub; private readonly IPushSubscriptionStore _subscriptionStore; private readonly IPushNotificationService _notificationService; public AppSettings _appSettings { get; } public DebugController(IOptions settings, IOptions appSettings, - HubLifetimeManager hubManager, + HubLifetimeManager hub, IOptions helpersSettings, IOptions audioFileStorageSettings, IOptions imageFileStorageSettings, @@ -47,7 +47,7 @@ namespace PodNoms.Api.Controllers { this._helpersSettings = helpersSettings.Value; this._audioFileStorageSettings = audioFileStorageSettings.Value; this._imageFileStorageSettings = imageFileStorageSettings.Value; - this._hubManager = hubManager; + this._hub = hub; this._subscriptionStore = subscriptionStore; this._notificationService = notificationService; } @@ -71,8 +71,8 @@ namespace PodNoms.Api.Controllers { [Authorize] [HttpPost("realtime")] public async Task Realtime([FromBody] string message) { - await _hubManager.SendUserAsync(User.Identity.Name, "Send", new string[] { $"User {User.Identity.Name}: {message}" }); - await _hubManager.SendAllAsync("Send", new string[] { $"All: {message}" }); + await _hub.SendUserAsync(User.Identity.Name, "Send", new string[] { $"User {User.Identity.Name}: {message}" }); + await _hub.SendAllAsync("Send", new string[] { $"All: {message}" }); return Ok(message); } [Authorize] diff --git a/server/Migrations/20170717195629_Initial.Designer.cs b/server/Migrations/20170717195629_Initial.Designer.cs index 92f935d..2a34567 100644 --- a/server/Migrations/20170717195629_Initial.Designer.cs +++ b/server/Migrations/20170717195629_Initial.Designer.cs @@ -11,7 +11,7 @@ using System; namespace PodNoms.Api.Migrations { - [DbContext(typeof(PodnomsDbContext))] + [DbContext(typeof(PodNomsDbContext))] [Migration("20170717195629_Initial")] partial class Initial { diff --git a/server/Migrations/20170717210912_SlugInUser.Designer.cs b/server/Migrations/20170717210912_SlugInUser.Designer.cs index 519b149..4c51646 100644 --- a/server/Migrations/20170717210912_SlugInUser.Designer.cs +++ b/server/Migrations/20170717210912_SlugInUser.Designer.cs @@ -11,7 +11,7 @@ using System; namespace PodNoms.Api.Migrations { - [DbContext(typeof(PodnomsDbContext))] + [DbContext(typeof(PodNomsDbContext))] [Migration("20170717210912_SlugInUser")] partial class SlugInUser { diff --git a/server/Migrations/20170718193205_AddedUserSlugKeys.Designer.cs b/server/Migrations/20170718193205_AddedUserSlugKeys.Designer.cs index 8d5c721..01b9a9a 100644 --- a/server/Migrations/20170718193205_AddedUserSlugKeys.Designer.cs +++ b/server/Migrations/20170718193205_AddedUserSlugKeys.Designer.cs @@ -11,7 +11,7 @@ using System; namespace PodNoms.Api.Migrations { - [DbContext(typeof(PodnomsDbContext))] + [DbContext(typeof(PodNomsDbContext))] [Migration("20170718193205_AddedUserSlugKeys")] partial class AddedUserSlugKeys { diff --git a/server/Migrations/20170720194622_CreatedDate defaults.Designer.cs b/server/Migrations/20170720194622_CreatedDate defaults.Designer.cs index 53303ef..3a38586 100644 --- a/server/Migrations/20170720194622_CreatedDate defaults.Designer.cs +++ b/server/Migrations/20170720194622_CreatedDate defaults.Designer.cs @@ -11,7 +11,7 @@ using System; namespace PodNoms.Api.Migrations { - [DbContext(typeof(PodnomsDbContext))] + [DbContext(typeof(PodNomsDbContext))] [Migration("20170720194622_CreatedDate defaults")] partial class CreatedDatedefaults { diff --git a/server/Migrations/20170806234745_UidInPodcastAndRemoveImageUrl.Designer.cs b/server/Migrations/20170806234745_UidInPodcastAndRemoveImageUrl.Designer.cs index de6e159..39ccf82 100644 --- a/server/Migrations/20170806234745_UidInPodcastAndRemoveImageUrl.Designer.cs +++ b/server/Migrations/20170806234745_UidInPodcastAndRemoveImageUrl.Designer.cs @@ -11,7 +11,7 @@ using System; namespace PodNoms.Api.Migrations { - [DbContext(typeof(PodnomsDbContext))] + [DbContext(typeof(PodNomsDbContext))] [Migration("20170806234745_UidInPodcastAndRemoveImageUrl")] partial class UidInPodcastAndRemoveImageUrl { diff --git a/server/Migrations/20171016143832_PodcastUniqueSlug.Designer.cs b/server/Migrations/20171016143832_PodcastUniqueSlug.Designer.cs index baad454..cf03c9b 100644 --- a/server/Migrations/20171016143832_PodcastUniqueSlug.Designer.cs +++ b/server/Migrations/20171016143832_PodcastUniqueSlug.Designer.cs @@ -11,7 +11,7 @@ using System; namespace PodNoms.Api.Migrations { - [DbContext(typeof(PodnomsDbContext))] + [DbContext(typeof(PodNomsDbContext))] [Migration("20171016143832_PodcastUniqueSlug")] partial class PodcastUniqueSlug { diff --git a/server/Migrations/20171023212048_RemoveSlugFromEntry.Designer.cs b/server/Migrations/20171023212048_RemoveSlugFromEntry.Designer.cs index ead7417..594ef5e 100644 --- a/server/Migrations/20171023212048_RemoveSlugFromEntry.Designer.cs +++ b/server/Migrations/20171023212048_RemoveSlugFromEntry.Designer.cs @@ -11,7 +11,7 @@ using System; namespace PodNoms.Api.Migrations { - [DbContext(typeof(PodnomsDbContext))] + [DbContext(typeof(PodNomsDbContext))] [Migration("20171023212048_RemoveSlugFromEntry")] partial class RemoveSlugFromEntry { diff --git a/server/Migrations/20171028164700_PodcastImageUrl.Designer.cs b/server/Migrations/20171028164700_PodcastImageUrl.Designer.cs index e8f1542..b629fb8 100644 --- a/server/Migrations/20171028164700_PodcastImageUrl.Designer.cs +++ b/server/Migrations/20171028164700_PodcastImageUrl.Designer.cs @@ -11,7 +11,7 @@ using System; namespace PodNoms.Api.Migrations { - [DbContext(typeof(PodnomsDbContext))] + [DbContext(typeof(PodNomsDbContext))] [Migration("20171028164700_PodcastImageUrl")] partial class PodcastImageUrl { diff --git a/server/Migrations/20171218202137_UserRefreshToken.Designer.cs b/server/Migrations/20171218202137_UserRefreshToken.Designer.cs index f281502..dc46ea0 100644 --- a/server/Migrations/20171218202137_UserRefreshToken.Designer.cs +++ b/server/Migrations/20171218202137_UserRefreshToken.Designer.cs @@ -11,7 +11,7 @@ using System; namespace PodNoms.Api.Migrations { - [DbContext(typeof(PodnomsDbContext))] + [DbContext(typeof(PodNomsDbContext))] [Migration("20171218202137_UserRefreshToken")] partial class UserRefreshToken { diff --git a/server/Migrations/20180313232409_Added playlist model.Designer.cs b/server/Migrations/20180313232409_Added playlist model.Designer.cs index 110cea7..188b45d 100644 --- a/server/Migrations/20180313232409_Added playlist model.Designer.cs +++ b/server/Migrations/20180313232409_Added playlist model.Designer.cs @@ -12,7 +12,7 @@ using PodNoms.Api.Persistence; namespace PodNoms.Api.Migrations { - [DbContext(typeof(PodnomsDbContext))] + [DbContext(typeof(PodNomsDbContext))] [Migration("20180313232409_Added playlist model")] partial class Addedplaylistmodel { diff --git a/server/Migrations/20180316223756_UidToUser.Designer.cs b/server/Migrations/20180316223756_UidToUser.Designer.cs index 239aa8f..a660c05 100644 --- a/server/Migrations/20180316223756_UidToUser.Designer.cs +++ b/server/Migrations/20180316223756_UidToUser.Designer.cs @@ -12,7 +12,7 @@ using PodNoms.Api.Persistence; namespace PodNoms.Api.Migrations { - [DbContext(typeof(PodnomsDbContext))] + [DbContext(typeof(PodNomsDbContext))] [Migration("20180316223756_UidToUser")] partial class UidToUser { diff --git a/server/Migrations/20180317002411_UidLenIncrease.Designer.cs b/server/Migrations/20180317002411_UidLenIncrease.Designer.cs index b298b79..c90b0b2 100644 --- a/server/Migrations/20180317002411_UidLenIncrease.Designer.cs +++ b/server/Migrations/20180317002411_UidLenIncrease.Designer.cs @@ -12,7 +12,7 @@ using PodNoms.Api.Persistence; namespace PodNoms.Api.Migrations { - [DbContext(typeof(PodnomsDbContext))] + [DbContext(typeof(PodNomsDbContext))] [Migration("20180317002411_UidLenIncrease")] partial class UidLenIncrease { diff --git a/server/Migrations/20180421161830_AddedAuthTables.Designer.cs b/server/Migrations/20180421161830_AddedAuthTables.Designer.cs index 8794cc7..8450f21 100644 --- a/server/Migrations/20180421161830_AddedAuthTables.Designer.cs +++ b/server/Migrations/20180421161830_AddedAuthTables.Designer.cs @@ -9,7 +9,7 @@ using PodNoms.Api.Persistence; namespace PodNoms.Api.Migrations { - [DbContext(typeof(PodnomsDbContext))] + [DbContext(typeof(PodNomsDbContext))] [Migration("20180421161830_AddedAuthTables")] partial class AddedAuthTables { diff --git a/server/Migrations/20180421162833_ChangeContextType.Designer.cs b/server/Migrations/20180421162833_ChangeContextType.Designer.cs index e3128ee..8dc4476 100644 --- a/server/Migrations/20180421162833_ChangeContextType.Designer.cs +++ b/server/Migrations/20180421162833_ChangeContextType.Designer.cs @@ -9,7 +9,7 @@ using PodNoms.Api.Persistence; namespace PodNoms.Api.Migrations { - [DbContext(typeof(PodnomsDbContext))] + [DbContext(typeof(PodNomsDbContext))] [Migration("20180421162833_ChangeContextType")] partial class ChangeContextType { diff --git a/server/Migrations/20180421215724_RenameUserTable.Designer.cs b/server/Migrations/20180421215724_RenameUserTable.Designer.cs index f8d2283..7502a07 100644 --- a/server/Migrations/20180421215724_RenameUserTable.Designer.cs +++ b/server/Migrations/20180421215724_RenameUserTable.Designer.cs @@ -9,7 +9,7 @@ using PodNoms.Api.Persistence; namespace PodNoms.Api.Migrations { - [DbContext(typeof(PodnomsDbContext))] + [DbContext(typeof(PodNomsDbContext))] [Migration("20180421215724_RenameUserTable")] partial class RenameUserTable { diff --git a/server/Migrations/20180422013049_JiggleUserModel.Designer.cs b/server/Migrations/20180422013049_JiggleUserModel.Designer.cs index 5ca2cb5..5d788ce 100644 --- a/server/Migrations/20180422013049_JiggleUserModel.Designer.cs +++ b/server/Migrations/20180422013049_JiggleUserModel.Designer.cs @@ -9,7 +9,7 @@ using PodNoms.Api.Persistence; namespace PodNoms.Api.Migrations { - [DbContext(typeof(PodnomsDbContext))] + [DbContext(typeof(PodNomsDbContext))] [Migration("20180422013049_JiggleUserModel")] partial class JiggleUserModel { diff --git a/server/Migrations/20180425154651_SlugUser.Designer.cs b/server/Migrations/20180425154651_SlugUser.Designer.cs index fbda905..44aaee5 100644 --- a/server/Migrations/20180425154651_SlugUser.Designer.cs +++ b/server/Migrations/20180425154651_SlugUser.Designer.cs @@ -9,7 +9,7 @@ using PodNoms.Api.Persistence; namespace PodNoms.Api.Migrations { - [DbContext(typeof(PodnomsDbContext))] + [DbContext(typeof(PodNomsDbContext))] [Migration("20180425154651_SlugUser")] partial class SlugUser { diff --git a/server/Migrations/20180427010607_ImageUrlUpdates.Designer.cs b/server/Migrations/20180427010607_ImageUrlUpdates.Designer.cs index 7e9e4b5..10af229 100644 --- a/server/Migrations/20180427010607_ImageUrlUpdates.Designer.cs +++ b/server/Migrations/20180427010607_ImageUrlUpdates.Designer.cs @@ -9,7 +9,7 @@ using PodNoms.Api.Persistence; namespace PodNoms.Api.Migrations { - [DbContext(typeof(PodnomsDbContext))] + [DbContext(typeof(PodNomsDbContext))] [Migration("20180427010607_ImageUrlUpdates")] partial class ImageUrlUpdates { diff --git a/server/Migrations/20180507153433_ParsedPlaylistVideos.Designer.cs b/server/Migrations/20180507153433_ParsedPlaylistVideos.Designer.cs index f658378..1d044a3 100644 --- a/server/Migrations/20180507153433_ParsedPlaylistVideos.Designer.cs +++ b/server/Migrations/20180507153433_ParsedPlaylistVideos.Designer.cs @@ -9,7 +9,7 @@ using PodNoms.Api.Persistence; namespace PodNoms.Api.Migrations { - [DbContext(typeof(PodnomsDbContext))] + [DbContext(typeof(PodNomsDbContext))] [Migration("20180507153433_ParsedPlaylistVideos")] partial class ParsedPlaylistVideos { diff --git a/server/Migrations/20180507155436_Rename_ParsedPlaylistVideos.Designer.cs b/server/Migrations/20180507155436_Rename_ParsedPlaylistVideos.Designer.cs index 387ba8d..e15657b 100644 --- a/server/Migrations/20180507155436_Rename_ParsedPlaylistVideos.Designer.cs +++ b/server/Migrations/20180507155436_Rename_ParsedPlaylistVideos.Designer.cs @@ -9,7 +9,7 @@ using PodNoms.Api.Persistence; namespace PodNoms.Api.Migrations { - [DbContext(typeof(PodnomsDbContext))] + [DbContext(typeof(PodNomsDbContext))] [Migration("20180507155436_Rename_ParsedPlaylistVideos")] partial class Rename_ParsedPlaylistVideos { diff --git a/server/Migrations/20180507162159_AddVideoTypeToPlaylistItem.Designer.cs b/server/Migrations/20180507162159_AddVideoTypeToPlaylistItem.Designer.cs index 61bfb4e..6498db8 100644 --- a/server/Migrations/20180507162159_AddVideoTypeToPlaylistItem.Designer.cs +++ b/server/Migrations/20180507162159_AddVideoTypeToPlaylistItem.Designer.cs @@ -9,7 +9,7 @@ using PodNoms.Api.Persistence; namespace PodNoms.Api.Migrations { - [DbContext(typeof(PodnomsDbContext))] + [DbContext(typeof(PodNomsDbContext))] [Migration("20180507162159_AddVideoTypeToPlaylistItem")] partial class AddVideoTypeToPlaylistItem { diff --git a/server/Migrations/20180511151301_AddedSeenToChatMessage.Designer.cs b/server/Migrations/20180511151301_AddedSeenToChatMessage.Designer.cs deleted file mode 100644 index 4ed7d0e..0000000 --- a/server/Migrations/20180511151301_AddedSeenToChatMessage.Designer.cs +++ /dev/null @@ -1,439 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using PodNoms.Api.Persistence; - -namespace PodNoms.Api.Migrations -{ - [DbContext(typeof(PodnomsDbContext))] - [Migration("20180511151301_AddedSeenToChatMessage")] - partial class AddedSeenToChatMessage - { - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "2.1.0-rc1-32029") - .HasAnnotation("Relational:MaxIdentifierLength", 128) - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken(); - - b.Property("Name") - .HasMaxLength(256); - - b.Property("NormalizedName") - .HasMaxLength(256); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasName("RoleNameIndex") - .HasFilter("[NormalizedName] IS NOT NULL"); - - b.ToTable("AspNetRoles"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - b.Property("ClaimType"); - - b.Property("ClaimValue"); - - b.Property("RoleId") - .IsRequired(); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - b.Property("ClaimType"); - - b.Property("ClaimValue"); - - b.Property("UserId") - .IsRequired(); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider"); - - b.Property("ProviderKey"); - - b.Property("ProviderDisplayName"); - - b.Property("UserId") - .IsRequired(); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId"); - - b.Property("RoleId"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetUserRoles"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId"); - - b.Property("LoginProvider"); - - b.Property("Name"); - - b.Property("Value"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens"); - }); - - modelBuilder.Entity("PodNoms.Api.Models.ChatMessage", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - b.Property("CreateDate"); - - b.Property("FromUserId"); - - b.Property("FromUserId1"); - - b.Property("Seen"); - - b.Property("ToUserId"); - - b.Property("ToUserId1"); - - b.Property("UpdateDate"); - - b.HasKey("Id"); - - b.HasIndex("FromUserId1"); - - b.HasIndex("ToUserId1"); - - b.ToTable("ChatMessages"); - }); - - modelBuilder.Entity("PodNoms.Api.Models.ParsedPlaylistItem", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - b.Property("CreateDate"); - - b.Property("IsProcessed"); - - b.Property("PlaylistId"); - - b.Property("UpdateDate"); - - b.Property("VideoId"); - - b.Property("VideoType"); - - b.HasKey("Id"); - - b.HasIndex("PlaylistId"); - - b.ToTable("ParsedPlaylistItems"); - }); - - modelBuilder.Entity("PodNoms.Api.Models.Playlist", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - b.Property("CreateDate"); - - b.Property("PodcastId"); - - b.Property("SourceUrl"); - - b.Property("UpdateDate"); - - b.HasKey("Id"); - - b.HasIndex("PodcastId"); - - b.ToTable("Playlists"); - }); - - modelBuilder.Entity("PodNoms.Api.Models.Podcast", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - b.Property("AppUserId"); - - b.Property("CreateDate"); - - b.Property("Description"); - - b.Property("Slug"); - - b.Property("TemporaryImageUrl"); - - b.Property("Title"); - - b.Property("Uid"); - - b.Property("UpdateDate"); - - b.HasKey("Id"); - - b.HasIndex("AppUserId"); - - b.ToTable("Podcasts"); - }); - - modelBuilder.Entity("PodNoms.Api.Models.PodcastEntry", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); - - b.Property("AudioFileSize"); - - b.Property("AudioLength"); - - b.Property("AudioUrl"); - - b.Property("Author"); - - b.Property("CreateDate"); - - b.Property("Description"); - - b.Property("ImageUrl"); - - b.Property("PlaylistId"); - - b.Property("PodcastId"); - - b.Property("Processed"); - - b.Property("ProcessingPayload"); - - b.Property("ProcessingStatus"); - - b.Property("SourceUrl"); - - b.Property("Title"); - - b.Property("Uid"); - - b.Property("UpdateDate"); - - b.HasKey("Id"); - - b.HasIndex("PlaylistId"); - - b.HasIndex("PodcastId"); - - b.ToTable("PodcastEntries"); - }); - - modelBuilder.Entity("PodNoms.Api.Services.Auth.ApplicationUser", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("AccessFailedCount"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken(); - - b.Property("Email") - .HasMaxLength(256); - - b.Property("EmailConfirmed"); - - b.Property("FacebookId"); - - b.Property("FirstName"); - - b.Property("LastName"); - - b.Property("LockoutEnabled"); - - b.Property("LockoutEnd"); - - b.Property("NormalizedEmail") - .HasMaxLength(256); - - b.Property("NormalizedUserName") - .HasMaxLength(256); - - b.Property("PasswordHash"); - - b.Property("PhoneNumber"); - - b.Property("PhoneNumberConfirmed"); - - b.Property("PictureUrl"); - - b.Property("SecurityStamp"); - - b.Property("Slug"); - - b.Property("TwoFactorEnabled"); - - b.Property("UserName") - .HasMaxLength(256); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasName("UserNameIndex") - .HasFilter("[NormalizedUserName] IS NOT NULL"); - - b.ToTable("AspNetUsers"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole") - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("PodNoms.Api.Services.Auth.ApplicationUser") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("PodNoms.Api.Services.Auth.ApplicationUser") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole") - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade); - - b.HasOne("PodNoms.Api.Services.Auth.ApplicationUser") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("PodNoms.Api.Services.Auth.ApplicationUser") - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("PodNoms.Api.Models.ChatMessage", b => - { - b.HasOne("PodNoms.Api.Services.Auth.ApplicationUser", "FromUser") - .WithMany() - .HasForeignKey("FromUserId1"); - - b.HasOne("PodNoms.Api.Services.Auth.ApplicationUser", "ToUser") - .WithMany() - .HasForeignKey("ToUserId1"); - }); - - modelBuilder.Entity("PodNoms.Api.Models.ParsedPlaylistItem", b => - { - b.HasOne("PodNoms.Api.Models.Playlist", "Playlist") - .WithMany("ParsedPlaylistItems") - .HasForeignKey("PlaylistId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("PodNoms.Api.Models.Playlist", b => - { - b.HasOne("PodNoms.Api.Models.Podcast", "Podcast") - .WithMany() - .HasForeignKey("PodcastId") - .OnDelete(DeleteBehavior.Cascade); - }); - - modelBuilder.Entity("PodNoms.Api.Models.Podcast", b => - { - b.HasOne("PodNoms.Api.Services.Auth.ApplicationUser", "AppUser") - .WithMany() - .HasForeignKey("AppUserId"); - }); - - modelBuilder.Entity("PodNoms.Api.Models.PodcastEntry", b => - { - b.HasOne("PodNoms.Api.Models.Playlist") - .WithMany("PodcastEntries") - .HasForeignKey("PlaylistId"); - - b.HasOne("PodNoms.Api.Models.Podcast", "Podcast") - .WithMany("PodcastEntries") - .HasForeignKey("PodcastId") - .OnDelete(DeleteBehavior.Cascade); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/server/Migrations/20180511151301_AddedSeenToChatMessage.cs b/server/Migrations/20180511151301_AddedSeenToChatMessage.cs deleted file mode 100644 index 981ca08..0000000 --- a/server/Migrations/20180511151301_AddedSeenToChatMessage.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -namespace PodNoms.Api.Migrations -{ - public partial class AddedSeenToChatMessage : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "Seen", - table: "ChatMessages", - nullable: true); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "Seen", - table: "ChatMessages"); - } - } -} diff --git a/server/Migrations/20180509115328_AddedChatDb.Designer.cs b/server/Migrations/20180511161156_AddedChatDb.Designer.cs similarity index 96% rename from server/Migrations/20180509115328_AddedChatDb.Designer.cs rename to server/Migrations/20180511161156_AddedChatDb.Designer.cs index 65fde55..179cab5 100644 --- a/server/Migrations/20180509115328_AddedChatDb.Designer.cs +++ b/server/Migrations/20180511161156_AddedChatDb.Designer.cs @@ -9,8 +9,8 @@ using PodNoms.Api.Persistence; namespace PodNoms.Api.Migrations { - [DbContext(typeof(PodnomsDbContext))] - [Migration("20180509115328_AddedChatDb")] + [DbContext(typeof(PodNomsDbContext))] + [Migration("20180511161156_AddedChatDb")] partial class AddedChatDb { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -139,21 +139,19 @@ namespace PodNoms.Api.Migrations b.Property("CreateDate"); - b.Property("FromUserId"); + b.Property("FromUserId"); - b.Property("FromUserId1"); + b.Property("MessageSeen"); - b.Property("ToUserId"); - - b.Property("ToUserId1"); + b.Property("ToUserId"); b.Property("UpdateDate"); b.HasKey("Id"); - b.HasIndex("FromUserId1"); + b.HasIndex("FromUserId"); - b.HasIndex("ToUserId1"); + b.HasIndex("ToUserId"); b.ToTable("ChatMessages"); }); @@ -390,11 +388,11 @@ namespace PodNoms.Api.Migrations { b.HasOne("PodNoms.Api.Services.Auth.ApplicationUser", "FromUser") .WithMany() - .HasForeignKey("FromUserId1"); + .HasForeignKey("FromUserId"); b.HasOne("PodNoms.Api.Services.Auth.ApplicationUser", "ToUser") .WithMany() - .HasForeignKey("ToUserId1"); + .HasForeignKey("ToUserId"); }); modelBuilder.Entity("PodNoms.Api.Models.ParsedPlaylistItem", b => diff --git a/server/Migrations/20180509115328_AddedChatDb.cs b/server/Migrations/20180511161156_AddedChatDb.cs similarity index 75% rename from server/Migrations/20180509115328_AddedChatDb.cs rename to server/Migrations/20180511161156_AddedChatDb.cs index cc73c28..a44a28b 100644 --- a/server/Migrations/20180509115328_AddedChatDb.cs +++ b/server/Migrations/20180511161156_AddedChatDb.cs @@ -16,37 +16,36 @@ namespace PodNoms.Api.Migrations UpdateDate = table.Column(nullable: false), Id = table.Column(nullable: false) .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), - FromUserId = table.Column(nullable: true), - FromUserId1 = table.Column(nullable: true), - ToUserId = table.Column(nullable: true), - ToUserId1 = table.Column(nullable: true) + FromUserId = table.Column(nullable: true), + ToUserId = table.Column(nullable: true), + MessageSeen = table.Column(nullable: true) }, constraints: table => { table.PrimaryKey("PK_ChatMessages", x => x.Id); table.ForeignKey( - name: "FK_ChatMessages_AspNetUsers_FromUserId1", - column: x => x.FromUserId1, + name: "FK_ChatMessages_AspNetUsers_FromUserId", + column: x => x.FromUserId, principalTable: "AspNetUsers", principalColumn: "Id", onDelete: ReferentialAction.Restrict); table.ForeignKey( - name: "FK_ChatMessages_AspNetUsers_ToUserId1", - column: x => x.ToUserId1, + name: "FK_ChatMessages_AspNetUsers_ToUserId", + column: x => x.ToUserId, principalTable: "AspNetUsers", principalColumn: "Id", onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateIndex( - name: "IX_ChatMessages_FromUserId1", + name: "IX_ChatMessages_FromUserId", table: "ChatMessages", - column: "FromUserId1"); + column: "FromUserId"); migrationBuilder.CreateIndex( - name: "IX_ChatMessages_ToUserId1", + name: "IX_ChatMessages_ToUserId", table: "ChatMessages", - column: "ToUserId1"); + column: "ToUserId"); } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/server/Migrations/PodnomsDbContextModelSnapshot.cs b/server/Migrations/PodNomsDbContextModelSnapshot.cs similarity index 96% rename from server/Migrations/PodnomsDbContextModelSnapshot.cs rename to server/Migrations/PodNomsDbContextModelSnapshot.cs index af713b3..b841d69 100644 --- a/server/Migrations/PodnomsDbContextModelSnapshot.cs +++ b/server/Migrations/PodNomsDbContextModelSnapshot.cs @@ -8,8 +8,8 @@ using PodNoms.Api.Persistence; namespace PodNoms.Api.Migrations { - [DbContext(typeof(PodnomsDbContext))] - partial class PodnomsDbContextModelSnapshot : ModelSnapshot + [DbContext(typeof(PodNomsDbContext))] + partial class PodNomsDbContextModelSnapshot : ModelSnapshot { protected override void BuildModel(ModelBuilder modelBuilder) { @@ -137,23 +137,19 @@ namespace PodNoms.Api.Migrations b.Property("CreateDate"); - b.Property("FromUserId"); + b.Property("FromUserId"); - b.Property("FromUserId1"); + b.Property("MessageSeen"); - b.Property("Seen"); - - b.Property("ToUserId"); - - b.Property("ToUserId1"); + b.Property("ToUserId"); b.Property("UpdateDate"); b.HasKey("Id"); - b.HasIndex("FromUserId1"); + b.HasIndex("FromUserId"); - b.HasIndex("ToUserId1"); + b.HasIndex("ToUserId"); b.ToTable("ChatMessages"); }); @@ -390,11 +386,11 @@ namespace PodNoms.Api.Migrations { b.HasOne("PodNoms.Api.Services.Auth.ApplicationUser", "FromUser") .WithMany() - .HasForeignKey("FromUserId1"); + .HasForeignKey("FromUserId"); b.HasOne("PodNoms.Api.Services.Auth.ApplicationUser", "ToUser") .WithMany() - .HasForeignKey("ToUserId1"); + .HasForeignKey("ToUserId"); }); modelBuilder.Entity("PodNoms.Api.Models.ParsedPlaylistItem", b => diff --git a/server/Models/Chat.cs b/server/Models/Chat.cs index cbfee09..363af5a 100644 --- a/server/Models/Chat.cs +++ b/server/Models/Chat.cs @@ -8,10 +8,10 @@ namespace PodNoms.Api.Models { public class ChatMessage : BaseModel { public int Id { get; set; } - public int? FromUserId { get; set; } public ApplicationUser FromUser { get; set; } - public int? ToUserId { get; set; } - public DateTime? Seen { get; set; } public ApplicationUser ToUser { get; set; } + + public DateTime? MessageSeen { get; set; } + } } diff --git a/server/Models/Playlist.cs b/server/Models/Playlist.cs index 0e2eee0..b0da12c 100644 --- a/server/Models/Playlist.cs +++ b/server/Models/Playlist.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; namespace PodNoms.Api.Models { public class Playlist : BaseModel { public int Id { get; set; } + //TODO: Update this to use concrete model public int PodcastId { get; set; } public string SourceUrl { get; set; } public Podcast Podcast { get; set; } diff --git a/server/Persistence/ChatRepository.cs b/server/Persistence/ChatRepository.cs index c1bd966..4ccf2aa 100644 --- a/server/Persistence/ChatRepository.cs +++ b/server/Persistence/ChatRepository.cs @@ -1,13 +1,14 @@ using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using PodNoms.Api.Models; namespace PodNoms.Api.Persistence { public class ChatRepository : IChatRepository { - private readonly PodnomsDbContext _context; + private readonly PodNomsDbContext _context; - public ChatRepository(PodnomsDbContext context) { + public ChatRepository(PodNomsDbContext context) { this._context = context; } public async Task AddOrUpdateChat(ChatMessage chat) { @@ -21,21 +22,43 @@ namespace PodNoms.Api.Persistence { return chat; } - public Task> GetChats(string fromUserId, string toUserId) { - throw new System.NotImplementedException(); + public async Task> GetAllChats(string userId) { + var chats = await _context.ChatMessages + .Where(c => c.FromUser.Id == userId || c.ToUser.Id == userId) + .Include(c => c.FromUser) + .Include(c => c.ToUser) + .ToListAsync(); + + return chats; + } + public async Task> GetChats(string fromUserId, string toUserId) { + var chats = await _context.ChatMessages + .Where(c => c.FromUser.Id == fromUserId && c.ToUser.Id == toUserId) + .Include(c => c.FromUser) + .Include(c => c.ToUser) + .ToListAsync(); + + return chats; } - public Task> GetReceivedChats(string fromUserId) { - throw new System.NotImplementedException(); + public async Task> GetReceivedChats(string toUserId) { + var chats = await _context.ChatMessages + .Where(c => c.ToUser.Id == toUserId) + .Include(c => c.FromUser) + .Include(c => c.ToUser) + .ToListAsync(); + + return chats; } - public Task> GetSentChats(string fromUserId) { - throw new System.NotImplementedException(); - } + public async Task> GetSentChats(string fromUserId) { + var chats = await _context.ChatMessages + .Where(c => c.FromUser.Id == fromUserId) + .Include(c => c.FromUser) + .Include(c => c.ToUser) + .ToListAsync(); - Task> IChatRepository.AddOrUpdateChat(ChatMessage message) { - throw new System.NotImplementedException(); + return chats; } } - } \ No newline at end of file diff --git a/server/Persistence/EntryRepository.cs b/server/Persistence/EntryRepository.cs index 8076b46..202f8d9 100644 --- a/server/Persistence/EntryRepository.cs +++ b/server/Persistence/EntryRepository.cs @@ -7,9 +7,9 @@ using PodNoms.Api.Models; namespace PodNoms.Api.Persistence { public class EntryRepository : IEntryRepository { - private readonly PodnomsDbContext _context; + private readonly PodNomsDbContext _context; - public EntryRepository(PodnomsDbContext context) { + public EntryRepository(PodNomsDbContext context) { this._context = context; } public async Task GetAsync(int id) { diff --git a/server/Persistence/IChatRepository.cs b/server/Persistence/IChatRepository.cs index 8a5f4f9..615b08c 100644 --- a/server/Persistence/IChatRepository.cs +++ b/server/Persistence/IChatRepository.cs @@ -7,7 +7,8 @@ namespace PodNoms.Api.Persistence { Task> GetSentChats(string fromUserId); Task> GetReceivedChats(string fromUserId); Task> GetChats(string fromUserId, string toUserId); - Task> AddOrUpdateChat(ChatMessage message); + Task> GetAllChats(string userId); + Task AddOrUpdateChat(ChatMessage message); } } \ No newline at end of file diff --git a/server/Persistence/PlaylistRepository.cs b/server/Persistence/PlaylistRepository.cs index 1a9a2d7..8b70270 100644 --- a/server/Persistence/PlaylistRepository.cs +++ b/server/Persistence/PlaylistRepository.cs @@ -6,9 +6,9 @@ using PodNoms.Api.Models; namespace PodNoms.Api.Persistence { public class PlaylistRepository : IPlaylistRepository { - private readonly PodnomsDbContext _context; + private readonly PodNomsDbContext _context; - public PlaylistRepository(PodnomsDbContext context) { + public PlaylistRepository(PodNomsDbContext context) { this._context = context; } public async Task GetAsync(int id) { diff --git a/server/Persistence/PodcastRepository.cs b/server/Persistence/PodcastRepository.cs index 79d1069..a491051 100644 --- a/server/Persistence/PodcastRepository.cs +++ b/server/Persistence/PodcastRepository.cs @@ -13,10 +13,10 @@ using PodNoms.Api.Utils.Extensions; namespace PodNoms.Api.Persistence { public class PodcastRepository : IPodcastRepository { - private readonly PodnomsDbContext _context; + private readonly PodNomsDbContext _context; public IFileUploader _fileUploader { get; } public ImageFileStorageSettings _imageStorageSettings { get; } - public PodcastRepository(PodnomsDbContext context, IFileUploader fileUploader, IOptions imageStorageSettings) { + public PodcastRepository(PodNomsDbContext context, IFileUploader fileUploader, IOptions imageStorageSettings) { this._imageStorageSettings = imageStorageSettings.Value; this._fileUploader = fileUploader; this._context = context; diff --git a/server/Persistence/PodnomsContext.cs b/server/Persistence/PodnomsContext.cs index 7b0c099..e5562fd 100644 --- a/server/Persistence/PodnomsContext.cs +++ b/server/Persistence/PodnomsContext.cs @@ -13,8 +13,8 @@ using PodNoms.Api.Services.Auth; namespace PodNoms.Api.Persistence { - public class PodnomsDbContext : IdentityDbContext { - public PodnomsDbContext(DbContextOptions options) : base(options) { } + public class PodNomsDbContext : IdentityDbContext { + public PodNomsDbContext(DbContextOptions options) : base(options) { } protected override void OnModelCreating(ModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); diff --git a/server/Persistence/UnitOfWork.cs b/server/Persistence/UnitOfWork.cs index 7551649..5ee5e07 100644 --- a/server/Persistence/UnitOfWork.cs +++ b/server/Persistence/UnitOfWork.cs @@ -5,9 +5,9 @@ using PodNoms.Api.Persistence; namespace PodNoms.Api.Persistence { public class UnitOfWork : IUnitOfWork { - private readonly PodnomsDbContext _context; + private readonly PodNomsDbContext _context; private readonly ILogger _logger; - public UnitOfWork(PodnomsDbContext context, ILogger logger) { + public UnitOfWork(PodNomsDbContext context, ILogger logger) { this._logger = logger; this._context = context; } diff --git a/server/Providers/MappingProvider.cs b/server/Providers/MappingProvider.cs index e1ac2fa..d1d492d 100644 --- a/server/Providers/MappingProvider.cs +++ b/server/Providers/MappingProvider.cs @@ -41,6 +41,8 @@ namespace PodNoms.Api.Providers { src => src.ProfileImage, map => map.MapFrom(s => s.PictureUrl)); + CreateMap(); + //API Resource to Domain CreateMap(); CreateMap() @@ -52,6 +54,12 @@ namespace PodNoms.Api.Providers { .ForMember( e => e.UserName, map => map.MapFrom(vm => vm.Email)); + + CreateMap() + .ForMember( + e => e.FromUser, + map => map.MapFrom(vm => e; + } } } \ No newline at end of file diff --git a/server/Services/Processor/UrlProcessService.cs b/server/Services/Processor/UrlProcessService.cs index defcada..11161b6 100644 --- a/server/Services/Processor/UrlProcessService.cs +++ b/server/Services/Processor/UrlProcessService.cs @@ -25,16 +25,16 @@ namespace PodNoms.Api.Services.Processor { private readonly IEntryRepository _repository; public HelpersSettings _helpersSettings { get; } - private readonly HubLifetimeManager _userUpdateHub; + private readonly HubLifetimeManager _hub; public UrlProcessService(IEntryRepository repository, IUnitOfWork unitOfWork, IFileUploader fileUploader, IOptions helpersSettings, - HubLifetimeManager userUpdateHub, + HubLifetimeManager hub, ILoggerFactory logger, IMapper mapper, IRealTimeUpdater realtimeUpdater) : base(logger, mapper, realtimeUpdater) { this._helpersSettings = helpersSettings.Value; this._repository = repository; this._unitOfWork = unitOfWork; - this._userUpdateHub = userUpdateHub; + this._hub = hub; } private async Task __downloader_progress(string userId, string uid, ProcessProgressEvent e) { @@ -98,7 +98,7 @@ namespace PodNoms.Api.Services.Processor { await _sendProcessCompleteMessage(entry); await _unitOfWork.CompleteAsync(); - await _userUpdateHub.SendAllAsync( + await _hub.SendAllAsync( entry.Podcast.AppUser.Id, new object[] { $"{entry.Title} has succesfully been processed" }); @@ -109,7 +109,7 @@ namespace PodNoms.Api.Services.Processor { entry.ProcessingPayload = ex.Message; await _unitOfWork.CompleteAsync(); await _sendProcessCompleteMessage(entry); - await _userUpdateHub.SendAllAsync( + await _hub.SendAllAsync( entry.Podcast.AppUser.Id, new object[] { $"Error processing {entry.Title}" }); } diff --git a/server/Services/Realtime/SignalRUpdater.cs b/server/Services/Realtime/SignalRUpdater.cs index 52a0096..72f4227 100644 --- a/server/Services/Realtime/SignalRUpdater.cs +++ b/server/Services/Realtime/SignalRUpdater.cs @@ -7,8 +7,8 @@ using PodNoms.Api.Services.Hubs; namespace PodNoms.Api.Services.Realtime { public class SignalRUpdater : IRealTimeUpdater { private readonly HubLifetimeManager _hub; - public SignalRUpdater(HubLifetimeManager audioProcessingHubContext) { - this._hub = audioProcessingHubContext; + public SignalRUpdater(HubLifetimeManager hub) { + this._hub = hub; } public async Task SendProcessUpdate(string userId, string channelName, string eventName, object data) { diff --git a/server/Services/SupportChatService.cs b/server/Services/SupportChatService.cs index 1e2d6fb..48ad66f 100644 --- a/server/Services/SupportChatService.cs +++ b/server/Services/SupportChatService.cs @@ -16,16 +16,16 @@ namespace PodNoms.Api.Services { public class SupportChatService : ISupportChatService { private readonly ChatSettings _chatSettings; private readonly IPushNotificationService _notificationService; - private readonly HubLifetimeManager _chatHub; + private readonly HubLifetimeManager _hub; private readonly UserManager _userManager; private readonly IPushSubscriptionStore _subscriptionStore; private readonly SlackSupportClient _slackSupport; public SupportChatService(UserManager userManager, IOptions chatSettings, IPushSubscriptionStore subscriptionStore, IPushNotificationService notificationService, - HubLifetimeManager chatHub, SlackSupportClient slackSupport) { + HubLifetimeManager hub, SlackSupportClient slackSupport) { this._chatSettings = chatSettings.Value; this._notificationService = notificationService; - this._chatHub = chatHub; + this._hub = hub; this._userManager = userManager; this._subscriptionStore = subscriptionStore; this._slackSupport = slackSupport; @@ -47,7 +47,7 @@ namespace PodNoms.Api.Services { }); //send SignalR message to notify in chat.component - await _chatHub.SendUserAsync(user.Email, "SendMessage", new object[] { message }); + await _hub.SendUserAsync(user.Email, "SendMessage", new object[] { message }); //send slack message var slackResult = await _slackSupport.NotifyUser(message); diff --git a/server/Startup.cs b/server/Startup.cs index 171e288..78e5011 100644 --- a/server/Startup.cs +++ b/server/Startup.cs @@ -93,7 +93,7 @@ namespace PodNoms.Api { public void ConfigureServices(IServiceCollection services) { Console.WriteLine($"Configuring services: {Configuration.ToString()}"); - services.AddDbContext(options => + services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"))); services.AddOptions(); @@ -178,7 +178,7 @@ namespace PodNoms.Api { o.Password.RequireNonAlphanumeric = false; }); identityBuilder = new IdentityBuilder(identityBuilder.UserType, typeof(IdentityRole), identityBuilder.Services); - identityBuilder.AddEntityFrameworkStores().AddDefaultTokenProviders(); + identityBuilder.AddEntityFrameworkStores().AddDefaultTokenProviders(); identityBuilder.AddUserManager(); services.AddMvc(options => { @@ -191,12 +191,12 @@ namespace PodNoms.Api { .AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Serialize; - }) + }) .AddXmlSerializerFormatters() .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining()); services.AddSwaggerGen(c => { - c.SwaggerDoc("v1", new Info { Title = "Podnoms.API", Version = "v1" }); + c.SwaggerDoc("v1", new Info { Title = "PodNoms.API", Version = "v1" }); c.DocumentFilter(); }); @@ -238,6 +238,7 @@ namespace PodNoms.Api { services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); @@ -263,15 +264,6 @@ namespace PodNoms.Api { app.UseExceptionHandler("/Home/Error"); } - Console.WriteLine("Performing migrations"); - //TODO: Fix this when EF sucks less - // using (var context = new PodnomsDbContext( - // app.ApplicationServices.GetRequiredService>())) - // { - // context.Database.Migrate(); - // } - Console.WriteLine("Successfully migrated"); - // app.UseHsts(); // app.UseHttpsRedirection(); app.UseStaticFiles();