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

     1  package controller
     2  
     3  import (
     4  	"context"
     5  
     6  	"flamingo.me/flamingo-commerce/v3/category/domain"
     7  	"flamingo.me/flamingo/v3/framework/web"
     8  )
     9  
    10  type (
    11  	// Tree controller for category tree retrieval
    12  	Tree struct {
    13  		categoryService domain.CategoryService
    14  	}
    15  
    16  	// Entity controller for category entity retrieval
    17  	Entity struct {
    18  		categoryService domain.CategoryService
    19  	}
    20  )
    21  
    22  // Inject the Tree controller required dependencies
    23  func (controller *Tree) Inject(service domain.CategoryService) {
    24  	controller.categoryService = service
    25  }
    26  
    27  // Data controller for category trees
    28  func (controller *Tree) Data(c context.Context, r *web.Request, params web.RequestParams) interface{} {
    29  	code := params["code"] // no err check, empty code is fine if not set
    30  
    31  	treeRoot, _ := controller.categoryService.Tree(c, code)
    32  
    33  	return treeRoot
    34  }
    35  
    36  // Inject the Entity controller required dependencies
    37  func (controller *Entity) Inject(service domain.CategoryService) {
    38  	controller.categoryService = service
    39  }
    40  
    41  // Data controller for category entities
    42  func (controller *Entity) Data(c context.Context, r *web.Request, params web.RequestParams) interface{} {
    43  	code := params["code"] // no err check, empty code is fine if not set
    44  
    45  	category, _ := controller.categoryService.Get(c, code)
    46  
    47  	return category
    48  }