Ignore:
Timestamp:
01/09/24 01:26:08 (11 months ago)
Author:
ppaunovski <paunovskipavel@…>
Branches:
master
Children:
e272096
Parents:
b101b69
Message:

All 3 main use cases implemented.

  1. Starting a commute
  2. Writing a ticket
  3. Starting an instance of a Bus Line
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  
    1111
    1212    public static void main(String[] args) {
     13
     14
    1315        SpringApplication.run(BusNGoApplication.class, args);
    1416    }
  • src/main/java/mk/ukim/finki/busngo/config/WebSecurityConfig.java

    rb101b69 rbde8b13  
    4646                        .permitAll()
    4747                        .failureUrl("/login?error=BadCredentials")
    48                         .defaultSuccessUrl("/", true)
     48                        .defaultSuccessUrl("/bilet", true)
    4949                )
    5050                .logout((logout) -> logout
  • src/main/java/mk/ukim/finki/busngo/model/entities/Bilet.java

    rb101b69 rbde8b13  
    1717    @Id
    1818    @Column(name = "b_id")
    19     private Long bId;
     19    private Long BId;
     20
    2021    @Basic
    2122    @Column(name = "b_datum_na_kupuvanje")
    2223    private Timestamp bDatumNaKupuvanje;
     24
    2325    @Basic
    2426    @Column(name = "b_status", columnDefinition = "string_kratok")
    2527    @Enumerated(EnumType.STRING)
    2628    private BILET_STATUS bStatus;
     29
    2730    @ManyToOne
    2831    @JoinColumn(name = "patnik_k_id", referencedColumnName = "k_id")
    29     private Korisnik korisnikByPatnikKId;
     32    private Patnik korisnikByPatnikKId;
     33
    3034    @ManyToOne
    3135    @JoinColumn(name = "tb_id", referencedColumnName = "tb_id")
  • src/main/java/mk/ukim/finki/busngo/model/entities/Instancanalinija.java

    rb101b69 rbde8b13  
    2424    @ManyToOne
    2525    @JoinColumn(name = "vozac_k_id", referencedColumnName = "k_id", nullable = false)
    26     private Korisnik korisnikByVozacKId;
     26    private Vozac korisnikByVozacKId;
    2727    @ManyToOne
    2828    @JoinColumn(name = "a_registracija", referencedColumnName = "a_registracija")
  • src/main/java/mk/ukim/finki/busngo/model/entities/Kazna.java

    rb101b69 rbde8b13  
    99@Data
    1010@Entity
     11@Inheritance(strategy = InheritanceType.JOINED)
    1112public class Kazna {
    1213    @GeneratedValue(strategy = GenerationType.IDENTITY)
     
    1415    @Column(name = "kz_id")
    1516    private Long kzId;
     17
    1618    @Basic
    1719    @Column(name = "kz_iznos")
    1820    private Double kzIznos;
     21
    1922    @Basic
    2023    @Column(name = "kz_plateno")
    2124    private Boolean kzPlateno;
     25
    2226    @Basic
    2327    @Column(name = "kz_datum")
    2428    private Timestamp kzDatum;
     29
    2530    @Basic
    2631    @Column(name = "kz_datum_plateno")
    2732    private Timestamp kzDatumPlateno;
     33
    2834    @Basic
    2935    @Column(name = "kz_dokument")
    3036    private String kzDokument;
     37
    3138    @ManyToOne
    3239    @JoinColumn(name = "kondukter_k_id", referencedColumnName = "k_id")
    33     private Korisnik korisnikByKondukterKId;
     40    private Kondukter korisnikByKondukterKId;
     41
    3442    @ManyToOne
    3543    @JoinColumn(name = "kontrola_id", referencedColumnName = "kontrola_id")
    3644    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;
    4151}
  • src/main/java/mk/ukim/finki/busngo/model/entities/Kaznazaneregistriran.java

    rb101b69 rbde8b13  
    88@Data
    99@Entity
    10 public class Kaznazaneregistriran {
    11     @GeneratedValue(strategy = GenerationType.IDENTITY)
    12     @Id
    13     @Column(name = "kz_id")
    14     private Long kzId;
     10public class Kaznazaneregistriran extends Kazna {
    1511    @Basic
    1612    @Column(name = "kzn_telefon")
    1713    private String kznTelefon;
     14
    1815    @Basic
    1916    @Column(name = "kzn_ime")
    2017    private String kznIme;
     18
    2119    @Basic
    2220    @Column(name = "kzn_adresa")
    2321    private String kznAdresa;
    24     @OneToOne
    25     @JoinColumn(name = "kz_id", referencedColumnName = "kz_id", nullable = false)
    26     private Kazna kaznaByKzId;
    2722}
  • src/main/java/mk/ukim/finki/busngo/model/entities/Kaznazaregistriran.java

    rb101b69 rbde8b13  
    88@Data
    99@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;
     10public class Kaznazaregistriran extends Kazna{
    1811    @ManyToOne
    1912    @JoinColumn(name = "patnik_k_id", referencedColumnName = "k_id")
    20     private Korisnik korisnikByPatnikKId;
     13    private Patnik korisnikByPatnikKId;
    2114}
  • src/main/java/mk/ukim/finki/busngo/model/entities/Kondukter.java

    rb101b69 rbde8b13  
    44import lombok.Data;
    55
     6import java.util.List;
    67import java.util.Objects;
    78
    89@Data
    910@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;
     11public class Kondukter extends Vraboten{
     12    @OneToMany(mappedBy = "korisnikByKondukterKId")
     13    private List<Kazna> kaznasByKId;
     14    @OneToMany(mappedBy = "korisnikByKondukterKId")
     15    private List<Kontroli> kontrolisByKId;
    1816
    1917}
  • src/main/java/mk/ukim/finki/busngo/model/entities/Kontroli.java

    rb101b69 rbde8b13  
    2323    @ManyToOne
    2424    @JoinColumn(name = "kondukter_k_id", referencedColumnName = "k_id")
    25     private Korisnik korisnikByKondukterKId;
     25    private Kondukter korisnikByKondukterKId;
    2626    @ManyToOne
    2727    @JoinColumn(name = "inl_id", referencedColumnName = "inl_id")
  • src/main/java/mk/ukim/finki/busngo/model/entities/Korisnik.java

    rb101b69 rbde8b13  
    1515@Data
    1616@Entity
     17@Inheritance(strategy = InheritanceType.JOINED)
    1718public class Korisnik implements UserDetails {
    1819    @GeneratedValue(strategy = GenerationType.IDENTITY)
     
    2021    @Column(name = "k_id")
    2122    private Long kId;
     23
    2224    @Basic
    2325    @Column(name = "k_ime")
    2426    private String kIme;
     27
    2528    @Basic
    2629    @Column(name = "k_adresa")
    2730    private String kAdresa;
     31
    2832    @Basic
    2933    @Column(name = "k_telefon")
    3034    private String kTelefon;
     35
    3136    @Basic
    3237    @Column(name = "k_email")
    3338    private String kEmail;
     39
    3440    @Basic
    3541    @Column(name = "k_embg")
    3642    private String kEmbg;
     43
    3744    @Basic
    3845    @Column(name = "k_is_admin")
    3946    private Boolean kIsAdmin;
     47
    4048    @Basic
    4149    @Column(name = "k_lozinka")
    4250    private String kLozinka;
    43     @OneToMany(mappedBy = "korisnikByPatnikKId")
    44     private List<Bilet> biletsByKId;
     51
     52//    @OneToMany(mappedBy = "korisnikByPatnikKId")
     53//    private List<Bilet> biletsByKId;
    4554//    private boolean isAccountNonExpired = true;
    4655//    private boolean isAccountNonLocked = true;
  • src/main/java/mk/ukim/finki/busngo/model/entities/Patnik.java

    rb101b69 rbde8b13  
    44import lombok.Data;
    55
     6import java.util.List;
    67import java.util.Objects;
    78
    89@Data
    910@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;
     11public 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;
    1820}
  • src/main/java/mk/ukim/finki/busngo/model/entities/Tipbilet.java

    rb101b69 rbde8b13  
    1919    private Long tbTrajnost;
    2020    @Basic
     21    @Column(name = "tb_cena")
     22    private Float tbCena;
     23    @Basic
    2124    @Column(name = "tb_ime")
    2225    private String tbIme;
  • src/main/java/mk/ukim/finki/busngo/model/entities/Vozac.java

    rb101b69 rbde8b13  
    44import lombok.Data;
    55
     6import java.util.List;
    67import java.util.Objects;
    78
    89@Data
    910@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;
     11public class Vozac extends Vraboten {
     12    @OneToMany(mappedBy = "korisnikByVozacKId")
     13    private List<Instancanalinija> instancanalinijasByKId;
    1814
    1915}
  • src/main/java/mk/ukim/finki/busngo/model/entities/Vozenje.java

    rb101b69 rbde8b13  
    2727    @ManyToOne
    2828    @JoinColumn(name = "patnik_k_id", referencedColumnName = "k_id")
    29     private Korisnik korisnikByPatnikKId;
     29    private Patnik korisnikByPatnikKId;
    3030    @ManyToOne
    3131    @JoinColumn(name = "kacuva_pnl_id", referencedColumnName = "pnl_id", nullable = false)
  • src/main/java/mk/ukim/finki/busngo/model/entities/Vraboten.java

    rb101b69 rbde8b13  
    1010@Data
    1111@Entity
    12 public class Vraboten {
    13     @GeneratedValue(strategy = GenerationType.IDENTITY)
    14     @Id
    15     @Column(name = "k_id")
    16     private Long kId;
     12public class Vraboten extends Korisnik {
    1713    @Basic
    1814    @Column(name = "v_plata")
    1915    private Double vPlata;
     16
    2017    @Basic
    2118    @Column(name = "v_datum_na_vrabotuvanje")
    2219    private Date vDatumNaVrabotuvanje;
     20
    2321    @Basic
    2422    @Column(name = "v_datum_prekin_vrabotuvanje")
    2523    private Date vDatumPrekinVrabotuvanje;
    26     @OneToOne
    27     @JoinColumn(name = "k_id", referencedColumnName = "k_id", nullable = false)
    28     private Korisnik korisnikByKId;
    2924
    3025}
  • src/main/java/mk/ukim/finki/busngo/model/enums/Role.java

    rb101b69 rbde8b13  
    66public enum Role implements GrantedAuthority {
    77    ROLE_USER,
     8    ROLE_PASSENGER,
     9    ROLE_DRIVER,
     10    ROLE_CONDUCTOR,
    811    ROLE_ADMIN;
    912
  • src/main/java/mk/ukim/finki/busngo/repository/BiletRepository.java

    rb101b69 rbde8b13  
    88
    99import java.util.List;
     10import java.util.Optional;
    1011
    1112
     
    1314//    List<Bilet> findAllByKorisnikByPatnikKIdAndBStatus(Korisnik korisnik, BILET_STATUS status);
    1415//    List<Bilet> findAllByKorisnikByPatnikKId(Korisnik korisnik);
     16    Optional<Bilet> findByBIdAndAndKorisnikByPatnikKId(Long bid, Patnik patnik);
    1517}
  • src/main/java/mk/ukim/finki/busngo/repository/KorisnikRepository.java

    rb101b69 rbde8b13  
    55import org.springframework.data.jpa.repository.JpaRepository;
    66import org.springframework.data.jpa.repository.Query;
     7import org.springframework.data.repository.NoRepositoryBean;
    78
    89import java.util.Optional;
     10
    911
    1012public interface KorisnikRepository extends JpaRepository<Korisnik, Long> {
  • src/main/java/mk/ukim/finki/busngo/repository/PatnikRepository.java

    rb101b69 rbde8b13  
    33import mk.ukim.finki.busngo.model.entities.Patnik;
    44import org.springframework.data.jpa.repository.JpaRepository;
     5import org.springframework.data.jpa.repository.Query;
    56import org.springframework.stereotype.Repository;
    67
     8import java.util.List;
     9import java.util.Optional;
     10
    711public interface PatnikRepository extends JpaRepository<Patnik, Long> {
    8 
     12    @Query("SELECT p from Patnik p where p.kEmail = ?1")
     13    Optional<Patnik> findByKEmail(String email);
    914}
  • src/main/java/mk/ukim/finki/busngo/service/AuthService.java

    rb101b69 rbde8b13  
    55public interface AuthService {
    66    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);
    88
    99}
  • src/main/java/mk/ukim/finki/busngo/service/BiletService.java

    rb101b69 rbde8b13  
    22
    33import mk.ukim.finki.busngo.model.entities.Bilet;
     4import mk.ukim.finki.busngo.model.entities.Patnik;
    45import mk.ukim.finki.busngo.model.enums.BILET_STATUS;
    56
     
    1314
    1415    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();
    1526}
  • src/main/java/mk/ukim/finki/busngo/service/PatnikService.java

    rb101b69 rbde8b13  
    22
    33import mk.ukim.finki.busngo.model.entities.Bilet;
     4import mk.ukim.finki.busngo.model.entities.Korisnik;
    45import mk.ukim.finki.busngo.model.entities.Patnik;
    56
     
    910    List<Patnik> listAll();
    1011    Patnik findById(Long id);
     12    Patnik loadUserByEmail(String email);
     13
     14    Patnik save(Korisnik korisnik);
    1115
    1216}
  • src/main/java/mk/ukim/finki/busngo/service/impl/AuthServiceImpl.java

    rb101b69 rbde8b13  
    22
    33import mk.ukim.finki.busngo.model.entities.Korisnik;
     4import mk.ukim.finki.busngo.model.entities.Patnik;
    45import mk.ukim.finki.busngo.model.exceptions.InvalidCredentialsException;
    56import mk.ukim.finki.busngo.model.exceptions.UserAlreadyExistsException;
    67import mk.ukim.finki.busngo.repository.KorisnikRepository;
     8import mk.ukim.finki.busngo.repository.PatnikRepository;
    79import mk.ukim.finki.busngo.service.AuthService;
    810import org.springframework.security.crypto.password.PasswordEncoder;
    911import org.springframework.stereotype.Service;
    1012
    11 import java.util.List;
    12 
    1313@Service
    1414public class AuthServiceImpl implements AuthService {
    1515    private final KorisnikRepository korisnikRepository;
     16    private final PatnikRepository patnikRepository;
    1617    private final PasswordEncoder passwordEncoder;
    1718
    18     public AuthServiceImpl(KorisnikRepository korisnikRepository, PasswordEncoder passwordEncoder) {
     19    public AuthServiceImpl(KorisnikRepository korisnikRepository, PatnikRepository patnikRepository, PasswordEncoder passwordEncoder) {
    1920        this.korisnikRepository = korisnikRepository;
     21        this.patnikRepository = patnikRepository;
    2022        this.passwordEncoder = passwordEncoder;
    2123    }
     
    2931
    3032    @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) {
    3234        if (email == null || password == null || email.isEmpty() || password.isEmpty()) {
    3335            throw new InvalidCredentialsException();
     
    4244        }
    4345
    44         Korisnik korisnik = new Korisnik();
     46        Patnik korisnik = new Patnik();
    4547        korisnik.setKIme(ime);
    4648        korisnik.setKAdresa(address);
     
    5052        korisnik.setKIsAdmin(false);
    5153
    52         return korisnikRepository.save(korisnik);
     54
     55        return patnikRepository.save(korisnik);
    5356    }
    5457
  • src/main/java/mk/ukim/finki/busngo/service/impl/BiletServiceImpl.java

    rb101b69 rbde8b13  
    33import mk.ukim.finki.busngo.model.entities.Bilet;
    44import mk.ukim.finki.busngo.model.entities.Korisnik;
     5import mk.ukim.finki.busngo.model.entities.Patnik;
    56import mk.ukim.finki.busngo.model.entities.Tipbilet;
    67import mk.ukim.finki.busngo.model.enums.BILET_STATUS;
     8import mk.ukim.finki.busngo.model.exceptions.InvalidBiletIdException;
    79import mk.ukim.finki.busngo.model.exceptions.InvalidTipBiletIdException;
    810import mk.ukim.finki.busngo.repository.BiletRepository;
     11import mk.ukim.finki.busngo.repository.KorisnikRepository;
    912import mk.ukim.finki.busngo.repository.TipBIletRepository;
    1013import mk.ukim.finki.busngo.service.BiletService;
    1114import mk.ukim.finki.busngo.service.KorisnikService;
    1215import mk.ukim.finki.busngo.service.PatnikService;
     16import org.springframework.security.crypto.password.PasswordEncoder;
    1317import org.springframework.stereotype.Service;
    1418
     
    2428    private final TipBIletRepository tipBIletRepository;
    2529    private final PatnikService patnikService;
     30    private final PasswordEncoder passwordEncoder;
     31    private final KorisnikRepository korisnikRepository;
    2632
    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) {
    2834        this.biletRepository = biletRepository;
    2935        this.korisnikService = korisnikService;
    3036        this.tipBIletRepository = tipBIletRepository;
    3137        this.patnikService = patnikService;
     38        this.passwordEncoder = passwordEncoder;
     39        this.korisnikRepository = korisnikRepository;
    3240    }
    3341
     
    3947    @Override
    4048    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();
    4351    }
    4452
     
    5260    public Bilet buy(Long tipbilet, LocalDateTime now, BILET_STATUS biletStatus, String name) {
    5361        Tipbilet tipbilet1 = tipBIletRepository.findById(tipbilet).orElseThrow(InvalidTipBiletIdException::new);
    54         Korisnik korisnik = korisnikService.loadUserByEmail(name);
     62        Patnik korisnik = patnikService.loadUserByEmail(name);
    5563        Bilet bilet = new Bilet();
    5664        bilet.setBStatus(biletStatus);
     
    6068        return biletRepository.save(bilet);
    6169    }
     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
    62125}
  • src/main/java/mk/ukim/finki/busngo/service/impl/PatnikServiceImpl.java

    rb101b69 rbde8b13  
    11package mk.ukim.finki.busngo.service.impl;
    22
     3import mk.ukim.finki.busngo.model.entities.Instancanalinija;
     4import mk.ukim.finki.busngo.model.entities.Korisnik;
    35import mk.ukim.finki.busngo.model.entities.Patnik;
    46import mk.ukim.finki.busngo.model.exceptions.InvalidPatnikIdException;
    57import mk.ukim.finki.busngo.repository.PatnikRepository;
     8import mk.ukim.finki.busngo.service.InstancaNaLinijaService;
    69import mk.ukim.finki.busngo.service.PatnikService;
    710import org.springframework.stereotype.Service;
    811
     12import java.util.Collections;
    913import java.util.List;
    1014
     
    1216public class PatnikServiceImpl implements PatnikService {
    1317    private final PatnikRepository patnikRepository;
     18    private final InstancaNaLinijaService instancaNaLinijaService;
    1419
    15     public PatnikServiceImpl(PatnikRepository patnikRepository) {
     20    public PatnikServiceImpl(PatnikRepository patnikRepository, InstancaNaLinijaService instancaNaLinijaService) {
    1621        this.patnikRepository = patnikRepository;
     22        this.instancaNaLinijaService = instancaNaLinijaService;
    1723    }
    1824
    1925    @Override
    2026    public List<Patnik> listAll() {
    21         return patnikRepository.findAll();
     27        return  patnikRepository.findAll();
    2228    }
    2329
     
    2632        return patnikRepository.findById(id).orElseThrow(InvalidPatnikIdException::new);
    2733    }
     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
    2855}
  • src/main/java/mk/ukim/finki/busngo/web/BiletController.java

    rb101b69 rbde8b13  
    11package mk.ukim.finki.busngo.web;
    22
     3import mk.ukim.finki.busngo.model.entities.Patnik;
    34import mk.ukim.finki.busngo.model.enums.BILET_STATUS;
     5import mk.ukim.finki.busngo.model.exceptions.InvalidPatnikIdException;
    46import mk.ukim.finki.busngo.service.AuthService;
    57import mk.ukim.finki.busngo.service.BiletService;
     8import mk.ukim.finki.busngo.service.PatnikService;
    69import mk.ukim.finki.busngo.service.TipBiletService;
    710import org.springframework.security.core.Authentication;
     
    2124    private final TipBiletService tipBiletService;
    2225    private final AuthService authService;
     26    private final PatnikService patnikService;
    2327
    24     public BiletController(BiletService biletService, TipBiletService tipBiletService, AuthService authService) {
     28    public BiletController(BiletService biletService, TipBiletService tipBiletService, AuthService authService, PatnikService patnikService) {
    2529        this.biletService = biletService;
    2630        this.tipBiletService = tipBiletService;
    2731        this.authService = authService;
     32        this.patnikService = patnikService;
    2833    }
    2934
     
    3136    public String getAllBileti(@RequestParam(required = false) Long id,
    3237                               @RequestParam(required = false) BILET_STATUS status,
    33                                Model model){
     38                               Model model,
     39                               Authentication authentication){
    3440        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
    3652        return "master-template";
    3753    }
     
    5066    }
    5167
     68//    @GetMapping("/encode")
     69//    public String encode(){
     70//        biletService.encode();
     71//        return "redirect:/bilet";
     72//    }
     73
    5274}
  • src/main/java/mk/ukim/finki/busngo/web/RegisterController.java

    rb101b69 rbde8b13  
    11package mk.ukim.finki.busngo.web;
    22
    3 import mk.ukim.finki.busngo.model.enums.Role;
     3import mk.ukim.finki.busngo.model.entities.Korisnik;
    44import mk.ukim.finki.busngo.model.exceptions.InvalidCredentialsException;
    55import mk.ukim.finki.busngo.model.exceptions.UserAlreadyExistsException;
    66import mk.ukim.finki.busngo.service.AuthService;
    77import mk.ukim.finki.busngo.service.KorisnikService;
     8import mk.ukim.finki.busngo.service.PatnikService;
    89import org.springframework.stereotype.Controller;
    910import org.springframework.ui.Model;
     
    1819    private final AuthService authService;
    1920    private final KorisnikService korisnikService;
     21    private final PatnikService patnikService;
    2022
    21     public RegisterController(AuthService authService, KorisnikService korisnikService) {
     23    public RegisterController(AuthService authService, KorisnikService korisnikService, PatnikService patnikService) {
    2224        this.authService = authService;
    2325        this.korisnikService = korisnikService;
     26        this.patnikService = patnikService;
    2427    }
    2528
     
    4447    ) {
    4548        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);
    4751            return "redirect:/login";
    4852        } catch (InvalidCredentialsException | UserAlreadyExistsException exception) {
     
    5155    }
    5256
     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
    5367}
Note: See TracChangeset for help on using the changeset viewer.