Skip to content

Commit

Permalink
Merge branch 'main' into feature/mobx-init-store
Browse files Browse the repository at this point in the history
  • Loading branch information
maspasov authored Jul 19, 2024
2 parents a6f922b + d5f5c1d commit a999d45
Show file tree
Hide file tree
Showing 111 changed files with 567 additions and 209 deletions.
74 changes: 74 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,77 @@ csharp_style_prefer_range_operator = false:none
dotnet_diagnostic.IDE0055.severity = none
# prefere brace indentation when creating objects etc
csharp_indent_braces = false

[**/*.Specs/**/*.cs]
# Resharper specific
resharper_inconsistent_naming_highlighting = none
resharper_check_namespace_highlighting = none
resharper_unused_member_local_highlighting = none
dotnet_diagnostic.CA1001.severity = none
dotnet_diagnostic.CA1008.severity = none
dotnet_diagnostic.CA1024.severity = none
dotnet_diagnostic.CA1034.severity = none
dotnet_diagnostic.CA1051.severity = none
dotnet_diagnostic.CA1305.severity = none
dotnet_diagnostic.CA1707.severity = none
dotnet_diagnostic.CA1813.severity = none
dotnet_diagnostic.CA1852.severity = none
dotnet_diagnostic.CA1861.severity = none
dotnet_diagnostic.CA2000.severity = none
dotnet_diagnostic.CA2201.severity = none
dotnet_diagnostic.CA2211.severity = none
dotnet_diagnostic.CA2252.severity = none
dotnet_diagnostic.CS8600.severity = none
dotnet_diagnostic.CS8601.severity = none
dotnet_diagnostic.CS8602.severity = none
dotnet_diagnostic.CS8604.severity = none
dotnet_diagnostic.CS8632.severity = none
dotnet_diagnostic.CS8618.severity = none
dotnet_diagnostic.CS8765.severity = none
dotnet_diagnostic.CS8981.severity = none
dotnet_diagnostic.CS9113.severity = none
dotnet_diagnostic.IDE0005.severity = none
dotnet_diagnostic.IDE0044.severity = none
dotnet_diagnostic.IDE0051.severity = none
dotnet_diagnostic.IDE0052.severity = none
dotnet_diagnostic.IDE0060.severity = none
dotnet_diagnostic.IDE1006.severity = none
dotnet_diagnostic.SA0001.severity = none
dotnet_diagnostic.SA1116.severity = none
dotnet_diagnostic.SA1122.severity = none
dotnet_diagnostic.SA1134.severity = none
dotnet_diagnostic.SA1201.severity = none
dotnet_diagnostic.SA1202.severity = none
dotnet_diagnostic.SA1203.severity = none
dotnet_diagnostic.SA1204.severity = none
dotnet_diagnostic.SA1214.severity = none
dotnet_diagnostic.SA1303.severity = none
dotnet_diagnostic.SA1304.severity = none
dotnet_diagnostic.SA1306.severity = none
dotnet_diagnostic.SA1307.severity = none
dotnet_diagnostic.SA1311.severity = none
dotnet_diagnostic.SA1312.severity = none
dotnet_diagnostic.SA1313.severity = none
dotnet_diagnostic.SA1402.severity = none
dotnet_diagnostic.SA1500.severity = none
dotnet_diagnostic.SA1502.severity = none
dotnet_diagnostic.SA1507.severity = none
dotnet_diagnostic.SA1600.severity = none
dotnet_diagnostic.RCS1018.severity = none
dotnet_diagnostic.RCS1036.severity = none
dotnet_diagnostic.RCS1090.severity = none
dotnet_diagnostic.RCS1163.severity = none
dotnet_diagnostic.RCS1169.severity = none
dotnet_diagnostic.RCS1202.severity = none
dotnet_diagnostic.RCS1213.severity = none
dotnet_diagnostic.RCS1225.severity = none
dotnet_diagnostic.RCS1241.severity = none
dotnet_diagnostic.MA0016.severity = none
dotnet_diagnostic.MA0036.severity = none
dotnet_diagnostic.MA0041.severity = none
dotnet_diagnostic.MA0044.severity = none
dotnet_diagnostic.MA0048.severity = none
dotnet_diagnostic.MA0069.severity = none
dotnet_diagnostic.MA0096.severity = none
dotnet_diagnostic.MA0097.severity = none
dotnet_diagnostic.MA0132.severity = none
3 changes: 3 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ on:
paths:
- "**"

permissions:
contents: write

jobs:
release:
runs-on: ubuntu-latest
Expand Down
11 changes: 3 additions & 8 deletions ApplicationModel.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DotNET", "DotNET", "{856932
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Applications", "Source\DotNET\Applications\Applications.csproj", "{AA6A18EA-D0F5-41C7-AF7D-1BD124022C71}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Specifications", "Specifications", "{597AD628-3D8C-411C-899D-7A03AF4E6E2B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Applications", "Specifications\Applications\Applications.csproj", "{B692D48E-BD85-4F12-ADE3-15F3D3A1F710}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Applications.Specs", "Source\DotNET\Applications.Specs\Applications.Specs.csproj", "{B692D48E-BD85-4F12-ADE3-15F3D3A1F710}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serilog", "Source\DotNET\Serilog\Serilog.csproj", "{B2BF4443-5421-4275-A6A4-83C3E1C140B5}"
EndProject
Expand All @@ -27,9 +25,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProxyGenerator", "Source\Do
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orleans", "Source\DotNET\Orleans\Orleans.csproj", "{972CE865-9F7F-45D7-900C-5D81151D8105}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orleans", "Specifications\Orleans\Orleans.csproj", "{5F687FC5-0763-470E-AF27-4C2E8C8DCCFD}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Orleans.Specs", "Source\DotNET\Orleans.Specs\Orleans.Specs.csproj", "{5F687FC5-0763-470E-AF27-4C2E8C8DCCFD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB", "Specifications\MongoDB\MongoDB.csproj", "{A9723526-B6DA-40E6-A80A-5F566892DF45}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB.Specs", "Source\DotNET\MongoDB.Specs\MongoDB.Specs.csproj", "{A9723526-B6DA-40E6-A80A-5F566892DF45}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MongoDB", "Source\DotNET\MongoDB\MongoDB.csproj", "{55CA3EF1-6CF9-4226-A3C3-89B0A654A268}"
EndProject
Expand Down Expand Up @@ -132,14 +130,11 @@ Global
GlobalSection(NestedProjects) = preSolution
{856932F6-D1D1-41CC-808B-A3741518DACC} = {CB36289F-614E-4733-B81A-74AC5658E5CB}
{AA6A18EA-D0F5-41C7-AF7D-1BD124022C71} = {856932F6-D1D1-41CC-808B-A3741518DACC}
{B692D48E-BD85-4F12-ADE3-15F3D3A1F710} = {597AD628-3D8C-411C-899D-7A03AF4E6E2B}
{B2BF4443-5421-4275-A6A4-83C3E1C140B5} = {856932F6-D1D1-41CC-808B-A3741518DACC}
{FC67C7C1-EBC1-430E-9229-BF694CC67820} = {CB36289F-614E-4733-B81A-74AC5658E5CB}
{A495F734-D1D2-453B-97BA-90FD1F95A66B} = {856932F6-D1D1-41CC-808B-A3741518DACC}
{D25312B1-B1F7-44EA-8FBF-1910DEC9C1FA} = {A495F734-D1D2-453B-97BA-90FD1F95A66B}
{972CE865-9F7F-45D7-900C-5D81151D8105} = {856932F6-D1D1-41CC-808B-A3741518DACC}
{5F687FC5-0763-470E-AF27-4C2E8C8DCCFD} = {597AD628-3D8C-411C-899D-7A03AF4E6E2B}
{A9723526-B6DA-40E6-A80A-5F566892DF45} = {597AD628-3D8C-411C-899D-7A03AF4E6E2B}
{55CA3EF1-6CF9-4226-A3C3-89B0A654A268} = {856932F6-D1D1-41CC-808B-A3741518DACC}
{BE230ADD-9372-479D-9912-CB1AF36ADD0A} = {A495F734-D1D2-453B-97BA-90FD1F95A66B}
{A699BADC-5E16-4AA0-B275-3FF5B9F6BA38} = {856932F6-D1D1-41CC-808B-A3741518DACC}
Expand Down
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Cratis.Fundamentals" Version="5.2.7" />
<PackageVersion Include="Cratis.Fundamentals" Version="5.3.1" />
<PackageVersion Include="Cratis.Applications.ProxyGenerator.Build" Version="1.0.0" />
<PackageVersion Include="Microsoft.Build.Framework" Version="17.9.5" />
<PackageVersion Include="Microsoft.Build.Utilities.Core" Version="17.9.5" />
Expand Down Expand Up @@ -52,5 +52,6 @@
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.1" />
<PackageVersion Include="moq" Version="4.20.70" />
<PackageVersion Include="Microsoft.NET.Test.SDK" Version="17.10.0" />
<PackageVersion Include="NSubstitute" Version="5.1.0" />
</ItemGroup>
</Project>
2 changes: 2 additions & 0 deletions Samples/eCommerce/Basic/API/Products/Catalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ namespace API.Products;
/// Represents the catalog API.
/// </summary>
/// <param name="grainFactory"><see cref="IGrainFactory"/> for working with grains.</param>
/// <param name="catalogQueries"><see cref="ICatalogQueries"/> for working with the catalog.</param>
/// <param name="collection"><see cref="IMongoCollection{TDocument}"/> for working with products.</param>
[Route("/api/products/catalog")]
public class Catalog(IGrainFactory grainFactory, ICatalogQueries catalogQueries, IMongoCollection<Product> collection) : ControllerBase
{
Expand Down
4 changes: 3 additions & 1 deletion Samples/eCommerce/Basic/API/Products/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ public class Inventory : ControllerBase
/// <param name="command">The command payload.</param>
/// <returns>Awaitable task.</returns>
[HttpPost("set-stock/{sku}")]
public Task SetStockForProduct([FromRoute] SKU sku, [FromBody] SetStockForProduct command)
public Task SetStockForProduct(
[FromRoute] SKU sku,
[FromBody] SetStockForProduct command)
{
Console.WriteLine($"Setting stock for product {sku} to {command.Quantity}");
return Task.CompletedTask;
Expand Down
50 changes: 49 additions & 1 deletion Samples/eCommerce/Basic/Web/API/Products/AllProducts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,76 @@
*--------------------------------------------------------------------------------------------*/

// eslint-disable-next-line header/header
import { QueryFor, QueryResultWithState, SortingForQuery, Paging } from '@cratis/applications/queries';
import { QueryFor, QueryResultWithState, SortingActions, SortingActionsForQuery, Paging } from '@cratis/applications/queries';
import { useQuery, useQueryWithPaging, PerformQuery, SetSorting, SetPage } from '@cratis/applications.react/queries';
import { Product } from './Product';
import Handlebars from 'handlebars';

const routeTemplate = Handlebars.compile('/api/products/catalog');

class AllProductsSortBy {
private _id: SortingActionsForQuery<Product[]>;
private _name: SortingActionsForQuery<Product[]>;
private _isRegistered: SortingActionsForQuery<Product[]>;

constructor(readonly query: AllProducts) {
this._id = new SortingActionsForQuery<Product[]>('id', query);
this._name = new SortingActionsForQuery<Product[]>('name', query);
this._isRegistered = new SortingActionsForQuery<Product[]>('isRegistered', query);
}

get id(): SortingActionsForQuery<Product[]> {
return this._id;
}
get name(): SortingActionsForQuery<Product[]> {
return this._name;
}
get isRegistered(): SortingActionsForQuery<Product[]> {
return this._isRegistered;
}
}

class AllProductsSortByWithoutQuery {
private _id: SortingActions = new SortingActions('id');
private _name: SortingActions = new SortingActions('name');
private _isRegistered: SortingActions = new SortingActions('isRegistered');

get id(): SortingActions {
return this._id;
}
get name(): SortingActions {
return this._name;
}
get isRegistered(): SortingActions {
return this._isRegistered;
}
}


export class AllProducts extends QueryFor<Product[]> {
readonly route: string = '/api/products/catalog';
readonly routeTemplate: Handlebars.TemplateDelegate = routeTemplate;
readonly defaultValue: Product[] = [];
private readonly _sortBy: AllProductsSortBy;
private static readonly _sortBy: AllProductsSortByWithoutQuery = new AllProductsSortByWithoutQuery();

constructor() {
super(Product, true);
this._sortBy = new AllProductsSortBy(this);
}

get requestArguments(): string[] {
return [
];
}

get sortBy(): AllProductsSortBy {
return this._sortBy;
}

static get sortBy(): AllProductsSortByWithoutQuery {
return this._sortBy;
}

static use(): [QueryResultWithState<Product[]>, PerformQuery, SetSorting] {
return useQuery<Product[], AllProducts>(AllProducts);
Expand Down
14 changes: 14 additions & 0 deletions Samples/eCommerce/Basic/Web/Catalog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useState } from 'react';

export const Catalog = withViewModel(CatalogViewModel, ({ viewModel }) => {
const [products, currentPage, perform, setSorting, setPage] = AllProducts.useWithPaging(10);
const [descending, setDescending] = useState(false);

return (
<div>
Expand All @@ -23,6 +24,19 @@ export const Catalog = withViewModel(CatalogViewModel, ({ viewModel }) => {
const page = currentPage + 1;
setPage(page);
}}>Next page</button>
<br/>

<button onClick={() => {
if (descending) {
setSorting(AllProducts.sortBy.id.ascending);
setPage(0);
setDescending(false);
} else {
setSorting(AllProducts.sortBy.id.descending);
setPage(0);
setDescending(true);
}
}}>Change sorting</button>
</div>
);
});
1 change: 0 additions & 1 deletion Samples/eCommerce/Basic/Web/Feature.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { useIdentity } from '@cratis/applications.react/identity';
export const Feature = withViewModel(FeatureViewModel, ({ viewModel }) => {

const identity = useIdentity();

return (
<div>
<h2>Hello {`${identity.name}`} your cart id is {`${viewModel.cart.id}`} </h2>
Expand Down
6 changes: 3 additions & 3 deletions Samples/eCommerce/Basic/Web/vite.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ export default defineConfig({
open: false,
proxy: {
'/api': {
target: 'http://localhost:5001',
target: 'http://localhost:5500',
ws: true
},
'/swagger': {
target: 'http://localhost:5001'
target: 'http://localhost:5500'
},
'/.cratis': {
target: 'http://localhost:5001'
target: 'http://localhost:5500'
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../../Source/DotNET/Applications/Applications.csproj"/>
<ProjectReference Include="../Applications/Applications.csproj"/>
</ItemGroup>

<ItemGroup>
Expand Down
6 changes: 6 additions & 0 deletions Source/DotNET/Applications/Assembly.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) Cratis. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Cratis.Applications.MongoDB")]
24 changes: 24 additions & 0 deletions Source/DotNET/Applications/Commands/CommandMethodExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (c) Cratis. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System.Reflection;
using Cratis.Reflection;
using Microsoft.AspNetCore.Mvc;

namespace Cratis.Applications.Commands;

/// <summary>
/// Extension methods for methods representing commands.
/// </summary>
public static class CommandMethodExtensions
{
/// <summary>
/// Check if a method is a command.
/// </summary>
/// <param name="methodInfo">The <see cref="MethodInfo"/> to check.</param>
/// <returns>True if it is a command, false if not.</returns>
public static bool IsCommand(this MethodInfo methodInfo) =>
methodInfo.HasAttribute<HttpPostAttribute>() &&
!methodInfo.HasAttribute<AspNetResultAttribute>() &&
(!methodInfo.DeclaringType?.HasAttribute<AspNetResultAttribute>() ?? false);
}
22 changes: 15 additions & 7 deletions Source/DotNET/Applications/Commands/CommandResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@

namespace Cratis.Applications.Commands;

#pragma warning disable SA1402 // File may only contain a single type

/// <summary>
/// Represents the result coming from executing a command.
/// </summary>
/// <typeparam name="T">Type of the data returned.</typeparam>
public class CommandResult<T>
public class CommandResult
{
/// <summary>
/// Represents a successful command result.
/// </summary>
public static readonly CommandResult<T> Success = new();

/// <summary>
/// Gets the <see cref="CorrelationId"/> associated with the command.
/// </summary>
Expand Down Expand Up @@ -56,6 +52,18 @@ public class CommandResult<T>
/// Gets the stack trace if there was an exception.
/// </summary>
public string ExceptionStackTrace { get; init; } = string.Empty;
}

/// <summary>
/// Represents the result coming from executing a command with a response.
/// </summary>
/// <typeparam name="T">Type of the data returned.</typeparam>
public class CommandResult<T> : CommandResult
{
/// <summary>
/// Represents a successful command result.
/// </summary>
public static readonly CommandResult<T> Success = new();

/// <summary>
/// Optional response object. Controller actions representing a command can optionally return a response as any type, this is where it would be.
Expand Down
Loading

0 comments on commit a999d45

Please sign in to comment.