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

[Tech Task] Delete separate endpoint for cancellation reason in order #6163 #1230

Merged
merged 1 commit into from
Sep 11, 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 @@ -39,7 +39,6 @@
import greencity.dto.violation.ViolationDetailInfoDto;
import greencity.dto.violation.ViolationsInfoDto;
import greencity.entity.parameters.CustomTableView;
import greencity.entity.user.User;
import greencity.filters.CertificateFilterCriteria;
import greencity.filters.CertificatePage;
import greencity.filters.OrderPage;
Expand Down Expand Up @@ -1008,30 +1007,6 @@ public ResponseEntity<NotTakenOrderReasonDto> getNotTakenOrderReason(
.body(ubsManagementService.getNotTakenOrderReason(orderId));
}

/**
* Controller updates info about order cancellation reason.
*
* @param id {@link Long}.
* @param dto {@link OrderCancellationReasonDto}
* @param uuid current {@link User}'s uuid.
* @return {@link HttpStatus} - http status.
*/
@ApiOperation(value = "updates info about order cancellation reason ")
@ApiResponses(value = {
@ApiResponse(code = 200, message = HttpStatuses.OK, response = OrderCancellationReasonDto.class),
@ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST),
@ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED),
@ApiResponse(code = 403, message = HttpStatuses.FORBIDDEN),
@ApiResponse(code = 404, message = HttpStatuses.NOT_FOUND)
})
@PostMapping("/order/{id}/cancellation")
public ResponseEntity<OrderCancellationReasonDto> updateCancellationReason(
@RequestBody final OrderCancellationReasonDto dto,
@PathVariable("id") final Long id,
@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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import greencity.dto.order.AdminCommentDto;
import greencity.dto.order.EcoNumberDto;
import greencity.dto.order.ExportDetailsDto;
import greencity.dto.order.OrderCancellationReasonDto;
import greencity.dto.order.OrderDetailStatusDto;
import greencity.dto.order.UpdateAllOrderPageDto;
import greencity.dto.order.UpdateOrderPageAdminDto;
Expand Down Expand Up @@ -493,17 +492,6 @@ void getNotTakenOrderReason() throws Exception {
verify(ubsManagementService).getNotTakenOrderReason(1L);
}

@Test
void updatesCancellationReason() throws Exception {
OrderCancellationReasonDto dto = ModelUtils.getCancellationDto();
ObjectMapper objectMapper = new ObjectMapper();
mockMvc.perform(post(ubsLink + "/order/{id}/cancellation", 1L)
.principal(ModelUtils.getPrincipal())
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(dto)))
.andExpect(status().isOk());
}

@Test
void saveOrderIdForRefundTest() throws Exception {
mockMvc.perform(post(ubsLink + "/save-order-for-refund/{orderId}", 1L)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,6 @@ public interface UBSClientService {
*/
OrderCancellationReasonDto getOrderCancellationReason(Long orderId, String uuid);

/**
* Method updates cancellation reason and comment.
*
* @param id {@link Long};
* @param dto {@link OrderCancellationReasonDto};
* @param uuid current {@link User}'s uuid;
* @return {@link OrderCancellationReasonDto} dto that contains cancellation
* reason and comment;
* @author Oleksandr Khomiakov
*/
OrderCancellationReasonDto updateOrderCancellationReason(long id, OrderCancellationReasonDto dto, String uuid);

/**
* Methods for finding all events for Order.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1423,22 +1423,6 @@ public OrderCancellationReasonDto getOrderCancellationReason(final Long orderId,
.build();
}

@Override
public OrderCancellationReasonDto updateOrderCancellationReason(
long id, OrderCancellationReasonDto dto, String uuid) {
Order order = orderRepository.findById(id)
.orElseThrow(() -> new NotFoundException(ORDER_WITH_CURRENT_ID_DOES_NOT_EXIST));
if (!order.getUser().equals(userRepository.findByUuid(uuid))) {
throw new AccessDeniedException(CANNOT_ACCESS_ORDER_CANCELLATION_REASON);
}
eventService.saveEvent(OrderHistory.ORDER_CANCELLED, uuid, order);
order.setCancellationReason(dto.getCancellationReason());
order.setCancellationComment(dto.getCancellationComment());
order.setId(id);
orderRepository.save(order);
return dto;
}

private long reduceOrderSumDueToUsedPoints(long sumToPayInCoins, int pointsToUse) {
if (sumToPayInCoins >= pointsToUse * 100L) {
sumToPayInCoins -= pointsToUse * 100L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2810,39 +2810,6 @@ void getOrderCancellationReasonAccessDeniedException() {
() -> ubsService.getOrderCancellationReason(1L, "abc"));
}

@Test
void testUpdateOrderCancellationReason() {
OrderCancellationReasonDto dto = getCancellationDto();
Order orderDto = getOrderTest();
when(orderRepository.findById(anyLong())).thenReturn(Optional.ofNullable(orderDto));
assert orderDto != null;
when(userRepository.findByUuid(anyString())).thenReturn(orderDto.getUser());
when(orderRepository.save(any())).thenReturn(orderDto);
OrderCancellationReasonDto result = ubsService.updateOrderCancellationReason(1L, dto, anyString());

verify(eventService, times(1))
.saveEvent("Статус Замовлення - Скасовано", "", orderDto);
assertEquals(dto.getCancellationReason(), result.getCancellationReason());
assertEquals(dto.getCancellationComment(), result.getCancellationComment());
verify(orderRepository).save(orderDto);
verify(orderRepository).findById(1L);
}

@Test
void updateOrderCancellationReasonOrderNotFoundException() {
when(orderRepository.findById(anyLong())).thenReturn(Optional.empty());
assertThrows(NotFoundException.class,
() -> ubsService.updateOrderCancellationReason(1L, null, "abc"));
}

@Test
void updateOrderCancellationReasonAccessDeniedException() {
when(orderRepository.findById(anyLong())).thenReturn(Optional.ofNullable(getOrderTest()));
when(userRepository.findByUuid(anyString())).thenReturn(getTestUser());
assertThrows(AccessDeniedException.class,
() -> ubsService.updateOrderCancellationReason(1L, null, "abc"));
}

@Test
void testGelAllEventsFromOrderByOrderId() {
List<Event> orderEvents = getListOfEvents();
Expand Down