diff --git a/pom.xml b/pom.xml index 87178dc..81ab720 100644 --- a/pom.xml +++ b/pom.xml @@ -46,6 +46,10 @@ + + + + org.hibernate hibernate-core @@ -71,6 +75,17 @@ + + + org.json + json + 20200518 + + + + + + diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/SecurityConfiguration.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/SecurityConfiguration.java index d5f927b..0df3a12 100644 --- a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/SecurityConfiguration.java +++ b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/SecurityConfiguration.java @@ -34,7 +34,7 @@ protected void configure(HttpSecurity httpSecurity) throws Exception { httpSecurity.csrf().disable(); httpSecurity.authorizeRequests() - .antMatchers("/trucks/all","/session/player/**").permitAll() + .antMatchers("/trucks/all","/session/player/**","/order/all").permitAll() .anyRequest().authenticated() .and() .formLogin().permitAll() @@ -46,37 +46,29 @@ protected void configure(HttpSecurity httpSecurity) .alwaysRemember(true) .tokenValiditySeconds(30*5); - - httpSecurity.headers() .frameOptions() .sameOrigin(); + } @Autowired protected void configureGlobal(AuthenticationManagerBuilder builder, MyUserDetailService myUserDetailService) throws Exception { -// builder.jdbcAuthentication() -// .dataSource(dataSource) -// .usersByUsernameQuery("select username,password,enabled from users where username = ?") -// .authoritiesByUsernameQuery("select username,authority from authorities where username = ?") -// -// ; builder.userDetailsService(myUserDetailService) .passwordEncoder(passwordEncoder()); - } - @Bean - public PasswordEncoder passwordEncoder () { + @Bean + public PasswordEncoder passwordEncoder () { return new BCryptPasswordEncoder(); - } + } - } +} diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/controller/OrderController.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/controller/OrderController.java index 0cb33e1..9821973 100644 --- a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/controller/OrderController.java +++ b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/controller/OrderController.java @@ -1,8 +1,92 @@ package pl.staszczykpiotr.truckforwarder_backend.controller; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.web.bind.annotation.*; +import pl.staszczykpiotr.truckforwarder_backend.dto.Course; +import pl.staszczykpiotr.truckforwarder_backend.dto.Order; +import pl.staszczykpiotr.truckforwarder_backend.repository.CourseRepository; +import pl.staszczykpiotr.truckforwarder_backend.repository.OrderRepository; + +import java.text.SimpleDateFormat; +import java.util.*; @RestController public class OrderController { + + private OrderRepository orderRepository; + private CourseRepository courseRepository; + + @Autowired + public OrderController(OrderRepository orderRepository, CourseRepository courseRepository){ + this.orderRepository = orderRepository; + this.courseRepository = courseRepository; + + } + + + @GetMapping("/order/all") + + public List getOrders() { + return orderRepository.findAll(); + } + + @GetMapping("/order/vieworders") + public List getViewOrders(){ + return orderRepository.findOrders(); + } + + @GetMapping("/session/course/viewcourses") + public List getViewCourses(){ + + return courseRepository.findCourses(SecurityContextHolder.getContext().getAuthentication().getName()); + } + + @PostMapping("/session/course/new") + public void postCreateCourse(@RequestBody com.fasterxml.jackson.databind.JsonNode userDataForCourse){ + + + + Calendar startTime = Calendar.getInstance(); + Calendar endTime = Calendar.getInstance(); + endTime.add(Calendar.SECOND,userDataForCourse.get("Distance").intValue()); + + Course course = new Course(); + course.setId(Math.toIntExact(courseRepository.count()+1)); + course.setStart_time(startTime); + course.setEnd_time(endTime); + course.setOwner(SecurityContextHolder.getContext().getAuthentication().getName()); + course.setIdbought(userDataForCourse.get("selectedTruckId").intValue()); + course.setIdorders(userDataForCourse.get("selectedOrderId").intValue()); + course.setDuration(userDataForCourse.get("Distance").floatValue()); + course.setFinished(false); + course.setProgress(0); + courseRepository.save(course); + + + //System.out.println(userDataForCourse.get("selectedOrderId")+"||"+userDataForCourse.get("selectedTruckId")+"||"+ userDataForCourse.get("Distance")); + + } + + + + + @GetMapping("/session/course/update_progress") + public List getProgress(int id, int progress){ + + + Course c = courseRepository.findById(id); + c.setProgress(progress); + courseRepository.save(c); + + + return courseRepository.getProgress(id); + } + + + + +// public List findCourses(){return courseRepository.findCourses(SecurityContextHolder.getContext().getAuthentication().getName());} + } diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/controller/PlayerController.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/controller/PlayerController.java index 723ed15..5db4606 100644 --- a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/controller/PlayerController.java +++ b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/controller/PlayerController.java @@ -2,10 +2,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.web.bind.annotation.*; -import pl.staszczykpiotr.truckforwarder_backend.MyUserDetailService; -import pl.staszczykpiotr.truckforwarder_backend.MyUserPrincipal; import pl.staszczykpiotr.truckforwarder_backend.dto.BoughtTrucks; import pl.staszczykpiotr.truckforwarder_backend.dto.Player; import pl.staszczykpiotr.truckforwarder_backend.dto.Truck; @@ -14,6 +11,7 @@ import pl.staszczykpiotr.truckforwarder_backend.repository.TruckRepository; import java.util.List; +import java.util.Map; @RestController @@ -21,35 +19,100 @@ public class PlayerController { private PlayerRepository playerRepository; private BoughtTrucksRepository boughtTrucksRepository; - - + private TruckRepository truckRepository; @Autowired - public PlayerController(PlayerRepository playerRepository, BoughtTrucksRepository boughtTrucksRepository) { + public PlayerController(PlayerRepository playerRepository, BoughtTrucksRepository boughtTrucksRepository, TruckRepository truckRepository ) { this.playerRepository = playerRepository; this.boughtTrucksRepository = boughtTrucksRepository; + this.truckRepository = truckRepository; + } + + @GetMapping("/trucks/all") + + public List getTrucks() { + return truckRepository.findAll(); } @GetMapping("/session/player/info") public Player getPlayer() { + return playerRepository.findByOwner(SecurityContextHolder.getContext().getAuthentication().getName()); + } - return playerRepository.findByOwner(SecurityContextHolder.getContext().getAuthentication().getName()); + @GetMapping("/session/player/bought_trucks") + public List getBoughtTrucks() { + System.out.println(SecurityContextHolder.getContext().getAuthentication().getName()); + System.out.println(boughtTrucksRepository.findBoughtTrucks(SecurityContextHolder.getContext().getAuthentication().getName())); + return boughtTrucksRepository.findBoughtTrucks(SecurityContextHolder.getContext().getAuthentication().getName()); } - @GetMapping("/session/player/bought_trucks") - public BoughtTrucks getBoughtTrucks(){ + + + + @PostMapping("/session/player/purchase_truck") + public void postPurchaseTruck(@RequestBody String SelectedTruck){ + + StringBuilder stringBuilder = new StringBuilder(); + String selectedTruckByUser; + stringBuilder.append(SelectedTruck); + stringBuilder.delete(0,18); + stringBuilder.delete(stringBuilder.length()-2,stringBuilder.length()); // Format String from Post to correctly form + selectedTruckByUser = stringBuilder.toString(); + + BoughtTrucks boughtTrucks = new BoughtTrucks(); + + boughtTrucks.setIdbought_trucks(Math.toIntExact(boughtTrucksRepository.count() + 1)); + boughtTrucks.setIdtrucks(truckRepository.findByName(selectedTruckByUser).getID()); + boughtTrucks.setIdplayers(playerRepository.findByOwner(SecurityContextHolder.getContext().getAuthentication().getName()).getIdplayers()); + boughtTrucks.setLife(100); + boughtTrucks.setAvailable(true); + boughtTrucks.setOwner(SecurityContextHolder.getContext().getAuthentication().getName()); + + boughtTrucksRepository.save(boughtTrucks); // Add Bought Truck + + + playerRepository.findByOwner(SecurityContextHolder.getContext().getAuthentication().getName()). + setCash(playerRepository.findByOwner(SecurityContextHolder.getContext().getAuthentication().getName()).getCash() - + truckRepository.findByName(selectedTruckByUser).getPrice()); // Set Cash Status + + playerRepository.save(playerRepository.findByOwner(SecurityContextHolder.getContext().getAuthentication().getName())); // Update Cash Status + + + + } + + @PostMapping("/session/player/changeAvailability") + public void changeAvailability (@RequestBody com.fasterxml.jackson.databind.JsonNode selectedTruck){ + + System.out.println(selectedTruck.get("selectedTruckId")); + BoughtTrucks bt = boughtTrucksRepository.findById(Integer.parseInt(selectedTruck.get("selectedTruckId").toString())); + bt.setAvailable(false); + boughtTrucksRepository.save(bt); + + } + + @PostMapping("/session/player/changeAvailabilityToTrue") + public void changeAvailabilityToTrue (@RequestBody com.fasterxml.jackson.databind.JsonNode selectedTruck){ + + System.out.println(selectedTruck.get("selectedTruckId")); + System.out.println(selectedTruck.get("rewardCash")); + playerRepository.findByOwner(SecurityContextHolder.getContext().getAuthentication().getName()). + setCash(playerRepository.findByOwner(SecurityContextHolder.getContext().getAuthentication().getName()).getCash() + selectedTruck.get("rewardCash").floatValue()); // Set Cash Status + playerRepository.save(playerRepository.findByOwner(SecurityContextHolder.getContext().getAuthentication().getName())); + + BoughtTrucks bt = boughtTrucksRepository.findById(Integer.parseInt(selectedTruck.get("selectedTruckId").toString())); + bt.setAvailable(true); + boughtTrucksRepository.save(bt); - return boughtTrucksRepository.findByOwner(SecurityContextHolder.getContext().getAuthentication().getName()); } - diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/controller/TruckController.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/controller/TruckController.java deleted file mode 100644 index 5b5eb2c..0000000 --- a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/controller/TruckController.java +++ /dev/null @@ -1,46 +0,0 @@ -package pl.staszczykpiotr.truckforwarder_backend.controller; - -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.cfg.Configuration; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; -import pl.staszczykpiotr.truckforwarder_backend.dto.Truck; -import pl.staszczykpiotr.truckforwarder_backend.repository.TruckRepository; - -import java.util.Iterator; -import java.util.List; - - -@RestController -public class TruckController { - - - - private TruckRepository truckRepository; - - @Autowired - public TruckController(TruckRepository truckRepository) { - this.truckRepository = truckRepository; - } - - - @GetMapping("/trucks/all") - - public List getTrucks() { - - - return truckRepository.findAll(); - } - - - -} - - - - diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/controller/UserController.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/controller/UserController.java index 477428c..749e9d4 100644 --- a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/controller/UserController.java +++ b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/controller/UserController.java @@ -48,9 +48,10 @@ public Principal retrievePrincipal(Principal principal) { @PostMapping() - public Player loginUser(@RequestBody String username, String password){ + public Boolean loginUser(@RequestBody String username, String password){ - return playerRepository.findByOwner(SecurityContextHolder.getContext().getAuthentication().getName()); + //return playerRepository.findByOwner(SecurityContextHolder.getContext().getAuthentication().getName()); + return SecurityContextHolder.getContext().getAuthentication().isAuthenticated(); } diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/BoughtTrucks.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/BoughtTrucks.java index 31c26dc..90a1a5b 100644 --- a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/BoughtTrucks.java +++ b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/BoughtTrucks.java @@ -7,17 +7,28 @@ @Table (name = "bought_trucks") public class BoughtTrucks { @Id + @Column (name = "id") private Integer idbought_trucks; @Column private Integer idtrucks; private Integer idplayers; - private Integer condition; + private Integer life; + @Column(nullable = false, columnDefinition = "TINYINT(1)") private Boolean available; private String owner; + public BoughtTrucks(Integer idbought_trucks, Integer idtrucks, Integer idplayers, Integer condition, Boolean available, String owner){ + this.idbought_trucks = idbought_trucks; + this.idtrucks = idtrucks; + this.idplayers = idplayers; + this.life = condition; + this.available = available; + this.owner = owner; + } + public BoughtTrucks(){} public String getOwner() { return owner; @@ -51,12 +62,12 @@ public void setIdplayers(Integer idplayers) { this.idplayers = idplayers; } - public Integer getCondition() { - return condition; + public Integer getLife() { + return life; } - public void setCondition(Integer condition) { - this.condition = condition; + public void setLife(Integer condition) { + this.life = condition; } public Boolean getAvailable() { diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/Cargo.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/Cargo.java new file mode 100644 index 0000000..4b37569 --- /dev/null +++ b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/Cargo.java @@ -0,0 +1,24 @@ +package pl.staszczykpiotr.truckforwarder_backend.dto; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table (name = "cargos") +public class Cargo { + @Id + @Column (name = "id") + private Integer id; + + @Column + String type; + Float size; + Float length; + Float width; + Float height; + Float weight; + Float capacity; + String desc; +} diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/Course.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/Course.java new file mode 100644 index 0000000..126c9a5 --- /dev/null +++ b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/Course.java @@ -0,0 +1,108 @@ +package pl.staszczykpiotr.truckforwarder_backend.dto; + +import javax.persistence.*; +import java.util.Calendar; +import java.util.Date; + +@Entity +@Table (name = "courses") + +public class Course { + @Id + @Column(name = "id") + private int id; + + public Course(){ + + }; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public Integer getIdorders() { + return idorders; + } + + public void setIdorders(Integer idorders) { + this.idorders = idorders; + } + + public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public Integer getIdbought() { + return idbought; + } + + public void setIdbought(Integer idbought) { + this.idbought = idbought; + } + + public Calendar getStart_time() { + return start_time; + } + + public void setStart_time(Calendar start_time) { + this.start_time = start_time; + } + + public Calendar getEnd_time() { + return end_time; + } + + public void setEnd_time(Calendar end_time) { + this.end_time = end_time; + } + + + + public Float getDuration() { + return duration; + } + + public void setDuration(Float duration) { + this.duration = duration; + } + + @Column + Integer idorders; + String owner; + Integer idbought; + Float duration; + + public Integer getProgress() { + return progress; + } + + public void setProgress(Integer progress) { + this.progress = progress; + } + + Integer progress; + + public Boolean getFinished() { + return finished; + } + + public void setFinished(Boolean finished) { + this.finished = finished; + } + + Boolean finished; + @Temporal(TemporalType.DATE) + Calendar start_time; + @Temporal(TemporalType.DATE) + Calendar end_time; +} + + diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/Customer.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/Customer.java new file mode 100644 index 0000000..af9e3f1 --- /dev/null +++ b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/Customer.java @@ -0,0 +1,17 @@ +package pl.staszczykpiotr.truckforwarder_backend.dto; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table (name = "customers") +public class Customer { + @Id + @Column(name = "id") + private int id; + + @Column + private String name; +} diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/Order.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/Order.java new file mode 100644 index 0000000..cbbbd28 --- /dev/null +++ b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/Order.java @@ -0,0 +1,68 @@ +package pl.staszczykpiotr.truckforwarder_backend.dto; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table (name="orders") +public class Order { + @Id + @Column (name="id") + private Integer idorder; + private String source; + private String destination; + private Float reward; + private Float distance; + private Integer idcustomers; + private Integer idcargos; + + public Order(){ + + }; + + public Integer getIdorder() { + return idorder; + } + public void setIdorder(Integer idorder) { + this.idorder = idorder; + } + public String getSource() { + return source; + } + public void setSource(String source) { + this.source = source; + } + public String getDestination() { + return destination; + } + public void setDestination(String destination) { + this.destination = destination; + } + public Float getReward() { + return reward; + } + public void setReward(Float reward) { + this.reward = reward; + } + public Float getDistance() { + return distance; + } + public void setDistance(Float distance) { + this.distance = distance; + } + public Integer getIdcustomers() { + return idcustomers; + } + public void setIdcustomers(Integer idcustomers) { + this.idcustomers = idcustomers; + } + public Integer getIdcargos() { + return idcargos; + } + public void setIdcargos(Integer idcargos) { + this.idcargos = idcargos; + } + +} diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/Player.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/Player.java index 141cd33..a47fd46 100644 --- a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/Player.java +++ b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/Player.java @@ -9,6 +9,7 @@ @Table(name="players") public class Player { @Id + @Column (name ="id") private int idplayers; @Column diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/Truck.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/Truck.java index 374506f..bec4a33 100644 --- a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/Truck.java +++ b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/dto/Truck.java @@ -5,13 +5,13 @@ import javax.persistence.*; -@Entity(name = "trucks") +@Entity @Table(name = "trucks") public class Truck implements ITruck{ - @Id + @Column(name = "id") //@GeneratedValue(strategy = GenerationType.IDENTITY) public Integer idtrucks; @@ -38,52 +38,41 @@ public Truck(){ }; - @Override public Integer getID() { return idtrucks; } - @Override public String getName() { return name; } - @Override public String getLoading() { return loadingtype; } - @Override public Float getLength() { return length; } - @Override public Float getWidth() { return width; } - @Override public Float getHeight() { return height; } - @Override public Float getWeight() { return weight; } - @Override public Float getCapacity() { return capacity; } - @Override public Float getPrice() { return price; } - - @Override public Byte getStatus() { return status; diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/repository/BoughtTrucksRepository.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/repository/BoughtTrucksRepository.java index 5987961..fd761b0 100644 --- a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/repository/BoughtTrucksRepository.java +++ b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/repository/BoughtTrucksRepository.java @@ -1,10 +1,28 @@ package pl.staszczykpiotr.truckforwarder_backend.repository; +import org.json.JSONObject; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import pl.staszczykpiotr.truckforwarder_backend.dto.BoughtTrucks; +import pl.staszczykpiotr.truckforwarder_backend.dto.Truck; + +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import static org.hibernate.loader.Loader.SELECT; public interface BoughtTrucksRepository extends JpaRepository { + @Query + (value = "SELECT bt.idbought_trucks as id, t.name as name, bt.life as life , bt.available as available, t.length as length, t.height as height, t.width as width, t.weight as weight from Truck t, BoughtTrucks bt where bt.idtrucks = t.idtrucks and bt.owner = :owner") + List findBoughtTrucks(@Param("owner") String owner); + + BoughtTrucks findByOwner(String owner); + List findAllByOwner(String owner); + + BoughtTrucks findById(int id); } diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/repository/CourseRepository.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/repository/CourseRepository.java new file mode 100644 index 0000000..4680135 --- /dev/null +++ b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/repository/CourseRepository.java @@ -0,0 +1,25 @@ +package pl.staszczykpiotr.truckforwarder_backend.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import pl.staszczykpiotr.truckforwarder_backend.dto.BoughtTrucks; +import pl.staszczykpiotr.truckforwarder_backend.dto.Course; + +import java.util.List; +import java.util.Map; + +public interface CourseRepository extends JpaRepository { + + @Query + (value = "SELECT c.id as id, c.start_time as start_time, c.end_time as end_time, c.duration as duration , c.progress as progress, bt.idbought_trucks as idbought_trucks, t.name as name, o.idorder as idorder, o.destination as destination, o.source as source, o.reward as reward from Course c, Order o, BoughtTrucks bt, Truck t where c.idbought = bt.idbought_trucks and bt.idtrucks = t.idtrucks and o.idorder = c.idorders and c.owner = :owner") + List findCourses(@Param("owner") String owner); + + + @Query + (value = "SELECT c.id as id, c.progress as progress, c.duration as duration from Course c where c.id = :id") + List getProgress(@Param("id") int id); + + Course findById(int id); + +} diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/repository/OrderRepository.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/repository/OrderRepository.java new file mode 100644 index 0000000..dda2152 --- /dev/null +++ b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/repository/OrderRepository.java @@ -0,0 +1,24 @@ +package pl.staszczykpiotr.truckforwarder_backend.repository; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; +import org.springframework.stereotype.Repository; +import pl.staszczykpiotr.truckforwarder_backend.dto.Order; +import pl.staszczykpiotr.truckforwarder_backend.dto.Player; + +import java.util.List; +import java.util.Map; + +@Repository +public interface OrderRepository extends JpaRepository { + @Query + (value = "SELECT ord.idorder as id, ord.source as source, ord.destination as destination , " + + "ord.distance as distance, ord.reward as reward, " + + "carg.type as type, carg.size as size, carg.length as length, carg.width as width, " + + "carg.height as height, carg.weight as weight, carg.capacity as capacity, carg.desc as desc, " + + "cst.name as client from Order ord, Cargo carg, Customer cst where ord.idcustomers = cst.id and ord.idcargos = carg.id") + List findOrders(); + + +} diff --git a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/repository/TruckRepository.java b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/repository/TruckRepository.java index 1d2b827..78a891a 100644 --- a/src/main/java/pl/staszczykpiotr/truckforwarder_backend/repository/TruckRepository.java +++ b/src/main/java/pl/staszczykpiotr/truckforwarder_backend/repository/TruckRepository.java @@ -3,6 +3,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.repository.CrudRepository; import org.springframework.stereotype.Repository; +import pl.staszczykpiotr.truckforwarder_backend.dto.Player; import pl.staszczykpiotr.truckforwarder_backend.dto.Truck; import java.util.List; @@ -11,6 +12,7 @@ @Repository("TruckController") public interface TruckRepository extends JpaRepository { + Truck findByName(String name); } \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index f66d6fa..e4e41bb 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,4 +1,4 @@ -spring.jpa.hibernate.ddl-auto=none +spring.jpa.hibernate.ddl-auto=update spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/sys?serverTimezone=Europe/Warsaw spring.jpa.database=mysql spring.datasource.username=root