Changeset d14176d for src/main/java/project/fmo/app/projcetfmo/Service/impl
- Timestamp:
- 07/07/23 12:14:58 (19 months ago)
- Branches:
- main
- Parents:
- 1dd9226
- Location:
- src/main/java/project/fmo/app/projcetfmo/Service/impl
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/project/fmo/app/projcetfmo/Service/impl/AuthServiceImpl.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service.impl;public class AuthServiceImpl { 1 package project.fmo.app.projcetfmo.Service.impl; 2 3 import org.springframework.stereotype.Service; 4 import project.fmo.app.projcetfmo.Model.Korisnik; 5 import project.fmo.app.projcetfmo.Repository.KorisnikRepository; 6 import project.fmo.app.projcetfmo.Service.AuthService; 7 8 @Service 9 public class AuthServiceImpl implements AuthService { 10 11 private final KorisnikRepository korisnikRepository; 12 13 public AuthServiceImpl(KorisnikRepository korisnikRepository) { 14 this.korisnikRepository = korisnikRepository; 15 } 16 17 @Override 18 public Korisnik login(String username, String password) { 19 return korisnikRepository.findByImePrezimeAndPasswordKorisnik(username,password); 20 } 2 21 } -
src/main/java/project/fmo/app/projcetfmo/Service/impl/CenaServiceImpl.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service.impl;public class CenaServiceImpl { 1 package project.fmo.app.projcetfmo.Service.impl; 2 3 import javax.transaction.Transactional; 4 import org.springframework.stereotype.Service; 5 import project.fmo.app.projcetfmo.Model.Cena; 6 import project.fmo.app.projcetfmo.Model.CenaPK; 7 import project.fmo.app.projcetfmo.Repository.CenaRepository; 8 import project.fmo.app.projcetfmo.Service.CenaService; 9 10 import java.sql.Date; 11 import java.util.List; 12 13 @Service 14 public class CenaServiceImpl implements CenaService { 15 16 private final CenaRepository cenaRepository; 17 18 public CenaServiceImpl(CenaRepository cenaRepository) { 19 this.cenaRepository = cenaRepository; 20 } 21 22 @Override 23 public Cena save(Integer idProdukt, java.sql.Date cenaOd, java.sql.Date cenaDo, int iznos) { 24 Cena c = new Cena(idProdukt,cenaOd,cenaDo,iznos); 25 cenaRepository.save(c); 26 return c; 27 } 28 29 @Transactional 30 @Override 31 public Cena edit(Integer idProdukt, Date cenaOd, Date cenaDo, int iznos) { 32 Cena c = cenaRepository.findByIdProdukt(idProdukt); 33 cenaRepository.deleteByIdProdukt(c.getIdProdukt()); 34 Cena c1 = new Cena(idProdukt,cenaOd,cenaDo,iznos); 35 cenaRepository.save(c1); 36 return c; 37 } 38 39 @Override 40 public List<Cena> findAll() { 41 return cenaRepository.findAll(); 42 } 43 44 @Override 45 public Cena findByIdProdukt(int idProdukt) { 46 return cenaRepository.findByIdProdukt(idProdukt); 47 } 48 49 @Transactional 50 @Override 51 public void deleteByIdProdukt(int idProdukt) { 52 cenaRepository.deleteByIdProdukt(idProdukt); 53 } 2 54 } -
src/main/java/project/fmo/app/projcetfmo/Service/impl/DostavaServiceImpl.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service.impl;public class DostavaServiceImpl { 1 package project.fmo.app.projcetfmo.Service.impl; 2 3 import org.springframework.stereotype.Service; 4 import project.fmo.app.projcetfmo.Model.Dostava; 5 import project.fmo.app.projcetfmo.Model.Dostavuvac; 6 import project.fmo.app.projcetfmo.Repository.DostavaRepository; 7 import project.fmo.app.projcetfmo.Service.DostavaService; 8 9 import java.util.List; 10 11 @Service 12 public class DostavaServiceImpl implements DostavaService { 13 14 private final DostavaRepository dostavaRepository; 15 16 public DostavaServiceImpl(DostavaRepository dostavaRepository) { 17 this.dostavaRepository = dostavaRepository; 18 } 19 20 @Override 21 public List<Dostava> findByIdKorisnikAndStatus(Dostavuvac dostavuvac, String status) { 22 return dostavaRepository.findByDostavuvacAndStatus(dostavuvac,status); 23 } 24 25 @Override 26 public Dostava edit(Integer id) { 27 Dostava d = dostavaRepository.findById(id).orElse(null); 28 assert d != null; 29 d.setStatus("dostavena"); 30 dostavaRepository.save(d); 31 return d; 32 } 2 33 } -
src/main/java/project/fmo/app/projcetfmo/Service/impl/DostavuvacServiceImpl.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service.impl;public class DostavuvacServiceImpl { 1 package project.fmo.app.projcetfmo.Service.impl; 2 3 import org.springframework.stereotype.Service; 4 import project.fmo.app.projcetfmo.Model.Dostavuvac; 5 import project.fmo.app.projcetfmo.Repository.DostavuvacRepository; 6 import project.fmo.app.projcetfmo.Service.DostavuvaceService; 7 8 @Service 9 public class DostavuvacServiceImpl implements DostavuvaceService { 10 11 private final DostavuvacRepository dostavuvacRepository; 12 13 public DostavuvacServiceImpl(DostavuvacRepository dostavuvacRepository) { 14 this.dostavuvacRepository = dostavuvacRepository; 15 } 16 17 @Override 18 public Dostavuvac findById(Integer id) { 19 return dostavuvacRepository.findById(id).orElse(null); 20 } 2 21 } -
src/main/java/project/fmo/app/projcetfmo/Service/impl/KategorijaServiceImpl.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service.impl;public class KategorijaServiceImpl { 1 package project.fmo.app.projcetfmo.Service.impl; 2 3 import org.springframework.stereotype.Service; 4 import project.fmo.app.projcetfmo.Model.Kategorija; 5 import project.fmo.app.projcetfmo.Repository.KategorijaRepository; 6 import project.fmo.app.projcetfmo.Service.KategorijaService; 7 8 import java.util.List; 9 10 @Service 11 public class KategorijaServiceImpl implements KategorijaService { 12 13 private final KategorijaRepository kategorijaRepository; 14 15 public KategorijaServiceImpl(KategorijaRepository kategorijaRepository) { 16 this.kategorijaRepository = kategorijaRepository; 17 } 18 19 @Override 20 public List<Kategorija> findAll() { 21 return kategorijaRepository.findAll(); 22 } 23 24 @Override 25 public Kategorija save(String ime) { 26 Kategorija k = new Kategorija(ime); 27 kategorijaRepository.save(k); 28 return k; 29 } 30 31 @Override 32 public Kategorija edit(Integer id, String ime) { 33 Kategorija k = kategorijaRepository.findById(id).orElse(null); 34 assert k != null; 35 k.setIme(ime); 36 kategorijaRepository.save(k); 37 return k; 38 } 2 39 } -
src/main/java/project/fmo/app/projcetfmo/Service/impl/KorisnikServiceImpl.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service.impl;public class KorisnikServiceImpl { 1 package project.fmo.app.projcetfmo.Service.impl; 2 3 import org.springframework.security.core.authority.SimpleGrantedAuthority; 4 import org.springframework.security.core.userdetails.User; 5 import org.springframework.security.core.userdetails.UserDetails; 6 import org.springframework.security.core.userdetails.UsernameNotFoundException; 7 import org.springframework.security.crypto.password.PasswordEncoder; 8 import org.springframework.stereotype.Service; 9 import project.fmo.app.projcetfmo.Model.*; 10 import project.fmo.app.projcetfmo.Repository.*; 11 import project.fmo.app.projcetfmo.Service.KorisnikService; 12 13 import java.sql.Timestamp; 14 import java.time.LocalDateTime; 15 import java.util.List; 16 import java.util.Objects; 17 import java.util.stream.Collectors; 18 import java.util.stream.Stream; 19 20 @Service 21 public class KorisnikServiceImpl implements KorisnikService { 22 23 private final PasswordEncoder passwordEncoder; 24 private final AdminRepository adminRepository; 25 private final DostavuvacRepository dostavuvacRepository; 26 27 private final TelefnoskiBrojRepository telefnoskiBrojRepository; 28 private final KupuvacRepository kupuvacRepository; 29 private final KorisnikRepository korisnikRepository; 30 31 public KorisnikServiceImpl(PasswordEncoder passwordEncoder, AdminRepository adminRepository, DostavuvacRepository dostavuvacRepository, TelefnoskiBrojRepository telefnoskiBrojRepository, KupuvacRepository kupuvacRepository, KorisnikRepository korisnikRepository) { 32 this.passwordEncoder = passwordEncoder; 33 this.adminRepository = adminRepository; 34 this.dostavuvacRepository = dostavuvacRepository; 35 this.telefnoskiBrojRepository = telefnoskiBrojRepository; 36 this.kupuvacRepository = kupuvacRepository; 37 this.korisnikRepository = korisnikRepository; 38 } 39 40 @Override 41 public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 42 Korisnik korisnik = korisnikRepository.findByImePrezime(username); 43 for (AdminKorisnik a: adminRepository.findAll()) { 44 if (a.getIdKorisnik() == korisnik.getIdKorisnik()) { 45 return new User(korisnik.getImePrezime(), korisnik.getPasswordKorisnik(), Stream.of(new SimpleGrantedAuthority("ROLE_ADMIN")).collect(Collectors.toList())); 46 } 47 } 48 for (Dostavuvac a: dostavuvacRepository.findAll()) { 49 if (a.getIdKorisnik() == korisnik.getIdKorisnik()) { 50 return new User(korisnik.getImePrezime(), korisnik.getPasswordKorisnik(), Stream.of(new SimpleGrantedAuthority("ROLE_DELIVER")).collect(Collectors.toList())); 51 } 52 } 53 for (Kupuvac a: kupuvacRepository.findAll()){ 54 if (a.getIdKorisnik() == korisnik.getIdKorisnik()){ 55 return new User(korisnik.getImePrezime(),korisnik.getPasswordKorisnik(), Stream.of(new SimpleGrantedAuthority("ROLE_USER")).collect(Collectors.toList()) ); 56 } 57 } 58 return null; 59 } 60 61 @Override 62 public Korisnik findbyImePrezime(String ime) { 63 return korisnikRepository.findByImePrezime(ime); 64 } 65 66 @Override 67 public Korisnik findById(Integer id) { 68 return korisnikRepository.findById(id).orElse(null); 69 } 70 71 @Override 72 public Korisnik register(String username, String password, String repeatPassword, String mail, String number) { 73 if (username==null || username.isEmpty() || password==null || password.isEmpty()) 74 throw new RuntimeException(); 75 if (!password.equals(repeatPassword)) 76 throw new RuntimeException(); 77 78 Korisnik korisnik = new Korisnik(username,password, Timestamp.valueOf(LocalDateTime.now())); 79 korisnikRepository.save(korisnik); 80 Kupuvac k = new Kupuvac(korisnik.getIdKorisnik(), mail); 81 kupuvacRepository.save(k); 82 Telefonskibroj t = new Telefonskibroj(new TelefonskibrojPK(korisnik.getIdKorisnik(),number)); 83 telefnoskiBrojRepository.save(t); 84 return korisnik; 85 86 } 87 88 @Override 89 public List<Object> statistics2() { 90 return korisnikRepository.statistics2(); 91 } 2 92 } -
src/main/java/project/fmo/app/projcetfmo/Service/impl/KupuvacServiceImpl.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service.impl;public class KupuvacServiceImpl { 1 package project.fmo.app.projcetfmo.Service.impl; 2 3 import org.springframework.stereotype.Service; 4 import project.fmo.app.projcetfmo.Model.Kupuvac; 5 import project.fmo.app.projcetfmo.Repository.KupuvacRepository; 6 import project.fmo.app.projcetfmo.Service.KupuvacService; 7 8 @Service 9 public class KupuvacServiceImpl implements KupuvacService { 10 11 private final KupuvacRepository kupuvacRepository; 12 13 public KupuvacServiceImpl(KupuvacRepository kupuvacRepository) { 14 this.kupuvacRepository = kupuvacRepository; 15 } 16 17 @Override 18 public Kupuvac findById(Integer id) { 19 return kupuvacRepository.findById(id).orElse(null); 20 } 2 21 } -
src/main/java/project/fmo/app/projcetfmo/Service/impl/NarackaServiceImpl.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service.impl;public class NarackaServiceImpl { 1 package project.fmo.app.projcetfmo.Service.impl; 2 3 import org.springframework.stereotype.Service; 4 import project.fmo.app.projcetfmo.Model.Kupuvac; 5 import project.fmo.app.projcetfmo.Model.Naracka; 6 import project.fmo.app.projcetfmo.Model.Produkt; 7 import project.fmo.app.projcetfmo.Repository.KupuvacRepository; 8 import project.fmo.app.projcetfmo.Repository.NarackaRepository; 9 import project.fmo.app.projcetfmo.Service.NarackaService; 10 11 import java.sql.Date; 12 import java.util.List; 13 14 @Service 15 public class NarackaServiceImpl implements NarackaService { 16 17 private final NarackaRepository narackaRepository; 18 private final KupuvacRepository kupuvacRepository; 19 20 public NarackaServiceImpl(NarackaRepository narackaRepository, KupuvacRepository kupuvacRepository) { 21 this.narackaRepository = narackaRepository; 22 this.kupuvacRepository = kupuvacRepository; 23 } 24 25 @Override 26 public List<Produkt> allProductsInOrder(Integer narackaId) { 27 return null; 28 } 29 30 @Override 31 public Naracka getActiveOrder(String username) { 32 return null; 33 } 34 35 @Override 36 public Naracka findByIdKorisniktAndStatus(Integer id, String s) { 37 Kupuvac k = kupuvacRepository.findById(id).orElse(null); 38 return narackaRepository.findByKupuvacAndStatus(k,s); 39 } 40 41 @Override 42 public Naracka save(int vkupnoSuma, Date date, String status, String adresa, Kupuvac k) { 43 return narackaRepository.save(new Naracka(vkupnoSuma,date,status,adresa,k)); 44 } 45 46 @Override 47 public Naracka edit(int vkupnoSuma, String status, String adresa, Integer idK, Integer idN) { 48 Kupuvac k = kupuvacRepository.findById(idK).orElse(null); 49 Naracka n = narackaRepository.findByKupuvacAndIdNaracka(k,idN); 50 n.setVkupnoSuma(n.getVkupnoSuma()+vkupnoSuma); 51 n.setStatus(status); 52 n.setAdresa(adresa); 53 narackaRepository.save(n); 54 return n; 55 } 56 57 @Override 58 public Naracka findByKupuvac(Kupuvac k) { 59 return narackaRepository.findByKupuvac(k); 60 } 61 62 @Override 63 public Naracka findByIdNaracka(Integer id) { 64 return narackaRepository.findById(id).orElse(null); 65 } 66 67 @Override 68 public List<Naracka> findAll() { 69 return narackaRepository.findAll(); 70 } 2 71 } -
src/main/java/project/fmo/app/projcetfmo/Service/impl/NarackaSodrziProduktServiceImpl.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service.impl;public class NarackaSodrziProduktServiceImpl { 1 package project.fmo.app.projcetfmo.Service.impl; 2 3 import org.springframework.stereotype.Service; 4 import project.fmo.app.projcetfmo.Model.NarackaSodrziProdukt; 5 import project.fmo.app.projcetfmo.Repository.NarackaSodrziProduktRepository; 6 import project.fmo.app.projcetfmo.Service.NarackaSodrziProduktService; 7 8 import java.util.List; 9 10 @Service 11 public class NarackaSodrziProduktServiceImpl implements NarackaSodrziProduktService { 12 13 private final NarackaSodrziProduktRepository narackaSodrziProduktRepository; 14 15 public NarackaSodrziProduktServiceImpl(NarackaSodrziProduktRepository narackaSodrziProduktRepository) { 16 this.narackaSodrziProduktRepository = narackaSodrziProduktRepository; 17 } 18 19 @Override 20 public NarackaSodrziProdukt findByIdProduktAndIdNaracka(Integer idP, Integer idN) { 21 return narackaSodrziProduktRepository.findByIdProduktAndIdNaracka(idP,idN); 22 } 23 24 @Override 25 public NarackaSodrziProdukt edit(Integer idP, Integer idN, Integer quantity, Integer price) { 26 NarackaSodrziProdukt n = narackaSodrziProduktRepository.findByIdProduktAndIdNaracka(idP,idN); 27 n.setCena(price); 28 n.setKolicina(n.getKolicina()+quantity); 29 narackaSodrziProduktRepository.save(n); 30 return n; 31 } 32 33 @Override 34 public NarackaSodrziProdukt save(Integer idP, Integer idN, Integer quantity, Integer price) { 35 NarackaSodrziProdukt n = new NarackaSodrziProdukt(idP,idN,quantity, price); 36 narackaSodrziProduktRepository.save(n); 37 return n; 38 } 39 40 @Override 41 public List<NarackaSodrziProdukt> findByIdNaracka(Integer id) { 42 return narackaSodrziProduktRepository.findByIdNaracka(id); 43 } 44 45 @Override 46 public void deleteProduct(Integer id) { 47 List<NarackaSodrziProdukt> narackaSodrziProdukts = narackaSodrziProduktRepository.findByIdProdukt(id); 48 narackaSodrziProduktRepository.deleteByIdProdukt(id); 49 } 50 51 @Override 52 public List<NarackaSodrziProdukt> findAll() { 53 return narackaSodrziProduktRepository.findAll(); 54 } 55 56 @Override 57 public List<NarackaSodrziProdukt> findByIdProdukt(Integer id) { 58 return narackaSodrziProduktRepository.findByIdProdukt(id); 59 } 60 61 2 62 } -
src/main/java/project/fmo/app/projcetfmo/Service/impl/ProduktEOdKategorijaServiceImpl.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service.impl;public class ProduktEOdKategorijaServiceImpl { 1 package project.fmo.app.projcetfmo.Service.impl; 2 3 import javax.transaction.Transactional; 4 import org.springframework.stereotype.Service; 5 import project.fmo.app.projcetfmo.Model.ProduktEOdKategorija; 6 import project.fmo.app.projcetfmo.Model.ProduktEOdKategorijaPK; 7 import project.fmo.app.projcetfmo.Repository.ProduktEOdKategorijaRepository; 8 import project.fmo.app.projcetfmo.Service.ProduktEOdKategorijaService; 9 import project.fmo.app.projcetfmo.Service.ProduktService; 10 11 import java.util.List; 12 13 @Service 14 public class ProduktEOdKategorijaServiceImpl implements ProduktEOdKategorijaService { 15 16 private final ProduktEOdKategorijaRepository produktEOdKategorijaRepository; 17 18 public ProduktEOdKategorijaServiceImpl(ProduktEOdKategorijaRepository produktEOdKategorijaRepository) { 19 this.produktEOdKategorijaRepository = produktEOdKategorijaRepository; 20 } 21 22 @Override 23 public ProduktEOdKategorija save(int idProdukt, int idKategorija) { 24 ProduktEOdKategorija produktEOdKategorija= new ProduktEOdKategorija(new ProduktEOdKategorijaPK(idProdukt, idKategorija)); 25 produktEOdKategorijaRepository.save(produktEOdKategorija); 26 return produktEOdKategorija; 27 } 28 29 @Transactional 30 @Override 31 public ProduktEOdKategorija edit(int idProdukt, int idKategorija) { 32 // ProduktEOdKategorijaPK pk = new ProduktEOdKategorijaPK(idProdukt,idKategorija); 33 ProduktEOdKategorija peodkD = produktEOdKategorijaRepository.findByIdProdukt(idProdukt); 34 produktEOdKategorijaRepository.deleteByIdProdukt(peodkD.getIdProdukt()); 35 ProduktEOdKategorijaPK pk = new ProduktEOdKategorijaPK(idProdukt, idKategorija); 36 ProduktEOdKategorija peodk = new ProduktEOdKategorija(pk); 37 produktEOdKategorijaRepository.save(peodk); 38 39 return peodk; 40 } 41 42 @Override 43 public List<ProduktEOdKategorija> findAll() { 44 return produktEOdKategorijaRepository.findAll(); 45 } 46 47 @Override 48 public ProduktEOdKategorija findByIdProdukt(int idProdukt) { 49 return produktEOdKategorijaRepository.findByIdProdukt(idProdukt); 50 } 51 52 @Transactional 53 @Override 54 public void deleteByIdProdukt(int idProdukt) { 55 56 this.produktEOdKategorijaRepository.deleteByIdProdukt(idProdukt); 57 } 58 59 @Override 60 public ProduktEOdKategorija findByIdProduktAndIdKategorija(int idProdukt, int idKategorija) { 61 return produktEOdKategorijaRepository.findByIdProduktAndIdKategorija(idProdukt,idKategorija); 62 } 2 63 } -
src/main/java/project/fmo/app/projcetfmo/Service/impl/ProduktServiceImpl.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service.impl;public class ProduktServiceImpl { 1 package project.fmo.app.projcetfmo.Service.impl; 2 3 import org.springframework.data.domain.Page; 4 import org.springframework.data.domain.Pageable; 5 import org.springframework.stereotype.Service; 6 import project.fmo.app.projcetfmo.Model.AdminKorisnik; 7 import project.fmo.app.projcetfmo.Model.Produkt; 8 import project.fmo.app.projcetfmo.Repository.AdminRepository; 9 import project.fmo.app.projcetfmo.Repository.ProduktRepository; 10 import project.fmo.app.projcetfmo.Service.ProduktService; 11 12 13 import java.util.List; 14 import java.util.Optional; 15 import java.util.Random; 16 17 @Service 18 public class ProduktServiceImpl implements ProduktService { 19 20 private final ProduktRepository produktRepository; 21 private final AdminRepository adminRepository; 22 23 public ProduktServiceImpl(ProduktRepository produktRepository, AdminRepository adminRepository) { 24 this.produktRepository = produktRepository; 25 this.adminRepository = adminRepository; 26 } 27 28 @Override 29 public Optional<Produkt> findById(Integer id) { 30 return produktRepository.findById(id); 31 } 32 33 @Override 34 public List<Produkt> findAll() { 35 return produktRepository.findAll(); 36 } 37 38 @Override 39 public Produkt save(String ime, String opis) { 40 List<AdminKorisnik> list = adminRepository.findAll(); 41 Random rand = new Random(); 42 int randomIndex = rand.nextInt(list.size()); 43 AdminKorisnik a = list.get(randomIndex); 44 if (a == null){ 45 throw new RuntimeException(); 46 } 47 Produkt p = new Produkt(ime, opis, a); 48 produktRepository.save(p); 49 return p; 50 } 51 52 @Override 53 public Produkt edit(Integer id, String ime, String opis) { 54 Produkt p = produktRepository.findById(id).orElse(null); 55 if (p == null ){ 56 throw new RuntimeException(); 57 } 58 p.setIme(ime); 59 p.setOpis(opis); 60 produktRepository.save(p); 61 return p; 62 } 63 64 @Override 65 public void deleteById(Integer id) { 66 produktRepository.deleteById(id); 67 } 68 69 @Override 70 public List<Object> statistics1() { 71 return produktRepository.statistics1(); 72 } 2 73 }
Note:
See TracChangeset
for help on using the changeset viewer.