Files
EnvelopeGenerator/EnvelopeGenerator.Application/Envelopes/Commands/CreateEnvelopeCommand.cs
TekH 9b2539e378 Refactor CreateEnvelopeCommand authorization method
Replaced the `Authorize` method with a new `WithAuth` method
in the `CreateEnvelopeCommand` class. The new method sets
the `UserId` property and returns the current instance,
enabling method chaining and improving usability.
2026-05-30 16:47:51 +02:00

58 lines
1.8 KiB
C#

using DigitalData.Core.Abstraction.Application.Repository;
using EnvelopeGenerator.Application.Common.Dto;
using EnvelopeGenerator.Application.Common.Interfaces.SQLExecutor;
using MediatR;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json.Serialization;
namespace EnvelopeGenerator.Application.Envelopes.Commands;
/// <summary>
/// Befehl zur Erstellung eines Umschlags.
/// </summary>
public record CreateEnvelopeCommand : IRequest<EnvelopeDto?>
{
/// <summary>
/// Der Titel des Umschlags. Dies ist ein Pflichtfeld.
/// </summary>
[Required]
public required string Title { get; set; }
/// <summary>
/// Die Nachricht, die im Umschlag enthalten sein soll. Dies ist ein Pflichtfeld.
/// </summary>
[Required]
public required string Message { get; set; }
/// <summary>
/// Gibt an, ob die Zwei-Faktor-Authentifizierung für den Umschlag aktiviert ist. Standardmäßig false.
/// </summary>
public bool TFAEnabled { get; set; } = false;
/// <summary>
/// ID des Absenders
/// </summary>
internal int UserId { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public CreateEnvelopeCommand WithAuth(int userId)
{
UserId = userId;
return this;
}
/// <summary>
/// Determines which component is used for envelope processing.
/// When <c>true</c>, processing is delegated to <see cref="IEnvelopeExecutor"/>;
/// when <c>false</c>, <see cref="IRepository{Envelope}"/> is used instead.
/// Note: <see cref="IRepository{Envelope}"/> should only be used in testing scenarios.
/// </summary>
[JsonIgnore]
[NotMapped]
public bool UseSQLExecutor { get; set; } = true;
}