- Timestamp:
- 01/09/24 01:26:08 (10 months ago)
- Branches:
- master
- Children:
- e272096
- Parents:
- b101b69
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.