1 | package com.project.beautycenter.service.impl;
|
---|
2 |
|
---|
3 | import com.project.beautycenter.model.Uslugi;
|
---|
4 | import com.project.beautycenter.model.Vraboteni;
|
---|
5 | import com.project.beautycenter.model.VraboteniUslugi;
|
---|
6 | import com.project.beautycenter.repository.UslugiRepository;
|
---|
7 | import com.project.beautycenter.repository.VraboteniRepository;
|
---|
8 | import com.project.beautycenter.repository.VraboteniUslugiRepository;
|
---|
9 | import com.project.beautycenter.service.VraboteniUslugiService;
|
---|
10 | import org.springframework.stereotype.Service;
|
---|
11 |
|
---|
12 | import java.util.ArrayList;
|
---|
13 | import java.util.List;
|
---|
14 |
|
---|
15 | @Service
|
---|
16 | public class VraboteniUslugiServiceImpl implements VraboteniUslugiService {
|
---|
17 |
|
---|
18 | private final VraboteniUslugiRepository repository;
|
---|
19 | private final UslugiRepository uslugiRepository;
|
---|
20 | private final VraboteniRepository vraboteniRepository;
|
---|
21 |
|
---|
22 | public VraboteniUslugiServiceImpl(VraboteniUslugiRepository repository, UslugiRepository uslugiRepository, VraboteniRepository vraboteniRepository) {
|
---|
23 | this.repository = repository;
|
---|
24 | this.uslugiRepository = uslugiRepository;
|
---|
25 | this.vraboteniRepository = vraboteniRepository;
|
---|
26 | }
|
---|
27 |
|
---|
28 | @Override
|
---|
29 | public List<VraboteniUslugi> listAll() {
|
---|
30 | return this.repository.findAll();
|
---|
31 | }
|
---|
32 |
|
---|
33 | @Override
|
---|
34 | public List<VraboteniUslugi> listByUsluga(Uslugi u) {
|
---|
35 | return this.repository.findAllByUsluga(u);
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Override
|
---|
39 | public List<VraboteniUslugi> deletebyUsluga(String id) {
|
---|
40 | Uslugi uslugi = this.uslugiRepository.getById(id);
|
---|
41 | List<VraboteniUslugi> vraboteniUslugi = this.repository.findAllByUsluga(uslugi);
|
---|
42 | for (var i = 0; i < vraboteniUslugi.size(); i++) {
|
---|
43 | this.repository.delete(vraboteniUslugi.get(i));
|
---|
44 | }
|
---|
45 | return vraboteniUslugi;
|
---|
46 | }
|
---|
47 |
|
---|
48 | public List<Vraboteni> getVraboteniByUsluga(Uslugi usluga) {
|
---|
49 | List<VraboteniUslugi> vrabUsluga = this.repository.findAllByUsluga(usluga);
|
---|
50 | List<Vraboteni> vraboteni = this.vraboteniRepository.findAll();
|
---|
51 |
|
---|
52 | List<Vraboteni> listOutput = new ArrayList<>();
|
---|
53 | for (var i = 0; i < vrabUsluga.size(); i++) {
|
---|
54 | for (var j = 0; j < vraboteni.size(); j++) {
|
---|
55 | if (vrabUsluga.get(i).getUserIdVraboten() == vraboteni.get(j))
|
---|
56 | listOutput.add(vrabUsluga.get(i).getUserIdVraboten());
|
---|
57 | }
|
---|
58 | }
|
---|
59 | return listOutput;
|
---|
60 | }
|
---|
61 |
|
---|
62 | }
|
---|