Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update working hours bugfix #941

Merged
merged 2 commits into from
Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class WorkshopServiceTests
{
private IWorkshopService workshopService;
private Mock<IWorkshopRepository> workshopRepository;
private Mock<IEntityRepository<long, DateTimeRange>> dateTimeRangeRepository;
private Mock<IRatingService> ratingService;
private Mock<ITeacherService> teacherService;
private Mock<ILogger<WorkshopService>> logger;
Expand All @@ -39,6 +40,7 @@ public class WorkshopServiceTests
public void SetUp()
{
workshopRepository = new Mock<IWorkshopRepository>();
dateTimeRangeRepository = new Mock<IEntityRepository<long, DateTimeRange>>();
ratingService = new Mock<IRatingService>();
teacherService = new Mock<ITeacherService>();
logger = new Mock<ILogger<WorkshopService>>();
Expand All @@ -48,6 +50,7 @@ public void SetUp()
workshopService =
new WorkshopService(
workshopRepository.Object,
dateTimeRangeRepository.Object,
ratingService.Object,
teacherService.Object,
logger.Object,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class WorkshopService : IWorkshopService
private readonly string includingPropertiesForMappingWorkShopCard = $"{nameof(Workshop.Address)}";

private readonly IWorkshopRepository workshopRepository;
private readonly IEntityRepository<long, DateTimeRange> dateTimeRangeRepository;
private readonly IRatingService ratingService;
private readonly ITeacherService teacherService;
private readonly ILogger<WorkshopService> logger;
Expand All @@ -37,20 +38,23 @@ public class WorkshopService : IWorkshopService
/// Initializes a new instance of the <see cref="WorkshopService"/> class.
/// </summary>
/// <param name="workshopRepository">Repository for Workshop entity.</param>
/// <param name="dateTimeRangeRepository">Repository for DateTimeRange entity.</param>
/// <param name="ratingService">Rating service.</param>
/// <param name="teacherService">Teacher service.</param>
/// <param name="logger">Logger.</param>
/// <param name="mapper">Automapper DI service.</param>
/// <param name="workshopImagesService">Workshop images mediator.</param>
public WorkshopService(
IWorkshopRepository workshopRepository,
IEntityRepository<long, DateTimeRange> dateTimeRangeRepository,
IRatingService ratingService,
ITeacherService teacherService,
ILogger<WorkshopService> logger,
IMapper mapper,
IImageDependentEntityImagesInteractionService<Workshop> workshopImagesService)
{
this.workshopRepository = workshopRepository;
this.dateTimeRangeRepository = dateTimeRangeRepository;
this.ratingService = ratingService;
this.teacherService = teacherService;
this.logger = logger;
Expand Down Expand Up @@ -330,6 +334,7 @@ public async Task<WorkshopUpdateResultDto> UpdateV2(WorkshopDTO dto)
async Task<(Workshop updatedWorkshop, MultipleImageChangingResult multipleImageChangingResult,
ImageChangingResult changingCoverImageResult)> UpdateWorkshopWithDependencies()
{
await UpdateDateTimeRanges(dto.DateTimeRanges, dto.Id).ConfigureAwait(false);
var currentWorkshop = await workshopRepository.GetWithNavigations(dto.Id).ConfigureAwait(false);

dto.ImageIds ??= new List<string>();
Expand Down Expand Up @@ -726,6 +731,19 @@ private async Task ChangeTeachers(Workshop currentWorkshop, List<TeacherDTO> tea
}
}

private async Task UpdateDateTimeRanges(List<DateTimeRangeDto> dtos, Guid workshopId)
{
var ranges = mapper.Map<List<DateTimeRange>>(dtos);
foreach (var range in ranges)
{
if (await dateTimeRangeRepository.Any(r => r.Id == range.Id))
{
range.WorkshopId = workshopId;
await dateTimeRangeRepository.Update(range);
}
}
}

private async Task UpdateWorkshop()
{
try
Expand Down