dto-implementation
/dto-implementation
Opisuje zasady implementacji DTO w projekcie HMIS: konstruktory, zapytania JPQL, metody fasad, relacje null i raporty oparte na DTO.
Ocena i bezpieczeństwo
- Pliki w paczce
- 1
- Skrypty
- 0
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 0
Brak sygnałów. Repozytorium zmienione 26.10.2026, bez odwołań do wycofanych modeli i API.
GPL-3.0, otwarta.
Co robi i kiedy
Opisuje zasady implementacji DTO w projekcie HMIS: konstruktory, zapytania JPQL, metody fasad, relacje null i raporty oparte na DTO.
Oryginalny opis (EN)
DTO implementation guidelines for the HMIS project. Use when creating or modifying DTOs, writing JPQL constructor queries, implementing DTO-based reports, converting entity code to DTO patterns, or troubleshooting DTO query issues. Covers constructor rules, facade methods, null relationship handling, and navigation patterns.
Jak działa
- Critical Rules
- Direct DTO Query Pattern
- Navigation Pattern: Use IDs, Not Entities
- Null Relationship Handling
- Constructor Rules
- Common Non-Persisted Properties (Cannot Use in JPQL)
Podgląd SKILL.md
---
name: dto-implementation
description: >
DTO implementation guidelines for the HMIS project. Use when creating or modifying DTOs,
writing JPQL constructor queries, implementing DTO-based reports, converting entity code
to DTO patterns, or troubleshooting DTO query issues. Covers constructor rules, facade
methods, null relationship handling, and navigation patterns.
user-invocable: true
---
# DTO Implementation Guidelines
## Critical Rules
1. **NEVER modify existing constructors** - only add new ones
2. **Use direct DTO queries** - avoid entity-to-DTO conversion loops
3. **JPQL PERSISTED FIELDS ONLY**: NEVER use derived properties like `nameWithTitle`, `age`, `displayName` in JPQL
## Direct DTO Query Pattern
```java
// CORRECT - Direct DTO query from database
String jpql = "SELECT new com.divudi.core.data.dto.StockDTO("
+ "s.id, s.itemBatch.item.name, s.itemBatch.item.code, "
+ "s.itemBatch.retailsaleRate, s.stock, "
+ "s.itemBatch.dateOfExpire, s.itemBatch.batchNo) "
+ "FROM Stock s WHERE ...";
// MUST use findLightsByJpql() with cast
List<StockDTO> dtos = (List<StockDTO>) facade.findLightsByJpql(jpql, params, TemporalType.TIMESTAMP);
```
```java
// WRONG - Never do entity-to-DTO loops
List<Stock> stocks = stockFacade.findByJpql(sql, params);
List<StockDTO> dtos = new ArrayList<>();
for (Stock stock : stocks) { dtos.add(new StockDTO(stock.getField1(), ...)); }
```
## Navigation Pattern: Use IDs, Not Entities
```java
// CORRECT - IDs and names for navigation
public class OpdSaleSummaryDTO {
private Long categoryId; // For navigation
private String categoryName; // For display
private Long itemId; // For navigation
private String itemName; // For display
private Double total;
}
```
## Null Relationship Handling
Accessing properties through nullable relationships causes **silent query failures** (0 results, no exception):
```java
// WRONG - Fails silently if cancelledBill is null
"b.cancelledBill.createdAt"
// CORRECT - Use LEFT JOIN
"FROM Bill b LEFT JOIN b.cancelledBill cb "
// Then use cb.createdAt with COALESCE
```
## Constructor Rules
- Always use **wrapper types** (`Boolean`, `Integer`, `Long`) for null safety
- Parameter count and order must match JPQL SELECT exactly
- Keep existing constructors intact; add new ones
## Common Non-Persisted Properties (Cannot Use in JPQL)
| Entity | Non-Persisted | Use Instead |
|--------|--------------|-------------|
| Person | nameWithTitle | name (or title, name separately) |
| Person | age | dob (calculate in Java) |
| Item | displayName | name |
For complete reference, read [developer_docs/dto/implementation-guidelines.md](../../../developer_docs/dto/implementation-guidelines.md).
Wersje
| Repozytorium | Wynik | Licencja |
|---|---|---|
| Ta strona · hmislk/hmis | 100 | GPL-3.0 |
| hmislk/hmis | 100 | GPL-3.0 |
Migawka bazy z 13.11.2026 · wersja paczki 45e4851bc3b6 (skrót SHA-256 całej paczki)
Pobrania w ostatnich 30 dniach: 1 · ranking
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 95dto-sync-patterns
Opisuje wzorce synchronizacji DTO między frontendem a backendem: współdzielone typy, generowanie kodu i synchronizację walidacji. - 100laravel-dto
Tworzy obiekty DTO w Laravel i PHP z bazową klasą SimpleDto oraz mapowaniem atrybutów. - 100dto-and-validation
Pomaga tworzyć DTO żądań i odpowiedzi w Symfony, stosować ograniczenia Validatora, mapować dane przez MapRequestPayload i MapQueryString oraz mapować DTO na encje i z powrotem. - 100add-dto
Dodaje DTO, czyli kształt żądania lub odpowiedzi wystawiany przez publiczne API narzędziom MCP, w api/public/dto, a typy wewnętrzne trzyma w contracts/. - 100documenting-contracts
Dokumentuje interfejsy maszynowe: API HTTP, ładunki wiadomości, kontrakty kolejek, DTO, formaty plików i webhooki, z czterema poziomami szczegółu, katalogiem DTO, typami wire i semantyką pominięcia kontra null. - 95zod-patterns
Stosuje wzorce schematów Zod z projektu Mix Space przy tworzeniu DTO i walidacji żądań.