flamingo.me/flamingo-commerce/v3@v3.11.0/order/interfaces/controller/data.go (about)

     1  package controller
     2  
     3  import (
     4  	"context"
     5  
     6  	"flamingo.me/flamingo/v3/core/auth"
     7  	"flamingo.me/flamingo/v3/framework/web"
     8  
     9  	"flamingo.me/flamingo-commerce/v3/order/domain"
    10  )
    11  
    12  type (
    13  	// DataControllerCustomerOrders for `get("orders.customerorders", ...)` requests
    14  	DataControllerCustomerOrders struct {
    15  		customerIdentityOrderService domain.CustomerIdentityOrderService
    16  		webIdentityService           *auth.WebIdentityService
    17  	}
    18  )
    19  
    20  // Inject dependencies
    21  func (dc *DataControllerCustomerOrders) Inject(
    22  	customerIdentityOrderService domain.CustomerIdentityOrderService,
    23  	webIdentityService *auth.WebIdentityService,
    24  ) {
    25  	dc.customerIdentityOrderService = customerIdentityOrderService
    26  	dc.webIdentityService = webIdentityService
    27  }
    28  
    29  // Data controller for blocks
    30  func (dc *DataControllerCustomerOrders) Data(ctx context.Context, r *web.Request, _ web.RequestParams) interface{} {
    31  	identity := dc.webIdentityService.Identify(ctx, r)
    32  	if identity == nil {
    33  		return nil
    34  	}
    35  
    36  	customerOrders, _ := dc.customerIdentityOrderService.Get(ctx, identity)
    37  
    38  	return customerOrders
    39  }