Ukázková Architektura

Začínáme logickou strukturou softwaru, která definuje všechny podstatné komponenty, jejich vlastnosti a reakce.

Ukázkový Backend

Druhým krokem je napsat v Javě nebo Kotlinu takový kód, aby komunikace s databází proběhla při každé akci uživatele bez mrknutí.

				
					extend type Query {
    getCurrencies: [CurrencyTO]
    getI0Wizard (wizardId: String!): I0WizardTO
} 
				
			
				
					input IOWizardInput{ 
    id: String!
    adminEmails: [String]! #Send only editable emails. 
    periodType: EPeriodType
    periodStart: Instant
    baseCurrency: String
    domainName: String
    warehouseName: String 
    safetyStock: Boolean 
    planType: EPLanType
}
				
			
				
					extend type Mutation {
    saveI0Wizard(wizard: IOWizardInput):I0WizardTO
} 

				
			
				
					type IOWizardTO{
    id: String!
    domainName: String 
    domainEditable: Boolean 
    adminEmails: [EmailTo]! 
    periodType: EPeriodType 
    periodStart: Instant 
    baseCurrency: String 
    warehouseName: String 
    safetyStock: Boolean 
    planType: EPLanType
}
				
			
				
					@Component
@RequiredArgsConstructor
public class IOWizardMutationResolver implements GraphQLMutationResolver {
    private final OnboardWizardService wizardService;
    private final TenantService tenantService;
    
    @PreAuthorize ("isAnonymous()")
    @Transactional
    public I0WizardTO saveI0Wizard(I0WizardInput wizard) {
        I0Wizard wizardEntity = mapToEntity(wizard);
        Tenant tenant = wizardEntity.getTenant();
        
        if (tenant.isDomainNameEditable() && (wizard.getDomainName () != null)) {
            String domain = wizard.getDomainName();
            if (!tenantService.isDomainNameFree (domain) && !domain.equals (tenant.getDomainName()))
                throw new IllegalArgumentException("Domain is already used!", domain);
                    
            tenant.setDomainName(domain);
        }
        wizardService.saveWizard(wizardEntity);
            
        return I0WizardTO.fromEntity(wizardEntity);
    }
				
			
				
					@Component
@RequiredArgsConstructor
public class I0WizardQueryResolver implements GraphQLQueryResolver {

private final OnboardWizardService wizardService;

    @PreAuthorize ("isAnonymous()")
    public IOWizardTO getI0Wizard(String wizardId) {
        return IOWizardTO.fromEntity((I0Wizard) wizardService.getWizardById(wizardId)
            .filter(t -> EWizardStatus.IN_PROGRESS.equals(t.getWizardStatus()))
            .filter(t -> t instanceof I0Wizard)
            .orElseThrow(C) -> new NotFoundException ("Wizard not found.", IOWizardTo.class.getSimpleName(), wizardId))
        );
    }
}
				
			
				
					@Slf4j
@RequiredArgsConstructor
public abstract class AbstractOnboardWizardService<T extends OnboardWizard> implements OnboardWizardService {

    protected final OnboardWizardRepository wizardRepository;
    
    @Override
    public Optional<OnboardWizard> getWizardById (String wizardId) {
        return wizardRepository.findById(wizardId);
    }
    
    @Override
    public void saveWizard (OnboardWizard wizard) {
        this.wizardRepository.saveAndFlush(wizard);
    }
}
				
			

Ukázkový Frontend

Nakonec tvoříme s MUI krásná grafická rozhraní, ve kterých se koncový uživatel cítí jako doma i mimo homepage.