Changeset d14176d for src/main/java/project/fmo
- Timestamp:
- 07/07/23 12:14:58 (16 months ago)
- Branches:
- main
- Parents:
- 1dd9226
- Location:
- src/main/java/project/fmo/app/projcetfmo
- Files:
-
- 66 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/project/fmo/app/projcetfmo/Model/AdminKorisnik.java
r1dd9226 rd14176d 1 package model;1 package project.fmo.app.projcetfmo.Model; 2 2 3 import ja karta.persistence.*;3 import javax.persistence.*; 4 4 5 5 import java.util.Objects; … … 8 8 @Table(name = "admin_korisnik", schema = "project", catalog = "db_202223z_va_prj_fmo") 9 9 public class AdminKorisnik { 10 @GeneratedValue(strategy = GenerationType.IDENTITY) 10 11 11 @Id 12 12 @Column(name = "id_korisnik") -
src/main/java/project/fmo/app/projcetfmo/Model/Cena.java
r1dd9226 rd14176d 1 package model;1 package project.fmo.app.projcetfmo.Model; 2 2 3 import ja karta.persistence.*;3 import javax.persistence.*; 4 4 5 5 import java.sql.Date; … … 7 7 8 8 @Entity 9 @Table(schema = "project", name = "cena", catalog = "db_202223z_va_prj_fmo") 9 10 @IdClass(CenaPK.class) 10 11 public class Cena { 11 @GeneratedValue(strategy = GenerationType.IDENTITY)12 12 @Id 13 13 @Column(name = "id_produkt") 14 private int idProdukt; 15 @GeneratedValue(strategy = GenerationType.IDENTITY) 14 private int idProdukt; 16 15 @Id 17 16 @Column(name = "cena_od") … … 23 22 @Column(name = "iznos") 24 23 private int iznos; 24 25 public Cena(){} 26 public Cena(int idProdukt, Date cenaOd, Date cenaDo, int iznos) { 27 this.idProdukt = idProdukt; 28 this.cenaOd = cenaOd; 29 this.cenaDo = cenaDo; 30 this.iznos = iznos; 31 } 32 33 public Cena(int idProdukt, Date cenaOd, int iznos) { 34 this.idProdukt = idProdukt; 35 this.cenaOd = cenaOd; 36 this.iznos = iznos; 37 } 25 38 26 39 public int getIdProdukt() { -
src/main/java/project/fmo/app/projcetfmo/Model/CenaPK.java
r1dd9226 rd14176d 1 package model;1 package project.fmo.app.projcetfmo.Model; 2 2 3 import jakarta.persistence.Column; 4 import jakarta.persistence.GeneratedValue; 5 import jakarta.persistence.GenerationType; 6 import jakarta.persistence.Id; 3 import javax.persistence.*; 7 4 8 5 import java.io.Serializable; … … 13 10 @Column(name = "id_produkt") 14 11 @Id 15 @GeneratedValue(strategy = GenerationType.IDENTITY)16 12 private int idProdukt; 17 13 @Column(name = "cena_od") 18 14 @Id 19 @GeneratedValue(strategy = GenerationType.IDENTITY)20 15 private Date cenaOd; 16 17 public CenaPK (){} 18 public CenaPK(Integer idProdukt, Date cenaOd) { 19 this.idProdukt = idProdukt; 20 this.cenaOd = cenaOd; 21 } 21 22 22 23 public int getIdProdukt() { -
src/main/java/project/fmo/app/projcetfmo/Model/Dostava.java
r1dd9226 rd14176d 1 package model;1 package project.fmo.app.projcetfmo.Model; 2 2 3 import jakarta.persistence.*; 3 import project.fmo.app.projcetfmo.Service.impl.DostavaServiceImpl; 4 5 import javax.persistence.*; 4 6 5 7 import java.sql.Date; … … 7 9 8 10 @Entity 11 @Table(schema = "project", name = "dostava", catalog = "db_202223z_va_prj_fmo") 9 12 public class Dostava { 10 @Basic 11 @Column(name = "id_korisnik") 12 private int idKorisnik; 13 @Basic 14 @Column(name = "id_naracka") 15 private int idNaracka; 16 @GeneratedValue(strategy = GenerationType.IDENTITY) 13 @ManyToOne 14 @JoinColumn(name = "id_korisnik") 15 private Dostavuvac dostavuvac; 16 @OneToOne 17 @JoinColumn(name = "id_naracka") 18 private Naracka naracka; 17 19 @Id 18 20 @Column(name = "id_dostava") … … 25 27 private String status; 26 28 29 public Dostava (){} 30 31 public Dostava(Dostavuvac dostavuvac, Naracka naracka, int idDostava, Date datum, String status) { 32 this.dostavuvac = dostavuvac; 33 this.naracka = naracka; 34 this.idDostava = idDostava; 35 this.datum = datum; 36 this.status = status; 37 } 38 27 39 public int getIdKorisnik() { 28 return idKorisnik;40 return dostavuvac.getIdKorisnik(); 29 41 } 30 42 31 43 public void setIdKorisnik(int idKorisnik) { 32 this. idKorisnik = idKorisnik;44 this.dostavuvac.setIdKorisnik(idKorisnik); 33 45 } 34 46 35 47 public int getIdNaracka() { 36 return idNaracka;48 return naracka.getIdNaracka(); 37 49 } 38 50 39 51 public void setIdNaracka(int idNaracka) { 40 this. idNaracka = idNaracka;52 this.naracka.setIdNaracka(idNaracka); 41 53 } 42 54 … … 70 82 if (o == null || getClass() != o.getClass()) return false; 71 83 Dostava dostava = (Dostava) o; 72 return idKorisnik == dostava.idKorisnik && idNaracka == dostava.idNaracka && idDostava == dostava.idDostava && Objects.equals(datum, dostava.datum) && Objects.equals(status, dostava.status);84 return dostavuvac == dostava.dostavuvac && naracka == dostava.naracka && idDostava == dostava.idDostava && Objects.equals(datum, dostava.datum) && Objects.equals(status, dostava.status); 73 85 } 74 86 75 87 @Override 76 88 public int hashCode() { 77 return Objects.hash( idKorisnik, idNaracka, idDostava, datum, status);89 return Objects.hash(dostavuvac, naracka, idDostava, datum, status); 78 90 } 79 91 } -
src/main/java/project/fmo/app/projcetfmo/Model/Dostavuvac.java
r1dd9226 rd14176d 1 package model;1 package project.fmo.app.projcetfmo.Model; 2 2 3 import ja karta.persistence.*;3 import javax.persistence.*; 4 4 5 5 import java.util.Objects; 6 6 7 7 @Entity 8 @Table(schema = "project", name = "dostavuvac", catalog = "db_202223z_va_prj_fmo") 8 9 public class Dostavuvac { 9 @GeneratedValue(strategy = GenerationType.IDENTITY) 10 10 11 @Id 11 12 @Column(name = "id_korisnik") 12 13 private int idKorisnik; 14 15 public Dostavuvac(){} 13 16 14 17 public int getIdKorisnik() { -
src/main/java/project/fmo/app/projcetfmo/Model/Kategorija.java
r1dd9226 rd14176d 1 package model;1 package project.fmo.app.projcetfmo.Model; 2 2 3 import ja karta.persistence.*;3 import javax.persistence.*; 4 4 5 5 import java.util.Objects; 6 6 7 7 @Entity 8 @Table(schema = "project", name = "kategorija", catalog = "db_202223z_va_prj_fmo") 8 9 public class Kategorija { 9 10 @GeneratedValue(strategy = GenerationType.IDENTITY) … … 14 15 @Column(name = "ime") 15 16 private String ime; 17 18 19 public Kategorija(){} 20 public Kategorija(String ime) { 21 this.ime = ime; 22 } 16 23 17 24 public int getIdKategorija() { -
src/main/java/project/fmo/app/projcetfmo/Model/Korisnik.java
r1dd9226 rd14176d 1 package model;1 package project.fmo.app.projcetfmo.Model; 2 2 3 import jakarta.persistence.*;4 3 4 import org.springframework.security.core.GrantedAuthority; 5 import org.springframework.security.core.userdetails.UserDetails; 6 7 import javax.persistence.*; 5 8 import java.sql.Timestamp; 9 import java.util.Collection; 10 import java.util.Collections; 6 11 import java.util.Objects; 7 12 8 13 @Entity 9 public class Korisnik { 14 @Table(schema = "project", name = "korisnik", catalog = "db_202223z_va_prj_fmo") 15 public class Korisnik implements UserDetails { 10 16 @GeneratedValue(strategy = GenerationType.IDENTITY) 11 17 @Id … … 21 27 @Column(name = "kreiran_na_datum") 22 28 private Timestamp kreiranNaDatum; 29 30 31 public Korisnik(){ 32 33 } 34 public Korisnik(String imePrezime, String passwordKorisnik, Timestamp kreiranNaDatum) { 35 this.imePrezime = imePrezime; 36 this.passwordKorisnik = passwordKorisnik; 37 this.kreiranNaDatum = kreiranNaDatum; 38 } 23 39 24 40 public int getIdKorisnik() { … … 66 82 return Objects.hash(idKorisnik, imePrezime, passwordKorisnik, kreiranNaDatum); 67 83 } 84 85 @Override 86 public Collection<? extends GrantedAuthority> getAuthorities() { 87 return null; 88 } 89 90 @Override 91 public String getPassword() { 92 return null; 93 } 94 95 @Override 96 public String getUsername() { 97 return null; 98 } 99 100 @Override 101 public boolean isAccountNonExpired() { 102 return false; 103 } 104 105 @Override 106 public boolean isAccountNonLocked() { 107 return false; 108 } 109 110 @Override 111 public boolean isCredentialsNonExpired() { 112 return false; 113 } 114 115 @Override 116 public boolean isEnabled() { 117 return false; 118 } 68 119 } -
src/main/java/project/fmo/app/projcetfmo/Model/Kupuvac.java
r1dd9226 rd14176d 1 package model;1 package project.fmo.app.projcetfmo.Model; 2 2 3 import jakarta.persistence.*;4 3 4 import javax.persistence.*; 5 5 import java.util.Objects; 6 6 7 7 @Entity 8 @Table(schema = "project", name = "kupuvac", catalog = "db_202223z_va_prj_fmo") 8 9 public class Kupuvac { 9 @GeneratedValue(strategy = GenerationType.IDENTITY) 10 10 11 @Id 11 12 @Column(name = "id_korisnik") … … 14 15 @Column(name = "mail") 15 16 private String mail; 17 18 public Kupuvac(int idKorisnik, String mail) { 19 this.idKorisnik=idKorisnik; 20 this.mail=mail; 21 } 22 23 public Kupuvac() { 24 } 16 25 17 26 public int getIdKorisnik() { -
src/main/java/project/fmo/app/projcetfmo/Model/Magacin.java
r1dd9226 rd14176d 1 package model;1 package project.fmo.app.projcetfmo.Model; 2 2 3 import ja karta.persistence.*;3 import javax.persistence.*; 4 4 5 5 import java.util.Objects; 6 6 7 7 @Entity 8 @Table(schema = "project", name = "magacin", catalog = "db_202223z_va_prj_fmo") 8 9 public class Magacin { 9 @GeneratedValue(strategy = GenerationType.IDENTITY) 10 10 11 @Id 11 12 @Column(name = "id_magacin") -
src/main/java/project/fmo/app/projcetfmo/Model/Magacioner.java
r1dd9226 rd14176d 1 package model;1 package project.fmo.app.projcetfmo.Model; 2 2 3 import ja karta.persistence.*;3 import javax.persistence.*; 4 4 5 5 import java.util.Objects; 6 6 7 7 @Entity 8 @Table(schema = "project", name = "magacioner", catalog = "db_202223z_va_prj_fmo") 8 9 public class Magacioner { 9 @GeneratedValue(strategy = GenerationType.IDENTITY)10 10 @Id 11 11 @Column(name = "id_korisnik") 12 12 private int idKorisnik; 13 @ Basic14 @ Column(name = "id_magacin")15 private int idMagacin;13 @ManyToOne 14 @JoinColumn(name = "id_magacin") 15 private Magacin magacin; 16 16 17 17 public int getIdKorisnik() { … … 23 23 } 24 24 25 public int getIdMagacin() {26 return idMagacin;25 public Magacin getMagacin() { 26 return magacin; 27 27 } 28 28 29 public void set IdMagacin(int idMagacin) {30 this. idMagacin = idMagacin;29 public void setMagacin(Magacin magacin) { 30 this.magacin = magacin; 31 31 } 32 32 … … 36 36 if (o == null || getClass() != o.getClass()) return false; 37 37 Magacioner that = (Magacioner) o; 38 return idKorisnik == that.idKorisnik && idMagacin == that.idMagacin;38 return idKorisnik == that.idKorisnik && magacin == that.magacin; 39 39 } 40 40 41 41 @Override 42 42 public int hashCode() { 43 return Objects.hash(idKorisnik, idMagacin);43 return Objects.hash(idKorisnik, magacin); 44 44 } 45 45 } -
src/main/java/project/fmo/app/projcetfmo/Model/Naracka.java
r1dd9226 rd14176d 1 package model;1 package project.fmo.app.projcetfmo.Model; 2 2 3 import ja karta.persistence.*;3 import javax.persistence.*; 4 4 5 5 import java.sql.Date; … … 7 7 8 8 @Entity 9 @Table(schema = "project", name = "naracka", catalog = "db_202223z_va_prj_fmo") 9 10 public class Naracka { 10 11 @GeneratedValue(strategy = GenerationType.IDENTITY) … … 24 25 @Column(name = "adresa") 25 26 private String adresa; 26 @Basic 27 @Column(name = "id_korisnik") 28 private int idKorisnik; 27 @ManyToOne 28 @JoinColumn(name = "id_korisnik") 29 private Kupuvac kupuvac; 30 31 public Naracka(){} 32 33 public Naracka(int vkupnoSuma, Date datum, String status, String adresa, Kupuvac kupuvac) { 34 this.vkupnoSuma = vkupnoSuma; 35 this.datum = datum; 36 this.status = status; 37 this.adresa = adresa; 38 this.kupuvac = kupuvac; 39 } 29 40 30 41 public int getIdNaracka() { … … 69 80 70 81 public int getIdKorisnik() { 71 return idKorisnik;82 return kupuvac.getIdKorisnik(); 72 83 } 73 84 74 85 public void setIdKorisnik(int idKorisnik) { 75 this. idKorisnik = idKorisnik;86 this.kupuvac.setIdKorisnik(idKorisnik); 76 87 } 77 88 … … 81 92 if (o == null || getClass() != o.getClass()) return false; 82 93 Naracka naracka = (Naracka) o; 83 return idNaracka == naracka.idNaracka && vkupnoSuma == naracka.vkupnoSuma && idKorisnik == naracka.idKorisnik&& Objects.equals(datum, naracka.datum) && Objects.equals(status, naracka.status) && Objects.equals(adresa, naracka.adresa);94 return idNaracka == naracka.idNaracka && vkupnoSuma == naracka.vkupnoSuma && kupuvac == naracka.kupuvac && Objects.equals(datum, naracka.datum) && Objects.equals(status, naracka.status) && Objects.equals(adresa, naracka.adresa); 84 95 } 85 96 86 97 @Override 87 98 public int hashCode() { 88 return Objects.hash(idNaracka, vkupnoSuma, datum, status, adresa, idKorisnik);99 return Objects.hash(idNaracka, vkupnoSuma, datum, status, adresa, kupuvac); 89 100 } 90 101 } -
src/main/java/project/fmo/app/projcetfmo/Model/NarackaSodrziProdukt.java
r1dd9226 rd14176d 1 package model;1 package project.fmo.app.projcetfmo.Model; 2 2 3 import ja karta.persistence.*;3 import javax.persistence.*; 4 4 5 5 import java.util.Objects; … … 9 9 @IdClass(NarackaSodrziProduktPK.class) 10 10 public class NarackaSodrziProdukt { 11 @GeneratedValue(strategy = GenerationType.IDENTITY)12 11 @Id 13 12 @Column(name = "id_produkt") 14 13 private int idProdukt; 15 @GeneratedValue(strategy = GenerationType.IDENTITY)16 14 @Id 17 15 @Column(name = "id_naracka") … … 23 21 @Column(name = "cena") 24 22 private int cena; 23 24 public NarackaSodrziProdukt(){} 25 26 public NarackaSodrziProdukt(int idProdukt, int idNaracka, int kolicina, int cena) { 27 this.idProdukt = idProdukt; 28 this.idNaracka = idNaracka; 29 this.kolicina = kolicina; 30 this.cena = cena; 31 } 25 32 26 33 public int getIdProdukt() { -
src/main/java/project/fmo/app/projcetfmo/Model/NarackaSodrziProduktPK.java
r1dd9226 rd14176d 1 package model;1 package project.fmo.app.projcetfmo.Model; 2 2 3 import jakarta.persistence.Column; 4 import jakarta.persistence.GeneratedValue; 5 import jakarta.persistence.GenerationType; 6 import jakarta.persistence.Id; 3 import javax.persistence.*; 4 7 5 8 6 import java.io.Serializable; … … 12 10 @Column(name = "id_produkt") 13 11 @Id 14 @GeneratedValue(strategy = GenerationType.IDENTITY)15 12 private int idProdukt; 16 13 @Column(name = "id_naracka") 17 14 @Id 18 @GeneratedValue(strategy = GenerationType.IDENTITY)19 15 private int idNaracka; 16 17 public NarackaSodrziProduktPK(){} 20 18 21 19 public int getIdProdukt() { -
src/main/java/project/fmo/app/projcetfmo/Model/Produkt.java
r1dd9226 rd14176d 1 package model;1 package project.fmo.app.projcetfmo.Model; 2 2 3 import jakarta.persistence.*; 3 import javax.persistence.*; 4 import org.springframework.boot.autoconfigure.kafka.KafkaProperties; 4 5 5 6 import java.util.Objects; 6 7 7 8 @Entity 9 @Table(schema = "project", name = "produkt", catalog = "db_202223z_va_prj_fmo") 8 10 public class Produkt { 9 11 @GeneratedValue(strategy = GenerationType.IDENTITY) … … 17 19 @Column(name = "opis") 18 20 private String opis; 19 @Basic 20 @Column(name = "id_korisnik") 21 private int idKorisnik; 21 22 @ManyToOne 23 @JoinColumn(name = "id_korisnik") 24 private AdminKorisnik adminKorisnik; 25 26 public Produkt(){} 27 28 public Produkt(String ime, String opis, AdminKorisnik adminKorisnik) { 29 this.ime = ime; 30 this.opis = opis; 31 this.adminKorisnik = adminKorisnik; 32 } 22 33 23 34 public int getIdProdukt() { … … 46 57 47 58 public int getIdKorisnik() { 48 return idKorisnik;59 return adminKorisnik.getIdKorisnik(); 49 60 } 50 61 51 public void setIdKorisnik( intidKorisnik) {52 this. idKorisnik = idKorisnik;62 public void setIdKorisnik(AdminKorisnik idKorisnik) { 63 this.adminKorisnik = idKorisnik; 53 64 } 54 65 … … 58 69 if (o == null || getClass() != o.getClass()) return false; 59 70 Produkt produkt = (Produkt) o; 60 return idProdukt == produkt.idProdukt && idKorisnik == produkt.idKorisnik && Objects.equals(ime, produkt.ime) && Objects.equals(opis, produkt.opis);71 return idProdukt == produkt.idProdukt && adminKorisnik == produkt.adminKorisnik && Objects.equals(ime, produkt.ime) && Objects.equals(opis, produkt.opis); 61 72 } 62 73 63 74 @Override 64 75 public int hashCode() { 65 return Objects.hash(idProdukt, ime, opis, idKorisnik);76 return Objects.hash(idProdukt, ime, opis, adminKorisnik); 66 77 } 67 78 } -
src/main/java/project/fmo/app/projcetfmo/Model/ProduktEOdKategorija.java
r1dd9226 rd14176d 1 package model;1 package project.fmo.app.projcetfmo.Model; 2 2 3 import ja karta.persistence.*;3 import javax.persistence.*; 4 4 5 5 import java.util.Objects; … … 9 9 @IdClass(ProduktEOdKategorijaPK.class) 10 10 public class ProduktEOdKategorija { 11 @GeneratedValue(strategy = GenerationType.IDENTITY)12 11 @Id 13 12 @Column(name = "id_produkt") 14 13 private int idProdukt; 15 @GeneratedValue(strategy = GenerationType.IDENTITY)16 14 @Id 17 15 @Column(name = "id_kategorija") 18 16 private int idKategorija; 17 18 public ProduktEOdKategorija(int idProdukt, int idKategorija) { 19 this.idProdukt = idProdukt; 20 this.idKategorija = idKategorija; 21 } 22 23 public ProduktEOdKategorija() { 24 } 25 26 public ProduktEOdKategorija(ProduktEOdKategorijaPK produktEOdKategorijaPK) { 27 this.idKategorija= produktEOdKategorijaPK.getIdKategorija(); 28 this.idProdukt=produktEOdKategorijaPK.getIdProdukt(); 29 } 19 30 20 31 public int getIdProdukt() { -
src/main/java/project/fmo/app/projcetfmo/Model/ProduktEOdKategorijaPK.java
r1dd9226 rd14176d 1 package model;1 package project.fmo.app.projcetfmo.Model; 2 2 3 import jakarta.persistence.Column; 4 import jakarta.persistence.GeneratedValue; 5 import jakarta.persistence.GenerationType; 6 import jakarta.persistence.Id; 3 import javax.persistence.*; 4 7 5 8 6 import java.io.Serializable; … … 12 10 @Column(name = "id_produkt") 13 11 @Id 14 @GeneratedValue(strategy = GenerationType.IDENTITY)15 12 private int idProdukt; 16 13 @Column(name = "id_kategorija") 17 14 @Id 18 @GeneratedValue(strategy = GenerationType.IDENTITY) 15 19 16 private int idKategorija; 17 18 19 public ProduktEOdKategorijaPK(){} 20 public ProduktEOdKategorijaPK(int idProdukt, int idKategorija) { 21 this.idKategorija=idKategorija; 22 this.idProdukt=idProdukt; 23 } 20 24 21 25 public int getIdProdukt() { -
src/main/java/project/fmo/app/projcetfmo/Model/ProduktEVoMagacin.java
r1dd9226 rd14176d 1 package model;1 package project.fmo.app.projcetfmo.Model; 2 2 3 import ja karta.persistence.*;3 import javax.persistence.*; 4 4 5 5 import java.util.Objects; -
src/main/java/project/fmo/app/projcetfmo/Model/ProduktEVoMagacinPK.java
r1dd9226 rd14176d 1 package model;1 package project.fmo.app.projcetfmo.Model; 2 2 3 import jakarta.persistence.Column; 4 import jakarta.persistence.GeneratedValue; 5 import jakarta.persistence.GenerationType; 6 import jakarta.persistence.Id; 3 import javax.persistence.*; 4 7 5 8 6 import java.io.Serializable; -
src/main/java/project/fmo/app/projcetfmo/Model/Telefonskibroj.java
r1dd9226 rd14176d 1 package model;1 package project.fmo.app.projcetfmo.Model; 2 2 3 import ja karta.persistence.*;3 import javax.persistence.*; 4 4 5 5 import java.util.Objects; 6 6 7 7 @Entity 8 @Table(schema = "project", name = "telefonskibroj", catalog = "db_202223z_va_prj_fmo") 8 9 @IdClass(TelefonskibrojPK.class) 9 10 public class Telefonskibroj { 10 @GeneratedValue(strategy = GenerationType.IDENTITY) 11 11 12 @Id 12 13 @Column(name = "id_korisnik") 13 14 private int idKorisnik; 14 @GeneratedValue(strategy = GenerationType.IDENTITY) 15 15 16 @Id 16 17 @Column(name = "telefonski_broj") 17 18 private String telefonskiBroj; 19 20 public Telefonskibroj(){} 21 22 public Telefonskibroj(TelefonskibrojPK telefonskibrojPK) { 23 this.idKorisnik = telefonskibrojPK.getIdKorisnik(); 24 this.telefonskiBroj = telefonskibrojPK.getTelefonskiBroj(); 25 } 18 26 19 27 public int getIdKorisnik() { -
src/main/java/project/fmo/app/projcetfmo/Model/TelefonskibrojPK.java
r1dd9226 rd14176d 1 package model;1 package project.fmo.app.projcetfmo.Model; 2 2 3 import jakarta.persistence.Column; 4 import jakarta.persistence.GeneratedValue; 5 import jakarta.persistence.GenerationType; 6 import jakarta.persistence.Id; 3 import javax.persistence.*; 7 4 8 5 import java.io.Serializable; … … 12 9 @Column(name = "id_korisnik") 13 10 @Id 14 @GeneratedValue(strategy = GenerationType.IDENTITY)15 11 private int idKorisnik; 16 12 @Column(name = "telefonski_broj") 17 13 @Id 18 @GeneratedValue(strategy = GenerationType.IDENTITY)19 14 private String telefonskiBroj; 15 16 17 public TelefonskibrojPK(){ 18 19 } 20 public TelefonskibrojPK(int idKorisnik, String telefonskiBroj) { 21 this.idKorisnik = idKorisnik; 22 this.telefonskiBroj = telefonskiBroj; 23 } 20 24 21 25 public int getIdKorisnik() { -
src/main/java/project/fmo/app/projcetfmo/Model/exception/InvalidUserCredentialsException.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Model.exception;public class InvalidUserCredentialsException { 1 package project.fmo.app.projcetfmo.Model.exception; 2 3 public class InvalidUserCredentialsException extends RuntimeException { 4 5 public InvalidUserCredentialsException() { 6 super("Invalid user credentials exception"); 7 } 2 8 } -
src/main/java/project/fmo/app/projcetfmo/Repository/AdminRepository.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Repository;public interface AdminRepository { 1 package project.fmo.app.projcetfmo.Repository; 2 3 import org.apache.catalina.User; 4 import org.springframework.data.domain.Page; 5 import org.springframework.data.domain.Pageable; 6 import org.springframework.data.jpa.repository.JpaRepository; 7 import org.springframework.data.jpa.repository.Query; 8 import project.fmo.app.projcetfmo.Model.AdminKorisnik; 9 10 import java.util.Collection; 11 12 public interface AdminRepository extends JpaRepository<AdminKorisnik, Integer> { 13 2 14 } -
src/main/java/project/fmo/app/projcetfmo/Repository/CenaRepository.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Repository;public interface CenaRepository { 1 package project.fmo.app.projcetfmo.Repository; 2 3 import org.springframework.data.jpa.repository.JpaRepository; 4 import project.fmo.app.projcetfmo.Model.Cena; 5 import project.fmo.app.projcetfmo.Model.CenaPK; 6 7 public interface CenaRepository extends JpaRepository<Cena, CenaPK> { 8 Cena findByIdProdukt(Integer idProdukt); 9 void deleteByIdProdukt(Integer idProdukt); 2 10 } -
src/main/java/project/fmo/app/projcetfmo/Repository/DostavaRepository.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Repository;public interface DostavaRepository { 1 package project.fmo.app.projcetfmo.Repository; 2 3 import org.springframework.data.jpa.repository.JpaRepository; 4 import project.fmo.app.projcetfmo.Model.Dostava; 5 import project.fmo.app.projcetfmo.Model.Dostavuvac; 6 7 import java.util.List; 8 9 public interface DostavaRepository extends JpaRepository<Dostava, Integer> { 10 List<Dostava> findByDostavuvacAndStatus(Dostavuvac dostavuvac, String status); 11 List<Dostava> findByStatus(String status); 2 12 } -
src/main/java/project/fmo/app/projcetfmo/Repository/DostavuvacRepository.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Repository;public interface DostavuvacRepository { 1 package project.fmo.app.projcetfmo.Repository; 2 3 import org.springframework.data.jpa.repository.JpaRepository; 4 import project.fmo.app.projcetfmo.Model.Dostavuvac; 5 6 public interface DostavuvacRepository extends JpaRepository<Dostavuvac, Integer> { 2 7 } -
src/main/java/project/fmo/app/projcetfmo/Repository/KategorijaRepository.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Repository;public interface KategorijaRepository { 1 package project.fmo.app.projcetfmo.Repository; 2 3 import org.springframework.data.jpa.repository.JpaRepository; 4 import project.fmo.app.projcetfmo.Model.Kategorija; 5 6 public interface KategorijaRepository extends JpaRepository<Kategorija, Integer> { 2 7 } -
src/main/java/project/fmo/app/projcetfmo/Repository/KorisnikRepository.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Repository;public interface KorisnikRepository { 1 package project.fmo.app.projcetfmo.Repository; 2 3 import org.springframework.data.jpa.repository.JpaRepository; 4 import org.springframework.data.jpa.repository.Query; 5 import project.fmo.app.projcetfmo.Model.Korisnik; 6 7 import java.util.List; 8 9 public interface KorisnikRepository extends JpaRepository<Korisnik, Integer> { 10 Korisnik findByImePrezime(String s); 11 Korisnik findByImePrezimeAndPasswordKorisnik(String s, String p); 12 13 @Query(value ="select k.id_korisnik,k.ime_prezime,\n" + 14 "\n" + 15 "(select count(n) from project.naracka as n\n" + 16 "where n.id_korisnik = k.id_korisnik)\n" + 17 "as vkupno_naracki, \n" + 18 "\n" + 19 "(select avg(vkupno_suma) from project.naracka )\n" + 20 "as prosecna_suma_na_naracka_za_site_kupuvaci,\n" + 21 "\n" + 22 "(select sum(n3.vkupno_suma) from project.naracka as n3 \n" + 23 "where k.id_korisnik = n3.id_korisnik) \n" + 24 "as vkupno_suma_od_site_naracki_na_kupuvacot,\n" + 25 "\n" + 26 "(select count(n2) from project.naracka as n2\n" + 27 "where k.id_korisnik = n2.id_korisnik \n" + 28 "and n2.datum between now() - interval '1year' and now() \n" + 29 "and n2.vkupno_suma > (select avg(vkupno_suma) from project.naracka) )\n" + 30 "as vkupno_naracki_nad_prosek_na_korisnikot,\n" + 31 "\n" + 32 "(select sum(n4.vkupno_suma) from project.naracka as n4 \n" + 33 "where k.id_korisnik = n4.id_korisnik \n" + 34 "and n4.datum between now() - interval '1year' and now() \n" + 35 "and n4.vkupno_suma > (select avg(vkupno_suma) from project.naracka) ) \n" + 36 "as vkupno_suma_na_naracki_nad_prosek_za_korisnikot\n" + 37 "\n" + 38 "from project.korisnik as k \n" + 39 "inner join project.kupuvac as k2 on k.id_korisnik = k2.id_korisnik \n" + 40 "group by k.ime_prezime,k.id_korisnik ;" , 41 nativeQuery = true) 42 List<Object> statistics2(); 2 43 } -
src/main/java/project/fmo/app/projcetfmo/Repository/KupuvacRepository.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Repository;public interface KupuvacRepository { 1 package project.fmo.app.projcetfmo.Repository; 2 3 import org.springframework.data.jpa.repository.JpaRepository; 4 import project.fmo.app.projcetfmo.Model.Kupuvac; 5 6 public interface KupuvacRepository extends JpaRepository<Kupuvac, Integer> { 2 7 } -
src/main/java/project/fmo/app/projcetfmo/Repository/NarackaRepository.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Repository;public class NarackaRepository { 1 package project.fmo.app.projcetfmo.Repository; 2 3 import org.springframework.data.jpa.repository.JpaRepository; 4 import project.fmo.app.projcetfmo.Model.Kupuvac; 5 import project.fmo.app.projcetfmo.Model.Naracka; 6 7 public interface NarackaRepository extends JpaRepository<Naracka, Integer> { 8 Naracka findByKupuvacAndStatus(Kupuvac kupuvac, String status); 9 Naracka findByKupuvacAndIdNaracka(Kupuvac kupuvac, Integer idN); 10 Naracka findByKupuvac(Kupuvac k); 11 2 12 } -
src/main/java/project/fmo/app/projcetfmo/Repository/NarackaSodrziProduktRepository.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Repository;public interface NarackaSodrziProduktRepository { 1 package project.fmo.app.projcetfmo.Repository; 2 3 import org.springframework.data.jpa.repository.JpaRepository; 4 import project.fmo.app.projcetfmo.Model.NarackaSodrziProdukt; 5 import project.fmo.app.projcetfmo.Model.NarackaSodrziProduktPK; 6 7 import javax.persistence.criteria.CriteriaBuilder; 8 import java.util.List; 9 10 public interface NarackaSodrziProduktRepository extends JpaRepository<NarackaSodrziProdukt, NarackaSodrziProduktPK> { 11 NarackaSodrziProdukt findByIdProduktAndIdNaracka(Integer idP, Integer idN); 12 List<NarackaSodrziProdukt> findByIdNaracka(Integer id); 13 void deleteByIdProdukt(Integer id); 14 List<NarackaSodrziProdukt> findByIdProdukt(Integer id); 2 15 } -
src/main/java/project/fmo/app/projcetfmo/Repository/ProduktEOdKategorijaRepository.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Repository;public interface ProduktEOdKategorijaRepository { 1 package project.fmo.app.projcetfmo.Repository; 2 3 import org.springframework.data.jpa.repository.JpaRepository; 4 import project.fmo.app.projcetfmo.Model.ProduktEOdKategorija; 5 import project.fmo.app.projcetfmo.Model.ProduktEOdKategorijaPK; 6 7 public interface ProduktEOdKategorijaRepository extends JpaRepository<ProduktEOdKategorija, ProduktEOdKategorijaPK> { 8 ProduktEOdKategorija findByIdProdukt(Integer idProdukt); 9 void deleteByIdProdukt(Integer idProdukt); 10 ProduktEOdKategorija findByIdProduktAndIdKategorija(Integer idProdukt,Integer idKategorija); 2 11 } -
src/main/java/project/fmo/app/projcetfmo/Repository/ProduktRepository.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Repository;public interface ProduktRepository { 1 package project.fmo.app.projcetfmo.Repository; 2 3 import org.springframework.data.domain.Pageable; 4 import org.springframework.data.jpa.repository.JpaRepository; 5 import org.springframework.data.jpa.repository.Query; 6 import project.fmo.app.projcetfmo.Model.Produkt; 7 8 import java.util.List; 9 10 public interface ProduktRepository extends JpaRepository<Produkt, Integer> { 11 @Query(value = """ 12 select p.id_produkt,p.ime,\s 13 count(nsp) as broj_na_naracki_vo_koi_e_prisuten_produktot,\s 14 sum(nsp.kolicina) as kolicina_prodadeno_od_produktot,\s 15 16 (select avg(n4.vkupno_suma) from project.naracka as n4\s 17 join project.naracka_sodrzi_produkt nsp4 on n4.id_naracka = nsp4.id_naracka \s 18 where n4.id_naracka =nsp4.id_naracka and p.id_produkt = nsp4.id_produkt and n4.datum between now() - interval '3months'\s 19 and now()) 20 as prosecna_suma_na_naracka_vo_koja_se_sodrzi_produktot, 21 22 (select count(n2) from project.naracka as n2\040 23 join project.naracka_sodrzi_produkt nsp2 on n2.id_naracka = nsp2.id_naracka\s 24 where nsp2.id_produkt = p.id_produkt and n2.adresa like '/'\s 25 and n2.datum between now() - interval '3months' and now()) 26 as broj_na_naracki_na_produktot_koi_korisnikot_sam_ke_gi_podigne, 27 28 (select sum(nsp2.kolicina) from project.naracka as n2\s 29 join project.naracka_sodrzi_produkt nsp2 on n2.id_naracka = nsp2.id_naracka\s 30 where nsp2.id_produkt = p.id_produkt and n2.adresa like '/'\s 31 and n2.datum between now() - interval '3months' and now())\s 32 as kolicina_prodadena_na_produktot_bez_dostava, 33 34 (select count(n3) from project.naracka as n3\s 35 join project.naracka_sodrzi_produkt nsp3 on n3.id_naracka = nsp3.id_naracka\s 36 where nsp3.id_produkt = p.id_produkt and n3.adresa not like '/' and n3.datum between now() - interval '3months' and now()) 37 as broj_na_naracki_na_produktot_koi_ke_bidat_dostaveni_na_korisnikot, 38 39 (select sum(nsp3.kolicina) from project.naracka as n3\s 40 join project.naracka_sodrzi_produkt nsp3 on n3.id_naracka = nsp3.id_naracka 41 where nsp3.id_produkt = p.id_produkt and n3.adresa not like '/' and n3.datum between now() - interval '3months' and now()) 42 as kolicina_prodadena_na_produktot_preku_dostava 43 44 from project.produkt as p 45 join project.naracka_sodrzi_produkt as nsp on p.id_produkt = nsp.id_produkt\s 46 join project.naracka as n on nsp.id_naracka = n.id_naracka\s 47 where n.datum between now() - interval '3months' and now() 48 group by p.ime,p.id_produkt;""", 49 nativeQuery = true) 50 List<Object> statistics1(); 51 2 52 } -
src/main/java/project/fmo/app/projcetfmo/Repository/TelefnoskiBrojRepository.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Repository;public class TelefnoskiBrojRepository { 1 package project.fmo.app.projcetfmo.Repository; 2 3 import org.springframework.data.jpa.repository.JpaRepository; 4 import project.fmo.app.projcetfmo.Model.Telefonskibroj; 5 import project.fmo.app.projcetfmo.Model.TelefonskibrojPK; 6 7 public interface TelefnoskiBrojRepository extends JpaRepository<Telefonskibroj, TelefonskibrojPK> { 8 2 9 } -
src/main/java/project/fmo/app/projcetfmo/Service/AdminService.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service;public interface AdminService { 1 package project.fmo.app.projcetfmo.Service; 2 3 public interface AdminService { 2 4 } -
src/main/java/project/fmo/app/projcetfmo/Service/AuthService.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service;public interface AuthService { 1 package project.fmo.app.projcetfmo.Service; 2 3 import project.fmo.app.projcetfmo.Model.Korisnik; 4 5 public interface AuthService { 6 Korisnik login(String username, String password); 2 7 } -
src/main/java/project/fmo/app/projcetfmo/Service/CenaService.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service;public interface CenaService { 1 package project.fmo.app.projcetfmo.Service; 2 3 import project.fmo.app.projcetfmo.Model.Cena; 4 5 import java.util.Date; 6 import java.util.List; 7 8 public interface CenaService { 9 10 11 Cena save(Integer idProdukt, java.sql.Date cenaOd, java.sql.Date cenaDo, int iznos); 12 Cena edit (Integer idProdukt, java.sql.Date cenaOd, java.sql.Date cenaDo, int iznos); 13 14 List<Cena> findAll(); 15 16 Cena findByIdProdukt(int idProdukt); 17 void deleteByIdProdukt(int idProdukt); 18 19 2 20 } -
src/main/java/project/fmo/app/projcetfmo/Service/DostavaService.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service;public interface DostavaService { 1 package project.fmo.app.projcetfmo.Service; 2 3 import project.fmo.app.projcetfmo.Model.Dostava; 4 import project.fmo.app.projcetfmo.Model.Dostavuvac; 5 6 import java.util.List; 7 8 public interface DostavaService { 9 10 List<Dostava> findByIdKorisnikAndStatus(Dostavuvac dostavuvac, String status); 11 Dostava edit(Integer id); 12 13 2 14 } -
src/main/java/project/fmo/app/projcetfmo/Service/DostavuvaceService.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service;public interface DostavuvaceService { 1 package project.fmo.app.projcetfmo.Service; 2 3 import project.fmo.app.projcetfmo.Model.Dostavuvac; 4 5 import javax.persistence.criteria.CriteriaBuilder; 6 7 public interface DostavuvaceService { 8 9 Dostavuvac findById(Integer id); 2 10 } -
src/main/java/project/fmo/app/projcetfmo/Service/KategorijaService.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service;public interface KategorijaService { 1 package project.fmo.app.projcetfmo.Service; 2 3 import project.fmo.app.projcetfmo.Model.Kategorija; 4 5 import java.util.List; 6 7 public interface KategorijaService { 8 9 10 List<Kategorija> findAll(); 11 Kategorija save(String ime); 12 Kategorija edit(Integer id, String ime); 13 2 14 } -
src/main/java/project/fmo/app/projcetfmo/Service/KorisnikService.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service;public interface KorisnikService { 1 package project.fmo.app.projcetfmo.Service; 2 3 import org.springframework.security.core.userdetails.UserDetails; 4 import org.springframework.security.core.userdetails.UserDetailsService; 5 import project.fmo.app.projcetfmo.Model.Korisnik; 6 import project.fmo.app.projcetfmo.Repository.KorisnikRepository; 7 8 import java.sql.Date; 9 import java.util.List; 10 11 public interface KorisnikService extends UserDetailsService { 12 Korisnik findbyImePrezime (String ime); 13 Korisnik findById(Integer id); 14 Korisnik register(String username, String password, String repeatPassword, String mail, String number); 15 16 List<Object> statistics2(); 2 17 } -
src/main/java/project/fmo/app/projcetfmo/Service/KupuvacService.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service;public class KupuvacRepository { 1 package project.fmo.app.projcetfmo.Service; 2 3 import project.fmo.app.projcetfmo.Model.Kupuvac; 4 5 public interface KupuvacService { 6 7 Kupuvac findById(Integer id); 2 8 } -
src/main/java/project/fmo/app/projcetfmo/Service/NarackaService.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service;public interface NarackaService { 1 package project.fmo.app.projcetfmo.Service; 2 3 import project.fmo.app.projcetfmo.Model.Kupuvac; 4 import project.fmo.app.projcetfmo.Model.Naracka; 5 import project.fmo.app.projcetfmo.Model.Produkt; 6 7 import java.sql.Date; 8 import java.util.List; 9 10 public interface NarackaService { 11 12 List<Produkt> allProductsInOrder(Integer narackaId); 13 Naracka getActiveOrder(String username); 14 Naracka findByIdKorisniktAndStatus(Integer id, String s); 15 16 Naracka save(int vkupnoSuma, Date date, String status, String adresa, Kupuvac k); 17 Naracka edit(int vkupnoSuma,String status,String adresa, Integer idK, Integer idN); 18 Naracka findByKupuvac(Kupuvac k); 19 Naracka findByIdNaracka(Integer id); 20 List<Naracka> findAll(); 21 22 2 23 } -
src/main/java/project/fmo/app/projcetfmo/Service/NarackaSodrziProduktService.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service;public interface NarackaSodrziProduktService { 1 package project.fmo.app.projcetfmo.Service; 2 3 import project.fmo.app.projcetfmo.Model.NarackaSodrziProdukt; 4 5 import javax.persistence.criteria.CriteriaBuilder; 6 import java.util.List; 7 8 public interface NarackaSodrziProduktService { 9 NarackaSodrziProdukt findByIdProduktAndIdNaracka(Integer idP, Integer idN); 10 NarackaSodrziProdukt edit(Integer idP, Integer idN, Integer quantity, Integer price); 11 NarackaSodrziProdukt save(Integer idP, Integer idN, Integer quantity, Integer price); 12 List<NarackaSodrziProdukt> findByIdNaracka(Integer id); 13 void deleteProduct(Integer id); 14 15 List<NarackaSodrziProdukt> findAll(); 16 17 List<NarackaSodrziProdukt> findByIdProdukt(Integer id); 2 18 } -
src/main/java/project/fmo/app/projcetfmo/Service/ProduktEOdKategorijaService.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service;public interface ProduktEOdKategorijaService { 1 package project.fmo.app.projcetfmo.Service; 2 3 import project.fmo.app.projcetfmo.Model.ProduktEOdKategorija; 4 5 import java.util.List; 6 7 public interface ProduktEOdKategorijaService { 8 9 10 ProduktEOdKategorija save(int idProdukt, int idKategorija); 11 ProduktEOdKategorija edit(int idProdukt, int idKategorija); 12 13 List<ProduktEOdKategorija> findAll(); 14 15 ProduktEOdKategorija findByIdProdukt(int idProdukt); 16 void deleteByIdProdukt(int idProdukt); 17 18 ProduktEOdKategorija findByIdProduktAndIdKategorija(int idProdukt, int idKategorija); 19 2 20 } -
src/main/java/project/fmo/app/projcetfmo/Service/ProduktService.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service;public interface ProduktService { 1 package project.fmo.app.projcetfmo.Service; 2 3 import org.springframework.data.domain.Page; 4 import project.fmo.app.projcetfmo.Model.Produkt; 5 6 import java.util.List; 7 import java.util.Optional; 8 9 public interface ProduktService { 10 11 Optional<Produkt> findById(Integer id); 12 List<Produkt> findAll(); 13 Produkt save(String ime, String opis); 14 Produkt edit(Integer id,String ime, String opis); 15 void deleteById(Integer id); 16 17 List<Object> statistics1(); 18 2 19 } -
src/main/java/project/fmo/app/projcetfmo/Service/impl/AuthServiceImpl.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service.impl;public class AuthServiceImpl { 1 package project.fmo.app.projcetfmo.Service.impl; 2 3 import org.springframework.stereotype.Service; 4 import project.fmo.app.projcetfmo.Model.Korisnik; 5 import project.fmo.app.projcetfmo.Repository.KorisnikRepository; 6 import project.fmo.app.projcetfmo.Service.AuthService; 7 8 @Service 9 public class AuthServiceImpl implements AuthService { 10 11 private final KorisnikRepository korisnikRepository; 12 13 public AuthServiceImpl(KorisnikRepository korisnikRepository) { 14 this.korisnikRepository = korisnikRepository; 15 } 16 17 @Override 18 public Korisnik login(String username, String password) { 19 return korisnikRepository.findByImePrezimeAndPasswordKorisnik(username,password); 20 } 2 21 } -
src/main/java/project/fmo/app/projcetfmo/Service/impl/CenaServiceImpl.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service.impl;public class CenaServiceImpl { 1 package project.fmo.app.projcetfmo.Service.impl; 2 3 import javax.transaction.Transactional; 4 import org.springframework.stereotype.Service; 5 import project.fmo.app.projcetfmo.Model.Cena; 6 import project.fmo.app.projcetfmo.Model.CenaPK; 7 import project.fmo.app.projcetfmo.Repository.CenaRepository; 8 import project.fmo.app.projcetfmo.Service.CenaService; 9 10 import java.sql.Date; 11 import java.util.List; 12 13 @Service 14 public class CenaServiceImpl implements CenaService { 15 16 private final CenaRepository cenaRepository; 17 18 public CenaServiceImpl(CenaRepository cenaRepository) { 19 this.cenaRepository = cenaRepository; 20 } 21 22 @Override 23 public Cena save(Integer idProdukt, java.sql.Date cenaOd, java.sql.Date cenaDo, int iznos) { 24 Cena c = new Cena(idProdukt,cenaOd,cenaDo,iznos); 25 cenaRepository.save(c); 26 return c; 27 } 28 29 @Transactional 30 @Override 31 public Cena edit(Integer idProdukt, Date cenaOd, Date cenaDo, int iznos) { 32 Cena c = cenaRepository.findByIdProdukt(idProdukt); 33 cenaRepository.deleteByIdProdukt(c.getIdProdukt()); 34 Cena c1 = new Cena(idProdukt,cenaOd,cenaDo,iznos); 35 cenaRepository.save(c1); 36 return c; 37 } 38 39 @Override 40 public List<Cena> findAll() { 41 return cenaRepository.findAll(); 42 } 43 44 @Override 45 public Cena findByIdProdukt(int idProdukt) { 46 return cenaRepository.findByIdProdukt(idProdukt); 47 } 48 49 @Transactional 50 @Override 51 public void deleteByIdProdukt(int idProdukt) { 52 cenaRepository.deleteByIdProdukt(idProdukt); 53 } 2 54 } -
src/main/java/project/fmo/app/projcetfmo/Service/impl/DostavaServiceImpl.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service.impl;public class DostavaServiceImpl { 1 package project.fmo.app.projcetfmo.Service.impl; 2 3 import org.springframework.stereotype.Service; 4 import project.fmo.app.projcetfmo.Model.Dostava; 5 import project.fmo.app.projcetfmo.Model.Dostavuvac; 6 import project.fmo.app.projcetfmo.Repository.DostavaRepository; 7 import project.fmo.app.projcetfmo.Service.DostavaService; 8 9 import java.util.List; 10 11 @Service 12 public class DostavaServiceImpl implements DostavaService { 13 14 private final DostavaRepository dostavaRepository; 15 16 public DostavaServiceImpl(DostavaRepository dostavaRepository) { 17 this.dostavaRepository = dostavaRepository; 18 } 19 20 @Override 21 public List<Dostava> findByIdKorisnikAndStatus(Dostavuvac dostavuvac, String status) { 22 return dostavaRepository.findByDostavuvacAndStatus(dostavuvac,status); 23 } 24 25 @Override 26 public Dostava edit(Integer id) { 27 Dostava d = dostavaRepository.findById(id).orElse(null); 28 assert d != null; 29 d.setStatus("dostavena"); 30 dostavaRepository.save(d); 31 return d; 32 } 2 33 } -
src/main/java/project/fmo/app/projcetfmo/Service/impl/DostavuvacServiceImpl.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service.impl;public class DostavuvacServiceImpl { 1 package project.fmo.app.projcetfmo.Service.impl; 2 3 import org.springframework.stereotype.Service; 4 import project.fmo.app.projcetfmo.Model.Dostavuvac; 5 import project.fmo.app.projcetfmo.Repository.DostavuvacRepository; 6 import project.fmo.app.projcetfmo.Service.DostavuvaceService; 7 8 @Service 9 public class DostavuvacServiceImpl implements DostavuvaceService { 10 11 private final DostavuvacRepository dostavuvacRepository; 12 13 public DostavuvacServiceImpl(DostavuvacRepository dostavuvacRepository) { 14 this.dostavuvacRepository = dostavuvacRepository; 15 } 16 17 @Override 18 public Dostavuvac findById(Integer id) { 19 return dostavuvacRepository.findById(id).orElse(null); 20 } 2 21 } -
src/main/java/project/fmo/app/projcetfmo/Service/impl/KategorijaServiceImpl.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service.impl;public class KategorijaServiceImpl { 1 package project.fmo.app.projcetfmo.Service.impl; 2 3 import org.springframework.stereotype.Service; 4 import project.fmo.app.projcetfmo.Model.Kategorija; 5 import project.fmo.app.projcetfmo.Repository.KategorijaRepository; 6 import project.fmo.app.projcetfmo.Service.KategorijaService; 7 8 import java.util.List; 9 10 @Service 11 public class KategorijaServiceImpl implements KategorijaService { 12 13 private final KategorijaRepository kategorijaRepository; 14 15 public KategorijaServiceImpl(KategorijaRepository kategorijaRepository) { 16 this.kategorijaRepository = kategorijaRepository; 17 } 18 19 @Override 20 public List<Kategorija> findAll() { 21 return kategorijaRepository.findAll(); 22 } 23 24 @Override 25 public Kategorija save(String ime) { 26 Kategorija k = new Kategorija(ime); 27 kategorijaRepository.save(k); 28 return k; 29 } 30 31 @Override 32 public Kategorija edit(Integer id, String ime) { 33 Kategorija k = kategorijaRepository.findById(id).orElse(null); 34 assert k != null; 35 k.setIme(ime); 36 kategorijaRepository.save(k); 37 return k; 38 } 2 39 } -
src/main/java/project/fmo/app/projcetfmo/Service/impl/KorisnikServiceImpl.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service.impl;public class KorisnikServiceImpl { 1 package project.fmo.app.projcetfmo.Service.impl; 2 3 import org.springframework.security.core.authority.SimpleGrantedAuthority; 4 import org.springframework.security.core.userdetails.User; 5 import org.springframework.security.core.userdetails.UserDetails; 6 import org.springframework.security.core.userdetails.UsernameNotFoundException; 7 import org.springframework.security.crypto.password.PasswordEncoder; 8 import org.springframework.stereotype.Service; 9 import project.fmo.app.projcetfmo.Model.*; 10 import project.fmo.app.projcetfmo.Repository.*; 11 import project.fmo.app.projcetfmo.Service.KorisnikService; 12 13 import java.sql.Timestamp; 14 import java.time.LocalDateTime; 15 import java.util.List; 16 import java.util.Objects; 17 import java.util.stream.Collectors; 18 import java.util.stream.Stream; 19 20 @Service 21 public class KorisnikServiceImpl implements KorisnikService { 22 23 private final PasswordEncoder passwordEncoder; 24 private final AdminRepository adminRepository; 25 private final DostavuvacRepository dostavuvacRepository; 26 27 private final TelefnoskiBrojRepository telefnoskiBrojRepository; 28 private final KupuvacRepository kupuvacRepository; 29 private final KorisnikRepository korisnikRepository; 30 31 public KorisnikServiceImpl(PasswordEncoder passwordEncoder, AdminRepository adminRepository, DostavuvacRepository dostavuvacRepository, TelefnoskiBrojRepository telefnoskiBrojRepository, KupuvacRepository kupuvacRepository, KorisnikRepository korisnikRepository) { 32 this.passwordEncoder = passwordEncoder; 33 this.adminRepository = adminRepository; 34 this.dostavuvacRepository = dostavuvacRepository; 35 this.telefnoskiBrojRepository = telefnoskiBrojRepository; 36 this.kupuvacRepository = kupuvacRepository; 37 this.korisnikRepository = korisnikRepository; 38 } 39 40 @Override 41 public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { 42 Korisnik korisnik = korisnikRepository.findByImePrezime(username); 43 for (AdminKorisnik a: adminRepository.findAll()) { 44 if (a.getIdKorisnik() == korisnik.getIdKorisnik()) { 45 return new User(korisnik.getImePrezime(), korisnik.getPasswordKorisnik(), Stream.of(new SimpleGrantedAuthority("ROLE_ADMIN")).collect(Collectors.toList())); 46 } 47 } 48 for (Dostavuvac a: dostavuvacRepository.findAll()) { 49 if (a.getIdKorisnik() == korisnik.getIdKorisnik()) { 50 return new User(korisnik.getImePrezime(), korisnik.getPasswordKorisnik(), Stream.of(new SimpleGrantedAuthority("ROLE_DELIVER")).collect(Collectors.toList())); 51 } 52 } 53 for (Kupuvac a: kupuvacRepository.findAll()){ 54 if (a.getIdKorisnik() == korisnik.getIdKorisnik()){ 55 return new User(korisnik.getImePrezime(),korisnik.getPasswordKorisnik(), Stream.of(new SimpleGrantedAuthority("ROLE_USER")).collect(Collectors.toList()) ); 56 } 57 } 58 return null; 59 } 60 61 @Override 62 public Korisnik findbyImePrezime(String ime) { 63 return korisnikRepository.findByImePrezime(ime); 64 } 65 66 @Override 67 public Korisnik findById(Integer id) { 68 return korisnikRepository.findById(id).orElse(null); 69 } 70 71 @Override 72 public Korisnik register(String username, String password, String repeatPassword, String mail, String number) { 73 if (username==null || username.isEmpty() || password==null || password.isEmpty()) 74 throw new RuntimeException(); 75 if (!password.equals(repeatPassword)) 76 throw new RuntimeException(); 77 78 Korisnik korisnik = new Korisnik(username,password, Timestamp.valueOf(LocalDateTime.now())); 79 korisnikRepository.save(korisnik); 80 Kupuvac k = new Kupuvac(korisnik.getIdKorisnik(), mail); 81 kupuvacRepository.save(k); 82 Telefonskibroj t = new Telefonskibroj(new TelefonskibrojPK(korisnik.getIdKorisnik(),number)); 83 telefnoskiBrojRepository.save(t); 84 return korisnik; 85 86 } 87 88 @Override 89 public List<Object> statistics2() { 90 return korisnikRepository.statistics2(); 91 } 2 92 } -
src/main/java/project/fmo/app/projcetfmo/Service/impl/KupuvacServiceImpl.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service.impl;public class KupuvacServiceImpl { 1 package project.fmo.app.projcetfmo.Service.impl; 2 3 import org.springframework.stereotype.Service; 4 import project.fmo.app.projcetfmo.Model.Kupuvac; 5 import project.fmo.app.projcetfmo.Repository.KupuvacRepository; 6 import project.fmo.app.projcetfmo.Service.KupuvacService; 7 8 @Service 9 public class KupuvacServiceImpl implements KupuvacService { 10 11 private final KupuvacRepository kupuvacRepository; 12 13 public KupuvacServiceImpl(KupuvacRepository kupuvacRepository) { 14 this.kupuvacRepository = kupuvacRepository; 15 } 16 17 @Override 18 public Kupuvac findById(Integer id) { 19 return kupuvacRepository.findById(id).orElse(null); 20 } 2 21 } -
src/main/java/project/fmo/app/projcetfmo/Service/impl/NarackaServiceImpl.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service.impl;public class NarackaServiceImpl { 1 package project.fmo.app.projcetfmo.Service.impl; 2 3 import org.springframework.stereotype.Service; 4 import project.fmo.app.projcetfmo.Model.Kupuvac; 5 import project.fmo.app.projcetfmo.Model.Naracka; 6 import project.fmo.app.projcetfmo.Model.Produkt; 7 import project.fmo.app.projcetfmo.Repository.KupuvacRepository; 8 import project.fmo.app.projcetfmo.Repository.NarackaRepository; 9 import project.fmo.app.projcetfmo.Service.NarackaService; 10 11 import java.sql.Date; 12 import java.util.List; 13 14 @Service 15 public class NarackaServiceImpl implements NarackaService { 16 17 private final NarackaRepository narackaRepository; 18 private final KupuvacRepository kupuvacRepository; 19 20 public NarackaServiceImpl(NarackaRepository narackaRepository, KupuvacRepository kupuvacRepository) { 21 this.narackaRepository = narackaRepository; 22 this.kupuvacRepository = kupuvacRepository; 23 } 24 25 @Override 26 public List<Produkt> allProductsInOrder(Integer narackaId) { 27 return null; 28 } 29 30 @Override 31 public Naracka getActiveOrder(String username) { 32 return null; 33 } 34 35 @Override 36 public Naracka findByIdKorisniktAndStatus(Integer id, String s) { 37 Kupuvac k = kupuvacRepository.findById(id).orElse(null); 38 return narackaRepository.findByKupuvacAndStatus(k,s); 39 } 40 41 @Override 42 public Naracka save(int vkupnoSuma, Date date, String status, String adresa, Kupuvac k) { 43 return narackaRepository.save(new Naracka(vkupnoSuma,date,status,adresa,k)); 44 } 45 46 @Override 47 public Naracka edit(int vkupnoSuma, String status, String adresa, Integer idK, Integer idN) { 48 Kupuvac k = kupuvacRepository.findById(idK).orElse(null); 49 Naracka n = narackaRepository.findByKupuvacAndIdNaracka(k,idN); 50 n.setVkupnoSuma(n.getVkupnoSuma()+vkupnoSuma); 51 n.setStatus(status); 52 n.setAdresa(adresa); 53 narackaRepository.save(n); 54 return n; 55 } 56 57 @Override 58 public Naracka findByKupuvac(Kupuvac k) { 59 return narackaRepository.findByKupuvac(k); 60 } 61 62 @Override 63 public Naracka findByIdNaracka(Integer id) { 64 return narackaRepository.findById(id).orElse(null); 65 } 66 67 @Override 68 public List<Naracka> findAll() { 69 return narackaRepository.findAll(); 70 } 2 71 } -
src/main/java/project/fmo/app/projcetfmo/Service/impl/NarackaSodrziProduktServiceImpl.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service.impl;public class NarackaSodrziProduktServiceImpl { 1 package project.fmo.app.projcetfmo.Service.impl; 2 3 import org.springframework.stereotype.Service; 4 import project.fmo.app.projcetfmo.Model.NarackaSodrziProdukt; 5 import project.fmo.app.projcetfmo.Repository.NarackaSodrziProduktRepository; 6 import project.fmo.app.projcetfmo.Service.NarackaSodrziProduktService; 7 8 import java.util.List; 9 10 @Service 11 public class NarackaSodrziProduktServiceImpl implements NarackaSodrziProduktService { 12 13 private final NarackaSodrziProduktRepository narackaSodrziProduktRepository; 14 15 public NarackaSodrziProduktServiceImpl(NarackaSodrziProduktRepository narackaSodrziProduktRepository) { 16 this.narackaSodrziProduktRepository = narackaSodrziProduktRepository; 17 } 18 19 @Override 20 public NarackaSodrziProdukt findByIdProduktAndIdNaracka(Integer idP, Integer idN) { 21 return narackaSodrziProduktRepository.findByIdProduktAndIdNaracka(idP,idN); 22 } 23 24 @Override 25 public NarackaSodrziProdukt edit(Integer idP, Integer idN, Integer quantity, Integer price) { 26 NarackaSodrziProdukt n = narackaSodrziProduktRepository.findByIdProduktAndIdNaracka(idP,idN); 27 n.setCena(price); 28 n.setKolicina(n.getKolicina()+quantity); 29 narackaSodrziProduktRepository.save(n); 30 return n; 31 } 32 33 @Override 34 public NarackaSodrziProdukt save(Integer idP, Integer idN, Integer quantity, Integer price) { 35 NarackaSodrziProdukt n = new NarackaSodrziProdukt(idP,idN,quantity, price); 36 narackaSodrziProduktRepository.save(n); 37 return n; 38 } 39 40 @Override 41 public List<NarackaSodrziProdukt> findByIdNaracka(Integer id) { 42 return narackaSodrziProduktRepository.findByIdNaracka(id); 43 } 44 45 @Override 46 public void deleteProduct(Integer id) { 47 List<NarackaSodrziProdukt> narackaSodrziProdukts = narackaSodrziProduktRepository.findByIdProdukt(id); 48 narackaSodrziProduktRepository.deleteByIdProdukt(id); 49 } 50 51 @Override 52 public List<NarackaSodrziProdukt> findAll() { 53 return narackaSodrziProduktRepository.findAll(); 54 } 55 56 @Override 57 public List<NarackaSodrziProdukt> findByIdProdukt(Integer id) { 58 return narackaSodrziProduktRepository.findByIdProdukt(id); 59 } 60 61 2 62 } -
src/main/java/project/fmo/app/projcetfmo/Service/impl/ProduktEOdKategorijaServiceImpl.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service.impl;public class ProduktEOdKategorijaServiceImpl { 1 package project.fmo.app.projcetfmo.Service.impl; 2 3 import javax.transaction.Transactional; 4 import org.springframework.stereotype.Service; 5 import project.fmo.app.projcetfmo.Model.ProduktEOdKategorija; 6 import project.fmo.app.projcetfmo.Model.ProduktEOdKategorijaPK; 7 import project.fmo.app.projcetfmo.Repository.ProduktEOdKategorijaRepository; 8 import project.fmo.app.projcetfmo.Service.ProduktEOdKategorijaService; 9 import project.fmo.app.projcetfmo.Service.ProduktService; 10 11 import java.util.List; 12 13 @Service 14 public class ProduktEOdKategorijaServiceImpl implements ProduktEOdKategorijaService { 15 16 private final ProduktEOdKategorijaRepository produktEOdKategorijaRepository; 17 18 public ProduktEOdKategorijaServiceImpl(ProduktEOdKategorijaRepository produktEOdKategorijaRepository) { 19 this.produktEOdKategorijaRepository = produktEOdKategorijaRepository; 20 } 21 22 @Override 23 public ProduktEOdKategorija save(int idProdukt, int idKategorija) { 24 ProduktEOdKategorija produktEOdKategorija= new ProduktEOdKategorija(new ProduktEOdKategorijaPK(idProdukt, idKategorija)); 25 produktEOdKategorijaRepository.save(produktEOdKategorija); 26 return produktEOdKategorija; 27 } 28 29 @Transactional 30 @Override 31 public ProduktEOdKategorija edit(int idProdukt, int idKategorija) { 32 // ProduktEOdKategorijaPK pk = new ProduktEOdKategorijaPK(idProdukt,idKategorija); 33 ProduktEOdKategorija peodkD = produktEOdKategorijaRepository.findByIdProdukt(idProdukt); 34 produktEOdKategorijaRepository.deleteByIdProdukt(peodkD.getIdProdukt()); 35 ProduktEOdKategorijaPK pk = new ProduktEOdKategorijaPK(idProdukt, idKategorija); 36 ProduktEOdKategorija peodk = new ProduktEOdKategorija(pk); 37 produktEOdKategorijaRepository.save(peodk); 38 39 return peodk; 40 } 41 42 @Override 43 public List<ProduktEOdKategorija> findAll() { 44 return produktEOdKategorijaRepository.findAll(); 45 } 46 47 @Override 48 public ProduktEOdKategorija findByIdProdukt(int idProdukt) { 49 return produktEOdKategorijaRepository.findByIdProdukt(idProdukt); 50 } 51 52 @Transactional 53 @Override 54 public void deleteByIdProdukt(int idProdukt) { 55 56 this.produktEOdKategorijaRepository.deleteByIdProdukt(idProdukt); 57 } 58 59 @Override 60 public ProduktEOdKategorija findByIdProduktAndIdKategorija(int idProdukt, int idKategorija) { 61 return produktEOdKategorijaRepository.findByIdProduktAndIdKategorija(idProdukt,idKategorija); 62 } 2 63 } -
src/main/java/project/fmo/app/projcetfmo/Service/impl/ProduktServiceImpl.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Service.impl;public class ProduktServiceImpl { 1 package project.fmo.app.projcetfmo.Service.impl; 2 3 import org.springframework.data.domain.Page; 4 import org.springframework.data.domain.Pageable; 5 import org.springframework.stereotype.Service; 6 import project.fmo.app.projcetfmo.Model.AdminKorisnik; 7 import project.fmo.app.projcetfmo.Model.Produkt; 8 import project.fmo.app.projcetfmo.Repository.AdminRepository; 9 import project.fmo.app.projcetfmo.Repository.ProduktRepository; 10 import project.fmo.app.projcetfmo.Service.ProduktService; 11 12 13 import java.util.List; 14 import java.util.Optional; 15 import java.util.Random; 16 17 @Service 18 public class ProduktServiceImpl implements ProduktService { 19 20 private final ProduktRepository produktRepository; 21 private final AdminRepository adminRepository; 22 23 public ProduktServiceImpl(ProduktRepository produktRepository, AdminRepository adminRepository) { 24 this.produktRepository = produktRepository; 25 this.adminRepository = adminRepository; 26 } 27 28 @Override 29 public Optional<Produkt> findById(Integer id) { 30 return produktRepository.findById(id); 31 } 32 33 @Override 34 public List<Produkt> findAll() { 35 return produktRepository.findAll(); 36 } 37 38 @Override 39 public Produkt save(String ime, String opis) { 40 List<AdminKorisnik> list = adminRepository.findAll(); 41 Random rand = new Random(); 42 int randomIndex = rand.nextInt(list.size()); 43 AdminKorisnik a = list.get(randomIndex); 44 if (a == null){ 45 throw new RuntimeException(); 46 } 47 Produkt p = new Produkt(ime, opis, a); 48 produktRepository.save(p); 49 return p; 50 } 51 52 @Override 53 public Produkt edit(Integer id, String ime, String opis) { 54 Produkt p = produktRepository.findById(id).orElse(null); 55 if (p == null ){ 56 throw new RuntimeException(); 57 } 58 p.setIme(ime); 59 p.setOpis(opis); 60 produktRepository.save(p); 61 return p; 62 } 63 64 @Override 65 public void deleteById(Integer id) { 66 produktRepository.deleteById(id); 67 } 68 69 @Override 70 public List<Object> statistics1() { 71 return produktRepository.statistics1(); 72 } 2 73 } -
src/main/java/project/fmo/app/projcetfmo/Web/DostavaController.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Web;public class DostavaController { 1 package project.fmo.app.projcetfmo.Web; 2 3 import org.springframework.stereotype.Controller; 4 import org.springframework.ui.Model; 5 import org.springframework.web.bind.annotation.GetMapping; 6 import org.springframework.web.bind.annotation.PathVariable; 7 import org.springframework.web.bind.annotation.PostMapping; 8 import org.springframework.web.bind.annotation.RequestMapping; 9 import project.fmo.app.projcetfmo.Model.Dostava; 10 import project.fmo.app.projcetfmo.Model.Dostavuvac; 11 import project.fmo.app.projcetfmo.Model.Korisnik; 12 import project.fmo.app.projcetfmo.Service.DostavaService; 13 import project.fmo.app.projcetfmo.Service.DostavuvaceService; 14 import project.fmo.app.projcetfmo.Service.KorisnikService; 15 import project.fmo.app.projcetfmo.Service.NarackaService; 16 17 import javax.servlet.http.HttpServletRequest; 18 import java.util.List; 19 20 @Controller 21 @RequestMapping("/delivery") 22 public class DostavaController { 23 24 private final DostavaService dostavaService; 25 private final DostavuvaceService dostavuvaceService; 26 private final KorisnikService korisnikService; 27 private final NarackaService narackaService; 28 29 public DostavaController(DostavaService dostavaService, DostavuvaceService dostavuvaceService, KorisnikService korisnikService, NarackaService narackaService) { 30 this.dostavaService = dostavaService; 31 this.dostavuvaceService = dostavuvaceService; 32 this.korisnikService = korisnikService; 33 this.narackaService = narackaService; 34 } 35 36 37 @GetMapping 38 public String getDelivery(Model model, HttpServletRequest req){ 39 String username = req.getRemoteUser(); 40 Korisnik korisnik = korisnikService.findbyImePrezime(username); 41 Dostavuvac dostavuvac = dostavuvaceService.findById(korisnik.getIdKorisnik()); 42 List<Dostava> dostavaList = dostavaService.findByIdKorisnikAndStatus(dostavuvac, "za dostava"); 43 model.addAttribute("user", korisnik); 44 model.addAttribute("orders", narackaService.findAll()); 45 model.addAttribute("delivers", dostavaList); 46 model.addAttribute("bodyContent", "delivery"); 47 return "master_template"; 48 } 49 50 @PostMapping("/{id}") 51 public String OrderDelivered(@PathVariable Integer id){ 52 dostavaService.edit(id); 53 return "redirect:/delivery"; 54 } 55 2 56 } -
src/main/java/project/fmo/app/projcetfmo/Web/HomeController.java
r1dd9226 rd14176d 9 9 @Controller 10 10 @RequestMapping({"/","/home"}) 11 public class StoreController {11 public class HomeController { 12 12 13 13 14 14 @GetMapping 15 public String getHomePage(){ 16 return "home"; 15 public String getHomePage(Model model){ 16 model.addAttribute("bodyContent", "home"); 17 return "master_template"; 17 18 } 18 19 20 @GetMapping("/access_denied") 21 public String getAccessDeniedPage(Model model) { 22 model.addAttribute("bodyContent", "access_denied"); 23 return "master-template"; 24 } 25 26 19 27 } -
src/main/java/project/fmo/app/projcetfmo/Web/LoginController.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Web;public class LoginController { 1 package project.fmo.app.projcetfmo.Web; 2 3 4 import org.springframework.stereotype.Controller; 5 import org.springframework.ui.Model; 6 import org.springframework.web.bind.annotation.GetMapping; 7 import org.springframework.web.bind.annotation.PostMapping; 8 import org.springframework.web.bind.annotation.RequestMapping; 9 import project.fmo.app.projcetfmo.Model.Korisnik; 10 import project.fmo.app.projcetfmo.Model.exception.InvalidUserCredentialsException; 11 import project.fmo.app.projcetfmo.Service.AuthService; 12 13 import javax.servlet.http.HttpServletRequest; 14 15 @Controller 16 @RequestMapping("/login") 17 public class LoginController { 18 19 private final AuthService authService; 20 21 public LoginController(AuthService authService) { 22 this.authService = authService; 23 } 24 25 @GetMapping 26 public String getLoginPage(Model model) { 27 model.addAttribute("bodyContent","login"); 28 return "master-template"; 29 } 30 31 @PostMapping 32 public String login(HttpServletRequest request, Model model) { 33 Korisnik user = null; 34 try{ 35 user = this.authService.login(request.getParameter("username"), 36 request.getParameter("password")); 37 request.getSession().setAttribute("user", user); 38 return "redirect:/home"; 39 } 40 catch (InvalidUserCredentialsException exception) { 41 model.addAttribute("hasError", true); 42 model.addAttribute("error", exception.getMessage()); 43 return "login"; 44 } 45 } 2 46 } -
src/main/java/project/fmo/app/projcetfmo/Web/LogoutController.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Web;public class LogoutController { 1 package project.fmo.app.projcetfmo.Web; 2 3 import org.springframework.stereotype.Controller; 4 import org.springframework.web.bind.annotation.GetMapping; 5 import org.springframework.web.bind.annotation.RequestMapping; 6 7 import javax.servlet.http.HttpServletRequest; 8 9 @Controller 10 @RequestMapping("/logout") 11 public class LogoutController { 12 13 @GetMapping 14 public String logout(HttpServletRequest request) { 15 request.getSession().invalidate(); 16 return "redirect:/"; 17 } 2 18 } -
src/main/java/project/fmo/app/projcetfmo/Web/NarackaController.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Web;public class NarackaController { 1 package project.fmo.app.projcetfmo.Web; 2 3 import org.springframework.stereotype.Controller; 4 import org.springframework.ui.Model; 5 import org.springframework.web.bind.annotation.*; 6 import project.fmo.app.projcetfmo.Model.*; 7 import project.fmo.app.projcetfmo.Service.*; 8 9 import javax.servlet.http.HttpServletRequest; 10 import java.util.List; 11 12 @Controller 13 @RequestMapping("/order") 14 public class NarackaController { 15 16 private final NarackaService narackaService; 17 private final NarackaSodrziProduktService narackaSodrziProduktService; 18 private final KorisnikService korisnikService; 19 private final KupuvacService kupuvacService; 20 private final CenaService cenaService; 21 22 private final ProduktService produktService; 23 24 public NarackaController(NarackaService narackaService, NarackaSodrziProduktService narackaSodrziProduktService, KorisnikService korisnikService, KupuvacService kupuvacService, CenaService cenaService, ProduktService produktService) { 25 this.narackaService = narackaService; 26 this.narackaSodrziProduktService = narackaSodrziProduktService; 27 this.korisnikService = korisnikService; 28 this.kupuvacService = kupuvacService; 29 this.cenaService = cenaService; 30 this.produktService = produktService; 31 } 32 33 @GetMapping 34 public String getShoppingCartPage(@RequestParam(required = false) String error, 35 HttpServletRequest req, 36 Model model) { 37 if (error != null && !error.isEmpty()) { 38 model.addAttribute("hasError", true); 39 model.addAttribute("error", error); 40 } 41 String username = req.getRemoteUser(); 42 Korisnik korisnik = korisnikService.findbyImePrezime(username); 43 Kupuvac kupuvac = kupuvacService.findById(korisnik.getIdKorisnik()); 44 Naracka naracka = this.narackaService.findByIdKorisniktAndStatus(kupuvac.getIdKorisnik(),"aktivna"); 45 if(naracka == null){ 46 model.addAttribute("bodyContent", "home"); 47 return "master_template"; 48 } 49 List<NarackaSodrziProdukt> narackaSodrziProdukt = narackaSodrziProduktService.findByIdNaracka(naracka.getIdNaracka()); 50 List<Produkt> produktList = produktService.findAll(); 51 model.addAttribute("order", naracka); 52 model.addAttribute("products", produktList); 53 model.addAttribute("po", narackaSodrziProdukt); 54 model.addAttribute("prices", cenaService.findAll()); 55 model.addAttribute("bodyContent", "cart"); 56 return "master_template"; 57 } 58 59 @PostMapping("/{id}/success") 60 public String processOrder(@PathVariable Integer id,HttpServletRequest req,@RequestParam(required = false) String address){ 61 Naracka n = narackaService.findByIdNaracka(id); 62 String username = req.getRemoteUser(); 63 Korisnik korisnik = korisnikService.findbyImePrezime(username); 64 Kupuvac kupuvac = kupuvacService.findById(korisnik.getIdKorisnik()); 65 if(address!=null) { 66 narackaService.edit(0, "se sprema", address, kupuvac.getIdKorisnik(), n.getIdNaracka()); 67 } 68 else { 69 narackaService.edit(0, "se sprema", "/", kupuvac.getIdKorisnik(), n.getIdNaracka()); 70 } 71 return "redirect:/products"; 72 } 73 74 75 2 76 } -
src/main/java/project/fmo/app/projcetfmo/Web/ProductController.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Web;public class ProductController { 1 package project.fmo.app.projcetfmo.Web; 2 3 4 import org.springframework.format.annotation.DateTimeFormat; 5 import org.springframework.stereotype.Controller; 6 import org.springframework.ui.Model; 7 import org.springframework.web.bind.annotation.*; 8 import project.fmo.app.projcetfmo.Model.*; 9 import project.fmo.app.projcetfmo.Service.*; 10 11 12 import java.sql.Date; 13 import java.text.ParseException; 14 15 import java.time.LocalDate; 16 import java.util.List; 17 18 19 @Controller 20 @RequestMapping("/products") 21 public class ProductController { 22 23 private final ProduktService produktService; 24 private final KategorijaService kategorijaService; 25 private final ProduktEOdKategorijaService produktEOdKategorijaService; 26 private final CenaService cenaService; 27 private final NarackaService narackaService; 28 private final NarackaSodrziProduktService narackaSodrziProduktService; 29 private final KupuvacService kupuvacService; 30 private final KorisnikService korisnikService; 31 32 public ProductController(ProduktService produktService, KategorijaService kategorijaService, ProduktEOdKategorijaService produktEOdKategorijaService, CenaService cenaService, NarackaService narackaService, NarackaSodrziProduktService narackaSodrziProduktService, KupuvacService kupuvacService, KorisnikService korisnikService) { 33 this.produktService = produktService; 34 this.kategorijaService = kategorijaService; 35 this.produktEOdKategorijaService = produktEOdKategorijaService; 36 this.cenaService = cenaService; 37 this.narackaService = narackaService; 38 this.narackaSodrziProduktService = narackaSodrziProduktService; 39 this.kupuvacService = kupuvacService; 40 this.korisnikService = korisnikService; 41 } 42 43 @GetMapping 44 public String getProductPage(Model model) { 45 List<Produkt> products = this.produktService.findAll(); 46 model.addAttribute("products", products); 47 model.addAttribute("kat", kategorijaService.findAll()); 48 model.addAttribute("categories", produktEOdKategorijaService.findAll()); 49 model.addAttribute("prices", cenaService.findAll()); 50 model.addAttribute("bodyContent", "products"); 51 return "master_template"; 52 } 53 54 @GetMapping("/{id}") 55 public String getProductInfo(Model model, @PathVariable Integer id){ 56 Produkt p = produktService.findById(id).orElse(null); 57 Cena c = cenaService.findByIdProdukt(id); 58 ProduktEOdKategorija pk = produktEOdKategorijaService.findByIdProdukt(id); 59 List<Kategorija> k = kategorijaService.findAll(); 60 Kategorija kat = null; 61 for ( Kategorija kategorija : k){ 62 if (kategorija.getIdKategorija() == pk.getIdKategorija()){ 63 kat=kategorija; 64 } 65 } 66 model.addAttribute("product", p); 67 model.addAttribute("price", c); 68 model.addAttribute("category",pk); 69 if(kat != null) { 70 model.addAttribute("kat", kat); 71 } 72 model.addAttribute("bodyContent", "product_info"); 73 return "master_template"; 74 } 75 76 @PostMapping("{id}/add-to-cart") 77 public String addProductToCart(@PathVariable Integer id, 78 @RequestParam String idKorisnik, 79 @RequestParam int cena, 80 @RequestParam int quantity){ 81 Korisnik kOrisnik = korisnikService.findbyImePrezime(idKorisnik); 82 Kupuvac k = kupuvacService.findById(kOrisnik.getIdKorisnik()); 83 Naracka n = narackaService.findByIdKorisniktAndStatus(k.getIdKorisnik(),"aktivna"); 84 if (n == null){ 85 //Naracka narackaNova = new Naracka(cena*quantity, Date.valueOf(LocalDate.now()), "aktivna", "/", k); 86 Naracka narackaNova = narackaService.save(cena*quantity, Date.valueOf(LocalDate.now()), "aktivna", "/", k); 87 NarackaSodrziProdukt nsp = new NarackaSodrziProdukt(id,narackaNova.getIdNaracka(),quantity,cena); 88 narackaSodrziProduktService.save(id,narackaNova.getIdNaracka(),quantity,cena); 89 90 return "redirect:/products"; 91 } 92 else { 93 narackaService.edit(cena*quantity,n.getStatus(),n.getAdresa(),k.getIdKorisnik(),n.getIdNaracka()); 94 NarackaSodrziProdukt narackaSodrziProdukt = narackaSodrziProduktService.findByIdProduktAndIdNaracka(id,n.getIdNaracka()); 95 if(narackaSodrziProdukt == null){ 96 NarackaSodrziProdukt nova = new NarackaSodrziProdukt(id,n.getIdNaracka(),quantity,cena); 97 narackaSodrziProduktService.save(id,n.getIdNaracka(),quantity,cena); 98 } 99 else{ 100 narackaSodrziProduktService.edit(id,n.getIdNaracka(),quantity,cena); 101 } 102 return "redirect:/products"; 103 } 104 } 105 106 @DeleteMapping("/delete/{id}") 107 public String deleteProduct(@PathVariable Integer id,Model model) { 108 if(narackaSodrziProduktService.findByIdProdukt(id).size() != 0){ 109 model.addAttribute("bodyContent", "not_valid_delete"); 110 return "master_template"; 111 } 112 this.cenaService.deleteByIdProdukt(id); 113 this.produktEOdKategorijaService.deleteByIdProdukt(id); 114 this.produktService.deleteById(id); 115 return "redirect:/products"; 116 } 117 118 @GetMapping("/edit-form/{id}") 119 public String editProductPage(@PathVariable Integer id, Model model) { 120 if (this.produktService.findById(id).isPresent()) { 121 Produkt product = this.produktService.findById(id).get(); 122 Cena c = cenaService.findByIdProdukt(product.getIdProdukt()); 123 ProduktEOdKategorija produktEOdKategorija = produktEOdKategorijaService.findByIdProdukt(product.getIdProdukt()); 124 model.addAttribute("chosen", produktEOdKategorija); 125 model.addAttribute("price", c); 126 List<Kategorija> categories = this.kategorijaService.findAll(); 127 model.addAttribute("categories", categories); 128 model.addAttribute("product", product); 129 model.addAttribute("bodyContent", "add_product"); 130 return "master_template"; 131 } 132 return "redirect:/products"; 133 } 134 135 @GetMapping("/add-form") 136 public String addProductPage(Model model) { 137 List<Kategorija> categories = this.kategorijaService.findAll(); 138 model.addAttribute("categories", categories); 139 model.addAttribute("bodyContent", "add_product"); 140 return "master_template"; 141 } 142 143 @PostMapping("/add") 144 public String saveProduct( 145 @RequestParam(required = false) Integer id, 146 @RequestParam String name, 147 @RequestParam(required = false) String description, 148 @RequestParam Integer category, 149 @RequestParam Date date, 150 @RequestParam(required = false) String dateTo, 151 @RequestParam int price) throws ParseException { 152 if(dateTo.length() != 0) { 153 Date d = Date.valueOf(dateTo); 154 155 if (id != null) { 156 this.produktService.edit(id, name, description); 157 this.cenaService.edit(id, date, d, price); 158 this.produktEOdKategorijaService.edit(id, category); 159 160 } else { 161 Produkt p = this.produktService.save(name, description); 162 this.cenaService.save(p.getIdProdukt(), date, d, price); 163 this.produktEOdKategorijaService.save(p.getIdProdukt(), category); 164 } 165 } 166 else{ 167 if (id != null) { 168 this.produktService.edit(id, name, description); 169 this.cenaService.edit(id, date, null, price); 170 this.produktEOdKategorijaService.edit(id, category); 171 172 } else { 173 Produkt p = this.produktService.save(name, description); 174 this.cenaService.save(p.getIdProdukt(), date, null, price); 175 this.produktEOdKategorijaService.save(p.getIdProdukt(), category); 176 } 177 178 } 179 return "redirect:/products"; 180 } 181 182 183 184 2 185 } -
src/main/java/project/fmo/app/projcetfmo/Web/RegisterController.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Web;public class RegisterController { 1 package project.fmo.app.projcetfmo.Web; 2 3 import org.springframework.stereotype.Controller; 4 import org.springframework.ui.Model; 5 import org.springframework.web.bind.annotation.GetMapping; 6 import org.springframework.web.bind.annotation.PostMapping; 7 import org.springframework.web.bind.annotation.RequestMapping; 8 import org.springframework.web.bind.annotation.RequestParam; 9 import project.fmo.app.projcetfmo.Service.KorisnikService; 10 11 @Controller 12 @RequestMapping("/register") 13 public class RegisterController { 14 15 private final KorisnikService korisnikService; 16 17 18 public RegisterController(KorisnikService korisnikService) { 19 this.korisnikService = korisnikService; 20 } 21 22 23 @GetMapping 24 public String getRegisterPage(@RequestParam(required = false) String error, Model model) { 25 if(error != null && !error.isEmpty()) { 26 model.addAttribute("hasError", true); 27 model.addAttribute("error", error); 28 } 29 model.addAttribute("bodyContent","register"); 30 return "master_template"; 31 } 32 33 @PostMapping 34 public String register(@RequestParam String name_surname, 35 @RequestParam String password, 36 @RequestParam String repeatedPassword, 37 @RequestParam String mail, 38 @RequestParam String number) { 39 try{ 40 if(korisnikService.findbyImePrezime(name_surname) != null) throw new RuntimeException(); 41 this.korisnikService.register(name_surname, password, repeatedPassword, mail, number); 42 return "redirect:/home"; 43 } catch (RuntimeException r) { 44 return "redirect:/register?error=InvalidRegistration"; 45 } 46 } 47 48 49 2 50 } -
src/main/java/project/fmo/app/projcetfmo/Web/StatisticsController.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.Web;public class StatisticsController { 1 package project.fmo.app.projcetfmo.Web; 2 3 import org.springframework.data.domain.Page; 4 import org.springframework.stereotype.Controller; 5 import org.springframework.ui.Model; 6 import org.springframework.web.bind.annotation.GetMapping; 7 import org.springframework.web.bind.annotation.RequestMapping; 8 import project.fmo.app.projcetfmo.Model.Korisnik; 9 import project.fmo.app.projcetfmo.Model.Produkt; 10 import project.fmo.app.projcetfmo.Service.KorisnikService; 11 import project.fmo.app.projcetfmo.Service.ProduktService; 12 13 import java.util.ArrayList; 14 import java.util.List; 15 16 @Controller 17 @RequestMapping("/statistics") 18 public class StatisticsController { 19 private final ProduktService produktService; 20 private final KorisnikService korisnikService; 21 22 public StatisticsController(ProduktService produktService, KorisnikService korisnikService) { 23 this.produktService = produktService; 24 this.korisnikService = korisnikService; 25 } 26 27 @GetMapping 28 public String getStatistics(Model model){ 29 List<Object> korisnikList = korisnikService.statistics2(); 30 List<String> ime = new ArrayList<>(); 31 List<String> id = new ArrayList<>(); 32 List<Integer> vkupno_naracki = new ArrayList<>(); 33 List<Float> prosecna_suma_na_naracka_za_site_kupuvaci = new ArrayList<>(); 34 List<Integer> vkupno_suma_od_site_naracki_na_kupuvacot = new ArrayList<>(); 35 List<Integer> vkupno_naracki_nad_prosek_na_korisnikot = new ArrayList<>(); 36 List<Integer> vkupno_suma_na_naracki_nad_prosek_za_korisnikot = new ArrayList<>(); 37 // for(int i =0 ; i< korisnikList.size();i++) { 38 // ime.add(korisnikList.get(i)[0].toString()); 39 // } 40 List<Object> produktList = produktService.statistics1(); 41 model.addAttribute("products", produktList); 42 model.addAttribute("users", korisnikList); 43 model.addAttribute("bodyContent", "statistics"); 44 return "master_template"; 45 46 } 2 47 } -
src/main/java/project/fmo/app/projcetfmo/config/CustomUsernamePasswordAuthenticationProvider.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.config;public class CustomUsernamePasswordAuthenticationProvider { 1 package project.fmo.app.projcetfmo.config; 2 3 import org.springframework.security.authentication.AuthenticationProvider; 4 import org.springframework.security.authentication.BadCredentialsException; 5 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; 6 import org.springframework.security.core.Authentication; 7 import org.springframework.security.core.AuthenticationException; 8 import org.springframework.security.core.userdetails.UserDetails; 9 import org.springframework.security.crypto.password.PasswordEncoder; 10 import org.springframework.stereotype.Component; 11 import project.fmo.app.projcetfmo.Service.KorisnikService; 12 13 @Component 14 public class CustomUsernamePasswordAuthenticationProvider implements AuthenticationProvider { 15 16 private final KorisnikService korisnikService; 17 private final PasswordEncoder passwordEncoder; 18 19 public CustomUsernamePasswordAuthenticationProvider(KorisnikService korisnikService, PasswordEncoder passwordEncoder) { 20 this.korisnikService = korisnikService; 21 this.passwordEncoder = passwordEncoder; 22 } 23 24 25 @Override 26 public Authentication authenticate(Authentication authentication) throws AuthenticationException { 27 String username = authentication.getName(); 28 String password = authentication.getCredentials().toString(); 29 30 if ("".equals(username) || "".equals(password)) { 31 throw new BadCredentialsException("Invalid Credentials"); 32 } 33 34 UserDetails userDetails = this.korisnikService.loadUserByUsername(username); 35 36 if (!password.equals(userDetails.getPassword())) { 37 throw new BadCredentialsException("Password is incorrect!"); 38 } 39 return new UsernamePasswordAuthenticationToken(userDetails, userDetails.getPassword(), userDetails.getAuthorities()); 40 41 } 42 43 @Override 44 public boolean supports(Class<?> authentication) { 45 return authentication.equals(UsernamePasswordAuthenticationToken.class); 46 } 2 47 } -
src/main/java/project/fmo/app/projcetfmo/config/WebSecurityConfig.java
r1dd9226 rd14176d 1 package project.fmo.app.projcetfmo.config;public class WebSecurityConfig { 1 package project.fmo.app.projcetfmo.config; 2 3 import org.springframework.context.annotation.Configuration; 4 import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 5 import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; 6 import org.springframework.security.config.annotation.web.builders.HttpSecurity; 7 import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; 8 import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 9 import org.springframework.security.crypto.password.PasswordEncoder; 10 11 @Configuration 12 @EnableWebSecurity 13 @EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true) 14 public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 15 16 17 private final PasswordEncoder passwordEncoder; 18 private final CustomUsernamePasswordAuthenticationProvider authenticationProvider; 19 20 public WebSecurityConfig(PasswordEncoder passwordEncoder, 21 CustomUsernamePasswordAuthenticationProvider authenticationProvider) { 22 this.passwordEncoder = passwordEncoder; 23 this.authenticationProvider = authenticationProvider; 24 } 25 26 @Override 27 protected void configure(HttpSecurity http) throws Exception { 28 29 http.csrf().disable() 30 .authorizeRequests() 31 .antMatchers("/","/**", "/home", "/register", "/products").permitAll() 32 .antMatchers("/admin/**").hasRole("ADMIN") 33 .anyRequest() 34 .authenticated() 35 .and() 36 .formLogin() 37 .permitAll() 38 .failureUrl("/login?error=BadCredentials") 39 .defaultSuccessUrl("/products", true) 40 .and() 41 .logout() 42 .clearAuthentication(true) 43 .invalidateHttpSession(true) 44 .deleteCookies("JSESSIONID") 45 .logoutSuccessUrl("/home") 46 .and() 47 .exceptionHandling().accessDeniedPage("/access_denied"); 48 49 } 50 51 @Override 52 protected void configure(AuthenticationManagerBuilder auth) { 53 auth.authenticationProvider(authenticationProvider); 54 } 55 2 56 }
Note:
See TracChangeset
for help on using the changeset viewer.