Changeset bde8b13 for src/main/java/mk/ukim
- Timestamp:
- 01/09/24 01:26:08 (11 months ago)
- Branches:
- master
- Children:
- e272096
- Parents:
- b101b69
- Location:
- src/main/java/mk/ukim/finki/busngo
- Files:
-
- 45 added
- 27 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/mk/ukim/finki/busngo/BusNGoApplication.java
rb101b69 rbde8b13 11 11 12 12 public static void main(String[] args) { 13 14 13 15 SpringApplication.run(BusNGoApplication.class, args); 14 16 } -
src/main/java/mk/ukim/finki/busngo/config/WebSecurityConfig.java
rb101b69 rbde8b13 46 46 .permitAll() 47 47 .failureUrl("/login?error=BadCredentials") 48 .defaultSuccessUrl("/ ", true)48 .defaultSuccessUrl("/bilet", true) 49 49 ) 50 50 .logout((logout) -> logout -
src/main/java/mk/ukim/finki/busngo/model/entities/Bilet.java
rb101b69 rbde8b13 17 17 @Id 18 18 @Column(name = "b_id") 19 private Long bId; 19 private Long BId; 20 20 21 @Basic 21 22 @Column(name = "b_datum_na_kupuvanje") 22 23 private Timestamp bDatumNaKupuvanje; 24 23 25 @Basic 24 26 @Column(name = "b_status", columnDefinition = "string_kratok") 25 27 @Enumerated(EnumType.STRING) 26 28 private BILET_STATUS bStatus; 29 27 30 @ManyToOne 28 31 @JoinColumn(name = "patnik_k_id", referencedColumnName = "k_id") 29 private Korisnik korisnikByPatnikKId; 32 private Patnik korisnikByPatnikKId; 33 30 34 @ManyToOne 31 35 @JoinColumn(name = "tb_id", referencedColumnName = "tb_id") -
src/main/java/mk/ukim/finki/busngo/model/entities/Instancanalinija.java
rb101b69 rbde8b13 24 24 @ManyToOne 25 25 @JoinColumn(name = "vozac_k_id", referencedColumnName = "k_id", nullable = false) 26 private KorisnikkorisnikByVozacKId;26 private Vozac korisnikByVozacKId; 27 27 @ManyToOne 28 28 @JoinColumn(name = "a_registracija", referencedColumnName = "a_registracija") -
src/main/java/mk/ukim/finki/busngo/model/entities/Kazna.java
rb101b69 rbde8b13 9 9 @Data 10 10 @Entity 11 @Inheritance(strategy = InheritanceType.JOINED) 11 12 public class Kazna { 12 13 @GeneratedValue(strategy = GenerationType.IDENTITY) … … 14 15 @Column(name = "kz_id") 15 16 private Long kzId; 17 16 18 @Basic 17 19 @Column(name = "kz_iznos") 18 20 private Double kzIznos; 21 19 22 @Basic 20 23 @Column(name = "kz_plateno") 21 24 private Boolean kzPlateno; 25 22 26 @Basic 23 27 @Column(name = "kz_datum") 24 28 private Timestamp kzDatum; 29 25 30 @Basic 26 31 @Column(name = "kz_datum_plateno") 27 32 private Timestamp kzDatumPlateno; 33 28 34 @Basic 29 35 @Column(name = "kz_dokument") 30 36 private String kzDokument; 37 31 38 @ManyToOne 32 39 @JoinColumn(name = "kondukter_k_id", referencedColumnName = "k_id") 33 private Korisnik korisnikByKondukterKId; 40 private Kondukter korisnikByKondukterKId; 41 34 42 @ManyToOne 35 43 @JoinColumn(name = "kontrola_id", referencedColumnName = "kontrola_id") 36 44 private Kontroli kontroliByKontrolaId; 37 @OneToOne(mappedBy = "kaznaByKzId") 38 private Kaznazaneregistriran kaznazaneregistriranByKzId; 39 @OneToOne(mappedBy = "kaznaByKzId") 40 private Kaznazaregistriran kaznazaregistriranByKzId; 45 46 // @OneToOne(mappedBy = "kaznaByKzId") 47 // private Kaznazaneregistriran kaznazaneregistriranByKzId; 48 // 49 // @OneToOne(mappedBy = "kaznaByKzId") 50 // private Kaznazaregistriran kaznazaregistriranByKzId; 41 51 } -
src/main/java/mk/ukim/finki/busngo/model/entities/Kaznazaneregistriran.java
rb101b69 rbde8b13 8 8 @Data 9 9 @Entity 10 public class Kaznazaneregistriran { 11 @GeneratedValue(strategy = GenerationType.IDENTITY) 12 @Id 13 @Column(name = "kz_id") 14 private Long kzId; 10 public class Kaznazaneregistriran extends Kazna { 15 11 @Basic 16 12 @Column(name = "kzn_telefon") 17 13 private String kznTelefon; 14 18 15 @Basic 19 16 @Column(name = "kzn_ime") 20 17 private String kznIme; 18 21 19 @Basic 22 20 @Column(name = "kzn_adresa") 23 21 private String kznAdresa; 24 @OneToOne25 @JoinColumn(name = "kz_id", referencedColumnName = "kz_id", nullable = false)26 private Kazna kaznaByKzId;27 22 } -
src/main/java/mk/ukim/finki/busngo/model/entities/Kaznazaregistriran.java
rb101b69 rbde8b13 8 8 @Data 9 9 @Entity 10 public class Kaznazaregistriran { 11 @GeneratedValue(strategy = GenerationType.IDENTITY) 12 @Id 13 @Column(name = "kz_id") 14 private Long kzId; 15 @OneToOne 16 @JoinColumn(name = "kz_id", referencedColumnName = "kz_id", nullable = false) 17 private Kazna kaznaByKzId; 10 public class Kaznazaregistriran extends Kazna{ 18 11 @ManyToOne 19 12 @JoinColumn(name = "patnik_k_id", referencedColumnName = "k_id") 20 private Korisnik korisnikByPatnikKId;13 private Patnik korisnikByPatnikKId; 21 14 } -
src/main/java/mk/ukim/finki/busngo/model/entities/Kondukter.java
rb101b69 rbde8b13 4 4 import lombok.Data; 5 5 6 import java.util.List; 6 7 import java.util.Objects; 7 8 8 9 @Data 9 10 @Entity 10 public class Kondukter { 11 @GeneratedValue(strategy = GenerationType.IDENTITY) 12 @Id 13 @Column(name = "k_id") 14 private Long kId; 15 @OneToOne 16 @JoinColumn(name = "k_id", referencedColumnName = "k_id", nullable = false) 17 private Korisnik korisnikByKId; 11 public class Kondukter extends Vraboten{ 12 @OneToMany(mappedBy = "korisnikByKondukterKId") 13 private List<Kazna> kaznasByKId; 14 @OneToMany(mappedBy = "korisnikByKondukterKId") 15 private List<Kontroli> kontrolisByKId; 18 16 19 17 } -
src/main/java/mk/ukim/finki/busngo/model/entities/Kontroli.java
rb101b69 rbde8b13 23 23 @ManyToOne 24 24 @JoinColumn(name = "kondukter_k_id", referencedColumnName = "k_id") 25 private Ko risnikkorisnikByKondukterKId;25 private Kondukter korisnikByKondukterKId; 26 26 @ManyToOne 27 27 @JoinColumn(name = "inl_id", referencedColumnName = "inl_id") -
src/main/java/mk/ukim/finki/busngo/model/entities/Korisnik.java
rb101b69 rbde8b13 15 15 @Data 16 16 @Entity 17 @Inheritance(strategy = InheritanceType.JOINED) 17 18 public class Korisnik implements UserDetails { 18 19 @GeneratedValue(strategy = GenerationType.IDENTITY) … … 20 21 @Column(name = "k_id") 21 22 private Long kId; 23 22 24 @Basic 23 25 @Column(name = "k_ime") 24 26 private String kIme; 27 25 28 @Basic 26 29 @Column(name = "k_adresa") 27 30 private String kAdresa; 31 28 32 @Basic 29 33 @Column(name = "k_telefon") 30 34 private String kTelefon; 35 31 36 @Basic 32 37 @Column(name = "k_email") 33 38 private String kEmail; 39 34 40 @Basic 35 41 @Column(name = "k_embg") 36 42 private String kEmbg; 43 37 44 @Basic 38 45 @Column(name = "k_is_admin") 39 46 private Boolean kIsAdmin; 47 40 48 @Basic 41 49 @Column(name = "k_lozinka") 42 50 private String kLozinka; 43 @OneToMany(mappedBy = "korisnikByPatnikKId") 44 private List<Bilet> biletsByKId; 51 52 // @OneToMany(mappedBy = "korisnikByPatnikKId") 53 // private List<Bilet> biletsByKId; 45 54 // private boolean isAccountNonExpired = true; 46 55 // private boolean isAccountNonLocked = true; -
src/main/java/mk/ukim/finki/busngo/model/entities/Patnik.java
rb101b69 rbde8b13 4 4 import lombok.Data; 5 5 6 import java.util.List; 6 7 import java.util.Objects; 7 8 8 9 @Data 9 10 @Entity 10 public class Patnik { 11 @GeneratedValue(strategy = GenerationType.IDENTITY) 12 @Id 13 @Column(name = "k_id") 14 private Long kId; 15 @OneToOne 16 @JoinColumn(name = "k_id", referencedColumnName = "k_id", nullable = false) 17 private Korisnik korisnikByKId; 11 public class Patnik extends Korisnik { 12 @OneToMany(mappedBy = "korisnikByPatnikKId") 13 private List<Bilet> biletsByKId; 14 15 @OneToMany(mappedBy = "korisnikByPatnikKId") 16 private List<Kaznazaregistriran> kaznazaregistriransByKId; 17 18 @OneToMany(mappedBy = "korisnikByPatnikKId") 19 private List<Vozenje> vozenjesByKId; 18 20 } -
src/main/java/mk/ukim/finki/busngo/model/entities/Tipbilet.java
rb101b69 rbde8b13 19 19 private Long tbTrajnost; 20 20 @Basic 21 @Column(name = "tb_cena") 22 private Float tbCena; 23 @Basic 21 24 @Column(name = "tb_ime") 22 25 private String tbIme; -
src/main/java/mk/ukim/finki/busngo/model/entities/Vozac.java
rb101b69 rbde8b13 4 4 import lombok.Data; 5 5 6 import java.util.List; 6 7 import java.util.Objects; 7 8 8 9 @Data 9 10 @Entity 10 public class Vozac { 11 @GeneratedValue(strategy = GenerationType.IDENTITY) 12 @Id 13 @Column(name = "k_id") 14 private Long kId; 15 @OneToOne 16 @JoinColumn(name = "k_id", referencedColumnName = "k_id", nullable = false) 17 private Korisnik korisnikByKId; 11 public class Vozac extends Vraboten { 12 @OneToMany(mappedBy = "korisnikByVozacKId") 13 private List<Instancanalinija> instancanalinijasByKId; 18 14 19 15 } -
src/main/java/mk/ukim/finki/busngo/model/entities/Vozenje.java
rb101b69 rbde8b13 27 27 @ManyToOne 28 28 @JoinColumn(name = "patnik_k_id", referencedColumnName = "k_id") 29 private Korisnik korisnikByPatnikKId;29 private Patnik korisnikByPatnikKId; 30 30 @ManyToOne 31 31 @JoinColumn(name = "kacuva_pnl_id", referencedColumnName = "pnl_id", nullable = false) -
src/main/java/mk/ukim/finki/busngo/model/entities/Vraboten.java
rb101b69 rbde8b13 10 10 @Data 11 11 @Entity 12 public class Vraboten { 13 @GeneratedValue(strategy = GenerationType.IDENTITY) 14 @Id 15 @Column(name = "k_id") 16 private Long kId; 12 public class Vraboten extends Korisnik { 17 13 @Basic 18 14 @Column(name = "v_plata") 19 15 private Double vPlata; 16 20 17 @Basic 21 18 @Column(name = "v_datum_na_vrabotuvanje") 22 19 private Date vDatumNaVrabotuvanje; 20 23 21 @Basic 24 22 @Column(name = "v_datum_prekin_vrabotuvanje") 25 23 private Date vDatumPrekinVrabotuvanje; 26 @OneToOne27 @JoinColumn(name = "k_id", referencedColumnName = "k_id", nullable = false)28 private Korisnik korisnikByKId;29 24 30 25 } -
src/main/java/mk/ukim/finki/busngo/model/enums/Role.java
rb101b69 rbde8b13 6 6 public enum Role implements GrantedAuthority { 7 7 ROLE_USER, 8 ROLE_PASSENGER, 9 ROLE_DRIVER, 10 ROLE_CONDUCTOR, 8 11 ROLE_ADMIN; 9 12 -
src/main/java/mk/ukim/finki/busngo/repository/BiletRepository.java
rb101b69 rbde8b13 8 8 9 9 import java.util.List; 10 import java.util.Optional; 10 11 11 12 … … 13 14 // List<Bilet> findAllByKorisnikByPatnikKIdAndBStatus(Korisnik korisnik, BILET_STATUS status); 14 15 // List<Bilet> findAllByKorisnikByPatnikKId(Korisnik korisnik); 16 Optional<Bilet> findByBIdAndAndKorisnikByPatnikKId(Long bid, Patnik patnik); 15 17 } -
src/main/java/mk/ukim/finki/busngo/repository/KorisnikRepository.java
rb101b69 rbde8b13 5 5 import org.springframework.data.jpa.repository.JpaRepository; 6 6 import org.springframework.data.jpa.repository.Query; 7 import org.springframework.data.repository.NoRepositoryBean; 7 8 8 9 import java.util.Optional; 10 9 11 10 12 public interface KorisnikRepository extends JpaRepository<Korisnik, Long> { -
src/main/java/mk/ukim/finki/busngo/repository/PatnikRepository.java
rb101b69 rbde8b13 3 3 import mk.ukim.finki.busngo.model.entities.Patnik; 4 4 import org.springframework.data.jpa.repository.JpaRepository; 5 import org.springframework.data.jpa.repository.Query; 5 6 import org.springframework.stereotype.Repository; 6 7 8 import java.util.List; 9 import java.util.Optional; 10 7 11 public interface PatnikRepository extends JpaRepository<Patnik, Long> { 8 12 @Query("SELECT p from Patnik p where p.kEmail = ?1") 13 Optional<Patnik> findByKEmail(String email); 9 14 } -
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 } -
src/main/java/mk/ukim/finki/busngo/web/BiletController.java
rb101b69 rbde8b13 1 1 package mk.ukim.finki.busngo.web; 2 2 3 import mk.ukim.finki.busngo.model.entities.Patnik; 3 4 import mk.ukim.finki.busngo.model.enums.BILET_STATUS; 5 import mk.ukim.finki.busngo.model.exceptions.InvalidPatnikIdException; 4 6 import mk.ukim.finki.busngo.service.AuthService; 5 7 import mk.ukim.finki.busngo.service.BiletService; 8 import mk.ukim.finki.busngo.service.PatnikService; 6 9 import mk.ukim.finki.busngo.service.TipBiletService; 7 10 import org.springframework.security.core.Authentication; … … 21 24 private final TipBiletService tipBiletService; 22 25 private final AuthService authService; 26 private final PatnikService patnikService; 23 27 24 public BiletController(BiletService biletService, TipBiletService tipBiletService, AuthService authService ) {28 public BiletController(BiletService biletService, TipBiletService tipBiletService, AuthService authService, PatnikService patnikService) { 25 29 this.biletService = biletService; 26 30 this.tipBiletService = tipBiletService; 27 31 this.authService = authService; 32 this.patnikService = patnikService; 28 33 } 29 34 … … 31 36 public String getAllBileti(@RequestParam(required = false) Long id, 32 37 @RequestParam(required = false) BILET_STATUS status, 33 Model model){ 38 Model model, 39 Authentication authentication){ 34 40 model.addAttribute("bodyContent", "listBileti"); 35 model.addAttribute("bileti", biletService.listAll()); 41 Patnik patnik = null; 42 try{ 43 model.addAttribute("bileti", biletService.findAllByPatnikEmail(authentication.getName())); 44 } 45 catch (InvalidPatnikIdException e){ 46 model.addAttribute("bodyContent", "listBileti"); 47 model.addAttribute("hasError", true); 48 model.addAttribute("error", e.getMessage()); 49 return "master-template"; 50 } 51 36 52 return "master-template"; 37 53 } … … 50 66 } 51 67 68 // @GetMapping("/encode") 69 // public String encode(){ 70 // biletService.encode(); 71 // return "redirect:/bilet"; 72 // } 73 52 74 } -
src/main/java/mk/ukim/finki/busngo/web/RegisterController.java
rb101b69 rbde8b13 1 1 package mk.ukim.finki.busngo.web; 2 2 3 import mk.ukim.finki.busngo.model.en ums.Role;3 import mk.ukim.finki.busngo.model.entities.Korisnik; 4 4 import mk.ukim.finki.busngo.model.exceptions.InvalidCredentialsException; 5 5 import mk.ukim.finki.busngo.model.exceptions.UserAlreadyExistsException; 6 6 import mk.ukim.finki.busngo.service.AuthService; 7 7 import mk.ukim.finki.busngo.service.KorisnikService; 8 import mk.ukim.finki.busngo.service.PatnikService; 8 9 import org.springframework.stereotype.Controller; 9 10 import org.springframework.ui.Model; … … 18 19 private final AuthService authService; 19 20 private final KorisnikService korisnikService; 21 private final PatnikService patnikService; 20 22 21 public RegisterController(AuthService authService, KorisnikService korisnikService ) {23 public RegisterController(AuthService authService, KorisnikService korisnikService, PatnikService patnikService) { 22 24 this.authService = authService; 23 25 this.korisnikService = korisnikService; 26 this.patnikService = patnikService; 24 27 } 25 28 … … 44 47 ) { 45 48 try{ 46 this.authService.register(name, email, password, confirmPassword, address, phone); 49 Korisnik korisnik = this.authService.registerPatnik(name, email, password, confirmPassword, address, phone); 50 this.patnikService.save(korisnik); 47 51 return "redirect:/login"; 48 52 } catch (InvalidCredentialsException | UserAlreadyExistsException exception) { … … 51 55 } 52 56 57 // @PostMapping 58 // public String registerVraboten(@RequestParam String name, 59 // @RequestParam String email, 60 // @RequestParam String password, 61 // @RequestParam String confirmPassword, 62 // @RequestParam String address, 63 // @RequestParam String phone){ 64 // 65 // } 66 53 67 }
Note:
See TracChangeset
for help on using the changeset viewer.