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

feat(breaking): Move notification check endpoint to /actions #1175

Merged
merged 5 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -38,8 +38,9 @@ public async Task<NotificationConditionResult> Handle(NotificationConditionQuery
{
var dialog = await _db.Dialogs
.AsNoTracking()
.Include(x => x.Activities)
.IgnoreQueryFilters()
.Include(x => x.Activities
.Where(x => request.TransmissionId == null || x.TransmissionId == request.TransmissionId)
.Where(x => x.TypeId == request.ActivityType))
.FirstOrDefaultAsync(x => x.Id == request.DialogId,
cancellationToken: cancellationToken);

Expand All @@ -48,20 +49,10 @@ public async Task<NotificationConditionResult> Handle(NotificationConditionQuery
return new EntityNotFound<DialogEntity>(request.DialogId);
}

var conditionMet = CheckDialogActivitiesCondition(dialog.Activities, request.ConditionType, request.ActivityType, request.TransmissionId);
var conditionMet = dialog.Activities.Count == 0
? request.ConditionType == NotificationConditionType.NotExists
: request.ConditionType == NotificationConditionType.Exists;
oskogstad marked this conversation as resolved.
Show resolved Hide resolved

return new NotificationConditionDto { SendNotification = conditionMet };
}

private static bool CheckDialogActivitiesCondition(
List<DialogActivity> activities,
NotificationConditionType conditionType,
DialogActivityType.Values activityType,
Guid? transmissionId) =>
activities.Where(
x => x.TypeId == activityType
&& (transmissionId is null || x.TransmissionId == transmissionId)).ToList()
.Count == 0
? conditionType == NotificationConditionType.NotExists
: conditionType == NotificationConditionType.Exists;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public NotificationConditionEndpoint(ISender sender)

public override void Configure()
{
Get("dialogs/{dialogId}/notification-condition");
Get("dialogs/{dialogId}/actions/should-send-notification");
oskogstad marked this conversation as resolved.
Show resolved Hide resolved
Policies(AuthorizationPolicy.NotificationConditionCheck);
Group<ServiceOwnerGroup>();

Expand Down
Loading