Skip to content

ECommerce Service

In order to help you build your own Solution, find below an example of a complete and functional YAML model. It contains all sections that can serve as the foundation for your project.

This model example reflects a real use case for the eCommerce Service, which is intended to perform certain registration operations (CRUD) and customized queries to the database.

The features of this solution are:

  • Customer registration;
  • Product and Category registration;
  • Purchase order registration;
  • OData Query Controllers for customized data queries;
  • User interface project/application for specified CRUD services

YAML Example:

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
Name: ECommerce # Solution name
RootNamespace: Sample.ECommerce # Solution root namespace

# Business entities

Entities:
- Name: Metatag1
  Properties:
  - Name: Keywords
    Type: string
  - Name: Description
    Type: string

- Name: Category
  KeyType: int
  Properties:
  - Name: Name
    Type: string
  - Name: Order
    Type: int
  - Name: Metatag
    Type: Metatag1
  - Name: Property
    Type: '[string]'
  - Name: Products
    Type: '[Product]' # Determines a relationship OneToMany with Product

- Name: Product
  KeyType: int
  Properties:
  - Name: Name
    Type: string
  - Name: Price
    Type: decimal
  - Name: Start_Promotion
    Type: DateTimeOffset
  - Name: End_Promotion
    Type: DateTimeOffset
  - Name: Category
    Type: Category # Determines a relationship OneToOne with Category
  - Name: Category_id
    Type: int
  - Name: ProductsSold
    Type: '[ProductSold]'

- Name: CustomerAddress
  KeyType: int
  Properties:
  - Name: Address
    Type: string
  - Name: Number
    Type: int
  - Name: City
    Type: string
  - Name: State
    Type: string
  - Name: Zip_Code
    Type: string
  - Name: Country
    Type: string
  - Name: Type
    Type: int
  - Name: Customer
    Type: Customer
  - Name: Customer_id
    Type: int

- Name: Customer
  KeyType: int
  Properties:
  - Name: Name
    Type: string
  - Name: Type
    Type: int
  - Name: Cpf
    Type: string
  - Name: Cnpj
    Type: string
  - Name: CustomerAddresses
    Type: '[CustomerAddress]'
  - Name: Orders
    Type: '[Order]'

- Name: ProductSold
  KeyType: int
  Properties:
  - Name: Order
    Type: Order
  - Name: Order_id
    Type: int
  - Name: Product
    Type: Product
  - Name: Product_id
    Type: int
  - Name: Price
    Type: decimal
  - Name: Quantity
    Type: int

- Name: Order
  KeyType: int
  Properties:
  - Name: Shipment
    Type: string
  - Name: Shipment_Value
    Type: decimal
  - Name: Discount
    Type: decimal
  - Name: Customer
    Type: Customer
  - Name: Customer_id
    Type: int
  - Name: ProductsSold
    Type: '[ProductSold]'

# Database instance types

DbInstances:
- Name: MyDbInstance01
  Type: SqlServer

# One database for all services

Databases:
- Name: MyDb01
  DbInstanceName: MyDbInstance01

# Identity Server configuration section

IdentityConfig:
  DatabaseName: MyDb01 # The database for Identity Server data storage

# Database data contexts

DbContexts:
- Name: Ctx01
  DatabaseName: MyDb01
  DbMappings: # Mapping between Entity and Database Tables
  - Name: CategoryDbMapping
    EntityName: Category
    Relationships:
    - ChildEntityName: Product
      ParentPropertyName: Products
      ChildPropertyName: Category
      Type: OneToMany
      ForeignKeyProperty: Category_id

  - Name: ProductDbMapping
    EntityName: Product
    Relationships:
    - ChildEntityName: ProductSold
      ParentPropertyName: ProductsSold
      ChildPropertyName: Product
      Type: OneToMany
      ForeignKeyProperty: Product_id

  - Name: CustomerDbMapping
    EntityName: Customer
    Relationships:
    - ChildEntityName: CustomerAddress
      ParentPropertyName: CustomerAddresses
      ChildPropertyName: Customer
      Type: OneToMany
      ForeignKeyProperty: Customer_id

    - ChildEntityName: Order
      ParentPropertyName: Orders
      ChildPropertyName: Customer
      Type: OneToMany
      ForeignKeyProperty: Customer_id

  - Name: CustomerAddressDbMapping
    EntityName: CustomerAddress

  - Name: OrderDbMapping
    EntityName: Order
    Relationships:
    - ChildEntityName: ProductSold
      ParentPropertyName: ProductsSold
      ChildPropertyName: Order
      Type: OneToMany
      ForeignKeyProperty: Order_id

  - Name: ProductSoldDbMapping
    EntityName: ProductSold

# Data access repository pattern

Repositories:
- Name: Repo01
  DbContextName: Ctx01
  EntityName: Category

- Name: Repo02
  DbContextName: Ctx01
  EntityName: Product

- Name: Repo03
  DbContextName: Ctx01
  EntityName: Customer

- Name: Repo04
  DbContextName: Ctx01
  EntityName: CustomerAddress

- Name: Repo05
  DbContextName: Ctx01
  EntityName: Order

- Name: Repo06
  DbContextName: Ctx01
  EntityName: ProductSold

# Validations rules for the business entity

EntityValidations:
- Name: ProductValidation_1
  Type: PropertyValidation
  EntityName: Product
  PropertyValidationParams:
  - PropertyName: Start_Promotion
    StopOnFirstRuleFailure: true
    Rules: # Pre-defined types that run sequentially
    - Type: IsNotEmpty
      Message: 'start_promotion is required'

    - Type: IsGreaterThan
      Expressions:
      - Value(@UtcToday) # Expression to get the current date
      Message: 'start_promotion must be greater than current date'

  - PropertyName: End_Promotion
    StopOnFirstRuleFailure: true
    Rules:
    - Type: IsNotEmpty
      Message: 'end_promotion is required'

    - Type: IsGreaterThan
      Expressions:
      - Value(@Prop::Start_Promotion) # Expression to get the value of another property
      Message: 'end_promotion must be greater than start_promotion'

- Name: IsCpfType
  Type: PropertyValidation
  EntityName: Customer
  PropertyValidationParams:
  - PropertyName: Type
    Rules:
    - Type: IsEqual
      Expressions:
      - Value(@ConstInt::1) # Expression to get the number 1 as constant

- Name: IsCnpjType
  Type: PropertyValidation
  EntityName: Customer
  PropertyValidationParams:
  - PropertyName: Type
    Rules:
    - Type: IsEqual
      Expressions:
      - Value(@ConstInt::2) # Expression to get the number 2 as constant

- Name: CustomerValidCPF
  Type: PropertyValidation
  EntityName: Customer
  PropertyValidationParams:
  - PropertyName: Cpf
    Rules:
    - Type: IsCpf
      Message: 'invalid CPF'

- Name: CustomerValidCnpj
  Type: PropertyValidation
  EntityName: Customer
  PropertyValidationParams:
  - PropertyName: Cnpj
    Rules:
    - Type: IsCnpj
      Message: 'invalid CNPJ'

# Services and Controllers (CRUD and QUERY)

Services:
- Name: OrderService
  Type: WebAPI
  Controllers:
  - Name: Category # Category registration
    Type: CRUD
    RepositoryName: Repo01
    EntityName: Category
    Contexts:
    - Context: Create
      Rules: # Business rules performed only for the "Create" context
      - Name: AddInRepository
        Type: WriteOperationRule # Executes a business rule for persisting data in the database
        Order: 1

    - Context: Update
      Rules:
      - Name: UpdateInRepository
        Type: WriteOperationRule
        Order: 1

    - Context: UpdatePartial
      Rules:
      - Name: UpdateInRepository
        Type: WriteOperationRule
        Order: 1

    - Context: Delete
      Rules:
      - Name: DeleteInRepository
        Type: WriteOperationRule
        Order: 1

    - Context: ReadAll
      Rules:
      - Name: ReadInRepository
        Type: ReadOperationRule # Executes a business rule for reading data from the database
        Order: 1

    - Context: ReadByKey
      Rules:
      - Name: ReadInRepository
        Type: ReadOperationRule
        Order: 1

  - Name: Product # Product registration
    Type: CRUD
    RepositoryName: Repo02
    EntityName: Product
    Contexts:
    - Context: Create
      Validations: # Validations performed only for the "Create" context
      - Name: ProductValidation
        Type: EntityValidation
        Order: 1
        ExecValidationName: ProductValidation_1 # Executes an EntityValidation type
      Rules:
      - Name: AddInRepository
        Type: WriteOperationRule
        Order: 1

    - Context: Update
      Rules:
      - Name: UpdateInRepository
        Type: WriteOperationRule
        Order: 1

    - Context: UpdatePartial
      Rules:
      - Name: UpdateInRepository
        Type: WriteOperationRule
        Order: 1

    - Context: Delete
      Rules:
      - Name: DeleteInRepository
        Type: WriteOperationRule
        Order: 1

    - Context: ReadAll
      Rules:
      - Name: ReadInRepository
        Type: ReadOperationRule
        Order: 1

    - Context: ReadByKey
      Rules:
      - Name: ReadInRepository
        Type: ReadOperationRule
        Order: 1

  - Name: Customer # Customer registration
    Type: CRUD
    RepositoryName: Repo03
    EntityName: Customer
    Contexts:
    - Context: Create
      Validations:
      - Name: CustomerValidCPF
        Type: EntityValidation
        Order: 1
        ExecValidationName: CustomerValidCPF # This validation is performed only if the conditional is valid
        ConditionalValidationName: IsCpfType # Conditional: Validates the CPF only if the customer type is "1-CPF"

      - Name: CustomerValidCnpj
        Type: EntityValidation
        Order: 2
        ExecValidationName: CustomerValidCnpj
        ConditionalValidationName: IsCnpjType
      Rules:
      - Name: AddInRepository
        Type: WriteOperationRule
        Order: 1

    - Context: Update
      Rules:
      - Name: UpdateInRepository
        Type: WriteOperationRule
        Order: 1

    - Context: UpdatePartial
      Rules:
      - Name: UpdateInRepository
        Type: WriteOperationRule
        Order: 1

    - Context: Delete
      Rules:
      - Name: DeleteInRepository
        Type: WriteOperationRule
        Order: 1

    - Context: ReadAll
      Rules:
      - Name: ReadInRepository
        Type: ReadOperationRule
        Order: 1

    - Context: ReadByKey
      Rules:
      - Name: ReadInRepository
        Type: ReadOperationRule
        Order: 1

  - Name: CustomerAddress
    Type: CRUD
    RepositoryName: Repo04
    EntityName: CustomerAddress
    Contexts:
    - Context: Create
      Rules:
      - Name: AddInRepository
        Type: WriteOperationRule
        Order: 1

    - Context: Update
      Rules:
      - Name: UpdateInRepository
        Type: WriteOperationRule
        Order: 1

    - Context: UpdatePartial
      Rules:
      - Name: UpdateInRepository
        Type: WriteOperationRule
        Order: 1

    - Context: Delete
      Rules:
      - Name: DeleteInRepository
        Type: WriteOperationRule
        Order: 1

    - Context: ReadAll
      Rules:
      - Name: ReadInRepository
        Type: ReadOperationRule
        Order: 1

    - Context: ReadByKey
      Rules:
      - Name: ReadInRepository
        Type: ReadOperationRule
        Order: 1

  - Name: Order # Purchase order registration
    Type: CRUD
    RepositoryName: Repo05
    EntityName: Order
    Contexts:
    - Context: Create
      Rules:
      - Name: AddInRepository
        Type: WriteOperationRule
        Order: 1

    - Context: Update
      Rules:
      - Name: UpdateInRepository
        Type: WriteOperationRule
        Order: 1

    - Context: UpdatePartial
      Rules:
      - Name: UpdateInRepository
        Type: WriteOperationRule
        Order: 1

    - Context: Delete
      Rules:
      - Name: DeleteInRepository
        Type: WriteOperationRule
        Order: 1

    - Context: ReadAll
      Rules:
      - Name: ReadInRepository
        Type: ReadOperationRule
        Order: 1

    - Context: ReadByKey
      Rules:
      - Name: ReadInRepository
        Type: ReadOperationRule
        Order: 1

  - Name: ProductSold
    Type: CRUD
    RepositoryName: Repo06
    EntityName: ProductSold
    Contexts:
    - Context: Create
      Rules:
      - Name: AddInRepository
        Type: WriteOperationRule
        Order: 1

    - Context: Update
      Rules:
      - Name: UpdateInRepository
        Type: WriteOperationRule
        Order: 1

    - Context: UpdatePartial
      Rules:
      - Name: UpdateInRepository
        Type: WriteOperationRule
        Order: 1

    - Context: Delete
      Rules:
      - Name: DeleteInRepository
        Type: WriteOperationRule
        Order: 1

    - Context: ReadAll
      Rules:
      - Name: ReadInRepository
        Type: ReadOperationRule
        Order: 1

    - Context: ReadByKey
      Rules:
      - Name: ReadInRepository
        Type: ReadOperationRule
        Order: 1

  - Name: OrderQ
    Type: Query # OData Query pattern for custom queries
    RepositoryName: Repo05
    EntityName: Order

OData Example

1
2
3
4
5
6
7
8
9
## OData Query Sample:
...

  - Name: OrderQ
    Type: Query
    RepositoryName: Repo05
    EntityName: Order

...

Expand Request Example

1
https://loadbalancer.bea.internal:44300/ecommerce/odata/OrderQQuery?$expand=Customer($expand=CustomerAddresses),ProductsSold($expand=Product)

Response

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
{ 
    "@odata.context": "https://loadbalancer.bea.internal:44300/orderservice/odata/$metadata#OrderQQuery(Customer(CustomerAddresses()),ProductsSold(Product()))",
    "value": [
        {
            "Id": 1,
            "shipment": "Sedex",
            "shipment_value": 12.00,
            "discount": 2.90,
            "customer_id": 1,
            "Customer": {
                "Id": 1,
                "name": "test customer",
                "type": 1,
                "cpf": "80544235002",
                "cnpj": null,
                "CustomerAddresses": [
                    {
                        "Id": 1,
                        "address": "test address",
                        "number": 456,
                        "city": "test city",
                        "state": "SP",
                        "zip_code": "04001-001",
                        "country": "BRA",
                        "type": 1,
                        "customer_id": 1
                    }
                ]
            },
            "ProductsSold": [
                {
                    "Id": 1,
                    "order_id": 1,
                    "product_id": 1,
                    "price": 42.90,
                    "quantity": 2,
                    "Product": {
                        "Id": 1,
                        "name": "test product",
                        "price": 0.01,
                        "start_promotion": "2022-05-13T00:00:00Z",
                        "end_promotion": "2022-05-14T00:00:00Z",
                        "category_id": 1
                    }
                }
            ]
        }
    ]
}

Back to top