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

[Pick up city UBS.Admin Cabinet] “Return money” button in the "Order payment" section is disabled when admin cancels the order and selects the "Return money" option #5803 #1176

Merged
merged 2 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ protected void configure(HttpSecurity http) throws Exception {
UBS_MANAG_LINK + "/add-manual-payment/{id}",
UBS_MANAG_LINK + "/add-bonuses-user/{id}",
UBS_MANAG_LINK + "/order/{id}/cancellation",
UBS_MANAG_LINK + "/save-order-for-refund/{orderId}",
ADMIN_EMPL_LINK + "/**",
SUPER_ADMIN_LINK + "/add-new-tariff",
SUPER_ADMIN_LINK + "/check-if-tariff-exists",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1041,4 +1041,27 @@ public ResponseEntity<OrderCancellationReasonDto> updateCancellationReason(
@ApiIgnore @CurrentUserUuid String uuid) {
return ResponseEntity.status(HttpStatus.OK).body(ubsClientService.updateOrderCancellationReason(id, dto, uuid));
}

/**
* Controller saves order ID of order for which we need to make a refund.
*
* @param orderId {@link Long}.
* @return {@link HttpStatus} - http status.
*
* @author Anton Bondar
*/
@ApiOperation(value = "saves order ID of order for which we need to make a refund")
@ApiResponses(value = {
@ApiResponse(code = 201, message = HttpStatuses.CREATED),
@ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST),
@ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED),
@ApiResponse(code = 404, message = HttpStatuses.NOT_FOUND)
})
@ResponseStatus(value = HttpStatus.CREATED)
@PostMapping("/save-order-for-refund/{orderId}")
public ResponseEntity<HttpStatus> saveOrderIdForRefund(
@Valid @PathVariable("orderId") Long orderId) {
ubsManagementService.saveOrderIdForRefund(orderId);
return new ResponseEntity<>(HttpStatus.CREATED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -501,4 +501,10 @@ void updatesCancellationReason() throws Exception {
.content(objectMapper.writeValueAsString(dto)))
.andExpect(status().isOk());
}

@Test
void saveOrderIdForRefundTest() throws Exception {
mockMvc.perform(post(ubsLink + "/save-order-for-refund/{orderId}", 1L)
.principal(principal)).andExpect(status().isCreated());
}
}
30 changes: 30 additions & 0 deletions dao/src/main/java/greencity/entity/order/Refund.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package greencity.entity.order;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Table(name = "refunds")
public class Refund {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "order_id")
@NotNull
private Long orderId;
}
9 changes: 9 additions & 0 deletions dao/src/main/java/greencity/repository/RefundRepository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package greencity.repository;

import greencity.entity.order.Refund;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface RefundRepository extends JpaRepository<Refund, Long> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,4 +213,5 @@
<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"/>
</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
https://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd">

<changeSet id="Anton-3" author="Bondar Anton">
<createTable tableName="refunds">
<column name="id" autoIncrement="true" type="BIGINT">
<constraints primaryKey="true"/>
</column>
<column name="order_id" type="BIGINT">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>
</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,24 @@
import greencity.dto.bag.ReasonNotTakeBagDto;
import greencity.dto.certificate.CertificateDtoForSearching;
import greencity.dto.employee.EmployeePositionDtoRequest;
import greencity.dto.order.*;
import greencity.dto.order.AdminCommentDto;
import greencity.dto.order.CounterOrderDetailsDto;
import greencity.dto.order.DetailsOrderInfoDto;
import greencity.dto.order.EcoNumberDto;
import greencity.dto.order.ExportDetailsDto;
import greencity.dto.order.ExportDetailsDtoUpdate;
import greencity.dto.order.NotTakenOrderReasonDto;
import greencity.dto.order.OrderAddressDtoResponse;
import greencity.dto.order.OrderAddressExportDetailsDtoUpdate;
import greencity.dto.order.OrderCancellationReasonDto;
import greencity.dto.order.OrderDetailInfoDto;
import greencity.dto.order.OrderDetailStatusDto;
import greencity.dto.order.OrderDetailStatusRequestDto;
import greencity.dto.order.OrderInfoDto;
import greencity.dto.order.OrderStatusPageDto;
import greencity.dto.order.ReadAddressByOrderDto;
import greencity.dto.order.UpdateAllOrderPageDto;
import greencity.dto.order.UpdateOrderPageAdminDto;
import greencity.dto.pageble.PageableDto;
import greencity.dto.payment.ManualPaymentRequestDto;
import greencity.dto.payment.ManualPaymentResponseDto;
Expand Down Expand Up @@ -301,4 +318,13 @@ void updateOrderAdminPageInfo(UpdateOrderPageAdminDto updateOrderPageAdminDto, L
* @author Kharchenko Volodymyr.
*/
NotTakenOrderReasonDto getNotTakenOrderReason(Long orderId);

/**
* Method saves order ID of order for which we need to make a refund.
*
* @param orderId {@link Long}.
*
* @author Anton Bondar.
*/
void saveOrderIdForRefund(Long orderId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import greencity.entity.order.OrderPaymentStatusTranslation;
import greencity.entity.order.OrderStatusTranslation;
import greencity.entity.order.Payment;
import greencity.entity.order.Refund;
import greencity.entity.order.TariffsInfo;
import greencity.entity.user.User;
import greencity.entity.user.employee.Employee;
Expand Down Expand Up @@ -83,6 +84,7 @@
import greencity.repository.PaymentRepository;
import greencity.repository.PositionRepository;
import greencity.repository.ReceivingStationRepository;
import greencity.repository.RefundRepository;
import greencity.repository.ServiceRepository;
import greencity.repository.TariffsInfoRepository;
import greencity.repository.UserRepository;
Expand Down Expand Up @@ -127,13 +129,13 @@
import static greencity.constant.ErrorMessage.EMPLOYEE_NOT_FOUND;
import static greencity.constant.ErrorMessage.INCORRECT_ECO_NUMBER;
import static greencity.constant.ErrorMessage.NOT_FOUND_ADDRESS_BY_ORDER_ID;
import static greencity.constant.ErrorMessage.ORDER_CAN_NOT_BE_UPDATED;
import static greencity.constant.ErrorMessage.ORDER_WITH_CURRENT_ID_DOES_NOT_EXIST;
import static greencity.constant.ErrorMessage.PAYMENT_NOT_FOUND;
import static greencity.constant.ErrorMessage.RECEIVING_STATION_NOT_FOUND;
import static greencity.constant.ErrorMessage.RECEIVING_STATION_NOT_FOUND_BY_ID;
import static greencity.constant.ErrorMessage.USER_HAS_NO_OVERPAYMENT;
import static greencity.constant.ErrorMessage.USER_WITH_CURRENT_UUID_DOES_NOT_EXIST;
import static greencity.constant.ErrorMessage.ORDER_CAN_NOT_BE_UPDATED;
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;

Expand Down Expand Up @@ -163,6 +165,7 @@ public class UBSManagementServiceImpl implements UBSManagementService {
private final OrderPaymentStatusTranslationRepository orderPaymentStatusTranslationRepository;
private final ServiceRepository serviceRepository;
private final OrdersAdminsPageService ordersAdminsPageService;
private final RefundRepository refundRepository;

private static final String DEFAULT_IMAGE_PATH = AppConstant.DEFAULT_IMAGE;

Expand Down Expand Up @@ -1831,4 +1834,11 @@ public NotTakenOrderReasonDto getNotTakenOrderReason(Long orderId) {
.images(order.getImageReasonNotTakingBags())
.build();
}

@Override
public void saveOrderIdForRefund(Long orderId) {
Order order = orderRepository.findById(orderId)
.orElseThrow(() -> new NotFoundException(ORDER_WITH_CURRENT_ID_DOES_NOT_EXIST + orderId));
refundRepository.save(Refund.builder().orderId(order.getId()).build());
}
}
5 changes: 5 additions & 0 deletions service/src/test/java/greencity/ModelUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
import greencity.entity.order.OrderPaymentStatusTranslation;
import greencity.entity.order.OrderStatusTranslation;
import greencity.entity.order.Payment;
import greencity.entity.order.Refund;
import greencity.entity.order.Service;
import greencity.entity.order.TariffLocation;
import greencity.entity.order.TariffsInfo;
Expand Down Expand Up @@ -4644,4 +4645,8 @@ public static PositionWithTranslateDto getPositionWithTranslateDto(Long id) {
.name(nameTranslations)
.build();
}

public static Refund getRefund(Long id) {
return Refund.builder().orderId(id).build();
}
}
Loading