add steps to numbers; remove constants

This commit is contained in:
2023-06-16 17:28:24 +02:00
parent b087edb793
commit c9df9333f8
7 changed files with 18 additions and 36 deletions
-21
View File
@@ -1,21 +0,0 @@
namespace zero.Configuration;
public static partial class Constants
{
public const string ErrorFieldNone = "__zero_no_field";
public static partial class Auth
{
public const string SystemUser = "system";
public const string DefaultScheme = "zeroScheme";
public const string BackofficeDisplayName = "Zero Backoffice";
public const string BackofficeScheme = "zeroBackoffice";
public const string BackofficeCookieName = "zero.be.session";
public const string DefaultCookieName = "zero.session";
}
public static partial class Database
{
public const string ReservationPrefix = "zero.";
}
}
+1 -1
View File
@@ -31,7 +31,7 @@ public static class ResultExtensions
public static Result AddError(this Result origin, string message)
{
origin.IsSuccess = false;
origin.Errors.Add(new(Constants.ErrorFieldNone, message));
origin.Errors.Add(new("__zero_no_field", message));
return origin;
}
-6
View File
@@ -45,12 +45,6 @@ public partial class ZeroUserStore<TUser> :
return IdentityResult.Failed(errors);
}
/// <summary>
/// Get the Raven compare/exchange key for this user.
/// This should be unique within the store, otherwise you can't create users with the same email in different stores.
/// </summary>
protected virtual string GetReservationKey(TUser user) => Constants.Database.ReservationPrefix + typeof(TUser) + ':' + user.Email;
/// <summary>
/// Whether an email is already reserved
/// </summary>
+5
View File
@@ -30,6 +30,11 @@ public class Number : ZeroEntity
/// </summary>
public int MinLength { get; set; } = 1;
/// <summary>
/// How far to increase
/// </summary>
public int Step { get; set; } = 1;
/// <summary>
/// Store current counters
/// </summary>
+2
View File
@@ -12,4 +12,6 @@ public class NumberOptionsItem
public long StartNumber { get; set; } = 1;
public int MinLength { get; set; } = 1;
public int Step { get; set; } = 1;
}
+2 -6
View File
@@ -6,14 +6,10 @@ public class NumberValidator : ZeroValidator<Number>
{
public NumberValidator()
{
//if (ctx.Context == null)
//{
// throw new ArgumentNullException("ctx.Context", "NumberValidator requires access to ");
//}
RuleFor(x => x.Template).NotEmpty().Length(2, 60);
RuleFor(x => x.Template).Must(x => x != null && x.Contains("{number}")).WithMessage("@shop.number.errors.invalid_template");
RuleFor(x => x.Template).Must(x => x != null && x.Contains("{number}"));
RuleFor(x => x.StartNumber).GreaterThanOrEqualTo(0);
RuleFor(x => x.MinLength).ExclusiveBetween(1, 32);
RuleFor(x => x.Step).GreaterThanOrEqualTo(1);
}
}
+8 -2
View File
@@ -40,7 +40,7 @@ public class Numbers : INumbers
// calculate new value
bool hasValue = counter.Count != 0;
long oldValue = hasValue ? counter.Count : number.StartNumber;
long newValue = oldValue + (hasValue ? 1 : 0);
long newValue = oldValue + (hasValue ? number.Step : 0);
// increment the value and store it in database
if (store)
@@ -176,7 +176,8 @@ public class Numbers : INumbers
Id = id,
Template = options.Template,
StartNumber = options.StartNumber,
MinLength = options.MinLength
MinLength = options.MinLength,
Step = options.Step
};
await Db.Create(number);
@@ -200,6 +201,11 @@ public class Numbers : INumbers
number.MinLength = options.MinLength;
changed = true;
}
if (!number.Step.Equals(options.Step))
{
number.Step = options.Step;
changed = true;
}
if (changed)
{