Skip to content

Commit

Permalink
[UBS] - Exception occurs when we try to update order page admin info …
Browse files Browse the repository at this point in the history
…#6128 (#1203)

* update order

* update order and save reason

* formatter

* tests

* formatting

* code refactoring

* code smells

* suggested changes

* required fields
  • Loading branch information
ABbondar authored Aug 11, 2023
1 parent 1f1058a commit aa9ecbf
Show file tree
Hide file tree
Showing 7 changed files with 615 additions and 452 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import greencity.annotations.CurrentUserUuid;
import greencity.constants.HttpStatuses;
import greencity.dto.bag.AdditionalBagInfoDto;
import greencity.dto.bag.ReasonNotTakeBagDto;
import greencity.dto.certificate.CertificateDtoForAdding;
import greencity.dto.certificate.CertificateDtoForSearching;
import greencity.dto.employee.EmployeePositionDtoRequest;
Expand Down Expand Up @@ -505,7 +504,7 @@ public ResponseEntity<OrderDetailStatusDto> getOrderDetailStatus(
}

/**
* Controller for update order and payment status.
* Controller for update order and payment status by id.
*
* @return {@link OrderDetailStatusDto}.
* @author Orest Mahdziak
Expand All @@ -524,7 +523,7 @@ public ResponseEntity<OrderDetailStatusDto> updateOrderDetailStatus(
@Valid @PathVariable("id") Long id, @RequestBody OrderDetailStatusRequestDto dto,
Principal principal) {
return ResponseEntity.status(HttpStatus.CREATED)
.body(ubsManagementService.updateOrderDetailStatus(id, dto, principal.getName()));
.body(ubsManagementService.updateOrderDetailStatusById(id, dto, principal.getName()));
}

/**
Expand Down Expand Up @@ -629,7 +628,7 @@ public ResponseEntity<ExportDetailsDto> updateOrderExportInfo(
@Valid @PathVariable("id") Long id, @RequestBody ExportDetailsDtoUpdate dto,
Principal principal) {
return ResponseEntity.status(HttpStatus.CREATED)
.body(ubsManagementService.updateOrderExportDetails(id, dto, principal.getName()));
.body(ubsManagementService.updateOrderExportDetailsById(id, dto, principal.getName()));
}

/**
Expand Down Expand Up @@ -836,26 +835,6 @@ public ResponseEntity<HttpStatus> updateUsersViolation(@Valid @RequestPart Updat
return new ResponseEntity<>(HttpStatus.CREATED);
}

/**
* Controller for save reason not taking the bag. *
*
* @return {ReasonNotTakeBagDto}. * @author Bohdan Fedorkiv
*/

@ApiOperation(value = "Save reason for not taking the bag")
@ApiResponses(value = {
@ApiResponse(code = 201, message = HttpStatuses.CREATED, response = ReasonNotTakeBagDto.class),
@ApiResponse(code = 401, message = HttpStatuses.UNAUTHORIZED),
@ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST),
@ApiResponse(code = 422, message = HttpStatuses.UNPROCESSABLE_ENTITY)})
@PutMapping(value = "/save-reason/{id}",
consumes = {MediaType.MULTIPART_FORM_DATA_VALUE, MediaType.APPLICATION_JSON_UTF8_VALUE})
public ResponseEntity<ReasonNotTakeBagDto> saveReason(@PathVariable("id") Long id,
@RequestPart String description,
@RequestPart(required = false) @Nullable MultipartFile[] images) {
return ResponseEntity.status(HttpStatus.CREATED).body(ubsManagementService.saveReason(id, description, images));
}

/**
* Controller for saving Admin comment.
*
Expand Down Expand Up @@ -898,19 +877,25 @@ public ResponseEntity<HttpStatus> saveAdminCommentToOrder(
public ResponseEntity<HttpStatus> updateEcoStoreIdToOrder(
@RequestBody @Valid EcoNumberDto ecoNumberDto, @PathVariable(name = "id") Long orderId,
Principal principal) {
ubsManagementService.updateEcoNumberForOrder(ecoNumberDto, orderId, principal.getName());
ubsManagementService.updateEcoNumberForOrderById(ecoNumberDto, orderId, principal.getName());
return ResponseEntity.status(HttpStatus.CREATED).build();
}

/**
* Controller for updating order admin page info.
* Controller for updating order admin page info and save reason if needed.
*
* @param updateOrderPageDto {@link UpdateOrderPageAdminDto}.
* @param orderId {@link Long}.
* @param orderId {@link Long}.
* @param updateOrderPageAdminDto {@link UpdateOrderPageAdminDto}.
* @param language {@link String}.
* @param principal {@link Principal}.
* @param description {@link String}.
* @param images {@link MultipartFile}.
*
* @author Bahlay Yuriy.
* @author Anton Bondar.
*/
@ApiOperation(value = "update order admin page info")

@ApiOperation(value = "update order admin page info and save reason if needed")
@ApiResponses(value = {
@ApiResponse(code = 201, message = HttpStatuses.CREATED),
@ApiResponse(code = 400, message = HttpStatuses.BAD_REQUEST),
Expand All @@ -920,11 +905,15 @@ public ResponseEntity<HttpStatus> updateEcoStoreIdToOrder(
@ApiResponse(code = 422, message = HttpStatuses.UNPROCESSABLE_ENTITY)
})
@PreAuthorize("@preAuthorizer.hasAuthority('EDIT_ORDER', authentication)")
@PatchMapping("/update-order-page-admin-info/{id}")
public ResponseEntity<HttpStatus> updatePageAdminInfo(
@RequestBody @Valid UpdateOrderPageAdminDto updateOrderPageDto, @PathVariable(name = "id") Long orderId,
@RequestParam String lang, Principal principal) {
ubsManagementService.updateOrderAdminPageInfo(updateOrderPageDto, orderId, lang, principal.getName());
@PatchMapping(value = "/update-order-page-admin-info/{id}",
consumes = {MediaType.MULTIPART_FORM_DATA_VALUE, MediaType.APPLICATION_JSON_UTF8_VALUE})
public ResponseEntity<HttpStatus> updatePageAdminInfo(@PathVariable(name = "id") Long orderId,
@Valid @RequestPart UpdateOrderPageAdminDto updateOrderPageAdminDto,
@RequestParam String language,
@ApiIgnore Principal principal, String description,
@RequestPart(required = false) @Nullable MultipartFile[] images) {
ubsManagementService.updateOrderAdminPageInfoAndSaveReason(orderId, updateOrderPageAdminDto, language,
principal.getName(), description, images);
return ResponseEntity.status(HttpStatus.CREATED).build();
}

Expand Down
11 changes: 11 additions & 0 deletions core/src/test/java/greencity/ModelUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@
import greencity.dto.order.OrderCancellationReasonDto;
import greencity.dto.order.OrderClientDto;
import greencity.dto.order.OrderDetailStatusDto;
import greencity.dto.order.OrderDetailStatusRequestDto;
import greencity.dto.order.OrderFondyClientDto;
import greencity.dto.order.OrderResponseDto;
import greencity.dto.order.RequestToChangeOrdersDataDto;
import greencity.dto.order.UpdateAllOrderPageDto;
import greencity.dto.order.UpdateOrderPageAdminDto;
import greencity.dto.payment.ManualPaymentRequestDto;
import greencity.dto.payment.PaymentResponseDto;
import greencity.dto.position.PositionDto;
Expand Down Expand Up @@ -597,4 +599,13 @@ public static UserProfileCreateDto getUserProfileCreateDto() {
.uuid("f81d4fae-7dec-11d0-a765-00a0c91e6bf6")
.build();
}

public static UpdateOrderPageAdminDto getUpdateOrderPageAdminDto() {
return UpdateOrderPageAdminDto.builder()
.generalOrderInfo(OrderDetailStatusRequestDto
.builder()
.orderStatus("NOT_TAKEN_OUT")
.build())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import greencity.dto.order.OrderCancellationReasonDto;
import greencity.dto.order.OrderDetailStatusDto;
import greencity.dto.order.UpdateAllOrderPageDto;
import greencity.dto.order.UpdateOrderPageAdminDto;
import greencity.dto.payment.ManualPaymentRequestDto;
import greencity.dto.user.AddBonusesToUserDto;
import greencity.dto.user.AddingPointsToUserDto;
Expand Down Expand Up @@ -43,6 +44,7 @@
import static greencity.ModelUtils.getAddBonusesToUserDto;
import static greencity.ModelUtils.getEcoNumberDto;
import static greencity.ModelUtils.getRequestDto;
import static greencity.ModelUtils.getUpdateOrderPageAdminDto;
import static greencity.ModelUtils.getUuid;
import static greencity.ModelUtils.getViolationDetailInfoDto;
import static org.mockito.Mockito.doNothing;
Expand All @@ -55,8 +57,8 @@
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@ExtendWith(MockitoExtension.class)
class ManagementOrderControllerTest {
Expand Down Expand Up @@ -507,4 +509,32 @@ void saveOrderIdForRefundTest() throws Exception {
mockMvc.perform(post(ubsLink + "/save-order-for-refund/{orderId}", 1L)
.principal(principal)).andExpect(status().isCreated());
}

@Test
void updatePageAdminInfoTest() throws Exception {
UpdateOrderPageAdminDto dto = getUpdateOrderPageAdminDto();
ObjectMapper objectMapper = new ObjectMapper();
String responseJSON = objectMapper.writeValueAsString(dto);

MockMultipartFile jsonFile = new MockMultipartFile(
"updateOrderPageAdminDto",
"updateOrderPageAdminDto.json",
"application/json",
responseJSON.getBytes());

MockMultipartHttpServletRequestBuilder builder =
MockMvcRequestBuilders.multipart(ubsLink + "/update-order-page-admin-info/{id}", 1L);
builder.with(request -> {
request.setMethod("PATCH");
return request;
});

mockMvc.perform(
builder.file(jsonFile)
.param("language", "en")
.param("description", "false")
.principal(principal)
.contentType(MediaType.MULTIPART_FORM_DATA))
.andExpect(status().isCreated());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package greencity.service.ubs;

import greencity.dto.bag.AdditionalBagInfoDto;
import greencity.dto.bag.ReasonNotTakeBagDto;
import greencity.dto.certificate.CertificateDtoForSearching;
import greencity.dto.employee.EmployeePositionDtoRequest;
import greencity.dto.order.AdminCommentDto;
Expand Down Expand Up @@ -29,6 +28,7 @@
import greencity.dto.user.AddBonusesToUserDto;
import greencity.dto.user.AddingPointsToUserDto;
import greencity.dto.violation.ViolationsInfoDto;
import greencity.entity.order.Order;
import greencity.enums.SortingOrder;
import org.springframework.data.domain.Pageable;
import org.springframework.web.multipart.MultipartFile;
Expand Down Expand Up @@ -91,12 +91,13 @@ PageableDto<CertificateDtoForSearching> getAllCertificates(Pageable page, String
/**
* Method that update address.
*
* @param dtoUpdate of {@link OrderAddressExportDetailsDtoUpdate} order id;
* @param dtoUpdate of {@link OrderAddressExportDetailsDtoUpdate} order id.
* @param order {@link Order}.
* @param email {@link String}.
* @return {@link OrderAddressDtoResponse} that contains address;
* @return {@link OrderAddressDtoResponse} that contains address.
* @author Mahdziak Orest
*/
Optional<OrderAddressDtoResponse> updateAddress(OrderAddressExportDetailsDtoUpdate dtoUpdate, Long orderId,
Optional<OrderAddressDtoResponse> updateAddress(OrderAddressExportDetailsDtoUpdate dtoUpdate, Order order,
String email);

/**
Expand All @@ -111,7 +112,7 @@ Optional<OrderAddressDtoResponse> updateAddress(OrderAddressExportDetailsDtoUpda
*
* @author Mahdziak Orest
*/
void setOrderDetail(Long orderId,
void setOrderDetail(Order order,
Map<Integer, Integer> confirmed, Map<Integer, Integer> exported, String email);

/**
Expand Down Expand Up @@ -150,12 +151,19 @@ void setOrderDetail(Long orderId,
*/
OrderDetailStatusDto getOrderDetailStatus(Long id);

/**
* Method that update order and payment status by id.
*
* @author Mahdziak Orest
*/
OrderDetailStatusDto updateOrderDetailStatusById(Long id, OrderDetailStatusRequestDto dto, String email);

/**
* Method that update order and payment status.
*
* @author Mahdziak Orest
*/
OrderDetailStatusDto updateOrderDetailStatus(Long id, OrderDetailStatusRequestDto dto, String email);
OrderDetailStatusDto updateOrderDetailStatus(Order order, OrderDetailStatusRequestDto dto, String email);

/**
* Method that get export details by order id.
Expand All @@ -169,7 +177,14 @@ void setOrderDetail(Long orderId,
*
* @author Mahdziak Orest
*/
ExportDetailsDto updateOrderExportDetails(Long id, ExportDetailsDtoUpdate dto, String uuid);
ExportDetailsDto updateOrderExportDetailsById(Long id, ExportDetailsDtoUpdate dto, String uuid);

/**
* Method that update export details by order.
*
* @author Mahdziak Orest
*/
ExportDetailsDto updateOrderExportDetails(Order order, ExportDetailsDtoUpdate dto, String uuid);

/**
* Method that gets bags additional information.
Expand Down Expand Up @@ -225,10 +240,10 @@ ManualPaymentResponseDto updateManualPayment(Long paymentId, ManualPaymentReques
/**
* Method that save ReasonNotTakeBagDto.
*/
ReasonNotTakeBagDto saveReason(Long orderId, String description, MultipartFile[] images);
void saveReason(Order order, String description, MultipartFile[] images);

/**
* This is method which is save Admin comment.
* This is method which save Admin comment.
*
* @param adminCommentDto {@link AdminCommentDto}.
* @param email {@link String}.
Expand All @@ -238,26 +253,53 @@ ManualPaymentResponseDto updateManualPayment(Long paymentId, ManualPaymentReques
void saveAdminCommentToOrder(AdminCommentDto adminCommentDto, String email);

/**
* This is method updates eco id from the shop for order.
* This is method updates eco id from the shop for order by id.
*
* @param ecoNumberDto {@link EcoNumberDto}.
* @param orderId {@link Long}.
* @param email {@link String}.
*
* @author Yuriy Bahlay.
*/
void updateEcoNumberForOrder(EcoNumberDto ecoNumberDto, Long orderId, String email);
void updateEcoNumberForOrderById(EcoNumberDto ecoNumberDto, Long orderId, String email);

/**
* This is method updates eco id from the shop for order.
*
* @param ecoNumberDto {@link EcoNumberDto}.
* @param order {@link Order}.
* @param email {@link String}.
*
* @author Yuriy Bahlay.
*/
void updateEcoNumberForOrder(EcoNumberDto ecoNumberDto, Order order, String email);

/**
* This is method which is updates admin page info for order and save reason.
*
* @param orderId {@link Long}.
* @param updateOrderPageAdminDto {@link UpdateOrderPageAdminDto}.
* @param language {@link String}.
* @param email {@link String}.
* @param description {@link String}.
* @param images {@link MultipartFile}.
*
* @author Anton Bondar.
*/
void updateOrderAdminPageInfoAndSaveReason(Long orderId, UpdateOrderPageAdminDto updateOrderPageAdminDto,
String language,
String email, String description, MultipartFile[] images);

/**
* This is method which is updates admin page info for order.
*
* @param updateOrderPageAdminDto {@link UpdateOrderPageAdminDto}.
* @param orderId {@link Long}.
* @param order {@link Order}.
* @param email {@link String}.
*
* @author Yuriy Bahlay.
*/
void updateOrderAdminPageInfo(UpdateOrderPageAdminDto updateOrderPageAdminDto, Long orderId, String lang,
void updateOrderAdminPageInfo(UpdateOrderPageAdminDto updateOrderPageAdminDto, Order order, String lang,
String email);

/**
Expand Down
Loading

0 comments on commit aa9ecbf

Please sign in to comment.