Skip to content

Commit

Permalink
v5.9.1 (#236)
Browse files Browse the repository at this point in the history
* CustomManagerOnly

* Remove redundant using.
  • Loading branch information
chullybun authored Jan 24, 2024
1 parent e44652d commit 334ec10
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 6 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

Represents the **NuGet** versions.

## v5.9.1
- *Fixed:* Simplified YAML specification where _only_ a custom manager is required to be implemented. For an `operation` set `type: CustomManagerOnly`, this is a shorthand for `type: Custom, managerCustom: true, excludeIDataSvc: true, excludeDataSvc: true, excludeIData: true, excludeData: true` (i.e. these other properties will no longer need to be set explicitly).

## v5.9.0
- *Fixed:* Upgraded `CoreEx` ([`v3.9.0`](https://github.com/Avanade/CoreEx/blob/main/CHANGELOG.md#v390)) and `DbEx` ([`v2.4.0`](https://github.com/Avanade/DbEx/blob/main/CHANGELOG.md#v240)) to include all related fixes and improvements; including dependent `UnitTestEx` ([`v4.0.1`](https://github.com/Avanade/UnitTestEx/blob/main/CHANGELOG.md#v410)) and related `NUnit` ([`v4.0.1`](https://docs.nunit.org/articles/nunit/release-notes/Nunit4.0-MigrationGuide.html)) upgrades.
- *Enhancement:* Updated the `dotnet new beef` template to target `net8.0` and updated `NUnit`.
Expand All @@ -21,7 +24,7 @@ Represents the **NuGet** versions.
- *Fixed:* The `count` code-generation command has been added to report the total number of files and lines for all and generated code.

## v5.7.2
- *Fixed:* The `Entity.HttpAgentCustomMapper` property has been added to the schema for correctly include within code-generation.
- *Fixed:* The `Entity.HttpAgentCustomMapper` property has been added to the schema to correctly include within code-generation.
- *Fixed:* Upgraded `CoreEx` (`v3.7.0`) to include all related fixes and improvements.

## v5.7.1
Expand Down
2 changes: 1 addition & 1 deletion Common.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>5.9.0</Version>
<Version>5.9.1</Version>
<LangVersion>preview</LangVersion>
<Authors>Avanade</Authors>
<Company>Avanade</Company>
Expand Down
3 changes: 2 additions & 1 deletion docs/Entity-Operation-Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The valid `Type` values are as follows:
- **[`Patch`](https://github.com/Avanade/CoreEx/blob/main/src/CoreEx/Json/Merge/JsonMergePatch.cs)** - indicates the patching (update) of an entity (leverages `Get` and `Update` to perform).
- **`Delete`** - indicates the deleting of an entity.
- **`Custom`** - indicates a customized operation where parameters and return value are explicitly defined. As this is a customised operation there is no `AutoImplement` and as such the underlying data implementation will need to be performed by the developer. This is the default where not specified.
- **`CustomManagerOnly`** - indicates `Custom` (as above) and automatically sets `ManagerCustom`, `ExcludeIDataSvc`, `ExcludeDataSvc`, `ExcludeIData`, `ExcludeData` properties to `true` (where not explicitly set).

<br/>

Expand Down Expand Up @@ -64,7 +65,7 @@ Provides the _key_ configuration.
Property | Description
-|-
**`name`** | The unique operation name. [Mandatory]
**`type`** | The type of operation that is to be code-generated. Valid options are: `Get`, `GetColl`, `Create`, `Update`, `Patch`, `Delete`, `Custom`.<br/>&dagger; Defaults to `Custom`.
**`type`** | The type of operation that is to be code-generated. Valid options are: `Get`, `GetColl`, `Create`, `Update`, `Patch`, `Delete`, `Custom`, `CustomManagerOnly`.<br/>&dagger; Defaults to `Custom`.
`text` | The text for use in comments.<br/>&dagger; The `Text` will be defaulted for all the `Operation.Type` options with the exception of `Custom`. To create a `<see cref="XXX"/>` within use moustache shorthand (e.g. {{Xxx}}).
**`primaryKey`** | Indicates whether the properties marked as a primary key (`Property.PrimaryKey`) are to be used as the parameters.<br/>&dagger; This simplifies the specification of these properties as parameters versus having to declare each specifically. Each of the parameters will also be set to be mandatory.
**`paging`** | Indicates whether a `PagingArgs` argument is to be added to the operation to enable (standardized) paging related logic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ public Task<IActionResult> PatchDetail(Guid id)
public Task<IActionResult> Add([FromBody] Person person)
=> _webApi.PostAsync(Request, p => _manager.AddAsync(person), statusCode: HttpStatusCode.Created, operationType: CoreEx.OperationType.Unspecified);

/// <summary>
/// Validate CustomManagerOnly.
/// </summary>
[HttpPost("api/v1/persons/cmo")]
[ProducesResponseType((int)HttpStatusCode.NoContent)]
public Task<IActionResult> CustomManagerOnly()
=> _webApi.PostAsync(Request, p => _manager.CustomManagerOnlyAsync(), statusCode: HttpStatusCode.NoContent, operationType: CoreEx.OperationType.Unspecified);

/// <summary>
/// Get Null.
/// </summary>
Expand Down
5 changes: 5 additions & 0 deletions samples/Demo/Beef.Demo.Business/Generated/IPersonManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ public partial interface IPersonManager
/// <returns>The selected <see cref="Person"/> where found.</returns>
Task<Person?> ManagerCustomAsync();

/// <summary>
/// Validate CustomManagerOnly.
/// </summary>
Task CustomManagerOnlyAsync();

/// <summary>
/// Get Null.
/// </summary>
Expand Down
6 changes: 6 additions & 0 deletions samples/Demo/Beef.Demo.Business/Generated/PersonManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,12 @@ await MultiValidator.Create()
return Cleaner.Clean(await ManagerCustomOnImplementationAsync().ConfigureAwait(false));
}, InvokerArgs.Read);

/// <inheritdoc/>
public Task CustomManagerOnlyAsync() => ManagerInvoker.Current.InvokeAsync(this, async (_, ct) =>
{
await CustomManagerOnlyOnImplementationAsync().ConfigureAwait(false);
}, InvokerArgs.Unspecified);

/// <inheritdoc/>
public Task<Person?> GetNullAsync(string? name, List<string>? names) => ManagerInvoker.Current.InvokeAsync(this, async (_, ct) =>
{
Expand Down
2 changes: 2 additions & 0 deletions samples/Demo/Beef.Demo.Business/PersonManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ private static Task AddOnImplementationAsync(Person value)
return Task.FromResult<Person?>(null);
}

private static Task CustomManagerOnlyOnImplementationAsync() => Task.CompletedTask;

private async Task UpdateOnPreValidateAsync(Person value, Guid id)
{
var curr = await GetAsync(id).ConfigureAwait(false);
Expand Down
1 change: 1 addition & 0 deletions samples/Demo/Beef.Demo.CodeGen/entity.beef-5.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ entities:
},
{ name: DataSvcCustom, type: Custom, text: Validate a DataSvc Custom generation, returnType: int, dataSvcCustom: true, excludeData: true, excludeIData: true, excludeWebApi: true, excludeWebApiAgent: true },
{ name: ManagerCustom, type: Get, text: Validate a Manager Custom generation, managerCustom: true, excludeIDataSvc: true, excludeDataSvc: true, excludeData: true, excludeIData: true, excludeWebApi: true, excludeWebApiAgent: true },
{ name: CustomManagerOnly, type: CustomManagerOnly, text: "Validate CustomManagerOnly", webApiMethod: HttpPost, webApiRoute: "cmo" },
{ name: GetNull, type: Custom, returnType: 'Person?', webApiRoute: 'null', webApiMethod: HttpGet, webApiAlternateStatus: NotFound,
parameters: [
{ name: Name, type: string },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ public partial interface IPersonAgent
/// <returns>A <see cref="HttpResult"/>.</returns>
Task<HttpResult> AddAsync(Person person, HttpRequestOptions? requestOptions = null, CancellationToken cancellationToken = default);

/// <summary>
/// Validate CustomManagerOnly.
/// </summary>
/// <param name="requestOptions">The optional <see cref="HttpRequestOptions"/>.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/>.</param>
/// <returns>A <see cref="HttpResult"/>.</returns>
Task<HttpResult> CustomManagerOnlyAsync(HttpRequestOptions? requestOptions = null, CancellationToken cancellationToken = default);

/// <summary>
/// Get Null.
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions samples/Demo/Beef.Demo.Common/Agents/Generated/PersonAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ public Task<HttpResult<PersonDetail>> PatchDetailAsync(HttpPatchOption patchOpti
public Task<HttpResult> AddAsync(Person person, HttpRequestOptions? requestOptions = null, CancellationToken cancellationToken = default)
=> PostAsync("api/v1/persons/fromBody", requestOptions: requestOptions, args: HttpArgs.Create(new HttpArg<Person>("person", person, HttpArgType.FromBody)), cancellationToken: cancellationToken);

/// <inheritdoc/>
public Task<HttpResult> CustomManagerOnlyAsync(HttpRequestOptions? requestOptions = null, CancellationToken cancellationToken = default)
=> PostAsync("api/v1/persons/cmo", requestOptions: requestOptions, cancellationToken: cancellationToken);

/// <inheritdoc/>
public Task<HttpResult<Person?>> GetNullAsync(string? name, List<string>? names, HttpRequestOptions? requestOptions = null, CancellationToken cancellationToken = default)
=> GetAsync<Person?>("api/v1/persons/null", requestOptions: requestOptions, args: HttpArgs.Create(new HttpArg<string?>("name", name), new HttpArg<List<string>?>("names", names)), cancellationToken: cancellationToken);
Expand Down
16 changes: 14 additions & 2 deletions tools/Beef.CodeGen.Core/Config/Entity/OperationConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ namespace Beef.CodeGen.Config.Entity
- **`Update`** - indicates the updating of an entity.
- **[`Patch`](https://github.com/Avanade/CoreEx/blob/main/src/CoreEx/Json/Merge/JsonMergePatch.cs)** - indicates the patching (update) of an entity (leverages `Get` and `Update` to perform).
- **`Delete`** - indicates the deleting of an entity.
- **`Custom`** - indicates a customized operation where parameters and return value are explicitly defined. As this is a customised operation there is no `AutoImplement` and as such the underlying data implementation will need to be performed by the developer. This is the default where not specified.",
- **`Custom`** - indicates a customized operation where parameters and return value are explicitly defined. As this is a customised operation there is no `AutoImplement` and as such the underlying data implementation will need to be performed by the developer. This is the default where not specified.
- **`CustomManagerOnly`** - indicates `Custom` (as above) and automatically sets `ManagerCustom`, `ExcludeIDataSvc`, `ExcludeDataSvc`, `ExcludeIData`, `ExcludeData` properties to `true` (where not explicitly set).",
ExampleMarkdown = @"A YAML configuration [example](../samples/My.Hr/My.Hr.CodeGen/entity.beef.yaml) is as follows:
``` yaml
operations: [
Expand Down Expand Up @@ -79,7 +80,7 @@ public class OperationConfig : ConfigBase<CodeGenConfig, EntityConfig>
/// </summary>
[JsonPropertyName("type")]
[CodeGenProperty("Key", Title = "The type of operation that is to be code-generated.", IsImportant = true,
Description = "Defaults to `Custom`.", Options = new string[] { "Get", "GetColl", "Create", "Update", "Patch", "Delete", "Custom" })]
Description = "Defaults to `Custom`.", Options = ["Get", "GetColl", "Create", "Update", "Patch", "Delete", "Custom", "CustomManagerOnly"])]
public string? Type { get; set; }

/// <summary>
Expand Down Expand Up @@ -996,6 +997,17 @@ public class OperationEvent
protected override async Task PrepareAsync()
{
Type = DefaultWhereNull(Type, () => "Custom");

if (Type == "CustomManagerOnly")
{
Type = "Custom";
ManagerCustom = DefaultWhereNull(ManagerCustom, () => true);
ExcludeIDataSvc = DefaultWhereNull(ExcludeIDataSvc, () => true);
ExcludeDataSvc = DefaultWhereNull(ExcludeDataSvc, () => true);
ExcludeIData = DefaultWhereNull(ExcludeIData, () => true);
ExcludeData = DefaultWhereNull(ExcludeData, () => true);
}

BaseReturnType = DefaultWhereNull(ReturnType, () => Type switch
{
"Get" => Parent!.EntityName,
Expand Down
3 changes: 2 additions & 1 deletion tools/Beef.CodeGen.Core/Schema/entity.beef-5.json
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,8 @@
"Update",
"Patch",
"Delete",
"Custom"
"Custom",
"CustomManagerOnly"
]
},
"text": {
Expand Down

0 comments on commit 334ec10

Please sign in to comment.