source: src/main/java/com/project/beautycenter/service/impl/VraboteniUslugiServiceImpl.java

Last change on this file was 850b344, checked in by Tamara Simikj <tamara.simic12@…>, 2 years ago

Initial commit

  • Property mode set to 100644
File size: 2.3 KB
RevLine 
[850b344]1package com.project.beautycenter.service.impl;
2
3import com.project.beautycenter.model.Uslugi;
4import com.project.beautycenter.model.Vraboteni;
5import com.project.beautycenter.model.VraboteniUslugi;
6import com.project.beautycenter.repository.UslugiRepository;
7import com.project.beautycenter.repository.VraboteniRepository;
8import com.project.beautycenter.repository.VraboteniUslugiRepository;
9import com.project.beautycenter.service.VraboteniUslugiService;
10import org.springframework.stereotype.Service;
11
12import java.util.ArrayList;
13import java.util.List;
14
15@Service
16public 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}
Note: See TracBrowser for help on using the repository browser.