(feature): improve patch operation details

This commit is contained in:
Maksym Sadovnychyy 2024-12-14 23:25:51 +01:00
parent eaa610a853
commit 9982ee3a8e
4 changed files with 31 additions and 10 deletions

View File

@ -1997,7 +1997,7 @@ var patch = new SomePatchRequestModel {
Username = "Updated Name"
Operations = new Dictionary<string, PatchOperation> {
{ "Username", PartchOperation.Replace }
{ "Username", PartchOperation.SetField }
}
};

View File

@ -23,5 +23,11 @@ public abstract class PatchRequestModelBase : RequestModelBase {
if (!HasNonNullPatchField) {
yield return new ValidationResult("At least one patch field must be provided", new string[] { "PatchField" });
}
foreach (var operation in Operations) {
if (!Enum.IsDefined(typeof(PatchOperation), operation.Value)) {
yield return new ValidationResult($"Invalid patch operation '{operation.Value}' for property '{operation.Key}'", new string[] { operation.Key });
}
}
}
}

View File

@ -8,7 +8,7 @@
<!-- NuGet package metadata -->
<PackageId>MaksIT.Core</PackageId>
<Version>1.2.3</Version>
<Version>1.2.4</Version>
<Authors>Maksym Sadovnychyy</Authors>
<Company>MAKS-IT</Company>
<Product>MaksIT.Core</Product>

View File

@ -3,22 +3,37 @@
public enum PatchOperation {
/// <summary>
/// When you need to replace some field, or relpace item in collection
/// When you need to set or replace a normal field
/// </summary>
Replace,
SetField,
/// <summary>
/// When you need to set some field, or add item to collection
/// When you need to set a normal field to null
/// </summary>
Add,
RemoveField,
/// <summary>
/// When you need to set some field to null, or remove item from collection
/// When you need to add an item to a collection
/// </summary>
Remove,
AddToCollection,
/// <summary>
/// When you need to clear collection
/// When you need to remove an item from a collection
/// </summary>
Clear
RemoveFromCollection,
/// <summary>
/// When you need to replace a collection
/// </summary>
ReplaceCollection,
/// <summary>
/// When you need to clear a collection
/// </summary>
ClearCollection,
/// <summary>
/// When you need to set a collection to null
/// </summary>
RemoveCollection
}