Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RyanBalfanz/e6fab94b0a8e8aeb0ff9af5f2d948ef4 to your computer and use it in GitHub Desktop.
Save RyanBalfanz/e6fab94b0a8e8aeb0ff9af5f2d948ef4 to your computer and use it in GitHub Desktop.
Our repository method for counting customer bookings
package bookings
type Repository struct {
// in reality, this client will likely be something we generate from a
// schema, or implement ourselves if needs be. Its not discussed here for
// conciseness
client bookingsServiceClient
}
type booking struct {
ID uint `json:"id"`
}
func (r *Repository) CountCustomerBookings(customerID uint) (uint, error) {
// we make a request to the bookings service here. This is done in pseudocode
// so as not to get bogged down in the details.
bookings, err := r.client.GetCustomerBookings(customerID)
var numBookings uint = len(bookings)
return numBookings, err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment