Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Orders] After changing tariff the price of paid order is not changing #1201

Merged
merged 76 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
61f3efb
OrderBagMapping created
juseti Jun 12, 2023
b8712cc
Merge branch 'dev' into fix_order_detailes_dissapears_if_tariff_deleted
juseti Jun 12, 2023
d9b1d88
changed bag functionality logic
juseti Jun 13, 2023
eaf1ce0
added bag status active and deleted
juseti Jun 15, 2023
97694be
#5927 [UBS] endpoint that returns deactivated locations (#1133)
Maksym-Lenets Jun 13, 2023
d7ace0e
- changed redirect.green-city-client url (#1132)
Markiro1 Jun 13, 2023
b3cbaa9
[UBS] - bug with manual payment #5940 (#1136)
juseti Jun 13, 2023
6b81ea8
added bag status active and deleted
juseti Jun 16, 2023
a00b52b
changed tariff service crud methods and some order methods
juseti Jul 5, 2023
b374849
Merge branch 'dev' into fix_order_detailes_dissapears_if_bag_or_servi…
ospodaryk Jul 10, 2023
0593101
removed bagstatus
ospodaryk Jul 23, 2023
50ee844
Merged dev
ospodaryk Jul 23, 2023
5fddf16
Returned all tests to dev
ospodaryk Jul 23, 2023
5ef962f
Formatted
ospodaryk Jul 23, 2023
b6bea96
Formatted
ospodaryk Jul 23, 2023
2de11a1
Returned by maximum to dev
ospodaryk Jul 23, 2023
ec214cf
Removed unnesesary methods from entity
ospodaryk Jul 23, 2023
52d73a9
fixed code
ospodaryk Jul 23, 2023
8869fca
Added to tariff when delete status DEACTIVATED
ospodaryk Jul 23, 2023
363e338
Formatted
ospodaryk Jul 23, 2023
ef8beeb
Fixed tests
ospodaryk Jul 23, 2023
b541d81
Unworking only 1 test in SuperAdminServiceImpl
ospodaryk Jul 23, 2023
547d520
Fixed tests(unworking 36)
ospodaryk Jul 23, 2023
370f8fd
Fixed tests in UBSClientServiceImplTest
ospodaryk Jul 24, 2023
9e06e58
All files working
ospodaryk Jul 24, 2023
455b4ae
Fixed tests and added new
ospodaryk Jul 24, 2023
e60e59f
Removed import *
ospodaryk Jul 24, 2023
0809420
added new tests
ospodaryk Jul 24, 2023
6f073dd
added new tests and fixed all
ospodaryk Jul 24, 2023
598de34
added new tests and fixed code smells
ospodaryk Jul 24, 2023
d2e4436
added new tests to cover
ospodaryk Jul 24, 2023
5ff7a97
added new tests to cover
ospodaryk Jul 24, 2023
32a0316
added new tests to cover
ospodaryk Jul 24, 2023
820f75c
Fixed bad moment
ospodaryk Jul 25, 2023
ac46ceb
Fixed bad moments
ospodaryk Jul 25, 2023
46f15f4
Fixed bad moments
ospodaryk Jul 25, 2023
27271c8
Formatted
ospodaryk Jul 25, 2023
77647a9
Fixed bugs
ospodaryk Jul 25, 2023
7c20251
Separated sql from xml; changed to peek
ospodaryk Jul 25, 2023
9dffcfb
Bug delete tariff (#1200)
ospodaryk Jul 28, 2023
ca5ea7a
Added tests
ospodaryk Jul 28, 2023
9f0d9b4
Removed bug
ospodaryk Jul 28, 2023
700b409
Added new tests
ospodaryk Jul 28, 2023
77ad515
Deleted unused method
ospodaryk Jul 28, 2023
b9143eb
Fixed tests
ospodaryk Jul 28, 2023
49a1aa3
Removed code smell
ospodaryk Jul 28, 2023
a8196ad
Added tests to cover superAdminService.deleteTariffService()
ospodaryk Jul 28, 2023
53887d4
Added new tests to cover all lines
ospodaryk Jul 28, 2023
86eaa6b
fixed tests
ospodaryk Jul 28, 2023
60daad8
formatted
ospodaryk Jul 28, 2023
5f6f7f5
Fixed code:renamed methods
ospodaryk Jul 31, 2023
31794bf
Fixed code
ospodaryk Jul 31, 2023
0a1b072
Fixed
ospodaryk Jul 31, 2023
21fbf5f
Fixed all code
ospodaryk Jul 31, 2023
59891ac
Fixed tests
ospodaryk Jul 31, 2023
5a5e8cd
Fixed tests
ospodaryk Jul 31, 2023
004bd17
Fixed code
ospodaryk Jul 31, 2023
444fe39
Fixed tests
ospodaryk Jul 31, 2023
de3b25a
Fixed code
ospodaryk Jul 31, 2023
757366b
Fixed code
ospodaryk Jul 31, 2023
1b19630
Fixed greencity.repository.AdditionalBagsInfoRepoTest
ospodaryk Jul 31, 2023
cddeb11
Fixed precondition
ospodaryk Jul 31, 2023
a3de9e4
Fixed bag
ospodaryk Jul 31, 2023
3007295
Fixed code
ospodaryk Jul 31, 2023
1cb4d93
Fixed игп
ospodaryk Jul 31, 2023
66ec2fc
inserted sql in xml
ospodaryk Jul 31, 2023
6db84ac
inserted sql in xml
ospodaryk Jul 31, 2023
6ea5742
inserted sql in different xml
ospodaryk Jul 31, 2023
d903985
formatted
ospodaryk Jul 31, 2023
93b8c5f
fixed tests
ospodaryk Jul 31, 2023
0d926bb
added tests to cover bagstatus
ospodaryk Jul 31, 2023
48618f6
removed codesmell
ospodaryk Jul 31, 2023
aab511b
Added tests to cover Bagstatus
ospodaryk Jul 31, 2023
d592be5
Removed codesmell in BagStatusTest
ospodaryk Jul 31, 2023
78d87fd
added anotations not
ospodaryk Jul 31, 2023
b026b08
deleted unnesessary anotations not
ospodaryk Jul 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions dao/src/main/java/greencity/entity/order/Bag.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
package greencity.entity.order;

import greencity.entity.user.employee.Employee;
import greencity.enums.BagStatus;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.Builder;

import javax.persistence.*;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.CascadeType;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.time.LocalDate;
Expand Down Expand Up @@ -76,7 +87,12 @@ public class Bag {
@JoinColumn
private Employee editedBy;

@ManyToOne
@ManyToOne(cascade = CascadeType.REMOVE,
fetch = FetchType.EAGER)
@JoinColumn(nullable = false)
private TariffsInfo tariffsInfo;

@Column(nullable = false)
@Enumerated(EnumType.STRING)
private BagStatus status;
}
42 changes: 35 additions & 7 deletions dao/src/main/java/greencity/entity/order/Order.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,43 @@
package greencity.entity.order;

import greencity.enums.CancellationReason;
import greencity.enums.OrderPaymentStatus;
import greencity.enums.OrderStatus;
import greencity.entity.notifications.UserNotification;
import greencity.entity.user.User;
import greencity.entity.user.employee.Employee;
import greencity.entity.user.employee.EmployeeOrderPosition;
import greencity.entity.user.employee.ReceivingStation;
import greencity.entity.user.ubs.UBSuser;
import greencity.enums.CancellationReason;
import greencity.enums.OrderPaymentStatus;
import greencity.enums.OrderStatus;
import greencity.filters.StringListConverter;
import lombok.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.Cascade;

import javax.persistence.*;
import javax.persistence.CascadeType;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.MapKeyColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -28,10 +50,10 @@
@Builder
@Table(name = "orders")
@EqualsAndHashCode(exclude = {"employeeOrderPositions", "userNotifications", "ubsUser",
"changeOfPointsList", "blockedByEmployee", "certificates", "attachedEmployees", "payment", "employeeOrderPositions",
"changeOfPointsList", "blockedByEmployee", "certificates", "payment", "employeeOrderPositions",
"events", "imageReasonNotTakingBags", "additionalOrders"})
@ToString(exclude = {"employeeOrderPositions", "userNotifications", "ubsUser",
"changeOfPointsList", "blockedByEmployee", "certificates", "attachedEmployees", "payment", "employeeOrderPositions",
"changeOfPointsList", "blockedByEmployee", "certificates", "payment", "employeeOrderPositions",
"events", "imageReasonNotTakingBags", "additionalOrders"})
public class Order {
@Id
Expand Down Expand Up @@ -160,4 +182,10 @@ public class Order {

@Column(name = "write_off_station_sum")
private Long writeOffStationSum;

@OneToMany(
mappedBy = "order",
cascade = CascadeType.ALL,
orphanRemoval = true)
private List<OrderBag> orderBags = new ArrayList<>();
}
70 changes: 70 additions & 0 deletions dao/src/main/java/greencity/entity/order/OrderBag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package greencity.entity.order;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;

@Entity
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(exclude = {"order", "bag"})
@ToString(exclude = {"order", "bag"})
@Getter
@Setter
@Builder
@Table(name = "order_bag_mapping")
public class OrderBag {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "order_id")
private Order order;

@ManyToOne(fetch = FetchType.EAGER)

@JoinColumn(name = "bag_id")
private Bag bag;

@Column(nullable = false)
private Integer amount;

@Column(name = "confirmed_quantity")
private Integer confirmedQuantity;

@Column(name = "exported_quantity")
private Integer exportedQuantity;

@Column(nullable = false)
private Integer capacity;

@Column(nullable = false)
private Long price;

@NotBlank
@Size(min = 1, max = 30)
@Column(nullable = false)
private String name;

@NotBlank
@Size(min = 1, max = 30)
@Column(nullable = false)
private String nameEng;
}
6 changes: 6 additions & 0 deletions dao/src/main/java/greencity/enums/BagStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package greencity.enums;

public enum BagStatus {
ACTIVE,
DELETED
}
38 changes: 21 additions & 17 deletions dao/src/main/java/greencity/repository/BagRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,10 @@

import java.util.List;
import java.util.Map;
import java.util.Optional;

@Repository
public interface BagRepository extends JpaRepository<Bag, Integer> {
/**
* method, that returns {@link List}of{@link Bag} that have bags by order id.
*
* @param id order id
* @return {@link List}of{@link Bag} by it's language and orderId.
* @author Mahdziak Orest
*/
@Query(value = "SELECT * FROM ORDER_BAG_MAPPING as OBM "
+ "JOIN BAG AS B ON OBM.ORDER_ID = :orderId and OBM.BAG_ID = B.ID "
+ "ORDER BY B.ID", nativeQuery = true)
List<Bag> findBagsByOrderId(@Param("orderId") Long id);

/**
* This is method which find capacity by id.
*
Expand Down Expand Up @@ -79,11 +68,26 @@ public interface BagRepository extends JpaRepository<Bag, Integer> {
List<Bag> findAllByOrder(@Param("orderId") Long orderId);

/**
* method, that returns {@link List} of {@link Bag} by tariff id.
* method, that returns {@link List} of {@link Bag} by id.
*
* @param bagId {@link Integer} tariff service id
* @return {@link Optional} of {@link Bag}
* @author Oksana Spodaryk
*/
@Query(nativeQuery = true,
value = "SELECT * FROM bag "
+ "WHERE id = :bagId AND status = 'ACTIVE'")
Optional<Bag> findActiveBagById(Integer bagId);

/**
* method, that returns {@link List} of active {@link Bag} by tariff id.
*
* @param tariffInfoId tariff id {@link Long}
* @return {@link List} of {@link Bag} by tariffInfoId.
* @author Safarov Renat
* @param tariffInfoId {@link Long} tariff id
* @return {@link List} of {@link Bag}
* @author Oksana Spodaryk
*/
List<Bag> findBagsByTariffsInfoId(Long tariffInfoId);
@Query(nativeQuery = true,
value = "SELECT * FROM bag "
+ "WHERE tariffs_info_id = :tariffInfoId AND status = 'ACTIVE'")
List<Bag> findAllActiveBagsByTariffsInfoId(Long tariffInfoId);
}
73 changes: 73 additions & 0 deletions dao/src/main/java/greencity/repository/OrderBagRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package greencity.repository;

import greencity.entity.order.OrderBag;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Repository
public interface OrderBagRepository extends JpaRepository<OrderBag, Long> {
/**
* Deletes the OrderBag from the ORDER_BAG_MAPPING table where the bagId and
* orderId match the provided values.
*
* @param bagId The ID of the bag to be deleted.
* @param orderId The ID of the order to which the bag is associated.
*/
@Transactional
@Modifying
@Query(value = "DELETE FROM ORDER_BAG_MAPPING WHERE BAG_ID = :bagId AND ORDER_ID = :orderId", nativeQuery = true)
void deleteOrderBagByBagIdAndOrderId(@Param("bagId") Integer bagId, @Param("orderId") Long orderId);

/**
* Retrieves a list of order bags based on the given bag ID.
*
* @param id the ID of the order
* @return a list of order bags matching the bag ID
*/
@Query(value = "SELECT * FROM ORDER_BAG_MAPPING as OBM "
+ "where OBM.BAG_ID = :bagId", nativeQuery = true)
List<OrderBag> findOrderBagsByBagId(@Param("bagId") Integer id);

/**
* Retrieves a list of order bags based on the given order ID.
*
* @param id the ID of the order
* @return a list of order bags matching the order ID
*/
@Query(value = "SELECT * FROM ORDER_BAG_MAPPING as OBM "
+ "where OBM.ORDER_ID = :orderId", nativeQuery = true)
List<OrderBag> findOrderBagsByOrderId(@Param("orderId") Long id);

/**
* method updates the bag data of OrderBag for all unpaid orders.
*
* @param bagId {@link Integer} bag id
* @param capacity {@link Integer} bag capacity
* @param price {@link Long} bag full price in coins
* @param name {@link String} bag name
* @param nameEng {@link String} bag english name
* @author Oksana Spodaryk
*/
@Transactional
@Modifying
@Query(value = "update order_bag_mapping obm "
+ "set capacity = :capacity, price = :price, name = :name, name_eng = :nameEng "
+ "from orders o "
+ "where o.id = obm.order_id and obm.bag_id = :bagId and o.order_payment_status = 'UNPAID'", nativeQuery = true)
void updateAllByBagIdForUnpaidOrders(Integer bagId, Integer capacity, Long price, String name, String nameEng);

/**
* method returns all OrderBags by bag id.
*
* @param bagId {@link Integer} bag id
* @return {@link List} of {@link OrderBag}
* @author Julia Seti
*/
List<OrderBag> findAllByBagId(Integer bagId);
}
18 changes: 18 additions & 0 deletions dao/src/main/java/greencity/repository/OrderRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,22 @@ void changeReceivingStationForAllOrders(@Param("receiving_station") Long station
void updateOrderStatusToExpected(@Param("actual_status") String actualStatus,
@Param("expected_status") String expectedStatus,
@Param("currentDate") LocalDate currentDate);

/**
* method returns all unpaid orders that contain a bag with id.
*/
@Query(nativeQuery = true,
value = "select * from orders o "
+ "left join order_bag_mapping obm on o.id = obm.order_id "
+ "where obm.bag_id = :bagId and o.order_payment_status = 'UNPAID'")
List<Order> findAllUnpaidOrdersByBagId(Integer bagId);

/**
* method returns all orders that contain a bag with id.
*/
@Query(nativeQuery = true,
value = "select * from orders o "
+ "left join order_bag_mapping obm on o.id = obm.order_id "
+ "where obm.bag_id = :bagId")
List<Order> findAllByBagId(Integer bagId);
}
3 changes: 3 additions & 0 deletions dao/src/main/resources/db/changelog/db.changelog-master.xml
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,14 @@
<include file="db/changelog/logs/ch-update-service-price-Seti.xml"/>
<include file="db/changelog/logs/ch-update_big_order_table_view-Seti.xml"/>
<include file="/db/changelog/logs/ch-modify-columns-name-name-eng-in-bag-and-service-tables.xml"/>
<include file="/db/changelog/logs/ch-add-column-order-bag-mapping-table-Spodaryk.xml"/>
<include file="/db/changelog/logs/ch-add-column-position-Spodaryk.xml"/>
<include file="/db/changelog/logs/ch-add-column-employee_filter_view-Spodaryk.xml"/>
<include file="/db/changelog/logs/ch-modify-columns-house-number-in-tables-address-and-order-address.xml"/>
<include file="/db/changelog/logs/ch-upd-notification-platforms-body-body_eng-Lenets.xml"/>
<include file="/db/changelog/logs/ch-update_big_order_table_view-with-bags-sorting-Lenets.xml"/>
<include file="/db/changelog/logs/ch-upd-notification-templates-titles-Lenets.xml"/>
<include file="db/changelog/logs/ch-add-table-refunds-Bondar.xml"/>
<include file="db/changelog/logs/ch-add-column-status-to-bag-table-Spodaryk.xml"/>
<include file="/db/changelog/logs/ch-update-order-bag-mapping-table-Spodaryk.xml"/>
</databaseChangeLog>
Loading