Order Service
Contains application logic for recording and reporting orders.
- Path
docs/examples/order_service/src/service.gb- Category
- Order Service
Services coordinate domain objects and repositories while keeping the entrypoint small.
Source
module order_service.src.service;
import order_service.src.domain as domain;
export class OrderService {
any repo;
func OrderService(any repo) {
this.repo = repo;
}
func record(string id, string customer, int totalCents): domain.Order {
let order = domain.Order(id, customer, totalCents);
this.repo.add(order);
return order;
}
func revenue(): int {
int total = 0;
for (order in this.repo.all()) {
total = total + order.totalCents;
}
return total;
}
}
export func newService(any repo): OrderService {
return OrderService(repo);
}