الـ Services: منطق العمل والتنسيق
في هذا الدرس 4 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
place rules and workflows in the service.
الموضوعات المخطط لها
- A service holds business rules and coordinates repositories and other services.
- It works with domain objects and plain values, not HTTP types.
- A service never returns
ResponseEntityor reads request headers. - Keep services stateless (JNR-010).
تفاصيل المخطط المبدئي
عرض عملي
@Service
class ProductService {
private final ProductRepository repo;
ProductService(ProductRepository repo) { this.repo = repo; }
ProductResponse get(long id) {
return ProductMapper.toResponse(repo.findById(id).orElseThrow(() -> new ProductNotFound(id)));
}
}اختبر فهمك
Should a service return ResponseEntity?
أظهر الإجابة
No; that is an HTTP concern for the edge.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.