Created
January 22, 2021 16:05
-
-
Save CharlesWinter/dd7b5bcc41dbddb48113b19966c52e2f to your computer and use it in GitHub Desktop.
Usecase after adding the new customer booking counter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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