Ignore:
Timestamp:
02/18/24 22:01:54 (9 months ago)
Author:
ppaunovski <paunovskipavel@…>
Branches:
master
Children:
4251327
Parents:
bde8b13
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:
2 added
19 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/mk/ukim/finki/busngo/repository/BiletRepository.java

    rbde8b13 re272096  
    1515//    List<Bilet> findAllByKorisnikByPatnikKId(Korisnik korisnik);
    1616    Optional<Bilet> findByBIdAndAndKorisnikByPatnikKId(Long bid, Patnik patnik);
     17//    List<Bilet> findAllByKorisnikByPatnikKIdAndBStatus(Patnik patnik, BILET_STATUS status);
    1718}
  • src/main/java/mk/ukim/finki/busngo/repository/VozenjeRepository.java

    rbde8b13 re272096  
    33import mk.ukim.finki.busngo.model.entities.Patnik;
    44import mk.ukim.finki.busngo.model.entities.Vozenje;
     5import mk.ukim.finki.busngo.model.enums.VOZENJE_STATUS;
    56import org.springframework.data.jpa.repository.JpaRepository;
    67
     
    910public interface VozenjeRepository extends JpaRepository<Vozenje, Long> {
    1011    List<Vozenje> findAllByKorisnikByPatnikKId(Patnik patnik);
     12    List<Vozenje> findAllByKorisnikByPatnikKIdAndAndVozenjeStatus(Patnik patnik, VOZENJE_STATUS vozenjeStatus);
    1113}
  • src/main/java/mk/ukim/finki/busngo/service/AuthService.java

    rbde8b13 re272096  
    22
    33import mk.ukim.finki.busngo.model.entities.Korisnik;
     4import mk.ukim.finki.busngo.model.enums.VrabotenType;
    45
    56public interface AuthService {
    67    Korisnik login(String email, String password);
    78    Korisnik registerPatnik(String ime, String email, String password, String confirmPassword, String address, String telefon);
     9    Korisnik registerVraboten(String ime, String email, String password, String confirmPassword, String address, String telefon, VrabotenType type, Double salary);
    810
    911}
  • src/main/java/mk/ukim/finki/busngo/service/BiletService.java

    rbde8b13 re272096  
    1616
    1717    List<Bilet> findAllByPatnikEmail(String email);
     18//    List<Bilet> findAllByPatnikEmailACTIVE(String email);
    1819    Bilet findBybIdAndPatnikEmail(Long bId, String email);
    1920
  • src/main/java/mk/ukim/finki/busngo/service/InstancaNaLinijaService.java

    rbde8b13 re272096  
    1111    Instancanalinija findById(Long inlId);
    1212    Instancanalinija start(Long liId, String a_registracija, String email);
    13     Instancanalinija end(Long inlId);
     13    Instancanalinija end(Long inlId, String email);
    1414    List<Instancanalinija> findAllActive();
    1515
  • src/main/java/mk/ukim/finki/busngo/service/KaznaService.java

    rbde8b13 re272096  
    88    List<Kazna> findAll();
    99    List<Kazna> findAllByKontrolaId(Long kontrolaId);
     10    Kazna pay(Long kaznaId);
     11    Kazna findById(Long id);
    1012}
  • src/main/java/mk/ukim/finki/busngo/service/KaznaZaRegistriranService.java

    rbde8b13 re272096  
    11package mk.ukim.finki.busngo.service;
    22
     3import mk.ukim.finki.busngo.model.entities.Kazna;
    34import mk.ukim.finki.busngo.model.entities.Kaznazaregistriran;
    45import mk.ukim.finki.busngo.model.exceptions.UserShouldNotBeTicketedException;
     
    1011
    1112    Kaznazaregistriran create(Long kontrolaId, String dokument, Double iznos, Long patnik, String email) throws UserShouldNotBeTicketedException;
     13    Kaznazaregistriran pay(Long kaznaId);
     14    Kaznazaregistriran findById(Long id);
    1215}
  • src/main/java/mk/ukim/finki/busngo/service/VozenjeService.java

    rbde8b13 re272096  
    22
    33import mk.ukim.finki.busngo.model.entities.Vozenje;
     4import mk.ukim.finki.busngo.model.enums.VOZENJE_STATUS;
    45
    56import java.util.List;
     
    78public interface VozenjeService {
    89    List<Vozenje> findVozenjaByPatnik(String email);
     10    List<Vozenje> findVozenjaByPatnikAndStatus(String email, VOZENJE_STATUS status);
    911    Vozenje start(String email, Long bId, Long pnlId, Long inlId);
    1012    Vozenje end(Long vozenjeId, Long pnlId);
  • src/main/java/mk/ukim/finki/busngo/service/impl/AuthServiceImpl.java

    rbde8b13 re272096  
    11package mk.ukim.finki.busngo.service.impl;
    22
     3import mk.ukim.finki.busngo.model.entities.Kondukter;
    34import mk.ukim.finki.busngo.model.entities.Korisnik;
    45import mk.ukim.finki.busngo.model.entities.Patnik;
     6import mk.ukim.finki.busngo.model.entities.Vozac;
     7import mk.ukim.finki.busngo.model.enums.VrabotenType;
    58import mk.ukim.finki.busngo.model.exceptions.InvalidCredentialsException;
    69import mk.ukim.finki.busngo.model.exceptions.UserAlreadyExistsException;
     10import mk.ukim.finki.busngo.repository.KondukterRepository;
    711import mk.ukim.finki.busngo.repository.KorisnikRepository;
    812import mk.ukim.finki.busngo.repository.PatnikRepository;
    9 import mk.ukim.finki.busngo.service.AuthService;
     13import mk.ukim.finki.busngo.repository.VozacRepository;
     14import mk.ukim.finki.busngo.service.*;
    1015import org.springframework.security.crypto.password.PasswordEncoder;
    1116import org.springframework.stereotype.Service;
     17
     18import java.sql.Date;
     19import java.time.LocalDate;
    1220
    1321@Service
     
    1523    private final KorisnikRepository korisnikRepository;
    1624    private final PatnikRepository patnikRepository;
     25    private final VozacRepository vozacRepository;
     26    private final KondukterRepository kondukterRepository;
    1727    private final PasswordEncoder passwordEncoder;
     28    private final PatnikService patnikService;
     29    private final KondukterService kondukterService;
     30    private final VozacService vozacService;
    1831
    19     public AuthServiceImpl(KorisnikRepository korisnikRepository, PatnikRepository patnikRepository, PasswordEncoder passwordEncoder) {
     32    public AuthServiceImpl(KorisnikRepository korisnikRepository, PatnikRepository patnikRepository, VozacRepository vozacRepository, KondukterRepository kondukterRepository, PasswordEncoder passwordEncoder, PatnikService patnikService, KondukterService kondukterService, VozacService vozacService) {
    2033        this.korisnikRepository = korisnikRepository;
    2134        this.patnikRepository = patnikRepository;
     35        this.vozacRepository = vozacRepository;
     36        this.kondukterRepository = kondukterRepository;
    2237        this.passwordEncoder = passwordEncoder;
     38        this.patnikService = patnikService;
     39        this.kondukterService = kondukterService;
     40        this.vozacService = vozacService;
    2341    }
    2442
     
    5270        korisnik.setKIsAdmin(false);
    5371
     72        return patnikRepository.save(korisnik);
     73    }
    5474
    55         return patnikRepository.save(korisnik);
     75    @Override
     76    public Korisnik registerVraboten(String ime, String email, String password, String confirmPassword, String address, String telefon, VrabotenType type, Double salary) {
     77        if (email == null || password == null || email.isEmpty() || password.isEmpty()) {
     78            throw new InvalidCredentialsException();
     79        }
     80
     81        if (!password.equals(confirmPassword)) {
     82            throw new InvalidCredentialsException();
     83        }
     84
     85        if(this.korisnikRepository.findByKEmail(email).isPresent()) {
     86            throw new UserAlreadyExistsException(email);
     87        }
     88
     89
     90        switch (type){
     91            case ADMIN:
     92                Korisnik korisnik = new Korisnik();
     93                korisnik.setKIme(ime);
     94                korisnik.setKAdresa(address);
     95                korisnik.setKLozinka(passwordEncoder.encode(password));
     96                korisnik.setKEmail(email);
     97                korisnik.setKTelefon(telefon);
     98                korisnik.setKIsAdmin(true);
     99                return korisnikRepository.save(korisnik);
     100            case VOZAC:
     101                Vozac vozac = new Vozac();
     102                vozac.setKIme(ime);
     103                vozac.setKAdresa(address);
     104                vozac.setKLozinka(passwordEncoder.encode(password));
     105                vozac.setKEmail(email);
     106                vozac.setKTelefon(telefon);
     107                vozac.setKIsAdmin(false);
     108                vozac.setVPlata(salary);
     109                vozac.setVDatumNaVrabotuvanje(Date.valueOf(LocalDate.now()));
     110                this.korisnikRepository.save(vozac);
     111
     112                return vozacRepository.save(vozac);
     113            case KONDUKTER:
     114                Kondukter kondukter = new Kondukter();
     115                kondukter.setKIme(ime);
     116                kondukter.setKAdresa(address);
     117                kondukter.setKLozinka(passwordEncoder.encode(password));
     118                kondukter.setKEmail(email);
     119                kondukter.setKTelefon(telefon);
     120                kondukter.setKIsAdmin(false);
     121                kondukter.setVPlata(salary);
     122                kondukter.setVDatumNaVrabotuvanje(Date.valueOf(LocalDate.now()));
     123                this.korisnikRepository.save(kondukter);
     124
     125                return kondukterRepository.save(kondukter);
     126        }
     127        return null;
    56128    }
    57129
  • src/main/java/mk/ukim/finki/busngo/service/impl/BiletServiceImpl.java

    rbde8b13 re272096  
    1616import org.springframework.security.crypto.password.PasswordEncoder;
    1717import org.springframework.stereotype.Service;
     18import org.thymeleaf.expression.Lists;
    1819
    1920import java.sql.Timestamp;
     
    7576    }
    7677
     78//    @Override
     79//    public List<Bilet> findAllByPatnikEmailACTIVE(String email) {
     80//        Patnik patnik = patnikService.loadUserByEmail(email);
     81//        List<Bilet> allByKorisnikByPatnikKIdAndBStatus = biletRepository.findAllByKorisnikByPatnikKIdAndBStatus(patnik, BILET_STATUS.ACTIVE);
     82//        List<Bilet> allByKorisnikByPatnikKIdAndBStatus1 = biletRepository.findAllByKorisnikByPatnikKIdAndBStatus(patnik, BILET_STATUS.INACTIVE);
     83//        allByKorisnikByPatnikKIdAndBStatus1.addAll(allByKorisnikByPatnikKIdAndBStatus);
     84//        return allByKorisnikByPatnikKIdAndBStatus1;
     85//    }
     86
    7787    @Override
    7888    public Bilet findBybIdAndPatnikEmail(Long bId, String email) {
  • src/main/java/mk/ukim/finki/busngo/service/impl/InstancaNaLinijaServiceImpl.java

    rbde8b13 re272096  
    5252
    5353    @Override
    54     public Instancanalinija end(Long inlId) {
     54    public Instancanalinija end(Long inlId, String email) {
     55        Vozac vozac = vozacService.findByEmail(email);
    5556        Instancanalinija instancanalinija = this.findById(inlId);
    5657        instancanalinija.setInlDatumEnd(Timestamp.valueOf(LocalDateTime.now()));
  • src/main/java/mk/ukim/finki/busngo/service/impl/KaznaServiceImpl.java

    rbde8b13 re272096  
    88import org.springframework.stereotype.Service;
    99
     10import java.sql.Timestamp;
     11import java.time.LocalDateTime;
    1012import java.util.List;
    1113
     
    3032        return kaznaRepository.findAllByKontroliByKontrolaId(kontroli);
    3133    }
     34
     35    @Override
     36    public Kazna pay(Long kaznaId) {
     37        Kazna kazna = this.findById(kaznaId);
     38        kazna.setKzPlateno(true);
     39        kazna.setKzDatumPlateno(Timestamp.valueOf(LocalDateTime.now()));
     40        return kaznaRepository.save(kazna);
     41    }
     42
     43    @Override
     44    public Kazna findById(Long id) {
     45        return kaznaRepository.findById(id).orElseThrow(RuntimeException::new);
     46    }
    3247}
  • src/main/java/mk/ukim/finki/busngo/service/impl/KaznaZaRegistriranServiceImpl.java

    rbde8b13 re272096  
    5959                kontroli.getInstancanalinijaByInlId().getInlId()));
    6060    }
     61
     62    @Override
     63    public Kaznazaregistriran pay(Long kaznaId) {
     64        Kaznazaregistriran kazna = this.findById(kaznaId);
     65        if(!kazna.getKzPlateno()){
     66            kazna.setKzPlateno(true);
     67            kazna.setKzDatumPlateno(Timestamp.valueOf(LocalDateTime.now()));
     68        }
     69        return kaznaZaRegistriranRepository.save(kazna);
     70    }
     71
     72    @Override
     73    public Kaznazaregistriran findById(Long id) {
     74        return kaznaZaRegistriranRepository.findById(id).orElseThrow(RuntimeException::new);
     75    }
    6176}
  • src/main/java/mk/ukim/finki/busngo/service/impl/VozenjeServiceImpl.java

    rbde8b13 re272096  
    3333        Patnik patnik = patnikService.loadUserByEmail(email);
    3434        return vozenjeRepository.findAllByKorisnikByPatnikKId(patnik);
     35    }
     36
     37    @Override
     38    public List<Vozenje> findVozenjaByPatnikAndStatus(String email, VOZENJE_STATUS status) {
     39        Patnik patnik = patnikService.loadUserByEmail(email);
     40        return vozenjeRepository.findAllByKorisnikByPatnikKIdAndAndVozenjeStatus(patnik, status);
    3541    }
    3642
  • src/main/java/mk/ukim/finki/busngo/web/BiletController.java

    rbde8b13 re272096  
    4141        Patnik patnik = null;
    4242        try{
     43            patnik = patnikService.loadUserByEmail(authentication.getName());
    4344            model.addAttribute("bileti", biletService.findAllByPatnikEmail(authentication.getName()));
    4445        }
  • src/main/java/mk/ukim/finki/busngo/web/InstancaNaLinijaController.java

    rbde8b13 re272096  
    7171
    7272    @PostMapping("/{inlId}/end")
    73     public String endInstanca(@PathVariable Long inlId){
    74         Instancanalinija ended = instancaNaLinijaService.end(inlId);
     73    public String endInstanca(@PathVariable Long inlId,
     74                              Authentication authentication){
     75        Instancanalinija ended = instancaNaLinijaService.end(inlId, authentication.getName());
    7576        return "redirect:/instanca-na-linija/" + ended.getInlId();
    7677    }
  • src/main/java/mk/ukim/finki/busngo/web/KaznaController.java

    rbde8b13 re272096  
    99import org.springframework.ui.Model;
    1010import org.springframework.web.bind.annotation.GetMapping;
     11import org.springframework.web.bind.annotation.PathVariable;
     12import org.springframework.web.bind.annotation.PostMapping;
    1113import org.springframework.web.bind.annotation.RequestMapping;
    1214
     
    3739        return "master-template";
    3840    }
     41
     42    @PostMapping("/{id}/pay")
     43    public String pay(@PathVariable Long id,
     44                      Model model){
     45        kaznaZaRegistriranService.pay(id);
     46        return "redirect:/kazna";
     47    }
     48
    3949}
  • src/main/java/mk/ukim/finki/busngo/web/RegisterController.java

    rbde8b13 re272096  
    22
    33import mk.ukim.finki.busngo.model.entities.Korisnik;
     4import mk.ukim.finki.busngo.model.enums.VrabotenType;
    45import mk.ukim.finki.busngo.model.exceptions.InvalidCredentialsException;
    56import mk.ukim.finki.busngo.model.exceptions.UserAlreadyExistsException;
     
    3435        }
    3536
     37        model.addAttribute("types", VrabotenType.values());
     38
    3639        model.addAttribute("bodyContent", "register");
    3740        return "master-template";
     
    4447                           @RequestParam String confirmPassword,
    4548                           @RequestParam String address,
    46                            @RequestParam String phone
    47     ) {
     49                           @RequestParam String phone,
     50                           @RequestParam(required = false)VrabotenType vrabotenType,
     51                           @RequestParam(required = false) Double salary
     52                           ) {
    4853        try{
    49             Korisnik korisnik = this.authService.registerPatnik(name, email, password, confirmPassword, address, phone);
    50             this.patnikService.save(korisnik);
     54            Korisnik korisnik;
     55            if(vrabotenType != null){
     56                 korisnik = this.authService.registerVraboten(name, email, password, confirmPassword, address, phone, vrabotenType, salary);
     57
     58            }
     59            else
     60                korisnik = this.authService.registerPatnik(name, email, password, confirmPassword, address, phone);
    5161            return "redirect:/login";
    5262        } catch (InvalidCredentialsException | UserAlreadyExistsException exception) {
  • src/main/java/mk/ukim/finki/busngo/web/VozenjeController.java

    rbde8b13 re272096  
    44import mk.ukim.finki.busngo.model.entities.Patnik;
    55import mk.ukim.finki.busngo.model.entities.Vozenje;
     6import mk.ukim.finki.busngo.model.enums.VOZENJE_STATUS;
    67import mk.ukim.finki.busngo.model.exceptions.InvalidPatnikIdException;
    78import mk.ukim.finki.busngo.model.exceptions.InvalidPostojkaNaLinijaIdException;
     
    2930    @GetMapping()
    3031    public String getVozenjePage(Model model,
    31                                  Authentication authentication){
     32                                 Authentication authentication,
     33                                 @RequestParam(required = false) VOZENJE_STATUS status){
    3234        model.addAttribute("bodyContent", "listVozenja");
    3335        Patnik patnik = null;
    3436        try{
    35             model.addAttribute("vozenja", vozenjeService.findVozenjaByPatnik(authentication.getName()));
     37            if(status != null)
     38                model.addAttribute("vozenja", vozenjeService.findVozenjaByPatnikAndStatus(authentication.getName(), status));
     39            else
     40                model.addAttribute("vozenja", vozenjeService.findVozenjaByPatnikAndStatus(authentication.getName(), VOZENJE_STATUS.ACTIVE));
     41            model.addAttribute("vozStatus", VOZENJE_STATUS.values());
    3642        }
    3743        catch (InvalidPatnikIdException e){
Note: See TracChangeset for help on using the changeset viewer.