Skip to content

Commit

Permalink
Allow only one message recipient and add possibility to configure mor…
Browse files Browse the repository at this point in the history
…e than one recipient (#1033)

* feat: added MaxNumberOfMessageRecipients

* fix: integration-test appsettings

* fix: updated Validator

* chore: removed custom validation name

---------

Co-authored-by: Eric Brunner <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 27, 2025
1 parent 6d4a4da commit 0421851
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .ci/appsettings.override.postgres.docker.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
},
"Messages": {
"Application": {
"DidDomainName": "localhost"
"DidDomainName": "localhost",
"MaxNumberOfMessageRecipients": 5
},
"Infrastructure": {
"SqlDatabase": {
Expand Down
3 changes: 2 additions & 1 deletion .ci/appsettings.override.postgres.local.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
},
"Messages": {
"Application": {
"DidDomainName": "localhost"
"DidDomainName": "localhost",
"MaxNumberOfMessageRecipients": 5
},
"Infrastructure": {
"SqlDatabase": {
Expand Down
3 changes: 2 additions & 1 deletion .ci/appsettings.override.sqlserver.docker.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
},
"Messages": {
"Application": {
"DidDomainName": "localhost"
"DidDomainName": "localhost",
"MaxNumberOfMessageRecipients": 5
},
"Infrastructure": {
"SqlDatabase": {
Expand Down
3 changes: 2 additions & 1 deletion .ci/appsettings.override.sqlserver.local.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
},
"Messages": {
"Application": {
"DidDomainName": "localhost"
"DidDomainName": "localhost",
"MaxNumberOfMessageRecipients": 5
},
"Infrastructure": {
"SqlDatabase": {
Expand Down
3 changes: 2 additions & 1 deletion Applications/ConsumerApi/src/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
"Pagination": {
"DefaultPageSize": 50,
"MaxPageSize": 200
}
},
"MaxNumberOfMessageRecipients": 1
},
"Infrastructure": {
"SqlDatabase": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
},
"Messages": {
"Application": {
"DidDomainName": "localhost"
"DidDomainName": "localhost",
"MaxNumberOfMessageRecipients": 5
},
"Infrastructure": {
"SqlDatabase": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public class ApplicationOptions
[MinLength(3)]
[MaxLength(45)]
public string DidDomainName { get; set; } = null!;

[Required]
public int MaxNumberOfMessageRecipients { get; set; }
}

public class PaginationOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
using Backbone.Modules.Messages.Domain.Ids;
using Backbone.Tooling.Extensions;
using FluentValidation;
using Microsoft.Extensions.Options;

namespace Backbone.Modules.Messages.Application.Messages.Commands.SendMessage;

public class Validator : AbstractValidator<SendMessageCommand>
{
public Validator()
public Validator(IOptions<ApplicationOptions> options)
{
RuleFor(m => m.Recipients)
.DetailedNotNull()
Expand All @@ -21,7 +22,8 @@ public Validator()
.SetValidator(new SendMessageCommandRecipientInformationValidator()));

RuleFor(m => m.Recipients.Count)
.InclusiveBetween(1, 50).WithErrorCode(GenericApplicationErrors.Validation.InvalidPropertyValue().Code);
.LessThanOrEqualTo(options.Value.MaxNumberOfMessageRecipients)
.WithErrorCode(GenericApplicationErrors.Validation.InvalidPropertyValue().Code);

RuleFor(m => m.Body).DetailedNotNull().NumberOfBytes(1, 10.Mebibytes());

Expand Down

0 comments on commit 0421851

Please sign in to comment.