From 736f285a6684298af591c9d7aca40699b14b64d5 Mon Sep 17 00:00:00 2001 From: Alexander Romanchuk Date: Tue, 26 Sep 2023 22:32:39 +0300 Subject: [PATCH 1/4] Chat messages, chat rooms --- .../Models/ChatWorkshop/ChatMessageWorkshop.cs | 9 +++++---- .../Models/ChatWorkshop/ChatRoomWorkshop.cs | 4 +++- .../Configurations/ChatMessageWorkshopConfiguration.cs | 4 ++++ .../Configurations/ChatRoomWorkshopConfiguration.cs | 4 ++++ .../OutOfSchoolDbContext.SoftDelete.cs | 2 -- .../ChatRoomWorkshopModelForChatListRepository.cs | 5 +++-- .../Services/ChatMessageWorkshopServiceTests.cs | 4 ++-- .../Services/ChatRoomWorkshopServiceTests.cs | 8 ++++---- .../Services/Database/WorkshopServiceTests.cs | 4 ++-- .../Services/ChatMessageWorkshopService.cs | 10 +++++----- .../Services/ChatRoomWorkshopService.cs | 4 ++-- .../Services/Database/WorkshopService.cs | 4 ++-- 12 files changed, 36 insertions(+), 26 deletions(-) diff --git a/OutOfSchool/OutOfSchool.DataAccess/Models/ChatWorkshop/ChatMessageWorkshop.cs b/OutOfSchool/OutOfSchool.DataAccess/Models/ChatWorkshop/ChatMessageWorkshop.cs index ab041d9f1e..e48beb2862 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Models/ChatWorkshop/ChatMessageWorkshop.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Models/ChatWorkshop/ChatMessageWorkshop.cs @@ -1,14 +1,15 @@ -using OutOfSchool.Common; -using System; +using System; using System.ComponentModel.DataAnnotations; -using System.Reflection.Metadata; +using OutOfSchool.Common; namespace OutOfSchool.Services.Models.ChatWorkshop; -public class ChatMessageWorkshop : IKeyedEntity +public class ChatMessageWorkshop : IKeyedEntity, ISoftDeleted { public Guid Id { get; set; } + public bool IsDeleted { get; set; } + [Required] public Guid ChatRoomId { get; set; } diff --git a/OutOfSchool/OutOfSchool.DataAccess/Models/ChatWorkshop/ChatRoomWorkshop.cs b/OutOfSchool/OutOfSchool.DataAccess/Models/ChatWorkshop/ChatRoomWorkshop.cs index 0172897dfe..409e2a3d8a 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Models/ChatWorkshop/ChatRoomWorkshop.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Models/ChatWorkshop/ChatRoomWorkshop.cs @@ -4,10 +4,12 @@ namespace OutOfSchool.Services.Models.ChatWorkshop; -public class ChatRoomWorkshop : IKeyedEntity +public class ChatRoomWorkshop : IKeyedEntity, ISoftDeleted { public Guid Id { get; set; } + public bool IsDeleted { get; set; } + [Required] public Guid WorkshopId { get; set; } diff --git a/OutOfSchool/OutOfSchool.DataAccess/Models/Configurations/ChatMessageWorkshopConfiguration.cs b/OutOfSchool/OutOfSchool.DataAccess/Models/Configurations/ChatMessageWorkshopConfiguration.cs index c3e6096ef6..2d5ba17fcd 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Models/Configurations/ChatMessageWorkshopConfiguration.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Models/Configurations/ChatMessageWorkshopConfiguration.cs @@ -11,6 +11,10 @@ public void Configure(EntityTypeBuilder builder) { builder.HasKey(x => x.Id); + builder.HasIndex(x => x.IsDeleted); + + builder.Property(x => x.IsDeleted).HasDefaultValue(false); + builder .HasOne(m => m.ChatRoom) .WithMany(r => r.ChatMessages) diff --git a/OutOfSchool/OutOfSchool.DataAccess/Models/Configurations/ChatRoomWorkshopConfiguration.cs b/OutOfSchool/OutOfSchool.DataAccess/Models/Configurations/ChatRoomWorkshopConfiguration.cs index befbdda1a6..7837332980 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Models/Configurations/ChatRoomWorkshopConfiguration.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Models/Configurations/ChatRoomWorkshopConfiguration.cs @@ -11,6 +11,10 @@ public void Configure(EntityTypeBuilder builder) { builder.HasKey(x => x.Id); + builder.HasIndex(x => x.IsDeleted); + + builder.Property(x => x.IsDeleted).HasDefaultValue(false); + builder .HasOne(r => r.Parent) .WithMany(p => p.ChatRooms) diff --git a/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.SoftDelete.cs b/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.SoftDelete.cs index cb0b6462bb..5625c313d8 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.SoftDelete.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.SoftDelete.cs @@ -47,8 +47,6 @@ private void ApplySoftDelete(ModelBuilder builder) .ApplySoftDelete
() .ApplySoftDelete() .ApplySoftDelete() - .ApplySoftDelete() - .ApplySoftDelete() .ApplySoftDelete() .ApplySoftDelete() .ApplySoftDelete() diff --git a/OutOfSchool/OutOfSchool.DataAccess/Repository/ChatRoomWorkshopModelForChatListRepository.cs b/OutOfSchool/OutOfSchool.DataAccess/Repository/ChatRoomWorkshopModelForChatListRepository.cs index 37b761857c..d48aa4b291 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Repository/ChatRoomWorkshopModelForChatListRepository.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Repository/ChatRoomWorkshopModelForChatListRepository.cs @@ -79,6 +79,7 @@ private Task> GetByParametersAsync(Expression< { var query = dbSet .Where(condition) + .Where(x => !x.IsDeleted) .Select(item => new ChatRoomWorkshopForChatList() { Id = item.Id, @@ -102,7 +103,7 @@ private Task> GetByParametersAsync(Expression< Email = item.Parent.User.Email, PhoneNumber = item.Parent.User.PhoneNumber, }, - LastMessage = item.ChatMessages.Where(mess => mess.CreatedDateTime == item.ChatMessages.Max(m => m.CreatedDateTime)) + LastMessage = item.ChatMessages.Where(mess => !mess.IsDeleted && mess.CreatedDateTime == item.ChatMessages.Where(m => !m.IsDeleted).Max(m => m.CreatedDateTime)) .Select(message => new ChatMessageInfoForChatList() { Id = message.Id, @@ -113,7 +114,7 @@ private Task> GetByParametersAsync(Expression< ReadDateTime = message.ReadDateTime, }) .FirstOrDefault(), - NotReadByCurrentUserMessagesCount = item.ChatMessages.Count(mess => mess.ReadDateTime == null && (mess.SenderRoleIsProvider != searchMessagesForProvider)), + NotReadByCurrentUserMessagesCount = item.ChatMessages.Count(mess => !mess.IsDeleted && mess.ReadDateTime == null && (mess.SenderRoleIsProvider != searchMessagesForProvider)), }) .OrderByDescending(x => x.LastMessage.CreatedDateTime); return query.ToListAsync(); diff --git a/OutOfSchool/OutOfSchool.WebApi.Tests/Services/ChatMessageWorkshopServiceTests.cs b/OutOfSchool/OutOfSchool.WebApi.Tests/Services/ChatMessageWorkshopServiceTests.cs index 27d003bf23..129d89caef 100644 --- a/OutOfSchool/OutOfSchool.WebApi.Tests/Services/ChatMessageWorkshopServiceTests.cs +++ b/OutOfSchool/OutOfSchool.WebApi.Tests/Services/ChatMessageWorkshopServiceTests.cs @@ -35,7 +35,7 @@ public class ChatMessageWorkshopServiceTests WorkshopId = Guid.NewGuid(), }; - private IEntityRepository messageRepository; + private IEntityRepositorySoftDeleted messageRepository; private Mock roomServiceMock; private Mock> workshopHub; private Mock> loggerMock; @@ -60,7 +60,7 @@ public void SetUp() options = builder.Options; dbContext = new OutOfSchoolDbContext(options); - messageRepository = new EntityRepository(dbContext); + messageRepository = new EntityRepositorySoftDeleted(dbContext); roomServiceMock = new Mock(); workshopHub = new Mock>(); loggerMock = new Mock>(); diff --git a/OutOfSchool/OutOfSchool.WebApi.Tests/Services/ChatRoomWorkshopServiceTests.cs b/OutOfSchool/OutOfSchool.WebApi.Tests/Services/ChatRoomWorkshopServiceTests.cs index 52b3ef4955..6dbb9254a5 100644 --- a/OutOfSchool/OutOfSchool.WebApi.Tests/Services/ChatRoomWorkshopServiceTests.cs +++ b/OutOfSchool/OutOfSchool.WebApi.Tests/Services/ChatRoomWorkshopServiceTests.cs @@ -34,7 +34,7 @@ public class ChatRoomWorkshopServiceTests private static ChatRoomWorkshop[] rooms; - private IEntityRepository roomRepository; + private IEntityRepositorySoftDeleted roomRepository; private Mock roomWithSpecialModelRepositoryMock; private Mock> loggerMock; private IMapper mapper; @@ -84,7 +84,7 @@ public void SetUp() options = builder.Options; dbContext = new OutOfSchoolDbContext(options); - roomRepository = new EntityRepository(dbContext); + roomRepository = new EntityRepositorySoftDeleted(dbContext); roomWithSpecialModelRepositoryMock = new Mock(); loggerMock = new Mock>(); mapper = TestHelper.CreateMapperInstanceOfProfileType(); @@ -142,13 +142,13 @@ public async Task Delete_WhenRoomExist_ShouldDeleteEntities() { // Arrange var existingId = rooms[0].Id; - var roomCount = dbContext.ChatRoomWorkshops.Count(); + var roomCount = dbContext.ChatRoomWorkshops.Count(x => !x.IsDeleted); // Act await roomService.DeleteAsync(existingId).ConfigureAwait(false); // Assert - Assert.AreEqual(roomCount - 1, dbContext.ChatRoomWorkshops.Count()); + Assert.AreEqual(roomCount - 1, dbContext.ChatRoomWorkshops.Count(x => !x.IsDeleted)); } [Test] diff --git a/OutOfSchool/OutOfSchool.WebApi.Tests/Services/Database/WorkshopServiceTests.cs b/OutOfSchool/OutOfSchool.WebApi.Tests/Services/Database/WorkshopServiceTests.cs index e929c4d319..00d0493e02 100644 --- a/OutOfSchool/OutOfSchool.WebApi.Tests/Services/Database/WorkshopServiceTests.cs +++ b/OutOfSchool/OutOfSchool.WebApi.Tests/Services/Database/WorkshopServiceTests.cs @@ -32,7 +32,7 @@ public class WorkshopServiceTests private IWorkshopService workshopService; private Mock workshopRepository; private Mock> dateTimeRangeRepository; - private Mock> roomRepository; + private Mock> roomRepository; private Mock teacherService; private Mock> logger; private Mock mapperMock; @@ -47,7 +47,7 @@ public void SetUp() { workshopRepository = new Mock(); dateTimeRangeRepository = new Mock>(); - roomRepository = new Mock>(); + roomRepository = new Mock>(); teacherService = new Mock(); logger = new Mock>(); mapperMock = new Mock(); diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/ChatMessageWorkshopService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/ChatMessageWorkshopService.cs index f2698c8d3b..688ed8365a 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/ChatMessageWorkshopService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/ChatMessageWorkshopService.cs @@ -13,7 +13,7 @@ namespace OutOfSchool.WebApi.Services; /// public class ChatMessageWorkshopService : IChatMessageWorkshopService { - private readonly IEntityRepository messageRepository; + private readonly IEntityRepositorySoftDeleted messageRepository; private readonly IChatRoomWorkshopService roomService; private readonly IHubContext workshopHub; private readonly ILogger logger; @@ -28,7 +28,7 @@ public class ChatMessageWorkshopService : IChatMessageWorkshopService /// Logger. /// Mapper. public ChatMessageWorkshopService( - IEntityRepository chatMessageRepository, + IEntityRepositorySoftDeleted chatMessageRepository, IChatRoomWorkshopService roomRepository, IHubContext workshopHub, ILogger logger, @@ -136,9 +136,9 @@ private async Task> GetMessagesForChatRoomDomainModelA try { var sortExpression = new Dictionary>, SortDirection> - { - { x => x.CreatedDateTime, SortDirection.Descending }, - }; + { + { x => x.CreatedDateTime, SortDirection.Descending }, + }; var query = messageRepository.Get( skip: offsetFilter.From, diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/ChatRoomWorkshopService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/ChatRoomWorkshopService.cs index 99c338fcc8..589ca0eba8 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/ChatRoomWorkshopService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/ChatRoomWorkshopService.cs @@ -13,7 +13,7 @@ namespace OutOfSchool.WebApi.Services; /// public class ChatRoomWorkshopService : IChatRoomWorkshopService { - private readonly IEntityRepository roomRepository; + private readonly IEntityRepositorySoftDeleted roomRepository; private readonly IChatRoomWorkshopModelForChatListRepository roomWorkshopWithLastMessageRepository; private readonly ILogger logger; private readonly IMapper mapper; @@ -25,7 +25,7 @@ public class ChatRoomWorkshopService : IChatRoomWorkshopService /// Logger. /// Mapper. public ChatRoomWorkshopService( - IEntityRepository chatRoomRepository, + IEntityRepositorySoftDeleted chatRoomRepository, ILogger logger, IChatRoomWorkshopModelForChatListRepository roomWorkshopWithLastMessageRepository, IMapper mapper) diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/Database/WorkshopService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/Database/WorkshopService.cs index 86716b40d9..6949008c53 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/Database/WorkshopService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/Database/WorkshopService.cs @@ -26,7 +26,7 @@ public class WorkshopService : IWorkshopService private readonly IWorkshopRepository workshopRepository; private readonly IEntityRepository dateTimeRangeRepository; - private readonly IEntityRepository roomRepository; + private readonly IEntityRepositorySoftDeleted roomRepository; private readonly ITeacherService teacherService; private readonly ILogger logger; private readonly IMapper mapper; @@ -51,7 +51,7 @@ public class WorkshopService : IWorkshopService public WorkshopService( IWorkshopRepository workshopRepository, IEntityRepository dateTimeRangeRepository, - IEntityRepository roomRepository, + IEntityRepositorySoftDeleted roomRepository, ITeacherService teacherService, ILogger logger, IMapper mapper, From 7d63e1ba79d24dea5864bebece0f5ad33f531b2e Mon Sep 17 00:00:00 2001 From: Alexander Romanchuk Date: Tue, 26 Sep 2023 23:48:53 +0300 Subject: [PATCH 2/4] Social groups --- .../SocialGroupConfiguration.cs | 14 ++++++++++ .../Models/SocialGroup.cs | 4 ++- .../OutOfSchoolDbContext.SoftDelete.cs | 1 - .../OutOfSchoolDbContext.cs | 1 + .../EntityRepositoryTest.cs | 8 +++--- .../Services/SocialGroupServiceTests.cs | 4 +-- .../Controllers/V1/SocialGroupController.cs | 12 ++------- .../Models/SocialGroup/SocialGroupDTO.cs | 3 +-- .../Services/ChildService.cs | 4 +-- .../Services/SocialGroupService.cs | 26 ++++++++----------- .../OutOfSchool.WebApi/Util/MappingProfile.cs | 3 ++- 11 files changed, 42 insertions(+), 38 deletions(-) create mode 100644 OutOfSchool/OutOfSchool.DataAccess/Models/Configurations/SocialGroupConfiguration.cs diff --git a/OutOfSchool/OutOfSchool.DataAccess/Models/Configurations/SocialGroupConfiguration.cs b/OutOfSchool/OutOfSchool.DataAccess/Models/Configurations/SocialGroupConfiguration.cs new file mode 100644 index 0000000000..632b3363e6 --- /dev/null +++ b/OutOfSchool/OutOfSchool.DataAccess/Models/Configurations/SocialGroupConfiguration.cs @@ -0,0 +1,14 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace OutOfSchool.Services.Models.Configurations; + +internal class SocialGroupConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.HasIndex(x => x.IsDeleted); + + builder.Property(x => x.IsDeleted).HasDefaultValue(false); + } +} diff --git a/OutOfSchool/OutOfSchool.DataAccess/Models/SocialGroup.cs b/OutOfSchool/OutOfSchool.DataAccess/Models/SocialGroup.cs index f28792679d..56d763eebb 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Models/SocialGroup.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Models/SocialGroup.cs @@ -4,10 +4,12 @@ namespace OutOfSchool.Services.Models; -public class SocialGroup : IKeyedEntity +public class SocialGroup : IKeyedEntity, ISoftDeleted { public long Id { get; set; } + public bool IsDeleted { get; set; } + [Required] [DataType(DataType.Text)] [MaxLength(100)] diff --git a/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.SoftDelete.cs b/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.SoftDelete.cs index 5625c313d8..46bd066b54 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.SoftDelete.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.SoftDelete.cs @@ -57,7 +57,6 @@ private void ApplySoftDelete(ModelBuilder builder) .ApplySoftDelete() .ApplySoftDelete() .ApplySoftDelete() - .ApplySoftDelete() .ApplySoftDelete() .ApplySoftDelete(); } diff --git a/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.cs b/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.cs index be5482c8a5..1a196a58e9 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.cs @@ -146,6 +146,7 @@ protected override void OnModelCreating(ModelBuilder builder) builder.ApplyConfiguration(new ProviderAdminConfiguration()); builder.ApplyConfiguration(new QuartzJobConfiguration()); builder.ApplyConfiguration(new RatingConfiguration()); + builder.ApplyConfiguration(new SocialGroupConfiguration()); builder.ApplyConfiguration(new TeacherConfiguration()); builder.ApplyConfiguration(new WorkshopConfiguration()); diff --git a/OutOfSchool/OutOfSchool.WebApi.Tests/EntityRepositoryTest.cs b/OutOfSchool/OutOfSchool.WebApi.Tests/EntityRepositoryTest.cs index ddc899cb30..7068c20bb3 100644 --- a/OutOfSchool/OutOfSchool.WebApi.Tests/EntityRepositoryTest.cs +++ b/OutOfSchool/OutOfSchool.WebApi.Tests/EntityRepositoryTest.cs @@ -20,7 +20,7 @@ public void GetById_Id_ReturnEntity() { using var context = new OutOfSchoolDbContext(UnitTestHelper.GetUnitTestDbOptions()); { - var repository = new EntityRepository(context); + var repository = new EntityRepositorySoftDeleted(context); // Act var group = repository.GetById(1).Result; @@ -103,7 +103,7 @@ public async Task Delete_DeleteEntity_DeleteFromDatabaseAsync() { using var context = new OutOfSchoolDbContext(UnitTestHelper.GetUnitTestDbOptions()); { - var repository = new EntityRepository(context); + var repository = new EntityRepositorySoftDeleted(context); SocialGroup socialGroup = new SocialGroup { Id = 1, Name = "sg1" }; // Act @@ -120,7 +120,7 @@ public void GetAll_ReturnAllValues() { using var context = new OutOfSchoolDbContext(UnitTestHelper.GetUnitTestDbOptions()); { - var repository = new EntityRepository(context); + var repository = new EntityRepositorySoftDeleted(context); // Act var socialGroups = repository.GetAll(); @@ -135,7 +135,7 @@ public void Update_UpatedInfo_UpdateEntityInDatabase() { using var context = new OutOfSchoolDbContext(UnitTestHelper.GetUnitTestDbOptions()); { - var repository = new EntityRepository(context); + var repository = new EntityRepositorySoftDeleted(context); // Act SocialGroup socialGroup = new SocialGroup { Id = 2, Name = "sg22" }; diff --git a/OutOfSchool/OutOfSchool.WebApi.Tests/Services/SocialGroupServiceTests.cs b/OutOfSchool/OutOfSchool.WebApi.Tests/Services/SocialGroupServiceTests.cs index c6f5b9073b..3dc61edf4a 100644 --- a/OutOfSchool/OutOfSchool.WebApi.Tests/Services/SocialGroupServiceTests.cs +++ b/OutOfSchool/OutOfSchool.WebApi.Tests/Services/SocialGroupServiceTests.cs @@ -24,7 +24,7 @@ public class SocialGroupServiceTests { private ISocialGroupService service; private OutOfSchoolDbContext context; - private IEntityRepository repository; + private IEntityRepositorySoftDeleted repository; private Mock> localizer; private Mock> logger; private DbContextOptions options; @@ -40,7 +40,7 @@ public void SetUp() options = builder.Options; context = new OutOfSchoolDbContext(options); localizer = new Mock>(); - repository = new EntityRepository(context); + repository = new EntityRepositorySoftDeleted(context); logger = new Mock>(); mapper = TestHelper.CreateMapperInstanceOfProfileType(); service = new SocialGroupService(repository, logger.Object, localizer.Object, mapper); diff --git a/OutOfSchool/OutOfSchool.WebApi/Controllers/V1/SocialGroupController.cs b/OutOfSchool/OutOfSchool.WebApi/Controllers/V1/SocialGroupController.cs index bcfc51d39e..be6585a257 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Controllers/V1/SocialGroupController.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Controllers/V1/SocialGroupController.cs @@ -1,15 +1,7 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Localization; -using OutOfSchool.Common.PermissionsModule; using OutOfSchool.WebApi.Enums; -using OutOfSchool.WebApi.Extensions; using OutOfSchool.WebApi.Models.SocialGroup; -using OutOfSchool.WebApi.Services; namespace OutOfSchool.WebApi.Controllers.V1; @@ -58,8 +50,8 @@ public async Task Get(LocalizationType localization = Localizatio /// /// Get Social Group by it's id. /// - /// Localization: Ua - 0, En - 1. /// Social Group id. + /// Localization: Ua - 0, En - 1. /// Social Group. [HasPermission(Permissions.ImpersonalDataRead)] [ProducesResponseType(StatusCodes.Status200OK, Type = typeof(SocialGroupDto))] diff --git a/OutOfSchool/OutOfSchool.WebApi/Models/SocialGroup/SocialGroupDTO.cs b/OutOfSchool/OutOfSchool.WebApi/Models/SocialGroup/SocialGroupDTO.cs index fb4657517f..d0624fc441 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Models/SocialGroup/SocialGroupDTO.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Models/SocialGroup/SocialGroupDTO.cs @@ -1,5 +1,4 @@ -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; namespace OutOfSchool.WebApi.Models.SocialGroup; diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/ChildService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/ChildService.cs index c86d8077d3..0b35d2b550 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/ChildService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/ChildService.cs @@ -28,7 +28,7 @@ public class ChildService : IChildService private readonly IEntityRepository childRepository; private readonly IParentRepository parentRepository; private readonly IApplicationRepository applicationRepository; - private readonly IEntityRepository socialGroupRepository; + private readonly IEntityRepositorySoftDeleted socialGroupRepository; private readonly ILogger logger; private readonly IMapper mapper; private readonly IOptions parentConfig; @@ -45,7 +45,7 @@ public class ChildService : IChildService public ChildService( IEntityRepository childRepository, IParentRepository parentRepository, - IEntityRepository socialGroupRepository, + IEntityRepositorySoftDeleted socialGroupRepository, ILogger logger, IMapper mapper, IApplicationRepository applicationRepository, diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/SocialGroupService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/SocialGroupService.cs index 50ca23aab8..74281be4ec 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/SocialGroupService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/SocialGroupService.cs @@ -1,15 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using AutoMapper; -using Microsoft.EntityFrameworkCore; +using AutoMapper; using Microsoft.Extensions.Localization; -using Microsoft.Extensions.Logging; -using OutOfSchool.Services.Models; -using OutOfSchool.Services.Repository; using OutOfSchool.WebApi.Enums; -using OutOfSchool.WebApi.Extensions; using OutOfSchool.WebApi.Models.SocialGroup; namespace OutOfSchool.WebApi.Services; @@ -19,7 +10,7 @@ namespace OutOfSchool.WebApi.Services; /// public class SocialGroupService : ISocialGroupService { - private readonly IEntityRepository repository; + private readonly IEntityRepositorySoftDeleted repository; private readonly ILogger logger; private readonly IStringLocalizer localizer; private readonly IMapper mapper; @@ -32,8 +23,7 @@ public class SocialGroupService : ISocialGroupService /// Localizer. /// Mapper. public SocialGroupService( - IEntityRepository repository, + IEntityRepositorySoftDeleted repository, ILogger logger, IStringLocalizer localizer, IMapper mapper) @@ -115,8 +105,14 @@ public async Task Update(SocialGroupDto dto, LocalizationType lo return null; } - if (localization == LocalizationType.En) socialGroupLocalized.NameEn = dto.Name; - else socialGroupLocalized.Name = dto.Name; + if (localization == LocalizationType.En) + { + socialGroupLocalized.NameEn = dto.Name; + } + else + { + socialGroupLocalized.Name = dto.Name; + } var socialGroup = await repository.Update(socialGroupLocalized).ConfigureAwait(false); diff --git a/OutOfSchool/OutOfSchool.WebApi/Util/MappingProfile.cs b/OutOfSchool/OutOfSchool.WebApi/Util/MappingProfile.cs index 2298c5ffed..0d6ce2304b 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Util/MappingProfile.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Util/MappingProfile.cs @@ -248,7 +248,8 @@ public MappingProfile() CreateMap().ReverseMap(); CreateMap() - .ForMember(dest => dest.MiddleName, opt => opt.MapFrom(src => src.MiddleName ?? string.Empty)); + .ForMember(dest => dest.MiddleName, opt => opt.MapFrom(src => src.MiddleName ?? string.Empty)) + .ForMember(dest => dest.SocialGroups, opt => opt.MapFrom(src => src.SocialGroups.Where(x => !x.IsDeleted))); CreateMap() .ForMember(c => c.Parent, m => m.Ignore()) From 0faa0af67eb038f7ca24ff103a03a93753d031f2 Mon Sep 17 00:00:00 2001 From: Alexander Romanchuk Date: Wed, 27 Sep 2023 13:11:00 +0300 Subject: [PATCH 3/4] BlockedProviderParent --- .../Models/BlockedProviderParent.cs | 4 +++- .../BlockedProviderParentConfiguration.cs | 14 ++++++++++++++ .../OutOfSchoolDbContext.SoftDelete.cs | 1 - .../OutOfSchool.DataAccess/OutOfSchoolDbContext.cs | 1 + .../Repository/BlockedProviderParentRepository.cs | 2 +- .../Repository/IBlockedProviderParentRepository.cs | 2 +- .../OutOfSchool.WebApi/Util/MappingProfile.cs | 2 +- 7 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 OutOfSchool/OutOfSchool.DataAccess/Models/Configurations/BlockedProviderParentConfiguration.cs diff --git a/OutOfSchool/OutOfSchool.DataAccess/Models/BlockedProviderParent.cs b/OutOfSchool/OutOfSchool.DataAccess/Models/BlockedProviderParent.cs index 7c2061f4d0..7a2fda3ec9 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Models/BlockedProviderParent.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Models/BlockedProviderParent.cs @@ -5,10 +5,12 @@ namespace OutOfSchool.Services.Models; -public class BlockedProviderParent : IKeyedEntity +public class BlockedProviderParent : IKeyedEntity, ISoftDeleted { public Guid Id { get; set; } + public bool IsDeleted { get; set; } + [Required] public Guid ParentId { get; set; } diff --git a/OutOfSchool/OutOfSchool.DataAccess/Models/Configurations/BlockedProviderParentConfiguration.cs b/OutOfSchool/OutOfSchool.DataAccess/Models/Configurations/BlockedProviderParentConfiguration.cs new file mode 100644 index 0000000000..5af7719ca8 --- /dev/null +++ b/OutOfSchool/OutOfSchool.DataAccess/Models/Configurations/BlockedProviderParentConfiguration.cs @@ -0,0 +1,14 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace OutOfSchool.Services.Models.Configurations; + +internal class BlockedProviderParentConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.HasIndex(x => x.IsDeleted); + + builder.Property(x => x.IsDeleted).HasDefaultValue(false); + } +} diff --git a/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.SoftDelete.cs b/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.SoftDelete.cs index 46bd066b54..b00f1c3b22 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.SoftDelete.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.SoftDelete.cs @@ -46,7 +46,6 @@ private void ApplySoftDelete(ModelBuilder builder) .ApplySoftDelete() .ApplySoftDelete
() .ApplySoftDelete() - .ApplySoftDelete() .ApplySoftDelete() .ApplySoftDelete() .ApplySoftDelete() diff --git a/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.cs b/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.cs index 1a196a58e9..fcb019624d 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.cs @@ -128,6 +128,7 @@ protected override void OnModelCreating(ModelBuilder builder) builder.ApplyConfiguration(new AddressConfiguration()); builder.ApplyConfiguration(new ApplicationConfiguration()); builder.ApplyConfiguration(new AverageRatingConfiguration()); + builder.ApplyConfiguration(new BlockedProviderParentConfiguration()); builder.ApplyConfiguration(new ChatMessageWorkshopConfiguration()); builder.ApplyConfiguration(new ChatRoomWorkshopConfiguration()); builder.ApplyConfiguration(new ChildConfiguration()); diff --git a/OutOfSchool/OutOfSchool.DataAccess/Repository/BlockedProviderParentRepository.cs b/OutOfSchool/OutOfSchool.DataAccess/Repository/BlockedProviderParentRepository.cs index 8f40d3cc03..a65f1f7ad3 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Repository/BlockedProviderParentRepository.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Repository/BlockedProviderParentRepository.cs @@ -6,7 +6,7 @@ namespace OutOfSchool.Services.Repository; -public class BlockedProviderParentRepository : SensitiveEntityRepository, IBlockedProviderParentRepository +public class BlockedProviderParentRepository : SensitiveEntityRepositorySoftDeleted, IBlockedProviderParentRepository { private readonly OutOfSchoolDbContext db; diff --git a/OutOfSchool/OutOfSchool.DataAccess/Repository/IBlockedProviderParentRepository.cs b/OutOfSchool/OutOfSchool.DataAccess/Repository/IBlockedProviderParentRepository.cs index b611ce5aca..0e33ab908c 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Repository/IBlockedProviderParentRepository.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Repository/IBlockedProviderParentRepository.cs @@ -3,7 +3,7 @@ namespace OutOfSchool.Services.Repository; -public interface IBlockedProviderParentRepository : ISensitiveEntityRepository +public interface IBlockedProviderParentRepository : ISensitiveEntityRepositorySoftDeleted { /// /// Create entity BlockedProviderParent. Update dependent entities (IsBlocked = true). diff --git a/OutOfSchool/OutOfSchool.WebApi/Util/MappingProfile.cs b/OutOfSchool/OutOfSchool.WebApi/Util/MappingProfile.cs index 0d6ce2304b..f3181f57ad 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Util/MappingProfile.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Util/MappingProfile.cs @@ -113,7 +113,7 @@ public MappingProfile() .ForMember(dest => dest.CATOTTG, opt => opt.Ignore()) .ForMember(dest => dest.GeoHash, opt => opt.Ignore()); - CreateMap() + CreateSoftDeletedMap() .ForMember(dest => dest.Id, opt => opt.Ignore()) .ForMember(dest => dest.UserIdBlock, opt => opt.Ignore()) .ForMember(dest => dest.UserIdUnblock, opt => opt.Ignore()) From 8512ad7afcd91957e5d3d6e011dba90d738b83e7 Mon Sep 17 00:00:00 2001 From: Alexander Romanchuk Date: Wed, 27 Sep 2023 14:30:39 +0300 Subject: [PATCH 4/4] CompanyInformation --- .../Models/CompanyInformation.cs | 4 +++- .../CompanyInformationConfiguration.cs | 14 ++++++++++++++ .../OutOfSchoolDbContext.SoftDelete.cs | 1 - .../OutOfSchool.DataAccess/OutOfSchoolDbContext.cs | 1 + .../Services/CompanyInformationServiceTests.cs | 4 ++-- .../Controllers/V1/CompanyInformationController.cs | 9 +-------- .../Models/CompanyInformationDto.cs | 4 +--- .../Services/CompanyInformationService.cs | 4 ++-- 8 files changed, 24 insertions(+), 17 deletions(-) create mode 100644 OutOfSchool/OutOfSchool.DataAccess/Models/Configurations/CompanyInformationConfiguration.cs diff --git a/OutOfSchool/OutOfSchool.DataAccess/Models/CompanyInformation.cs b/OutOfSchool/OutOfSchool.DataAccess/Models/CompanyInformation.cs index 9b221b8351..43bb428a09 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/Models/CompanyInformation.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/Models/CompanyInformation.cs @@ -5,10 +5,12 @@ namespace OutOfSchool.Services.Models; -public class CompanyInformation : IKeyedEntity +public class CompanyInformation : IKeyedEntity, ISoftDeleted { public Guid Id { get; set; } + public bool IsDeleted { get; set; } + [MaxLength(200)] public string Title { get; set; } diff --git a/OutOfSchool/OutOfSchool.DataAccess/Models/Configurations/CompanyInformationConfiguration.cs b/OutOfSchool/OutOfSchool.DataAccess/Models/Configurations/CompanyInformationConfiguration.cs new file mode 100644 index 0000000000..c887dc459a --- /dev/null +++ b/OutOfSchool/OutOfSchool.DataAccess/Models/Configurations/CompanyInformationConfiguration.cs @@ -0,0 +1,14 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace OutOfSchool.Services.Models.Configurations; + +internal class CompanyInformationConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.HasIndex(x => x.IsDeleted); + + builder.Property(x => x.IsDeleted).HasDefaultValue(false); + } +} \ No newline at end of file diff --git a/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.SoftDelete.cs b/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.SoftDelete.cs index b00f1c3b22..324207ba68 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.SoftDelete.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.SoftDelete.cs @@ -48,7 +48,6 @@ private void ApplySoftDelete(ModelBuilder builder) .ApplySoftDelete() .ApplySoftDelete() .ApplySoftDelete() - .ApplySoftDelete() .ApplySoftDelete() .ApplySoftDelete() .ApplySoftDelete() diff --git a/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.cs b/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.cs index fcb019624d..2823c61a80 100644 --- a/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.cs +++ b/OutOfSchool/OutOfSchool.DataAccess/OutOfSchoolDbContext.cs @@ -133,6 +133,7 @@ protected override void OnModelCreating(ModelBuilder builder) builder.ApplyConfiguration(new ChatRoomWorkshopConfiguration()); builder.ApplyConfiguration(new ChildConfiguration()); builder.ApplyConfiguration(new CodeficatorConfiguration()); + builder.ApplyConfiguration(new CompanyInformationConfiguration()); builder.ApplyConfiguration(new DirectionConfiguration()); builder.ApplyConfiguration(new EntityImagesConfiguration()); builder.ApplyConfiguration(new EntityImagesConfiguration()); diff --git a/OutOfSchool/OutOfSchool.WebApi.Tests/Services/CompanyInformationServiceTests.cs b/OutOfSchool/OutOfSchool.WebApi.Tests/Services/CompanyInformationServiceTests.cs index 3dcd06a517..9c8be7b0f7 100644 --- a/OutOfSchool/OutOfSchool.WebApi.Tests/Services/CompanyInformationServiceTests.cs +++ b/OutOfSchool/OutOfSchool.WebApi.Tests/Services/CompanyInformationServiceTests.cs @@ -22,7 +22,7 @@ public class CompanyInformationServiceTests { private DbContextOptions options; private OutOfSchoolDbContext context; - private ISensitiveEntityRepository repository; + private ISensitiveEntityRepositorySoftDeleted repository; private ICompanyInformationService service; private Mock> logger; private Mock mapper; @@ -39,7 +39,7 @@ public void SetUp() logger = new Mock>(); mapper = new Mock(); - repository = new SensitiveEntityRepository(context); + repository = new SensitiveEntityRepositorySoftDeleted(context); service = new CompanyInformationService(repository, logger.Object, mapper.Object); SeedDatabase(); diff --git a/OutOfSchool/OutOfSchool.WebApi/Controllers/V1/CompanyInformationController.cs b/OutOfSchool/OutOfSchool.WebApi/Controllers/V1/CompanyInformationController.cs index c0c92dabde..e194de11c2 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Controllers/V1/CompanyInformationController.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Controllers/V1/CompanyInformationController.cs @@ -1,14 +1,7 @@ -using System; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Localization; -using Microsoft.Extensions.Logging; -using OutOfSchool.Common.PermissionsModule; using OutOfSchool.Services.Enums; using OutOfSchool.WebApi.Models; -using OutOfSchool.WebApi.Services; namespace OutOfSchool.WebApi.Controllers.V1; diff --git a/OutOfSchool/OutOfSchool.WebApi/Models/CompanyInformationDto.cs b/OutOfSchool/OutOfSchool.WebApi/Models/CompanyInformationDto.cs index f38c177d50..8ea4724b6d 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Models/CompanyInformationDto.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Models/CompanyInformationDto.cs @@ -1,6 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using OutOfSchool.Services.Enums; diff --git a/OutOfSchool/OutOfSchool.WebApi/Services/CompanyInformationService.cs b/OutOfSchool/OutOfSchool.WebApi/Services/CompanyInformationService.cs index 1077d873fa..ca970d40c9 100644 --- a/OutOfSchool/OutOfSchool.WebApi/Services/CompanyInformationService.cs +++ b/OutOfSchool/OutOfSchool.WebApi/Services/CompanyInformationService.cs @@ -20,7 +20,7 @@ public class CompanyInformationService : ICompanyInformationService { private const int LimitOfItems = 10; private const int MainLimit = 1; - private readonly ISensitiveEntityRepository companyInformationRepository; + private readonly ISensitiveEntityRepositorySoftDeleted companyInformationRepository; private readonly ILogger logger; private readonly IMapper mapper; @@ -31,7 +31,7 @@ public class CompanyInformationService : ICompanyInformationService /// Logger. /// Mapper. public CompanyInformationService( - ISensitiveEntityRepository companyInformationRepository, + ISensitiveEntityRepositorySoftDeleted companyInformationRepository, ILogger logger, IMapper mapper) {