package com.project.beautycenter.service.impl; import com.project.beautycenter.model.Uslugi; import com.project.beautycenter.model.Vraboteni; import com.project.beautycenter.model.VraboteniUslugi; import com.project.beautycenter.repository.UslugiRepository; import com.project.beautycenter.repository.VraboteniRepository; import com.project.beautycenter.repository.VraboteniUslugiRepository; import com.project.beautycenter.service.VraboteniUslugiService; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.List; @Service public class VraboteniUslugiServiceImpl implements VraboteniUslugiService { private final VraboteniUslugiRepository repository; private final UslugiRepository uslugiRepository; private final VraboteniRepository vraboteniRepository; public VraboteniUslugiServiceImpl(VraboteniUslugiRepository repository, UslugiRepository uslugiRepository, VraboteniRepository vraboteniRepository) { this.repository = repository; this.uslugiRepository = uslugiRepository; this.vraboteniRepository = vraboteniRepository; } @Override public List listAll() { return this.repository.findAll(); } @Override public List listByUsluga(Uslugi u) { return this.repository.findAllByUsluga(u); } @Override public List deletebyUsluga(String id) { Uslugi uslugi = this.uslugiRepository.getById(id); List vraboteniUslugi = this.repository.findAllByUsluga(uslugi); for (var i = 0; i < vraboteniUslugi.size(); i++) { this.repository.delete(vraboteniUslugi.get(i)); } return vraboteniUslugi; } public List getVraboteniByUsluga(Uslugi usluga) { List vrabUsluga = this.repository.findAllByUsluga(usluga); List vraboteni = this.vraboteniRepository.findAll(); List listOutput = new ArrayList<>(); for (var i = 0; i < vrabUsluga.size(); i++) { for (var j = 0; j < vraboteni.size(); j++) { if (vrabUsluga.get(i).getUserIdVraboten() == vraboteni.get(j)) listOutput.add(vrabUsluga.get(i).getUserIdVraboten()); } } return listOutput; } }