Skip to content

Instantly share code, notes, and snippets.

@CharlesWinter
Created January 22, 2021 16:05
Show Gist options
  • Select an option

  • Save CharlesWinter/dd7b5bcc41dbddb48113b19966c52e2f to your computer and use it in GitHub Desktop.

Select an option

Save CharlesWinter/dd7b5bcc41dbddb48113b19966c52e2f to your computer and use it in GitHub Desktop.
Usecase after adding the new customer booking counter
package usecases
import "github.com/example/go-abstractions/entities"
type CustomerGetter interface {
GetCustomer(customerID uint) (entities.Customer, error)
}
type CustomerBookingsCounter interface {
CountCustomerBookings(customerID uint) (uint, error)
}
func NewGetCustomerUseCase(customerGetter CustomerGetter, customerBookingsCounter CustomerBookingsCounter) func(uint) (entities.Customer, error) {
return func(customerID uint) (entities.Customer, error) {
customer, err := customerGetter.GetCustomer(customerID)
if err != nil {
return entities.Customer{}, err
}
numberBookings, err := customerBookingsCounter.CountCustomerBookings(customerID)
if err != nil {
return entities.Customer{}, err
}
customer.NumberBookings = numberBookings
return customer, nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment