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

Raise the prod #1261

Merged
merged 81 commits into from
Nov 28, 2023
Merged
Changes from 1 commit
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
736f44d
addresses regexp (#1149)
ABbondar Jun 24, 2023
e28e931
Added UBS_EMPLOYEE to access notifications (#1148)
ospodaryk Jun 26, 2023
24c3917
- unnecessary check removed (#1150)
Markiro1 Jun 26, 2023
f87ba60
#5978 [UBS] update notification templates (#1151)
Maksym-Lenets Jun 27, 2023
e0b7006
update big_order_table (#1152)
Maksym-Lenets Jun 27, 2023
af9fd12
changed repetitive strings on constants (#1154)
Yurii-Midianyi Jun 30, 2023
ca4240d
Fix code smell in table column width for employee test (#1158)
Yurii-Midianyi Jul 3, 2023
3a3c514
[API. Save order address] The API documentation includes an incorrect…
ABbondar Jul 3, 2023
e84a157
[API] [User Bonuses] Mistake in Swagger documentation #6027 Open (#1167)
ABbondar Jul 3, 2023
63c2f2d
[Admin. Orders] Missing of the option "Без менеджера/логіста/штурмана…
ABbondar Jul 4, 2023
bffd6d6
[Admin cabinet] Fixed nameEN in Position (#1166)
ospodaryk Jul 4, 2023
b69e08e
refactored method getPriceDetails in order to decrease its cognitive …
Yurii-Midianyi Jul 4, 2023
02d2305
added table params (#1170)
ABbondar Jul 4, 2023
cf1aad8
update GetEmployeeDto (#1171)
Maksym-Lenets Jul 5, 2023
1d4e95e
delete location endpoint (#1172)
ABbondar Jul 5, 2023
90c59d4
Fix minor code smell in files (#1169)
Yurii-Midianyi Jul 5, 2023
95cd5ad
refactored updateOrderAdminPageInfo to decrease its cognitive complex…
Yurii-Midianyi Jul 6, 2023
799da3a
[UBS Address] User can choose districts on own (#1161)
ospodaryk Jul 6, 2023
ee0f657
updated changelog with new titles for notifications (#1174)
Maksym-Lenets Jul 7, 2023
a25748a
Resolved codeSmells in ViolationServiceImpl and UBSManagementEmployee…
Yurii-Midianyi Jul 9, 2023
98291d7
[Pick up city UBS.Admin Cabinet] “Return money” button in the "Order …
ABbondar Jul 10, 2023
e9f66a6
[Admin cabinet] Fix districts field (#1175)
ospodaryk Jul 11, 2023
614673e
[UBS user] Fix bug location (#1178)
ospodaryk Jul 11, 2023
dbb3464
[UBS user] Fixed bugs with location (#1179)
ospodaryk Jul 12, 2023
63262f9
delete unused endpoint (#1180)
ABbondar Jul 12, 2023
32ae1ef
[UBS user] Fix controller (#1183)
ospodaryk Jul 13, 2023
b1ad430
Revert "[UBS user] Fix controller (#1183)" (#1185)
ospodaryk Jul 13, 2023
2622da0
[UBS User] Fix update user endpoint (#1186)
ospodaryk Jul 14, 2023
b14fb9c
fix bug with receivingStation empty (#1184)
2or5 Jul 14, 2023
2121323
sender info in order (#1189)
ABbondar Jul 14, 2023
0dec700
[UBS_Prod. Tariff page] Changed to show only active locations (#1188)
ospodaryk Jul 14, 2023
62bffe9
used bonuses (#1190)
ABbondar Jul 18, 2023
c046bbb
regions (#1191)
ABbondar Jul 18, 2023
526cca7
Revert "regions (#1191)" (#1192)
ABbondar Jul 19, 2023
c020a53
[Orders] After changing tariff the price of paid order is not changin…
ospodaryk Jul 25, 2023
d1dc1a4
Revert "[Orders] After changing tariff the price of paid order is not…
ospodaryk Jul 26, 2023
2097a33
[UBS] Change region name when we save order address on user profile p…
ABbondar Jul 27, 2023
2da2493
#6125 Numeric data entered in the Name and Surname text fields is not…
Maksym-Lenets Jul 31, 2023
4decde5
[Orders] After changing tariff the price of paid order is not changin…
ospodaryk Jul 31, 2023
d11d585
Revert "[Orders] After changing tariff the price of paid order is not…
ospodaryk Jul 31, 2023
0903928
addresses in order (#1205)
ABbondar Aug 7, 2023
fc17bc4
[UBS] - Add an option for the user to save the garbage collection add…
ABbondar Aug 7, 2023
0b7c954
Commit with change of max characters for Tariff Service Name from 30 …
HelenSotnik Aug 7, 2023
cee8928
5579 bug change tariff service name from30 to255 char (#1210)
HelenSotnik Aug 7, 2023
1f1058a
Commit with changes columns length to 255 and validation max length i…
HelenSotnik Aug 9, 2023
aa9ecbf
[UBS] - Exception occurs when we try to update order page admin info …
ABbondar Aug 11, 2023
ac2d69b
[UBS] - Exception occurs when we try to update order page admin info …
ABbondar Aug 14, 2023
c2db044
Revert "[UBS] - Exception occurs when we try to update order page adm…
ABbondar Aug 14, 2023
1c35404
update order params (#1216)
ABbondar Aug 15, 2023
54f14e6
[Orders] After changing tariff the price of paid order is not changin…
ospodaryk Aug 16, 2023
f4abcaf
[UBS Address] Fixed edit district (#1218)
ospodaryk Aug 18, 2023
15d5ee4
Changed authorities (#1217)
ospodaryk Aug 18, 2023
879b6d4
Deleted concatenation <employee.getFirstName() + employee.getLastName…
ospodaryk Aug 21, 2023
ceb4294
[Employee (Admin cabinet)] Add activate employee (#1220)
ospodaryk Aug 22, 2023
3b6e9f9
[UBS User] The user can't make changes in user profile #6152 (#1225)
ABbondar Aug 28, 2023
538999b
Added caching to LocationServiceApi (#1226)
ospodaryk Aug 30, 2023
b1f9d6c
Delete ru (#1228)
ospodaryk Sep 8, 2023
b927735
[UBS Admin History] Fixed edit order (#1229)
ospodaryk Sep 8, 2023
6a05e6f
delete unused endpoint (#1230)
ABbondar Sep 11, 2023
290131d
Bug-employee-pagination-after-filtering (#1227)
HelenSotnik Sep 12, 2023
00134b0
Change in method initializeGetEmployeeDtoCollections (#1232)
HelenSotnik Sep 13, 2023
b36f072
Bug employee positions get all mapping (#1233)
HelenSotnik Sep 13, 2023
e42b5a8
Deleted unlogic method (#1235)
ospodaryk Oct 5, 2023
900fa66
Added new user to system (#1234)
ospodaryk Oct 5, 2023
d2f8368
Revert "Added new user to system (#1234)" (#1238)
ospodaryk Oct 6, 2023
d711114
Create greencity admin (#1237)
ospodaryk Oct 6, 2023
5986433
#6521 Exception when updating unpaid order (#1236)
Maksym-Lenets Oct 9, 2023
4fd8219
Commit with change regex for additionalOrders in OrderResponseDto (#1…
HelenSotnik Oct 13, 2023
cdcd88c
#4675 the issue of changing the status of an order from "Confirmed" t…
Maksym-Lenets Oct 17, 2023
e315cab
Commit with Orders sort and order cancelation (#1241)
HelenSotnik Oct 17, 2023
74209e3
fixed time zone (#1242)
Maksym-Lenets Oct 17, 2023
37a4933
fixed time zone (#1244)
Maksym-Lenets Oct 19, 2023
f9cc0e6
Commit with change value validation regex (#1243)
HelenSotnik Oct 20, 2023
0faae69
Added setting of status (#1246)
ospodaryk Oct 24, 2023
0e2c6e2
#5920 notofication for brought by himself orders (#1245)
Maksym-Lenets Oct 24, 2023
67b0dc4
changed admin email (#1249)
Yurii-Midianyi Nov 13, 2023
efe5c21
create method save eng event to db (#1248)
2or5 Nov 15, 2023
d52b548
create method save eng event to db (#1248)
2or5 Nov 15, 2023
7cc72a9
Update liqpay library
Skyere Nov 24, 2023
0ef928f
fix bug with translate events (#1259)
2or5 Nov 27, 2023
26292fc
resolved merge conflicts
Yurii-Midianyi Nov 28, 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
Prev Previous commit
Next Next commit
Revert "[Orders] After changing tariff the price of paid order is not…
… changing (#1201)" (#1204)

This reverts commit 4decde5.
ospodaryk authored Jul 31, 2023
commit d11d585d2927a9ea9456be86c2239dc059e0de26
22 changes: 3 additions & 19 deletions dao/src/main/java/greencity/entity/order/Bag.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
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.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.persistence.*;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.time.LocalDate;
@@ -87,12 +76,7 @@ public class Bag {
@JoinColumn
private Employee editedBy;

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

@Column(nullable = false)
@Enumerated(EnumType.STRING)
private BagStatus status;
}
42 changes: 7 additions & 35 deletions dao/src/main/java/greencity/entity/order/Order.java
Original file line number Diff line number Diff line change
@@ -1,43 +1,21 @@
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.AllArgsConstructor;
import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.*;
import org.hibernate.annotations.Cascade;

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 javax.persistence.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -50,10 +28,10 @@
@Builder
@Table(name = "orders")
@EqualsAndHashCode(exclude = {"employeeOrderPositions", "userNotifications", "ubsUser",
"changeOfPointsList", "blockedByEmployee", "certificates", "payment", "employeeOrderPositions",
"changeOfPointsList", "blockedByEmployee", "certificates", "attachedEmployees", "payment", "employeeOrderPositions",
"events", "imageReasonNotTakingBags", "additionalOrders"})
@ToString(exclude = {"employeeOrderPositions", "userNotifications", "ubsUser",
"changeOfPointsList", "blockedByEmployee", "certificates", "payment", "employeeOrderPositions",
"changeOfPointsList", "blockedByEmployee", "certificates", "attachedEmployees", "payment", "employeeOrderPositions",
"events", "imageReasonNotTakingBags", "additionalOrders"})
public class Order {
@Id
@@ -182,10 +160,4 @@ 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: 0 additions & 70 deletions dao/src/main/java/greencity/entity/order/OrderBag.java

This file was deleted.

6 changes: 0 additions & 6 deletions dao/src/main/java/greencity/enums/BagStatus.java

This file was deleted.

38 changes: 17 additions & 21 deletions dao/src/main/java/greencity/repository/BagRepository.java
Original file line number Diff line number Diff line change
@@ -8,10 +8,21 @@

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.
*
@@ -68,26 +79,11 @@ public interface BagRepository extends JpaRepository<Bag, Integer> {
List<Bag> findAllByOrder(@Param("orderId") Long orderId);

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

This file was deleted.

18 changes: 0 additions & 18 deletions dao/src/main/java/greencity/repository/OrderRepository.java
Original file line number Diff line number Diff line change
@@ -251,22 +251,4 @@ 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: 0 additions & 3 deletions dao/src/main/resources/db/changelog/db.changelog-master.xml
Original file line number Diff line number Diff line change
@@ -207,14 +207,11 @@
<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>

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

45 changes: 0 additions & 45 deletions dao/src/test/java/greencity/enums/BagStatusTest.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -2,21 +2,21 @@

import greencity.constant.AppConstant;
import greencity.dto.bag.BagForUserDto;
import greencity.entity.order.OrderBag;
import greencity.entity.order.Bag;
import org.modelmapper.AbstractConverter;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

@Component
public class BagForUserDtoMapper extends AbstractConverter<OrderBag, BagForUserDto> {
public class BagForUserDtoMapper extends AbstractConverter<Bag, BagForUserDto> {
@Override
protected BagForUserDto convert(OrderBag source) {
protected BagForUserDto convert(Bag source) {
return BagForUserDto.builder()
.service(source.getName())
.serviceEng(source.getNameEng())
.capacity(source.getCapacity())
.fullPrice(BigDecimal.valueOf(source.getPrice())
.fullPrice(BigDecimal.valueOf(source.getFullPrice())
.movePointLeft(AppConstant.TWO_DECIMALS_AFTER_POINT_IN_CURRENCY)
.doubleValue())
.build();
Original file line number Diff line number Diff line change
@@ -20,7 +20,6 @@
import greencity.exceptions.http.AccessDeniedException;
import greencity.repository.*;
import greencity.service.ubs.NotificationService;
import greencity.service.ubs.OrderBagService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
@@ -76,8 +75,6 @@ public class NotificationServiceImpl implements NotificationService {
private static final String ORDER_NUMBER_KEY = "orderNumber";
private static final String AMOUNT_TO_PAY_KEY = "amountToPay";
private static final String PAY_BUTTON = "payButton";
@Autowired
private final OrderBagService orderBagService;

/**
* {@inheritDoc}
@@ -242,7 +239,7 @@ private Double getAmountToPay(Order order) {
long ubsCourierSumInCoins = order.getUbsCourierSum() == null ? 0L : order.getUbsCourierSum();
long writeStationSumInCoins = order.getWriteOffStationSum() == null ? 0L : order.getWriteOffStationSum();

List<Bag> bagsType = orderBagService.findAllBagsByOrderId(order.getId());
List<Bag> bagsType = bagRepository.findBagsByOrderId(order.getId());
Map<Integer, Integer> bagsAmount;
if (MapUtils.isNotEmpty(order.getExportedQuantity())) {
bagsAmount = order.getExportedQuantity();
90 changes: 0 additions & 90 deletions service/src/main/java/greencity/service/ubs/OrderBagService.java

This file was deleted.

105 changes: 22 additions & 83 deletions service/src/main/java/greencity/service/ubs/SuperAdminServiceImpl.java
Original file line number Diff line number Diff line change
@@ -24,8 +24,6 @@
import greencity.dto.tariff.GetTariffsInfoDto;
import greencity.dto.tariff.SetTariffLimitsDto;
import greencity.entity.coords.Coordinates;
import greencity.entity.order.Order;
import greencity.entity.order.OrderBag;
import greencity.entity.order.Bag;
import greencity.entity.order.Courier;
import greencity.entity.order.Service;
@@ -35,9 +33,7 @@
import greencity.entity.user.Region;
import greencity.entity.user.employee.Employee;
import greencity.entity.user.employee.ReceivingStation;
import greencity.enums.BagStatus;
import greencity.enums.CourierLimit;
import greencity.enums.OrderPaymentStatus;
import greencity.enums.CourierStatus;
import greencity.enums.LocationStatus;
import greencity.enums.StationStatus;
@@ -52,8 +48,6 @@
import greencity.filters.TariffsInfoSpecification;
import greencity.repository.BagRepository;
import greencity.repository.CourierRepository;
import greencity.repository.OrderBagRepository;
import greencity.repository.OrderRepository;
import greencity.repository.DeactivateChosenEntityRepository;
import greencity.repository.EmployeeRepository;
import greencity.repository.LocationRepository;
@@ -77,7 +71,6 @@
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
@@ -120,9 +113,6 @@ public class SuperAdminServiceImpl implements SuperAdminService {
"Current region: %s or cities: %s or receiving stations: %s don't exist.";
private static final String REGION_OR_CITIES_OR_RECEIVING_STATIONS_OR_COURIER_NOT_EXIST_MESSAGE =
"Current region: %s or cities: %s or receiving stations: %s or courier: %s don't exist.";
private final OrderBagRepository orderBagRepository;
private final OrderRepository orderRepository;
private final OrderBagService orderBagService;

@Override
public GetTariffServiceDto addTariffService(long tariffId, TariffServiceDto dto, String employeeUuid) {
@@ -134,7 +124,6 @@ private Bag createBag(long tariffId, TariffServiceDto dto, String employeeUuid)
TariffsInfo tariffsInfo = tryToFindTariffById(tariffId);
Employee employee = tryToFindEmployeeByUuid(employeeUuid);
Bag bag = modelMapper.map(dto, Bag.class);
bag.setStatus(BagStatus.ACTIVE);
bag.setTariffsInfo(tariffsInfo);
bag.setCreatedBy(employee);
return bag;
@@ -143,7 +132,7 @@ private Bag createBag(long tariffId, TariffServiceDto dto, String employeeUuid)
@Override
public List<GetTariffServiceDto> getTariffService(long tariffId) {
if (tariffsInfoRepository.existsById(tariffId)) {
return bagRepository.findAllActiveBagsByTariffsInfoId(tariffId)
return bagRepository.findBagsByTariffsInfoId(tariffId)
.stream()
.map(it -> modelMapper.map(it, GetTariffServiceDto.class))
.collect(Collectors.toList());
@@ -153,41 +142,13 @@ public List<GetTariffServiceDto> getTariffService(long tariffId) {
}

@Override
@Transactional
public void deleteTariffService(Integer bagId) {
Bag bag = tryToFindBagById(bagId);
if (CollectionUtils.isEmpty(orderBagRepository.findOrderBagsByBagId(bagId))) {
bagRepository.delete(bag);
return;
}
bag.setStatus(BagStatus.DELETED);
bagRepository.save(bag);
deleteTariffsInfo(bag);
orderRepository.findAllByBagId(bagId).forEach(order -> deleteBagFromOrder(order, bag));
}

private void deleteBagFromOrder(Order order, Bag bag) {
Integer bagId = bag.getId();
Map<Integer, Integer> amount = orderBagService.getActualBagsAmountForOrder(order.getOrderBags());
Integer totalBagsAmount = amount.values().stream().reduce(0, Integer::sum);
if (amount.get(bagId).equals(0) || order.getOrderPaymentStatus().equals(OrderPaymentStatus.UNPAID)) {
if (totalBagsAmount.equals(amount.get(bagId))) {
order.setOrderBags(new ArrayList<>());
orderRepository.delete(order);
return;
}
order.getOrderBags().stream().filter(orderBag -> orderBag.getBag().getId().equals(bagId))
.findFirst()
.ifPresent(orderBag -> orderBagRepository.deleteOrderBagByBagIdAndOrderId(bagId, order.getId()));
orderRepository.save(order);
}
}

private void deleteTariffsInfo(Bag bag) {
TariffsInfo tariffsInfo = bag.getTariffsInfo();
List<Bag> bags = bagRepository.findAllActiveBagsByTariffsInfoId(tariffsInfo.getId());
bagRepository.delete(bag);
List<Bag> bags = bagRepository.findBagsByTariffsInfoId(tariffsInfo.getId());
if (bags.isEmpty() || bags.stream().noneMatch(Bag::getLimitIncluded)) {
tariffsInfo.setTariffStatus(TariffStatus.DEACTIVATED);
tariffsInfo.setTariffStatus(TariffStatus.NEW);
tariffsInfo.setBags(bags);
tariffsInfo.setMax(null);
tariffsInfo.setMin(null);
@@ -198,39 +159,9 @@ private void deleteTariffsInfo(Bag bag) {
}

@Override
@Transactional
public GetTariffServiceDto editTariffService(TariffServiceDto dto, Integer bagId, String employeeUuid) {
Bag bag = tryToFindBagById(bagId);
public GetTariffServiceDto editTariffService(TariffServiceDto dto, Integer id, String employeeUuid) {
Bag bag = tryToFindBagById(id);
Employee employee = tryToFindEmployeeByUuid(employeeUuid);
updateTariffService(dto, bag);
bag.setEditedBy(employee);

orderBagRepository.updateAllByBagIdForUnpaidOrders(
bagId, bag.getCapacity(), bag.getFullPrice(), bag.getName(), bag.getNameEng());

List<Order> orders = orderRepository.findAllUnpaidOrdersByBagId(bagId);
if (CollectionUtils.isNotEmpty(orders)) {
orders.forEach(it -> updateOrderSumToPay(it, bag));
orderRepository.saveAll(orders);
}
return modelMapper.map(bagRepository.save(bag), GetTariffServiceDto.class);
}

private void updateOrderSumToPay(Order order, Bag bag) {
Map<Integer, Integer> amount = orderBagService.getActualBagsAmountForOrder(order.getOrderBags());
Long sumToPayInCoins = order.getOrderBags().stream()
.map(orderBag -> amount.get(orderBag.getBag().getId()) * getBagPrice(orderBag, bag))
.reduce(0L, Long::sum);
order.setSumTotalAmountWithoutDiscounts(sumToPayInCoins);
}

private Long getBagPrice(OrderBag orderBag, Bag bag) {
return bag.getId().equals(orderBag.getBag().getId())
? bag.getFullPrice()
: orderBag.getPrice();
}

private void updateTariffService(TariffServiceDto dto, Bag bag) {
bag.setCapacity(dto.getCapacity());
bag.setPrice(convertBillsIntoCoins(dto.getPrice()));
bag.setCommission(convertBillsIntoCoins(dto.getCommission()));
@@ -240,6 +171,8 @@ private void updateTariffService(TariffServiceDto dto, Bag bag) {
bag.setDescription(dto.getDescription());
bag.setDescriptionEng(dto.getDescriptionEng());
bag.setEditedAt(LocalDate.now());
bag.setEditedBy(employee);
return modelMapper.map(bagRepository.save(bag), GetTariffServiceDto.class);
}

private Long convertBillsIntoCoins(Double bills) {
@@ -252,8 +185,8 @@ private Long convertBillsIntoCoins(Double bills) {
}

private Bag tryToFindBagById(Integer id) {
return bagRepository.findActiveBagById(id).orElseThrow(
() -> new NotFoundException(ErrorMessage.BAG_NOT_FOUND + id));
return bagRepository.findById(id)
.orElseThrow(() -> new NotFoundException(ErrorMessage.BAG_NOT_FOUND + id));
}

private Long getFullPrice(Double price, Double commission) {
@@ -267,9 +200,9 @@ public GetServiceDto addService(Long tariffId, ServiceDto dto, String employeeUu
}

private Service createService(Long tariffId, ServiceDto dto, String employeeUuid) {
TariffsInfo tariffsInfo = tryToFindTariffById(tariffId);
if (serviceRepository.findServiceByTariffsInfoId(tariffId).isEmpty()) {
if (tryToFindServiceByTariffsInfoId(tariffId).isEmpty()) {
Employee employee = tryToFindEmployeeByUuid(employeeUuid);
TariffsInfo tariffsInfo = tryToFindTariffById(tariffId);
Service service = modelMapper.map(dto, Service.class);
service.setCreatedBy(employee);
service.setCreatedAt(LocalDate.now());
@@ -282,16 +215,14 @@ private Service createService(Long tariffId, ServiceDto dto, String employeeUuid

@Override
public GetServiceDto getService(long tariffId) {
tryToFindTariffById(tariffId);
return serviceRepository.findServiceByTariffsInfoId(tariffId)
return tryToFindServiceByTariffsInfoId(tariffId)
.map(it -> modelMapper.map(it, GetServiceDto.class))
.orElse(null);
}

@Override
public void deleteService(long id) {
Service service = tryToFindServiceById(id);
serviceRepository.delete(service);
serviceRepository.delete(tryToFindServiceById(id));
}

@Override
@@ -313,6 +244,14 @@ private Employee tryToFindEmployeeByUuid(String employeeUuid) {
.orElseThrow(() -> new NotFoundException(ErrorMessage.EMPLOYEE_WITH_UUID_NOT_FOUND + employeeUuid));
}

private Optional<Service> tryToFindServiceByTariffsInfoId(long tariffId) {
if (tariffsInfoRepository.existsById(tariffId)) {
return serviceRepository.findServiceByTariffsInfoId(tariffId);
} else {
throw new NotFoundException(ErrorMessage.TARIFF_NOT_FOUND + tariffId);
}
}

private Service tryToFindServiceById(long id) {
return serviceRepository.findById(id)
.orElseThrow(() -> new NotFoundException(ErrorMessage.SERVICE_IS_NOT_FOUND_BY_ID + id));
110 changes: 56 additions & 54 deletions service/src/main/java/greencity/service/ubs/UBSClientServiceImpl.java
Original file line number Diff line number Diff line change
@@ -59,7 +59,6 @@
import greencity.entity.order.ChangeOfPoints;
import greencity.entity.order.Event;
import greencity.entity.order.Order;
import greencity.entity.order.OrderBag;
import greencity.entity.order.OrderPaymentStatusTranslation;
import greencity.entity.order.OrderStatusTranslation;
import greencity.entity.order.Payment;
@@ -73,7 +72,6 @@
import greencity.entity.user.ubs.UBSuser;
import greencity.entity.viber.ViberBot;
import greencity.enums.AddressStatus;
import greencity.enums.BagStatus;
import greencity.enums.BotType;
import greencity.enums.CertificateStatus;
import greencity.enums.CourierLimit;
@@ -96,7 +94,6 @@
import greencity.repository.EventRepository;
import greencity.repository.LocationRepository;
import greencity.repository.OrderAddressRepository;
import greencity.repository.OrderBagRepository;
import greencity.repository.OrderPaymentStatusTranslationRepository;
import greencity.repository.OrderRepository;
import greencity.repository.OrderStatusTranslationRepository;
@@ -117,6 +114,7 @@
import greencity.util.OrderUtils;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.json.JSONObject;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
@@ -125,6 +123,7 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import javax.persistence.EntityNotFoundException;
import javax.transaction.Transactional;
import java.math.BigDecimal;
@@ -137,6 +136,7 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
@@ -148,6 +148,7 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.LongStream;

import static greencity.constant.ErrorMessage.ACTUAL_ADDRESS_NOT_FOUND;
import static greencity.constant.ErrorMessage.ADDRESS_ALREADY_EXISTS;
import static greencity.constant.ErrorMessage.BAD_ORDER_STATUS_REQUEST;
@@ -191,6 +192,7 @@
import static greencity.constant.ErrorMessage.USER_DONT_HAVE_ENOUGH_POINTS;
import static greencity.constant.ErrorMessage.USER_WITH_CURRENT_ID_DOES_NOT_EXIST;
import static greencity.constant.ErrorMessage.USER_WITH_CURRENT_UUID_DOES_NOT_EXIST;

import static java.util.Objects.nonNull;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
@@ -229,9 +231,6 @@ public class UBSClientServiceImpl implements UBSClientService {
private final TelegramBotRepository telegramBotRepository;
private final ViberBotRepository viberBotRepository;
private final LocationApiService locationApiService;
private final OrderBagRepository orderBagRepository;
private final OrderBagService orderBagService;

@Lazy
@Autowired
private UBSManagementService ubsManagementService;
@@ -359,7 +358,7 @@ private boolean isTariffAvailableForCurrentLocation(TariffsInfo tariffsInfo, Loc

private UserPointsAndAllBagsDto getUserPointsAndAllBagsDtoByTariffIdAndUserPoints(Long tariffId,
Integer userPoints) {
var bagTranslationDtoList = bagRepository.findAllActiveBagsByTariffsInfoId(tariffId).stream()
var bagTranslationDtoList = bagRepository.findBagsByTariffsInfoId(tariffId).stream()
.map(bag -> modelMapper.map(bag, BagTranslationDto.class))
.collect(toList());
return new UserPointsAndAllBagsDto(bagTranslationDtoList, userPoints);
@@ -380,9 +379,8 @@ private Location getLocationByOrderIdThroughLazyInitialization(Order order) {
public PersonalDataDto getSecondPageData(String uuid) {
User currentUser = userRepository.findByUuid(uuid);
List<UBSuser> ubsUser = ubsUserRepository.findUBSuserByUser(currentUser);

if (ubsUser.isEmpty()) {
ubsUser = Collections.singletonList(UBSuser.builder().id(null).build());
ubsUser.add(UBSuser.builder().id(null).build());
}
PersonalDataDto dto = modelMapper.map(currentUser, PersonalDataDto.class);
dto.setUbsUserId(ubsUser.get(0).getId());
@@ -425,14 +423,14 @@ private void checkSumIfCourierLimitBySumOfOrder(TariffsInfo tariffsInfo, Long su
public FondyOrderResponse saveFullOrderToDB(OrderResponseDto dto, String uuid, Long orderId) {
final User currentUser = userRepository.findByUuid(uuid);
TariffsInfo tariffsInfo = tryToFindTariffsInfoByBagIds(getBagIds(dto.getBags()), dto.getLocationId());
List<OrderBag> bagsOrdered = new ArrayList<>();
Map<Integer, Integer> amountOfBagsOrderedMap = new HashMap<>();

if (!dto.isShouldBePaid()) {
dto.setCertificates(Collections.emptySet());
dto.setPointsToUse(0);
}

long sumToPayWithoutDiscountInCoins = formBagsToBeSavedAndCalculateOrderSum(bagsOrdered,
long sumToPayWithoutDiscountInCoins = formBagsToBeSavedAndCalculateOrderSum(amountOfBagsOrderedMap,
dto.getBags(), tariffsInfo);
checkIfUserHaveEnoughPoints(currentUser.getCurrentPoints(), dto.getPointsToUse());
long sumToPayInCoins = reduceOrderSumDueToUsedPoints(sumToPayWithoutDiscountInCoins, dto.getPointsToUse());
@@ -445,7 +443,7 @@ public FondyOrderResponse saveFullOrderToDB(OrderResponseDto dto, String uuid, L
UBSuser userData =
formUserDataToBeSaved(dto.getPersonalData(), dto.getAddressId(), dto.getLocationId(), currentUser);

getOrder(dto, currentUser, bagsOrdered, sumToPayInCoins, order, orderCertificates, userData);
getOrder(dto, currentUser, amountOfBagsOrderedMap, sumToPayInCoins, order, orderCertificates, userData);
eventService.save(OrderHistory.ORDER_FORMED, OrderHistory.CLIENT, order);

if (sumToPayInCoins <= 0 || !dto.isShouldBePaid()) {
@@ -463,8 +461,8 @@ private List<Integer> getBagIds(List<BagDto> dto) {
.collect(Collectors.toList());
}

private Bag findActiveBagById(Integer id) {
return bagRepository.findActiveBagById(id)
private Bag tryToGetBagById(Integer id) {
return bagRepository.findById(id)
.orElseThrow(() -> new NotFoundException(BAG_NOT_FOUND + id));
}

@@ -911,17 +909,31 @@ private AddressInfoDto addressInfoDtoBuilder(Order order) {
}

private List<BagForUserDto> bagForUserDtosBuilder(Order order) {
List<OrderBag> bagsAmountInOrder = order.getOrderBags();
Map<Integer, Integer> actualBagsAmount = orderBagService.getActualBagsAmountForOrder(bagsAmountInOrder);
return bagsAmountInOrder.stream()
.map(orderBag -> buildBagForUserDto(orderBag, actualBagsAmount.get(orderBag.getBag().getId())))
Map<Integer, Integer> actualBagAmounts = getActualBagAmountsForOrder(order);
List<Bag> bagsForOrder = bagRepository.findBagsByOrderId(order.getId());
return bagsForOrder.stream()
.filter(bag -> actualBagAmounts.containsKey(bag.getId()))
.map(bag -> buildBagForUserDto(bag, actualBagAmounts.get(bag.getId())))
.collect(toList());
}

private BagForUserDto buildBagForUserDto(OrderBag orderBag, int count) {
BagForUserDto bagDto = modelMapper.map(orderBag, BagForUserDto.class);
private Map<Integer, Integer> getActualBagAmountsForOrder(Order order) {
if (MapUtils.isNotEmpty(order.getExportedQuantity())) {
return order.getExportedQuantity();
}
if (MapUtils.isNotEmpty(order.getConfirmedQuantity())) {
return order.getConfirmedQuantity();
}
if (MapUtils.isNotEmpty(order.getAmountOfBagsOrdered())) {
return order.getAmountOfBagsOrdered();
}
return new HashMap<>();
}

private BagForUserDto buildBagForUserDto(Bag bag, int count) {
BagForUserDto bagDto = modelMapper.map(bag, BagForUserDto.class);
bagDto.setCount(count);
bagDto.setTotalPrice(convertCoinsIntoBills(count * orderBag.getPrice()));
bagDto.setTotalPrice(convertCoinsIntoBills(count * bag.getFullPrice()));
return bagDto;
}

@@ -1050,15 +1062,15 @@ private UBSuser updateRecipientDataInOrder(UBSuser ubsUser, UbsCustomersDtoUpdat
}

private Order formAndSaveOrder(Order order, Set<Certificate> orderCertificates,
List<OrderBag> bagsOrdered, UBSuser userData,
Map<Integer, Integer> amountOfBagsOrderedMap, UBSuser userData,
User currentUser, long sumToPayInCoins) {
order.setOrderStatus(OrderStatus.FORMED);
order.setCertificates(orderCertificates);
order.setOrderBags(bagsOrdered);
order.setAmountOfBagsOrdered(amountOfBagsOrderedMap);
order.setUbsUser(userData);
order.setUser(currentUser);
order.setSumTotalAmountWithoutDiscounts(
calculateOrderSumWithoutDiscounts(bagsOrdered));
formBagsToBeSavedAndCalculateOrderSumClient(amountOfBagsOrderedMap));
setOrderPaymentStatus(order, sumToPayInCoins);

Payment payment = Payment.builder()
@@ -1073,7 +1085,7 @@ private Order formAndSaveOrder(Order order, Set<Certificate> orderCertificates,
order.setPayment(new ArrayList<>());
}
order.getPayment().add(payment);
bagsOrdered.forEach(orderBag -> orderBag.setOrder(order));

orderRepository.save(order);
return order;
}
@@ -1214,44 +1226,35 @@ private void checkAmountOfBagsIfCourierLimitByAmountOfBag(TariffsInfo courierLoc
}
}

private long calculateOrderSumWithoutDiscounts(List<OrderBag> getOrderBagsAndQuantity) {
return getOrderBagsAndQuantity.stream()
.map(orderBag -> orderBag.getPrice() * orderBag.getAmount())
.reduce(0L, Long::sum);
private long formBagsToBeSavedAndCalculateOrderSumClient(
Map<Integer, Integer> getOrderBagsAndQuantity) {
long sumToPayInCoins = 0L;

for (Map.Entry<Integer, Integer> temp : getOrderBagsAndQuantity.entrySet()) {
Integer amount = getOrderBagsAndQuantity.get(temp.getKey());
Bag bag = bagRepository.findById(temp.getKey())
.orElseThrow(() -> new NotFoundException(BAG_NOT_FOUND + temp.getKey()));
sumToPayInCoins += bag.getFullPrice() * amount;
}
return sumToPayInCoins;
}

private long formBagsToBeSavedAndCalculateOrderSum(List<OrderBag> orderBagList, List<BagDto> bags,
TariffsInfo tariffsInfo) {
private long formBagsToBeSavedAndCalculateOrderSum(
Map<Integer, Integer> map, List<BagDto> bags, TariffsInfo tariffsInfo) {
long sumToPayInCoins = 0L;
List<Integer> bagIds = bags.stream().map(BagDto::getId).collect(toList());

for (BagDto temp : bags) {
Bag bag = findActiveBagById(temp.getId());
Bag bag = tryToGetBagById(temp.getId());
if (bag.getLimitIncluded().booleanValue()) {
checkAmountOfBagsIfCourierLimitByAmountOfBag(tariffsInfo, temp.getAmount());
checkSumIfCourierLimitBySumOfOrder(tariffsInfo, bag.getFullPrice() * temp.getAmount());
}
sumToPayInCoins += bag.getFullPrice() * temp.getAmount();
OrderBag orderBag = createOrderBag(bag);
orderBag.setAmount(temp.getAmount());
orderBagList.add(orderBag);
}
List<OrderBag> notOrderedBags = tariffsInfo.getBags().stream()
.filter(orderBag -> orderBag.getStatus() == BagStatus.ACTIVE && !bagIds.contains(orderBag.getId()))
.map(this::createOrderBag).collect(toList());
orderBagList.addAll(notOrderedBags.stream().peek(orderBag -> orderBag.setAmount(0)).collect(toList()));
map.put(temp.getId(), temp.getAmount());
}
return sumToPayInCoins;
}

private OrderBag createOrderBag(Bag bag) {
return OrderBag.builder()
.bag(bag)
.capacity(bag.getCapacity())
.price(bag.getFullPrice())
.name(bag.getName())
.nameEng(bag.getNameEng())
.build();
}

private void validateCertificate(Certificate certificate) {
if (certificate.getCertificateStatus() == CertificateStatus.NEW) {
throw new CertificateIsNotActivated(CERTIFICATE_IS_NOT_ACTIVATED + certificate.getCode());
@@ -1405,9 +1408,9 @@ private long reduceOrderSumDueToUsedPoints(long sumToPayInCoins, int pointsToUse
return sumToPayInCoins;
}

private void getOrder(OrderResponseDto dto, User currentUser, List<OrderBag> amountOfBagsOrdered,
private void getOrder(OrderResponseDto dto, User currentUser, Map<Integer, Integer> amountOfBagsOrderedMap,
long sumToPayInCoins, Order order, Set<Certificate> orderCertificates, UBSuser userData) {
formAndSaveOrder(order, orderCertificates, amountOfBagsOrdered, userData, currentUser, sumToPayInCoins);
formAndSaveOrder(order, orderCertificates, amountOfBagsOrderedMap, userData, currentUser, sumToPayInCoins);

formAndSaveUser(currentUser, dto.getPointsToUse(), order);
}
@@ -1452,7 +1455,6 @@ public void deleteOrder(String uuid, Long id) {
if (order == null) {
throw new NotFoundException(ORDER_WITH_CURRENT_ID_DOES_NOT_EXIST);
}
order.setOrderBags(Collections.emptyList());
orderRepository.delete(order);
}

Original file line number Diff line number Diff line change
@@ -73,7 +73,6 @@
import greencity.enums.SortingOrder;
import greencity.exceptions.BadRequestException;
import greencity.exceptions.NotFoundException;
import greencity.repository.OrderBagRepository;
import greencity.repository.BagRepository;
import greencity.repository.CertificateRepository;
import greencity.repository.EmployeeOrderPositionRepository;
@@ -110,6 +109,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.server.ResponseStatusException;

import javax.persistence.EntityNotFoundException;
import java.math.BigDecimal;
import java.math.RoundingMode;
@@ -179,10 +179,6 @@ public class UBSManagementServiceImpl implements UBSManagementService {
@Lazy
@Autowired
private UBSClientService ubsClientService;
@Autowired
private final OrderBagService orderBagService;
@Autowired
private final OrderBagRepository orderBagRepository;

/**
* Method gets all order payments, count paid amount, amount which user should
@@ -370,7 +366,7 @@ public OrderStatusPageDto getOrderStatusData(Long orderId, String email) {
checkAvailableOrderForEmployee(order, email);
CounterOrderDetailsDto prices = getPriceDetails(orderId);

var bagInfoDtoList = bagRepository.findAllActiveBagsByTariffsInfoId(order.getTariffsInfo().getId()).stream()
var bagInfoDtoList = bagRepository.findBagsByTariffsInfoId(order.getTariffsInfo().getId()).stream()
.map(bag -> modelMapper.map(bag, BagInfoDto.class))
.collect(Collectors.toList());

@@ -713,7 +709,7 @@ private void collectEventAboutConfirmWaste(Map<Integer, Integer> confirmed, Orde
Long orderId, int countOfChanges, StringBuilder values) {
for (Map.Entry<Integer, Integer> entry : confirmed.entrySet()) {
Integer capacity = bagRepository.findCapacityById(entry.getKey());
Optional<Bag> bagOptional = bagRepository.findActiveBagById(entry.getKey());
Optional<Bag> bagOptional = bagRepository.findById(entry.getKey());
if (bagOptional.isPresent() && checkOrderStatusAboutConfirmWaste(order)) {
Optional<Long> confirmWasteWas = Optional.empty();
Optional<Long> initialAmount = Optional.empty();
@@ -740,7 +736,7 @@ private void collectEventAboutExportedWaste(Map<Integer, Integer> exported, Orde
Long orderId, int countOfChanges, StringBuilder values) {
for (Map.Entry<Integer, Integer> entry : exported.entrySet()) {
Integer capacity = bagRepository.findCapacityById(entry.getKey());
Optional<Bag> bagOptional = bagRepository.findActiveBagById(entry.getKey());
Optional<Bag> bagOptional = bagRepository.findById(entry.getKey());
if (bagOptional.isPresent() && checkOrderStatusAboutExportedWaste(order)) {
Optional<Long> exporterWasteWas = Optional.empty();
Optional<Long> confirmWasteWas = Optional.empty();
@@ -825,7 +821,7 @@ private CounterOrderDetailsDto getPriceDetails(Long id) {
CounterOrderDetailsDto dto = new CounterOrderDetailsDto();
Order order = orderRepository.getOrderDetails(id)
.orElseThrow(() -> new NotFoundException(ORDER_WITH_CURRENT_ID_DOES_NOT_EXIST + id));
List<Bag> bag = orderBagService.findAllBagsInOrderBagsList(orderBagRepository.findOrderBagsByOrderId(id));
List<Bag> bag = bagRepository.findBagsByOrderId(id);
final List<Certificate> currentCertificate = certificateRepository.findCertificate(id);

long sumAmountInCoins = 0;
@@ -1064,7 +1060,7 @@ private void setOrderDetailDto(OrderDetailDto dto, Order order) {
dto.setAmount(modelMapper.map(order, new TypeToken<List<BagMappingDto>>() {
}.getType()));

dto.setCapacityAndPrice(orderBagService.findAllBagsByOrderId(order.getId())
dto.setCapacityAndPrice(bagRepository.findBagsByOrderId(order.getId())
.stream()
.map(b -> modelMapper.map(b, BagInfoDto.class))
.collect(Collectors.toList()));
179 changes: 10 additions & 169 deletions service/src/test/java/greencity/ModelUtils.java
Original file line number Diff line number Diff line change
@@ -129,7 +129,6 @@
import greencity.entity.order.Courier;
import greencity.entity.order.Event;
import greencity.entity.order.Order;
import greencity.entity.order.OrderBag;
import greencity.entity.order.OrderPaymentStatusTranslation;
import greencity.entity.order.OrderStatusTranslation;
import greencity.entity.order.Payment;
@@ -154,7 +153,6 @@
import greencity.entity.user.ubs.UBSuser;
import greencity.entity.viber.ViberBot;
import greencity.enums.AddressStatus;
import greencity.enums.BagStatus;
import greencity.enums.CancellationReason;
import greencity.enums.CertificateStatus;
import greencity.enums.CourierLimit;
@@ -173,6 +171,7 @@
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
@@ -188,6 +187,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;

import static greencity.enums.NotificationReceiverType.EMAIL;
import static greencity.enums.NotificationReceiverType.MOBILE;
import static greencity.enums.NotificationReceiverType.SITE;
@@ -209,8 +209,7 @@ public class ModelUtils {
public static final List<Payment> TEST_PAYMENT_LIST = createPaymentList();
public static final OrderDetailStatusDto ORDER_DETAIL_STATUS_DTO = createOrderDetailStatusDto();
public static final List<BagMappingDto> TEST_BAG_MAPPING_DTO_LIST = createBagMappingDtoList();
public static final Bag TEST_BAG = createBag(1);
public static final OrderBag TEST_ORDER_BAG = createOrderBag();
public static final Bag TEST_BAG = createBag();
public static final BagForUserDto TEST_BAG_FOR_USER_DTO = createBagForUserDto();
public static final BagInfoDto TEST_BAG_INFO_DTO = createBagInfoDto();
public static final List<Bag> TEST_BAG_LIST = singletonList(TEST_BAG);
@@ -260,7 +259,6 @@ public class ModelUtils {
public static final NotificationDto TEST_NOTIFICATION_DTO = createNotificationDto();
public static final UpdateOrderPageAdminDto UPDATE_ORDER_PAGE_ADMIN_DTO = updateOrderPageAdminDto();
public static final CourierUpdateDto UPDATE_COURIER_DTO = getUpdateCourierDto();
public static final List<Bag> TEST_BAG_LIST2 = Arrays.asList(createBag(1), createBag(2), createBag(3));

public static final String KYIV_REGION_EN = "Kyiv Oblast";
public static final String KYIV_REGION_UA = "Київська область";
@@ -2302,7 +2300,7 @@ private static BagInfoDto createBagInfoDto() {
.capacity(20)
.name("Name")
.nameEng("NameEng")
.price(1000.00)
.price(100.00)
.build();
}

@@ -2313,10 +2311,9 @@ private static List<BagMappingDto> createBagMappingDtoList() {
.build());
}

private static Bag createBag(int id) {
Bag bag = Bag.builder()
.status(BagStatus.ACTIVE)
.id(id)
private static Bag createBag() {
return Bag.builder()
.id(1)
.name("Name")
.nameEng("NameEng")
.capacity(20)
@@ -2331,19 +2328,6 @@ private static Bag createBag(int id) {
.id(1L)
.build())
.build();
return bag.setFullPrice(100000L);
}

private static OrderBag createOrderBag() {
return OrderBag.builder()
.id(1L)
.name("Name")
.nameEng("NameEng")
.capacity(20)
.price(100_00L)
.order(createOrder())
.bag(createBag(1))
.build();
}

private static BagForUserDto createBagForUserDto() {
@@ -2724,7 +2708,6 @@ public static GetTariffServiceDto getGetTariffServiceDto() {

public static Optional<Bag> getOptionalBag() {
return Optional.of(Bag.builder()
.status(BagStatus.ACTIVE)
.id(1)
.capacity(120)
.commission(50_00L)
@@ -2739,94 +2722,7 @@ public static Optional<Bag> getOptionalBag() {
.build());
}

public static OrderBag getOrderBag2() {
return OrderBag.builder()
.id(2L)
.capacity(2200)
.price(22000_00L)
.name("name")
.nameEng("name eng")
.amount(20)
.bag(getBag2())
.order(getOrder())
.build();
}

public static Bag getBag() {
return Bag.builder()
.status(BagStatus.ACTIVE)
.id(1)
.capacity(120)
.commission(50_00L)
.price(120_00L)
.fullPrice(120_00L)
.createdAt(LocalDate.now())
.createdBy(getEmployee())
.editedBy(getEmployee())
.limitIncluded(true)
.tariffsInfo(getTariffInfo())
.build();
}

public static Bag getBag2() {
return Bag.builder()
.status(BagStatus.ACTIVE)
.id(2)
.capacity(120)
.commission(50_00L)
.price(120_00L)
.fullPrice(2200000L)
.createdAt(LocalDate.now())
.createdBy(getEmployee())
.editedBy(getEmployee())
.limitIncluded(true)
.tariffsInfo(getTariffInfo())
.build();
}

public static OrderBag getOrderBag() {
return OrderBag.builder()
.id(1L)
.capacity(120)
.price(120_00L)
.name("name")
.nameEng("name eng")
.amount(1)
.bag(getBag())
.order(getOrder())
.build();
}

public static OrderBag getOrderBagWithConfirmedAmount() {
return OrderBag.builder()
.id(1L)
.capacity(120)
.price(120_00L)
.name("name")
.nameEng("name eng")
.amount(1)
.confirmedQuantity(2)
.bag(getBag())
.order(getOrder())
.build();
}

public static OrderBag getOrderBagWithExportedAmount() {
return OrderBag.builder()
.id(1L)
.capacity(120)
.price(120_00L)
.name("name")
.nameEng("name eng")
.amount(1)
.confirmedQuantity(2)
.exportedQuantity(2)
.bag(getBag())
.order(getOrder())
.build();
}

public static Bag getBagDeleted() {
return Bag.builder()
.id(1)
.capacity(120)
@@ -2839,14 +2735,11 @@ public static Bag getBagDeleted() {
.description("Description")
.descriptionEng("DescriptionEng")
.limitIncluded(true)
.status(BagStatus.DELETED)
.tariffsInfo(getTariffInfo())
.build();
}

public static Bag getBagForOrder() {
return Bag.builder()
.status(BagStatus.ACTIVE)
.id(3)
.capacity(120)
.commission(50_00L)
@@ -2865,47 +2758,14 @@ public static Bag getBagForOrder() {
public static TariffServiceDto getTariffServiceDto() {
return TariffServiceDto.builder()
.name("Бавовняна сумка")
.capacity(20)
.price(100.0)
.capacity(120)
.price(120.0)
.commission(50.0)
.description("Description")
.build();

}

public static Bag getEditedBag() {
return Bag.builder()
.status(BagStatus.ACTIVE)
.id(1)
.capacity(20)
.price(100_00L)
.fullPrice(150_00L)
.commission(50_00L)
.name("Бавовняна сумка")
.description("Description")
.createdAt(LocalDate.now())
.createdBy(getEmployee())
.editedBy(getEmployee())
.editedAt(LocalDate.now())
.limitIncluded(true)
.status(BagStatus.ACTIVE)
.tariffsInfo(getTariffInfo())
.build();

}

public static OrderBag getEditedOrderBag() {
return OrderBag.builder()
.id(1L)
.amount(1)
.price(150_00L)
.capacity(20)
.name("Бавовняна сумка")
.bag(getBag())
.order(getOrder())
.build();
}

public static Location getLocation() {
return Location.builder()
.id(1L)
@@ -2963,7 +2823,6 @@ public static CourierDto getCourierDto() {

public static Bag getTariffBag() {
return Bag.builder()
.status(BagStatus.ACTIVE)
.id(1)
.capacity(20)
.price(100_00L)
@@ -2993,7 +2852,6 @@ public static BagTranslationDto getBagTranslationDto() {

public static Bag getNewBag() {
return Bag.builder()
.status(BagStatus.ACTIVE)
.capacity(20)
.price(100_00L)
.commission(50_00L)
@@ -3135,7 +2993,6 @@ public static Order getOrderUserSecond() {

public static List<Bag> getBag1list() {
return List.of(Bag.builder()
.status(BagStatus.ACTIVE)
.id(1)
.price(100_00L)
.capacity(20)
@@ -3149,15 +3006,13 @@ public static List<Bag> getBag1list() {

public static List<Bag> getBaglist() {
return List.of(Bag.builder()
.status(BagStatus.ACTIVE)
.id(1)
.price(100_00L)
.capacity(10)
.commission(21_00L)
.fullPrice(20_00L)
.build(),
Bag.builder()
.status(BagStatus.ACTIVE)
.id(2)
.price(100_00L)
.capacity(10)
@@ -3168,7 +3023,6 @@ public static List<Bag> getBaglist() {

public static List<Bag> getBag2list() {
return List.of(Bag.builder()
.status(BagStatus.ACTIVE)
.id(1)
.price(100_00L)
.capacity(10)
@@ -3179,15 +3033,13 @@ public static List<Bag> getBag2list() {

public static List<Bag> getBag3list() {
return List.of(Bag.builder()
.status(BagStatus.ACTIVE)
.id(1)
.price(100_00L)
.capacity(10)
.commission(21_00L)
.fullPrice(2000_00L)
.build(),
Bag.builder()
.status(BagStatus.ACTIVE)
.id(2)
.price(100_00L)
.capacity(10)
@@ -3198,7 +3050,6 @@ public static List<Bag> getBag3list() {

public static List<Bag> getBag4list() {
return List.of(Bag.builder()
.status(BagStatus.ACTIVE)
.id(1)
.price(100_00L)
.capacity(10)
@@ -3209,7 +3060,6 @@ public static List<Bag> getBag4list() {
.limitIncluded(false)
.build(),
Bag.builder()
.status(BagStatus.ACTIVE)
.id(2)
.price(100_00L)
.capacity(10)
@@ -3483,7 +3333,6 @@ public static Location getLocationDto() {

public static Bag bagDto() {
return Bag.builder()
.status(BagStatus.ACTIVE)
.id(1)
.limitIncluded(false)
.description("Description")
@@ -3754,20 +3603,12 @@ public static BigOrderTableViews getBigOrderTableViewsByDateNullTest() {
.setResponsibleNavigator(null);
}

public static Map<Integer, Integer> getAmount() {
Map<Integer, Integer> hashMap = new HashMap<>();
hashMap.put(1, 1);
hashMap.put(2, 1);
return hashMap;
}

public static Order getOrderForGetOrderStatusData2Test() {
Map<Integer, Integer> hashMap = new HashMap<>();
hashMap.put(1, 1);
hashMap.put(2, 1);

return Order.builder()
.orderBags(Arrays.asList(getOrderBag(), getOrderBag2()))
.id(1L)
.amountOfBagsOrdered(hashMap)
.confirmedQuantity(hashMap)
@@ -5066,4 +4907,4 @@ public static PositionWithTranslateDto getPositionWithTranslateDto(Long id) {
public static Refund getRefund(Long id) {
return Refund.builder().orderId(id).build();
}
}
}
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

import greencity.ModelUtils;
import greencity.dto.bag.BagForUserDto;
import greencity.entity.order.OrderBag;
import greencity.entity.order.Bag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
@@ -18,8 +18,8 @@ class BagForUserDtoMapperTest {
@Test
void convert() {
BagForUserDto expected = ModelUtils.TEST_BAG_FOR_USER_DTO;
OrderBag orderBag = ModelUtils.TEST_ORDER_BAG;
BagForUserDto actual = bagForUserDtoMapper.convert(orderBag);
Bag bag = ModelUtils.TEST_BAG;
BagForUserDto actual = bagForUserDtoMapper.convert(bag);

assertEquals(expected.getService(), actual.getService());
assertEquals(expected.getServiceEng(), actual.getServiceEng());
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@
import greencity.exceptions.NotFoundException;
import greencity.exceptions.http.AccessDeniedException;
import greencity.repository.*;
import greencity.service.ubs.OrderBagService;
import lombok.SneakyThrows;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
@@ -85,8 +84,6 @@ class NotificationServiceImplTest {
private Clock fixedClock;

ExecutorService mockExecutor = MoreExecutors.newDirectExecutorService();
@Mock
private OrderBagService orderBagService;

@Nested
class ClockNotification {
@@ -304,7 +301,7 @@ void testNotifyInactiveAccounts() {
List.of(abstractNotificationProvider),
templateRepository,
mockExecutor,
internalUrlConfigProp, orderBagService);
internalUrlConfigProp);
User user = User.builder().id(42L).build();
User user1 = User.builder().id(43L).build();
UserNotification notification = new UserNotification();
@@ -412,7 +409,7 @@ void testNotifyAllHalfPaidPackages() {
parameters.add(NotificationParameter.builder().key("orderNumber")
.value(orders.get(0).getId().toString()).build());

when(orderBagService.findAllBagsByOrderId(any())).thenReturn(getBag1list());
when(bagRepository.findBagsByOrderId(any())).thenReturn(getBag1list());
when(userNotificationRepository.save(any())).thenReturn(notification);
when(notificationParameterRepository.saveAll(any())).thenReturn(new ArrayList<>(parameters));

@@ -513,7 +510,7 @@ void testNotifyUnpaidOrderForBroughtByHimself() {

when(userNotificationRepository.save(any())).thenReturn(notification);
when(notificationParameterRepository.saveAll(any())).thenReturn(new ArrayList<>(parameters));
when(orderBagService.findAllBagsByOrderId(any())).thenReturn(getBag4list());
when(bagRepository.findBagsByOrderId(any())).thenReturn(getBag4list());

notificationService.notifyUnpaidOrder(order);

@@ -544,7 +541,7 @@ void testNotifyUnpaidOrderForDone() {

when(userNotificationRepository.save(any())).thenReturn(notification);
when(notificationParameterRepository.saveAll(any())).thenReturn(new ArrayList<>(parameters));
when(orderBagService.findAllBagsByOrderId(any())).thenReturn(getBag4list());
when(bagRepository.findBagsByOrderId(any())).thenReturn(getBag4list());
notificationService.notifyUnpaidOrder(order);

verify(userNotificationRepository).save(any());
@@ -575,7 +572,7 @@ void testNotifyUnpaidOrderForCancel() {

when(userNotificationRepository.save(any())).thenReturn(notification);
when(notificationParameterRepository.saveAll(any())).thenReturn(new ArrayList<>(parameters));
when(orderBagService.findAllBagsByOrderId(any())).thenReturn(getBag4list());
when(bagRepository.findBagsByOrderId(any())).thenReturn(getBag4list());

notificationService.notifyUnpaidOrder(order);

@@ -606,7 +603,7 @@ void testNotifyHalfPaidOrderForDone() {

when(userNotificationRepository.save(any())).thenReturn(notification);
when(notificationParameterRepository.saveAll(any())).thenReturn(new ArrayList<>(parameters));
when(orderBagService.findAllBagsByOrderId(any())).thenReturn(getBag4list());
when(bagRepository.findBagsByOrderId(any())).thenReturn(getBag4list());

notificationService.notifyHalfPaidPackage(order);

@@ -633,7 +630,7 @@ void testNotifyHalfPaidOrderForBroughtByHimself() {

when(userNotificationRepository.save(any())).thenReturn(notification);
when(notificationParameterRepository.saveAll(any())).thenReturn(new ArrayList<>(parameters));
when(orderBagService.findAllBagsByOrderId(any())).thenReturn(getBag4list());
when(bagRepository.findBagsByOrderId(any())).thenReturn(getBag4list());

notificationService.notifyHalfPaidPackage(order);

151 changes: 0 additions & 151 deletions service/src/test/java/greencity/service/ubs/OrderBagServiceTest.java

This file was deleted.

Large diffs are not rendered by default.

503 changes: 164 additions & 339 deletions service/src/test/java/greencity/service/ubs/UBSClientServiceImplTest.java

Large diffs are not rendered by default.

Large diffs are not rendered by default.