From 81762ecb645c100e7c7a02ec6c226bfccac372a2 Mon Sep 17 00:00:00 2001 From: "Amir.H Khademi" Date: Thu, 25 Jul 2024 18:42:18 +0330 Subject: [PATCH] fix bugs , push befor start fixing --- .../AppSettings/appsettings.Development.json | 4 ++-- Brizco.Api/Brizco.Api.csproj | 1 + Brizco.Api/Controllers/ActivityController.cs | 4 +--- .../Controllers/NotificationController.cs | 9 +++++++++ .../.installation | 1 + Brizco.Common/Brizco.Common.csproj | 8 ++++---- .../EntityServices/ShiftPlanService.cs | 2 +- Brizco.Domain/Brizco.Domain.csproj | 8 ++++---- Brizco.Domain/Mappers/TaskMapper.g.cs | 1 + Brizco.Domain/Mappers/TaskPositionMapper.g.cs | 1 + Brizco.Domain/Mappers/TaskShiftMapper.g.cs | 1 + Brizco.Domain/MapsterRegister.cs | 6 +----- Brizco.Repository/Brizco.Repository.csproj | 1 + .../ReadNotificationCommandHandler.cs | 20 ++++++++----------- 14 files changed, 36 insertions(+), 31 deletions(-) create mode 100644 Brizco.Api/Sentry/9DC334EC83D3BBA80249F4426A4CB422C68089AE/.installation diff --git a/Brizco.Api/AppSettings/appsettings.Development.json b/Brizco.Api/AppSettings/appsettings.Development.json index aaafaa7..1b5d28b 100644 --- a/Brizco.Api/AppSettings/appsettings.Development.json +++ b/Brizco.Api/AppSettings/appsettings.Development.json @@ -1,8 +1,8 @@ { "ConnectionStrings": { "PostgresServer": "Host=185.220.227.123;port=5432;Username=postgres;Password=ub0J7sFFThkSBmkc0TzSKsCfheRnQpyu;Database=BrizcoDB", - "Postgres": "Host=pg-0,pg-1;Username=igarsonAgent;Password=xHTpBf4wC+bBeNg2pL6Ga7VEWKFJx7VPEUpqxwPFfOc2YYTVwFQuHfsiqoVeT9+6;Database=BrizcoDB;Load Balance Hosts=true;Target Session Attributes=primary;Application Name=iGLS", - "MartenDB": "Host=pg-0,pg-1;Username=igarsonAgent;Password=xHTpBf4wC+bBeNg2pL6Ga7VEWKFJx7VPEUpqxwPFfOc2YYTVwFQuHfsiqoVeT9+6;Database=BrizcoMartenDB;" + "Postgres": "Host=pg-0;Username=postgres;Password=xHTpBf4wC+bBeNg2pL6Ga7VEWKFJx7VPEUpqxwPFfOc2YYTVwFQuHfsiqoVeT9+6;Database=BrizcoDB;Application Name=BrizCo", + "MartenDB": "Host=pg-0;Username=postgres;Password=xHTpBf4wC+bBeNg2pL6Ga7VEWKFJx7VPEUpqxwPFfOc2YYTVwFQuHfsiqoVeT9+6;Database=BrizcoMartenDB;" }, "Logging": { "LogLevel": { diff --git a/Brizco.Api/Brizco.Api.csproj b/Brizco.Api/Brizco.Api.csproj index 99a3101..ad8afbf 100644 --- a/Brizco.Api/Brizco.Api.csproj +++ b/Brizco.Api/Brizco.Api.csproj @@ -74,6 +74,7 @@ + diff --git a/Brizco.Api/Controllers/ActivityController.cs b/Brizco.Api/Controllers/ActivityController.cs index 349712a..fc5ef20 100644 --- a/Brizco.Api/Controllers/ActivityController.cs +++ b/Brizco.Api/Controllers/ActivityController.cs @@ -1,5 +1,4 @@ -using Brizco.Common.Models.Claims; -using Brizco.Domain.Enums; +using Brizco.Domain.Enums; namespace Brizco.Api.Controllers; @@ -7,7 +6,6 @@ public class ActivityController : ICarterModule { public void AddRoutes(IEndpointRouteBuilder app) { - var group = app.NewVersionedApi("Activity") .MapGroup($"api/activity") .RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser()); diff --git a/Brizco.Api/Controllers/NotificationController.cs b/Brizco.Api/Controllers/NotificationController.cs index 8bb138f..668b6b9 100644 --- a/Brizco.Api/Controllers/NotificationController.cs +++ b/Brizco.Api/Controllers/NotificationController.cs @@ -13,8 +13,17 @@ public class NotificationController : ICarterModule .RequireAuthorization(builder=>builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser()) .HasApiVersion(1.0); + group.MapPost("{id}/read",ReadNotificationAsync) + .WithDisplayName("Read Notification") + .WithDescription("Read notification , by JWT user id") + .RequireAuthorization(builder => builder.AddAuthenticationSchemes("Bearer").RequireAuthenticatedUser()) + .HasApiVersion(1.0); + } + private async Task ReadNotificationAsync([FromRoute] Guid id, [FromServices] IMediator mediator, CancellationToken cancellationToken) + => TypedResults.Ok(await mediator.Send(new ReadNotificationCommand(id), cancellationToken)); + private async Task GetUserNotificationsAsync([FromQuery] int page, [FromQuery] int count, [FromServices] IMediator mediator, CancellationToken cancellationToken) => TypedResults.Ok(await mediator.Send(new GetNotificationsQuery(page, count), cancellationToken)); diff --git a/Brizco.Api/Sentry/9DC334EC83D3BBA80249F4426A4CB422C68089AE/.installation b/Brizco.Api/Sentry/9DC334EC83D3BBA80249F4426A4CB422C68089AE/.installation new file mode 100644 index 0000000..2eae656 --- /dev/null +++ b/Brizco.Api/Sentry/9DC334EC83D3BBA80249F4426A4CB422C68089AE/.installation @@ -0,0 +1 @@ +7bec0081-0f19-4cf7-84a9-7deed79e4f61 \ No newline at end of file diff --git a/Brizco.Common/Brizco.Common.csproj b/Brizco.Common/Brizco.Common.csproj index 8b1d127..393ed47 100644 --- a/Brizco.Common/Brizco.Common.csproj +++ b/Brizco.Common/Brizco.Common.csproj @@ -1,6 +1,6 @@  - + - + diff --git a/Brizco.Core/EntityServices/ShiftPlanService.cs b/Brizco.Core/EntityServices/ShiftPlanService.cs index 2f4ce03..b76fa18 100644 --- a/Brizco.Core/EntityServices/ShiftPlanService.cs +++ b/Brizco.Core/EntityServices/ShiftPlanService.cs @@ -12,7 +12,7 @@ public class ShiftPlanService(IMediator mediator, IActivityService activityServi { var shiftPlan = await mediator.Send(createShiftPlanCommand, cancellationToken); await activityService.CreateActivitiesByShiftPlan(shiftPlan.Id, cancellationToken); - await mediator.Send(new CreateShiftPlanNotificationsCommand(shiftPlan.Id), cancellationToken); + await mediator.Send(new CreateShiftPlanNotificationsCommand(shiftPlan.Id,true), cancellationToken); return true; } diff --git a/Brizco.Domain/Brizco.Domain.csproj b/Brizco.Domain/Brizco.Domain.csproj index 97677fb..8ad6271 100644 --- a/Brizco.Domain/Brizco.Domain.csproj +++ b/Brizco.Domain/Brizco.Domain.csproj @@ -1,6 +1,6 @@  - + - + diff --git a/Brizco.Domain/Mappers/TaskMapper.g.cs b/Brizco.Domain/Mappers/TaskMapper.g.cs index f089fba..2f6020b 100644 --- a/Brizco.Domain/Mappers/TaskMapper.g.cs +++ b/Brizco.Domain/Mappers/TaskMapper.g.cs @@ -9,6 +9,7 @@ using Brizco.Domain.Entities.Complexes; using Brizco.Domain.Entities.Shifts; using Brizco.Domain.Entities.Tasks; using Mapster.Models; +using Task = Brizco.Domain.Entities.Tasks.Task; namespace Brizco.Domain.Mappers { diff --git a/Brizco.Domain/Mappers/TaskPositionMapper.g.cs b/Brizco.Domain/Mappers/TaskPositionMapper.g.cs index b703d2c..d657ca0 100644 --- a/Brizco.Domain/Mappers/TaskPositionMapper.g.cs +++ b/Brizco.Domain/Mappers/TaskPositionMapper.g.cs @@ -4,6 +4,7 @@ using Brizco.Domain.Dtos.SmallDtos; using Brizco.Domain.Entities.Complexes; using Brizco.Domain.Entities.Tasks; using Mapster.Models; +using Task = Brizco.Domain.Entities.Tasks.Task; namespace Brizco.Domain.Mappers { diff --git a/Brizco.Domain/Mappers/TaskShiftMapper.g.cs b/Brizco.Domain/Mappers/TaskShiftMapper.g.cs index 7ae1787..372eaad 100644 --- a/Brizco.Domain/Mappers/TaskShiftMapper.g.cs +++ b/Brizco.Domain/Mappers/TaskShiftMapper.g.cs @@ -4,6 +4,7 @@ using Brizco.Domain.Dtos.SmallDtos; using Brizco.Domain.Entities.Shifts; using Brizco.Domain.Entities.Tasks; using Mapster.Models; +using Task = Brizco.Domain.Entities.Tasks.Task; namespace Brizco.Domain.Mappers { diff --git a/Brizco.Domain/MapsterRegister.cs b/Brizco.Domain/MapsterRegister.cs index 90b8624..e0ef9b1 100644 --- a/Brizco.Domain/MapsterRegister.cs +++ b/Brizco.Domain/MapsterRegister.cs @@ -1,8 +1,4 @@ -using Brizco.Domain.Dtos.LargeDtos; -using Brizco.Domain.Entities.Complexes; -using Brizco.Domain.Entities.ShiftPlans; -using Brizco.Domain.Entities.Tasks; -using MD.PersianDateTime.Standard; +using Brizco.Domain.Entities.Tasks; using Task = Brizco.Domain.Entities.Tasks.Task; namespace Brizco.Domain; diff --git a/Brizco.Repository/Brizco.Repository.csproj b/Brizco.Repository/Brizco.Repository.csproj index 4f55406..33db06e 100644 --- a/Brizco.Repository/Brizco.Repository.csproj +++ b/Brizco.Repository/Brizco.Repository.csproj @@ -50,6 +50,7 @@ + diff --git a/Brizco.Repository/MartenHandlers/Notifications/ReadNotificationCommandHandler.cs b/Brizco.Repository/MartenHandlers/Notifications/ReadNotificationCommandHandler.cs index 447e528..86b2f13 100644 --- a/Brizco.Repository/MartenHandlers/Notifications/ReadNotificationCommandHandler.cs +++ b/Brizco.Repository/MartenHandlers/Notifications/ReadNotificationCommandHandler.cs @@ -2,26 +2,22 @@ namespace Brizco.Repository.MartenHandlers.Notifications; -public class ReadNotificationCommandHandler : IRequestHandler +public class ReadNotificationCommandHandler(IMartenRepositoryWrapper martenRepositoryWrapper, ICurrentUserService currentUserService) : IRequestHandler { - private readonly IMartenRepositoryWrapper _martenRepositoryWrapper; - private readonly ICurrentUserService _currentUserService; - - public ReadNotificationCommandHandler(IMartenRepositoryWrapper martenRepositoryWrapper, ICurrentUserService currentUserService) - { - _martenRepositoryWrapper = martenRepositoryWrapper; - _currentUserService = currentUserService; - } public async Task Handle(ReadNotificationCommand request, CancellationToken cancellationToken) { - var notification = await _martenRepositoryWrapper.SetRepository() + var notification = await martenRepositoryWrapper.SetRepository() .GetEntityAsync(request.Id, cancellationToken); if (notification == null) - throw new BaseApiException(ApiResultStatusCode.NotFound,"Notification not found"); + throw new BaseApiException(ApiResultStatusCode.NotFound, "Notification not found"); + if (!Guid.TryParse(currentUserService.UserId, out Guid userId)) + throw new BaseApiException(ApiResultStatusCode.NotFound, "User id is null"); + if (notification.UserId != userId) + throw new BaseApiException(ApiResultStatusCode.NotFound, "This is not your notification"); notification.IsRead = true; - await _martenRepositoryWrapper.SetRepository() + await martenRepositoryWrapper.SetRepository() .AddOrUpdateEntityAsync(notification, cancellationToken); return true; }