Changeset bde8b13 for src/main/java/mk/ukim/finki/busngo/service
- Timestamp:
- 01/09/24 01:26:08 (11 months ago)
- Branches:
- master
- Children:
- e272096
- Parents:
- b101b69
- Location:
- src/main/java/mk/ukim/finki/busngo/service
- Files:
-
- 22 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/mk/ukim/finki/busngo/service/AuthService.java
rb101b69 rbde8b13 5 5 public interface AuthService { 6 6 Korisnik login(String email, String password); 7 Korisnik register (String ime, String email, String password, String confirmPassword, String address, String telefon);7 Korisnik registerPatnik(String ime, String email, String password, String confirmPassword, String address, String telefon); 8 8 9 9 } -
src/main/java/mk/ukim/finki/busngo/service/BiletService.java
rb101b69 rbde8b13 2 2 3 3 import mk.ukim.finki.busngo.model.entities.Bilet; 4 import mk.ukim.finki.busngo.model.entities.Patnik; 4 5 import mk.ukim.finki.busngo.model.enums.BILET_STATUS; 5 6 … … 13 14 14 15 Bilet buy(Long tipbilet, LocalDateTime now, BILET_STATUS biletStatus, String name); 16 17 List<Bilet> findAllByPatnikEmail(String email); 18 Bilet findBybIdAndPatnikEmail(Long bId, String email); 19 20 Bilet activate(Long bId); 21 Bilet findById(Long bId); 22 Bilet finish(Long bId); 23 24 boolean checkExpiration(Long bId); 25 // void encode(); 15 26 } -
src/main/java/mk/ukim/finki/busngo/service/PatnikService.java
rb101b69 rbde8b13 2 2 3 3 import mk.ukim.finki.busngo.model.entities.Bilet; 4 import mk.ukim.finki.busngo.model.entities.Korisnik; 4 5 import mk.ukim.finki.busngo.model.entities.Patnik; 5 6 … … 9 10 List<Patnik> listAll(); 10 11 Patnik findById(Long id); 12 Patnik loadUserByEmail(String email); 13 14 Patnik save(Korisnik korisnik); 11 15 12 16 } -
src/main/java/mk/ukim/finki/busngo/service/impl/AuthServiceImpl.java
rb101b69 rbde8b13 2 2 3 3 import mk.ukim.finki.busngo.model.entities.Korisnik; 4 import mk.ukim.finki.busngo.model.entities.Patnik; 4 5 import mk.ukim.finki.busngo.model.exceptions.InvalidCredentialsException; 5 6 import mk.ukim.finki.busngo.model.exceptions.UserAlreadyExistsException; 6 7 import mk.ukim.finki.busngo.repository.KorisnikRepository; 8 import mk.ukim.finki.busngo.repository.PatnikRepository; 7 9 import mk.ukim.finki.busngo.service.AuthService; 8 10 import org.springframework.security.crypto.password.PasswordEncoder; 9 11 import org.springframework.stereotype.Service; 10 12 11 import java.util.List;12 13 13 @Service 14 14 public class AuthServiceImpl implements AuthService { 15 15 private final KorisnikRepository korisnikRepository; 16 private final PatnikRepository patnikRepository; 16 17 private final PasswordEncoder passwordEncoder; 17 18 18 public AuthServiceImpl(KorisnikRepository korisnikRepository, Pa sswordEncoder passwordEncoder) {19 public AuthServiceImpl(KorisnikRepository korisnikRepository, PatnikRepository patnikRepository, PasswordEncoder passwordEncoder) { 19 20 this.korisnikRepository = korisnikRepository; 21 this.patnikRepository = patnikRepository; 20 22 this.passwordEncoder = passwordEncoder; 21 23 } … … 29 31 30 32 @Override 31 public Korisnik register (String ime, String email, String password, String confirmPassword, String address, String telefon) {33 public Korisnik registerPatnik(String ime, String email, String password, String confirmPassword, String address, String telefon) { 32 34 if (email == null || password == null || email.isEmpty() || password.isEmpty()) { 33 35 throw new InvalidCredentialsException(); … … 42 44 } 43 45 44 Korisnik korisnik = new Korisnik();46 Patnik korisnik = new Patnik(); 45 47 korisnik.setKIme(ime); 46 48 korisnik.setKAdresa(address); … … 50 52 korisnik.setKIsAdmin(false); 51 53 52 return korisnikRepository.save(korisnik); 54 55 return patnikRepository.save(korisnik); 53 56 } 54 57 -
src/main/java/mk/ukim/finki/busngo/service/impl/BiletServiceImpl.java
rb101b69 rbde8b13 3 3 import mk.ukim.finki.busngo.model.entities.Bilet; 4 4 import mk.ukim.finki.busngo.model.entities.Korisnik; 5 import mk.ukim.finki.busngo.model.entities.Patnik; 5 6 import mk.ukim.finki.busngo.model.entities.Tipbilet; 6 7 import mk.ukim.finki.busngo.model.enums.BILET_STATUS; 8 import mk.ukim.finki.busngo.model.exceptions.InvalidBiletIdException; 7 9 import mk.ukim.finki.busngo.model.exceptions.InvalidTipBiletIdException; 8 10 import mk.ukim.finki.busngo.repository.BiletRepository; 11 import mk.ukim.finki.busngo.repository.KorisnikRepository; 9 12 import mk.ukim.finki.busngo.repository.TipBIletRepository; 10 13 import mk.ukim.finki.busngo.service.BiletService; 11 14 import mk.ukim.finki.busngo.service.KorisnikService; 12 15 import mk.ukim.finki.busngo.service.PatnikService; 16 import org.springframework.security.crypto.password.PasswordEncoder; 13 17 import org.springframework.stereotype.Service; 14 18 … … 24 28 private final TipBIletRepository tipBIletRepository; 25 29 private final PatnikService patnikService; 30 private final PasswordEncoder passwordEncoder; 31 private final KorisnikRepository korisnikRepository; 26 32 27 public BiletServiceImpl(BiletRepository biletRepository, KorisnikService korisnikService, TipBIletRepository tipBIletRepository, PatnikService patnikService ) {33 public BiletServiceImpl(BiletRepository biletRepository, KorisnikService korisnikService, TipBIletRepository tipBIletRepository, PatnikService patnikService, PasswordEncoder passwordEncoder, KorisnikRepository korisnikRepository) { 28 34 this.biletRepository = biletRepository; 29 35 this.korisnikService = korisnikService; 30 36 this.tipBIletRepository = tipBIletRepository; 31 37 this.patnikService = patnikService; 38 this.passwordEncoder = passwordEncoder; 39 this.korisnikRepository = korisnikRepository; 32 40 } 33 41 … … 39 47 @Override 40 48 public List<Bilet> findAllByPatnikId(Long id) { 41 Korisnik korisnik = korisnikService.findById(id);42 return new ArrayList<>();49 Patnik patnik = patnikService.findById(id); 50 return patnik.getBiletsByKId(); 43 51 } 44 52 … … 52 60 public Bilet buy(Long tipbilet, LocalDateTime now, BILET_STATUS biletStatus, String name) { 53 61 Tipbilet tipbilet1 = tipBIletRepository.findById(tipbilet).orElseThrow(InvalidTipBiletIdException::new); 54 Korisnik korisnik = korisnikService.loadUserByEmail(name);62 Patnik korisnik = patnikService.loadUserByEmail(name); 55 63 Bilet bilet = new Bilet(); 56 64 bilet.setBStatus(biletStatus); … … 60 68 return biletRepository.save(bilet); 61 69 } 70 71 @Override 72 public List<Bilet> findAllByPatnikEmail(String email) { 73 Patnik patnik = patnikService.loadUserByEmail(email); 74 return patnik.getBiletsByKId(); 75 } 76 77 @Override 78 public Bilet findBybIdAndPatnikEmail(Long bId, String email) { 79 Patnik patnik = patnikService.loadUserByEmail(email); 80 return biletRepository.findByBIdAndAndKorisnikByPatnikKId(bId, patnik).orElseThrow(InvalidBiletIdException::new); 81 } 82 83 @Override 84 public Bilet activate(Long bId) { 85 Bilet bilet = this.findById(bId); 86 bilet.setBStatus(BILET_STATUS.ACTIVE); 87 return biletRepository.save(bilet); 88 } 89 90 @Override 91 public Bilet findById(Long bId) { 92 return biletRepository.findById(bId).orElseThrow(RuntimeException::new); 93 } 94 95 @Override 96 public Bilet finish(Long bId) { 97 Bilet bilet = this.findById(bId); 98 bilet.setBStatus(BILET_STATUS.EXPIRED); 99 return biletRepository.save(bilet); 100 } 101 102 @Override 103 public boolean checkExpiration(Long bId) { 104 Bilet bilet = this.findById(bId); 105 LocalDateTime timeBought = bilet.getBDatumNaKupuvanje().toLocalDateTime(); 106 107 if(timeBought.plusSeconds(bilet.getTipbiletByTbId().getTbTrajnost()).isBefore(LocalDateTime.now())){ 108 bilet.setBStatus(BILET_STATUS.EXPIRED); 109 biletRepository.save(bilet); 110 return true; 111 } 112 113 return false; 114 } 115 116 // @Override 117 // public void encode(){ 118 // List<Korisnik> all = korisnikRepository.findAll(); 119 // all.forEach(p -> p.setKLozinka(passwordEncoder.encode(p.getKLozinka()))); 120 // korisnikRepository.saveAll(all); 121 // System.out.println("DONE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); 122 // } 123 124 62 125 } -
src/main/java/mk/ukim/finki/busngo/service/impl/PatnikServiceImpl.java
rb101b69 rbde8b13 1 1 package mk.ukim.finki.busngo.service.impl; 2 2 3 import mk.ukim.finki.busngo.model.entities.Instancanalinija; 4 import mk.ukim.finki.busngo.model.entities.Korisnik; 3 5 import mk.ukim.finki.busngo.model.entities.Patnik; 4 6 import mk.ukim.finki.busngo.model.exceptions.InvalidPatnikIdException; 5 7 import mk.ukim.finki.busngo.repository.PatnikRepository; 8 import mk.ukim.finki.busngo.service.InstancaNaLinijaService; 6 9 import mk.ukim.finki.busngo.service.PatnikService; 7 10 import org.springframework.stereotype.Service; 8 11 12 import java.util.Collections; 9 13 import java.util.List; 10 14 … … 12 16 public class PatnikServiceImpl implements PatnikService { 13 17 private final PatnikRepository patnikRepository; 18 private final InstancaNaLinijaService instancaNaLinijaService; 14 19 15 public PatnikServiceImpl(PatnikRepository patnikRepository ) {20 public PatnikServiceImpl(PatnikRepository patnikRepository, InstancaNaLinijaService instancaNaLinijaService) { 16 21 this.patnikRepository = patnikRepository; 22 this.instancaNaLinijaService = instancaNaLinijaService; 17 23 } 18 24 19 25 @Override 20 26 public List<Patnik> listAll() { 21 return patnikRepository.findAll();27 return patnikRepository.findAll(); 22 28 } 23 29 … … 26 32 return patnikRepository.findById(id).orElseThrow(InvalidPatnikIdException::new); 27 33 } 34 35 @Override 36 public Patnik loadUserByEmail(String email) { 37 return patnikRepository.findByKEmail(email).orElseThrow(InvalidPatnikIdException::new); 38 } 39 40 @Override 41 public Patnik save(Korisnik korisnik) { 42 Patnik patnik = new Patnik(); 43 patnik.setKId(korisnik.getKId()); 44 patnik.setKEmail(korisnik.getKEmail()); 45 patnik.setKAdresa(korisnik.getKAdresa()); 46 patnik.setKIme(korisnik.getKIme()); 47 patnik.setKTelefon(korisnik.getKTelefon()); 48 patnik.setKIsAdmin(korisnik.getKIsAdmin()); 49 patnik.setKLozinka(korisnik.getKLozinka()); 50 51 return patnikRepository.save((Patnik) korisnik); 52 } 53 54 28 55 }
Note:
See TracChangeset
for help on using the changeset viewer.