Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. package internal
  2.  
  3. type Service interface {
  4. GetAll(productType string) []Product
  5. }
  6.  
  7. type productService struct {
  8. repository Repository
  9. }
  10.  
  11. func NewProductService(productRepository Repository) Service {
  12. return productService{repository: productRepository}
  13. }
  14.  
  15. func (ps productService) GetAll(productType string) []Product {
  16. products := ps.repository.Get()
  17. var specificProducts []Product
  18. for _, product := range products {
  19. if product.ProductType == productType {
  20. specificProducts = append(specificProducts, product)
  21. }
  22. }
  23. return specificProducts
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement