cart

package
v0.0.0-...-bb960d5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2025 License: MIT Imports: 11 Imported by: 0

README

UC-1: Cart workflows

Events

  • Global Events
    • CreateCustomer - Create a new customer
    • DeleteCustomer - Delete a customer
  • Cart Events
    • AddItems - Add items to cart
    • RemoveItems - Remove items from cart
    • GetCart - Get cart state
    • ResetCart - Reset cart state

State Diagram

@startuml
skinparam state {
    BackgroundColor<<CartState>> Yellow
    BackgroundColor<<Add>> Lime
    BackgroundColor<<Remove>> Tomato
    BackgroundColor<<Get>> Ivory
}

[*] --> Cart : Create customer (event from another service)

state Cart <<CartState>> {
  AddItems<<Add>> -left-> ResettingCart<<Remove>>
  AddItems<<Add>> -down-> RemovingItems<<Remove>>
  AddItems<<Add>> --right--> GetCart<<Get>>
  
  RemovingItems<<Remove>> -up-> AddItems<<Add>>
  RemovingItems<<Remove>> -left-> ResettingCart<<Remove>>
  RemovingItems<<Remove>> -right-> GetCart<<Get>>
  
  GetCart<<Get>> ---> RemovingItems<<Remove>>
  GetCart<<Get>> ---> ResettingCart<<Remove>>
  GetCart<<Get>> --left--> AddItems<<Add>>
  
  ResettingCart<<Remove>> -right-> AddItems<<Add>>
  ResettingCart<<Remove>> -up-> GetCart<<Get>>
  ResettingCart<<Remove>> -left-> RemovingItems<<Remove>>
}

Cart --> [*] : Delete User (event from another service)
@enduml

Sequence Diagram

@startuml
actor User

participant "Temporal Service" as Temporal
participant "Cart Workflow" as CartWF
participant "Cart Service" as CartService

== Create customer ==
User -> Temporal : Create customer
Temporal -> CartWF : Start new workflow
CartWF -> CartService : Initialize cart for new customer (user_id)
CartService --> CartWF : Cart initialized
CartWF -> Temporal : Workflow completed

== Add items to cart ==
User -> Temporal : Add(AddRequest)
note right: AddRequest {\n user_id: string,\n item: [CartItem] {\n product_id: string,\n quantity: int32\n }\n}
Temporal -> CartWF : Start add item workflow
CartWF -> CartService : Add(AddRequest)
CartService --> CartWF : Item(s) added
CartWF -> Temporal : Workflow completed

== Remove items from cart ==
User -> Temporal : Remove(RemoveRequest)
note right: RemoveRequest {\n user_id: string,\n item: [CartItem] {\n product_id: string,\n quantity: int32\n }\n}
Temporal -> CartWF : Start remove item workflow
CartWF -> CartService : Remove(RemoveRequest)
CartService --> CartWF : Item(s) removed
CartWF -> Temporal : Workflow completed

== Get cart state ==
User -> Temporal : Get(GetRequest)
note right: GetRequest {\n user_id: string\n}
Temporal -> CartWF : Start get cart workflow
CartWF -> CartService : Get(GetRequest)
CartService --> CartWF : GetResponse (CartState)
note right: GetResponse {\n state: CartState {\n cart_id: string,\n user_id: string,\n items: [CartItem],\n created_at: Timestamp,\n updated_at: Timestamp\n }\n}
CartWF --> Temporal : GetResponse (CartState)
Temporal --> User : GetResponse (CartState)

== Reset cart ==
User -> Temporal : Reset(ResetRequest)
note right: ResetRequest {\n user_id: string\n}
Temporal -> CartWF : Start reset cart workflow
CartWF -> CartService : Reset(ResetRequest)
CartService --> CartWF : Cart reset
CartWF -> Temporal : Workflow completed

== Delete customer ==
User -> Temporal : Delete User
Temporal -> CartWF : Start delete workflow
CartWF -> CartService : Delete customer cart (user_id)
CartService --> CartWF : Cart deleted
CartWF -> Temporal : Workflow completed

@enduml

Documentation

Overview

OMS UC. Application layer

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type UC

type UC struct {
	// contains filtered or unexported fields
}

func New

func New(log logger.Logger, permissionClient *authzed.Client, temporalClient client.Client) (*UC, error)

New creates a new cart usecase

func (*UC) Add

func (uc *UC) Add(ctx context.Context, in *v1.CartState) error

Add adds an item to the cart.

func (*UC) Get

func (uc *UC) Get(ctx context.Context, customerId uuid.UUID) (*v1.CartState, error)

Get gets the cart.

func (*UC) Remove

func (uc *UC) Remove(ctx context.Context, in *domain.CartState) error

Remove removes items from the cart.

func (*UC) Reset

func (uc *UC) Reset(ctx context.Context, customerId uuid.UUID) error

Reset resets the cart.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL