Skip to content

Commit

Permalink
Add product page and refactor code (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
thangchung authored Apr 19, 2020
1 parent dd7d1a9 commit f097f49
Show file tree
Hide file tree
Showing 151 changed files with 13,161 additions and 1,128 deletions.
98 changes: 6 additions & 92 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,105 +8,19 @@ A lightweight low ceremony microservices without Docker, Docker-compose and Helm
![product-catalog-api](https://github.com/thangchung/practical-dapr/workflows/product-catalog-ci/badge.svg?branch=master)
![inventory-api](https://github.com/thangchung/practical-dapr/workflows/inventory-ci/badge.svg?branch=master)

## Give a Star! :star:
## Show your support

If you liked `practical-dapr` project or if it helped you, please give a star :star: for this repository. That will not only help strengthen our .NET community but also improve cloud-native apps development skills for .NET developers in around the world. Thank you very much :+1:

# High Level Architecture
# CoolStore application

![](assets/high_level_architecture.png)
![](docs/assets/webui-products.png)

# Communication Style
# High level architecture

![](assets/commucation_style.png)
![](docs/assets/high_level_architecture.png)

# Get starting

## Start required components

- We need Docker for Desktop installed with Kubernetes is enabled.
- Follow those steps at https://github.com/dapr/cli to install Dapr CLI.
- Follow these steps at https://github.com/dotnet/tye/blob/master/docs/getting_started.md to install `tye` CLI.

## One tye command to rule them all

```bash
$ tye run
```

Then you can see `tye dashboard` as below

![](assets/tye-dashboard.png)

## Testing it

- Go to `webui`, and on `Bindings` column click to `http` link (http://localhost:58275 in the picture) to access to `Blazor Web UI`
- Go to `identity-api`, and on `Bindings` column click to `http` link (http://localhost:58269 in the picture) to access to `Identity Server 4`
- Go to `graph-api`, and on `Bindings` column click to `http` link (http://localhost:58267 in the picture) to access to `GraphQL Api Server`

### GraphQL Server Playground

On the `graph-api` link above, you will be redirected to GraphQL Playground, and you can play with it as following:

```js
query {
products(
page: 1
pageSize: 5
where: { price_lte: 10000 }
order_by: { price: DESC }
) {
edges {
id
name
imageUrl
price
categoryId
categoryName
inventoryId
inventoryLocation
}
totalCount
}
}
```

![](assets/graphql_playground_query_products.png)

### Mutation

```js
mutation createProductMutation($createProductInput: CreateProductInput!) {
createProduct(createProductInput: $createProductInput) {
product {
id
name
}
}
}
```

```js
{
"createProductInput": {
"name": "product 1",
"description": "this is a description",
"imageUrl": "https://picsum.photos/1200/900?image=100",
"price": 100,
"categoryId": "77666AA8-682C-4047-B075-04839281630A",
"inventoryId": "90C9479E-A11C-4D6D-AAAA-0405B6C0EFCD"
}
}
```

![](assets/graphql_playground_mutation.png)

## Debugging application

Follow steps at [Debugging Dapr application using Tye tool](https://dev.to/thangchung/debugging-dapr-application-using-tye-tool-1djb)

## Setup Azure
- [Publish docker image to ACR and AKS](https://docs.microsoft.com/en-us/azure/dev-spaces/how-to/github-actions) and [example](https://github.com/Azure/dev-spaces/blob/master/.github/workflows/bikes.yml)
# **Don't believe it, check yourself at [Developer Guidance](/docs/developer_guide.md)**.

## Contributing

Expand Down
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
Binary file added docs/assets/webui-products.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
109 changes: 109 additions & 0 deletions docs/developer_guide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# Developer Guide

## Install pre-requisites

- Docker for Desktop installed with Kubernetes is enabled.
- Follow those steps at https://github.com/dapr/cli to install Dapr CLI.
- Follow these steps at https://github.com/dotnet/tye/blob/master/docs/getting_started.md to install `tye` CLI.
- EF Core CLI

## Building the code

Clone the source code at https://github.com/thangchung/practical-dapr

```bash
$ git@github.com:thangchung/practical-dapr.git
```

## Development

- Step 1: Open up `src\Identity\CoolStore.IdentityServer\appsettings.json`, and turn `IsDev` to `true`
- Step 2: Open up `tye.yaml`, and comment out `name: webui`
- Step 3: At root of project, open up terminal and type `tye run`, and we get `IdentityUrl` and `GraphQLUrl` from the `tye dashboard`
- Step 4: Open up `src\WebUI\CoolStore.WebUI.Host\appsettings.json`, and turn `IsDev` to `true`, and replace `IdentityUrl` with the value at Step 3, and also replace `GraphQLUrl` with the value at Step 3. Final step, change `src\WebUI\CoolStore.WebUI.Host\GraphQL\berry.json` with the `GraphQL` endpoint at the Step 3
- Step 5: Run `CoolStore.WebUI.Host` at the debug mode, then we are ready to develop the `practical-dapr` project.

### One tye command to rule them all

```bash
$ tye run
```

Then you can see `tye dashboard` as below

![](assets/tye-dashboard.png)

### Testing it

- Go to `webui`, and on `Bindings` column click to `http` link (http://localhost:58275 in the picture) to access to `Blazor Web UI`
- Go to `identity-api`, and on `Bindings` column click to `http` link (http://localhost:58269 in the picture) to access to `Identity Server 4`
- Go to `graph-api`, and on `Bindings` column click to `http` link (http://localhost:58267 in the picture) to access to `GraphQL Api Server`

#### GraphQL server playground

On the `graph-api` link above, you will be redirected to GraphQL Playground, and you can play with it as following:

```js
query {
products(
page: 1
pageSize: 5
where: { price_lte: 10000 }
order_by: { price: DESC }
) {
edges {
id
name
imageUrl
price
categoryId
categoryName
inventoryId
inventoryLocation
}
totalCount
}
}
```

![](assets/graphql_playground_query_products.png)

#### Mutation

```js
mutation createProductMutation($createProductInput: CreateProductInput!) {
createProduct(createProductInput: $createProductInput) {
product {
id
name
}
}
}
```

```js
{
"createProductInput": {
"name": "product 1",
"description": "this is a description",
"imageUrl": "https://picsum.photos/1200/900?image=100",
"price": 100,
"categoryId": "77666AA8-682C-4047-B075-04839281630A",
"inventoryId": "90C9479E-A11C-4D6D-AAAA-0405B6C0EFCD"
}
}
```

![](assets/graphql_playground_mutation.png)

# Communication style

![](assets/commucation_style.png)

## Debugging the application

Follow steps at [Debugging Dapr application using Tye tool](https://dev.to/thangchung/debugging-dapr-application-using-tye-tool-1djb)

## Setup azure cloud services

- [Publish docker image to ACR and AKS](https://docs.microsoft.com/en-us/azure/dev-spaces/how-to/github-actions) and [example](https://github.com/Azure/dev-spaces/blob/master/.github/workflows/bikes.yml)
Binary file added docs/grpc-server/dapr_grpc_client.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/grpc-server/dapr_grpc_server.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/grpc-server/graphql_dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 16 additions & 19 deletions practical-dapr.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "N8T.Domain", "src\BuildingB
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "__", "__", "{9DCADFAA-8ECD-4959-9320-EE08ECADE524}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitattributes = .gitattributes
.gitignore = .gitignore
global.json = global.json
LICENSE = LICENSE
nuget.config = nuget.config
README.md = README.md
services.json = services.json
tye.yaml = tye.yaml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "GraphApi", "GraphApi", "{5C0DE234-8C59-4ADD-8D43-83CDC84A4A13}"
Expand Down Expand Up @@ -46,16 +48,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Order", "Order", "{BCEFF6E3
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoolStore.OrderApi", "src\Order\CoolStore.OrderApi\CoolStore.OrderApi.csproj", "{1A3DCA3D-6E35-43F8-BD1F-164C9719AC80}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{49AD1C33-D5BC-45C7-B78C-75D11AD86B05}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WebUI", "WebUI", "{2BC95510-F8A7-45EE-B681-AEB3EF543451}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WebUI", "WebUI", "{42D6E17C-BD7A-4499-94F0-13889869F7E8}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoolStore.WebUI", "src\WebUI\CoolStore.WebUI\CoolStore.WebUI.csproj", "{AB351DE3-BEC6-4DA4-9D89-8EA4B0194D1D}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoolStore.WebUI.Host", "src\WebUI\CoolStore.WebUI.Host\CoolStore.WebUI.Host.csproj", "{464235CB-7E36-4015-BF14-99B614938135}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoolStore.WebUI.Host", "src\WebUI\CoolStore.WebUI.Host\CoolStore.WebUI.Host.csproj", "{2796AF2D-0688-4669-BDBC-923353C7DAB0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CoolStore.WebUI", "src\WebUI\CoolStore.WebUI\CoolStore.WebUI.csproj", "{2AF38C8A-7CE1-4C03-B9EF-A7766DDA6FAB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -95,14 +92,14 @@ Global
{1A3DCA3D-6E35-43F8-BD1F-164C9719AC80}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1A3DCA3D-6E35-43F8-BD1F-164C9719AC80}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1A3DCA3D-6E35-43F8-BD1F-164C9719AC80}.Release|Any CPU.Build.0 = Release|Any CPU
{AB351DE3-BEC6-4DA4-9D89-8EA4B0194D1D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AB351DE3-BEC6-4DA4-9D89-8EA4B0194D1D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AB351DE3-BEC6-4DA4-9D89-8EA4B0194D1D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AB351DE3-BEC6-4DA4-9D89-8EA4B0194D1D}.Release|Any CPU.Build.0 = Release|Any CPU
{2796AF2D-0688-4669-BDBC-923353C7DAB0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2796AF2D-0688-4669-BDBC-923353C7DAB0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2796AF2D-0688-4669-BDBC-923353C7DAB0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2796AF2D-0688-4669-BDBC-923353C7DAB0}.Release|Any CPU.Build.0 = Release|Any CPU
{464235CB-7E36-4015-BF14-99B614938135}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{464235CB-7E36-4015-BF14-99B614938135}.Debug|Any CPU.Build.0 = Debug|Any CPU
{464235CB-7E36-4015-BF14-99B614938135}.Release|Any CPU.ActiveCfg = Release|Any CPU
{464235CB-7E36-4015-BF14-99B614938135}.Release|Any CPU.Build.0 = Release|Any CPU
{2AF38C8A-7CE1-4C03-B9EF-A7766DDA6FAB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2AF38C8A-7CE1-4C03-B9EF-A7766DDA6FAB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2AF38C8A-7CE1-4C03-B9EF-A7766DDA6FAB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2AF38C8A-7CE1-4C03-B9EF-A7766DDA6FAB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -123,9 +120,9 @@ Global
{417E233D-4A16-4EA5-A221-A3B879F03E58} = {9814F542-3D82-41B7-BE56-943A5E69278A}
{BCEFF6E3-BD86-4268-B0FF-3797F56EB803} = {A4A723DA-686E-4AF3-8CF8-709E1E75C99C}
{1A3DCA3D-6E35-43F8-BD1F-164C9719AC80} = {BCEFF6E3-BD86-4268-B0FF-3797F56EB803}
{2BC95510-F8A7-45EE-B681-AEB3EF543451} = {A4A723DA-686E-4AF3-8CF8-709E1E75C99C}
{AB351DE3-BEC6-4DA4-9D89-8EA4B0194D1D} = {2BC95510-F8A7-45EE-B681-AEB3EF543451}
{2796AF2D-0688-4669-BDBC-923353C7DAB0} = {2BC95510-F8A7-45EE-B681-AEB3EF543451}
{42D6E17C-BD7A-4499-94F0-13889869F7E8} = {A4A723DA-686E-4AF3-8CF8-709E1E75C99C}
{464235CB-7E36-4015-BF14-99B614938135} = {42D6E17C-BD7A-4499-94F0-13889869F7E8}
{2AF38C8A-7CE1-4C03-B9EF-A7766DDA6FAB} = {42D6E17C-BD7A-4499-94F0-13889869F7E8}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {765FF0DA-E88E-4254-9C2B-434D0AFF69C0}
Expand Down
29 changes: 0 additions & 29 deletions services.json

This file was deleted.

21 changes: 21 additions & 0 deletions src/BuildingBlocks/N8T.Domain/DomainEventBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using MediatR;

namespace N8T.Domain
{
public interface IDomainEvent : INotification
{
DateTime CreatedAt { get; }
}

public interface IDomainEventContext
{
IEnumerable<DomainEventBase> GetDomainEvents();
}

public abstract class DomainEventBase : IDomainEvent
{
public DateTime CreatedAt { get; }
}
}
12 changes: 6 additions & 6 deletions src/BuildingBlocks/N8T.Domain/EntityBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;

namespace N8T.Domain
Expand All @@ -7,17 +7,17 @@ public abstract class EntityBase
{
public DateTime Created { get; protected set; }
public DateTime? Updated { get; protected set; }
public HashSet<IDomainEvent> DomainEvents { get; private set; }
public HashSet<DomainEventBase> DomainEvents { get; private set; }

public void AddDomainEvent(IDomainEvent eventItem)
public void AddDomainEvent(DomainEventBase eventItem)
{
DomainEvents ??= new HashSet<IDomainEvent>();
DomainEvents ??= new HashSet<DomainEventBase>();
DomainEvents.Add(eventItem);
}

public void RemoveDomainEvent(IDomainEvent eventItem)
public void RemoveDomainEvent(DomainEventBase eventItem)
{
DomainEvents?.Remove(eventItem);
}
}
}
}
10 changes: 0 additions & 10 deletions src/BuildingBlocks/N8T.Domain/IDomainEvent.cs

This file was deleted.

Loading

0 comments on commit f097f49

Please sign in to comment.