use of com.ncedu.fooddelivery.api.v1.entities.Moderator in project 2021-msk-food-delivery by netcracker-edu.
the class ProfileControllerTest method getModeratorProfile.
@Test
public void getModeratorProfile() {
ModeratorInfoDTO moderatorInfoDTO = new ModeratorInfoDTO(1L, "MODERATOR", "moderator@mail.ru");
when(moderatorServiceMock.getModeratorDTOById(1L)).thenReturn(moderatorInfoDTO);
User user = new User();
user.setId(1L);
user.setRole(Role.MODERATOR);
UserInfoDTO resultModeratorDTO = profileController.getProfile(user);
assertEquals(moderatorInfoDTO, resultModeratorDTO);
}
use of com.ncedu.fooddelivery.api.v1.entities.Moderator in project 2021-msk-food-delivery by netcracker-edu.
the class AuthServiceImpl method signUp.
@Override
public isCreatedDTO signUp(NewUserDTO userInfo) {
RegistrationMapper regMapper = RegistrationMapper.INSTANCE;
userInfo.setPassword(encoder.encode(userInfo.getPassword()));
User user = regMapper.dtoToUser(userInfo);
user.setRegDate(Timestamp.valueOf(LocalDateTime.now()));
if (Role.isCLIENT(userInfo.getRole())) {
Client client = regMapper.dtoToClient(userInfo);
user.setClient(client);
}
if (Role.isMODERATOR(userInfo.getRole())) {
Moderator moderator = regMapper.dtoToModerator(userInfo);
user.setModerator(moderator);
}
user = userRepo.save(user);
Long userId = user.getId();
return new isCreatedDTO(userId);
}
use of com.ncedu.fooddelivery.api.v1.entities.Moderator in project 2021-msk-food-delivery by netcracker-edu.
the class ProductPositionController method shipProductPositionsFromOrder.
@PatchMapping("/api/v1/order/{id}/productPositions/currentAmount")
@PreAuthorize("hasAnyAuthority('ADMIN', 'MODERATOR')")
public ResponseEntity<?> shipProductPositionsFromOrder(@Min(value = 1) @Max(value = Long.MAX_VALUE) @PathVariable(name = "id") Long id, @Valid @RequestBody ProductPositionsShipmentDTO productPositionsShipmentDTO, @AuthenticationPrincipal User user) {
Order order = orderService.getOrder(id);
if (order == null)
throw new NotFoundEx(String.valueOf(id));
if (user.getRole() == Role.MODERATOR) {
if (!user.getModerator().getWarehouseId().equals(order.getWarehouse().getId()))
throw new CustomAccessDeniedException();
}
productPositionService.shipProductPositions(id, productPositionsShipmentDTO);
return new ResponseEntity<>(HttpStatus.OK);
}
use of com.ncedu.fooddelivery.api.v1.entities.Moderator in project 2021-msk-food-delivery by netcracker-edu.
the class ProductPositionController method acceptSupply.
@PostMapping(path = "/api/v1/productPosition")
@PreAuthorize("hasAnyAuthority('ADMIN', 'MODERATOR')")
public isCreatedDTO acceptSupply(@AuthenticationPrincipal User user, @Valid @RequestBody AcceptSupplyDTO acceptSupplyDTO) {
if (Role.isMODERATOR(user.getRole().toString())) {
if (!user.getModerator().getWarehouseId().equals(acceptSupplyDTO.getWarehouseId())) {
throw new CustomAccessDeniedException();
}
}
Long id = productPositionService.acceptSupply(acceptSupplyDTO);
isCreatedDTO isCreated = new isCreatedDTO();
isCreated.setId(id);
return isCreated;
}
use of com.ncedu.fooddelivery.api.v1.entities.Moderator in project 2021-msk-food-delivery by netcracker-edu.
the class ProductPositionController method findFiltered.
@GetMapping("/api/v1/productPositions")
@PreAuthorize("hasAnyAuthority('ADMIN', 'MODERATOR')")
public ResponseEntity<List<ProductPositionInfoDTO>> findFiltered(@AuthenticationPrincipal User user, @Valid ProductPositionFilterDTO filterDTO, Pageable pageable) {
List<ProductPositionInfoDTO> filteredPositions;
if (user.getRole() == Role.MODERATOR) {
Long moderatorWarehouseId = user.getModerator().getWarehouseId();
if (filterDTO.getWarehouseId() != null) {
if (!filterDTO.getWarehouseId().equals(moderatorWarehouseId))
throw new CustomAccessDeniedException();
}
filterDTO.setWarehouseId(moderatorWarehouseId);
Specification<ProductPositionNotHierarchical> spec = ProductPositionSpecifications.getFilterSpecification(filterDTO);
filteredPositions = productPositionService.findFiltered(spec, pageable);
} else {
Specification<ProductPositionNotHierarchical> spec = ProductPositionSpecifications.getFilterSpecification(filterDTO);
filteredPositions = productPositionService.findFiltered(spec, pageable);
}
return ResponseEntity.status(HttpStatus.OK).body(filteredPositions);
}
Aggregations