use of com.ncedu.fooddelivery.api.v1.entities.User in project youtubechannel by lspil.
the class JPAUserDetailsService method loadUserByUsername.
@Override
public UserDetails loadUserByUsername(String username) {
Optional<User> user = userRepository.findUserByUsername(username);
User u = user.orElseThrow(() -> new UsernameNotFoundException("Error!"));
return new SecurityUser(u);
}
use of com.ncedu.fooddelivery.api.v1.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class DeliverySessionServiceImpl method finishSession.
@Override
public void finishSession(User user, User targetUser) {
if (targetUser.getRole() != Role.COURIER)
throw new IncorrectUserRoleRequestException();
Courier courier = targetUser.getCourier();
if (user.getRole() == Role.MODERATOR)
checkModeratorAccess(user.getModerator(), courier);
DeliverySession currentSession = deliverySessionRepo.getActiveSession(courier.getId());
if (currentSession == null)
throw new NoActiveDeliverySessionException();
Order activeOrder = orderService.findCouriersActiveOrder(courier);
if (activeOrder != null)
throw new DeliverySessionFinishException(activeOrder.getId());
currentSession.setEndTime(LocalDateTime.now());
// db trigger does other work
deliverySessionRepo.save(currentSession);
}
use of com.ncedu.fooddelivery.api.v1.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class DeliverySessionServiceImpl method finishSession.
@Override
public void finishSession(User user, DeliverySession deliverySession) {
if (user.getRole() == Role.MODERATOR)
checkModeratorAccess(user.getModerator(), deliverySession.getCourier());
if (deliverySession.getEndTime() != null)
throw new DeliverySessionAlreadyFinishedException(deliverySession.getId());
Order activeOrder = orderService.findCouriersActiveOrder(deliverySession.getCourier());
if (activeOrder != null)
throw new DeliverySessionFinishException(activeOrder.getId());
deliverySession.setEndTime(LocalDateTime.now());
// db trigger does other work
deliverySessionRepo.save(deliverySession);
}
use of com.ncedu.fooddelivery.api.v1.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class FileServiceImpl method save.
@Override
public FileLinkDTO save(MultipartFile file, User owner) {
try {
String originalFileName = file.getOriginalFilename();
String fileName = getFileNameWithoutExt(originalFileName);
FileType fileType = getFileType(originalFileName);
Long fileSize = file.getSize();
UUID fileUuid = UUID.randomUUID();
Path fullPathToFile = createFullPathToFile(fileUuid);
if (owner.getRole() == Role.CLIENT || owner.getRole() == Role.COURIER) {
InputStream is = file.getInputStream();
BufferedImage bufferedImage = ImageIO.read(is);
boolean isExceedImageSize = checkExceedImageSize(bufferedImage);
if (isExceedImageSize) {
bufferedImage = resizeImage(bufferedImage);
}
if (fileType == FileType.PNG) {
bufferedImage = convertPNGtoJPG(bufferedImage);
}
ImageIO.write(bufferedImage, "jpg", fullPathToFile.toFile());
fileSize = Files.size(fullPathToFile);
fileType = FileType.JPEG;
} else {
Files.copy(file.getInputStream(), fullPathToFile, StandardCopyOption.REPLACE_EXISTING);
}
File fileEntity = new File(fileUuid, fileType, fileName, fileSize, Timestamp.valueOf(LocalDateTime.now()), owner);
fileRepo.save(fileEntity);
String fileLink = createFileLink(fileUuid);
return new FileLinkDTO(fileLink, fileUuid.toString());
} catch (BadFileExtensionException e) {
throw e;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new FileStorageException();
}
}
use of com.ncedu.fooddelivery.api.v1.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class OrderServiceImpl1 method changeOrderStatus.
@Override
public void changeOrderStatus(Order order, User user, ChangeOrderStatusDTO dto) {
if (user.getRole() == Role.MODERATOR) {
if (!order.getWarehouse().getId().equals(user.getModerator().getWarehouseId()))
throw new CustomAccessDeniedException();
} else if (user.getRole() == Role.COURIER) {
if (!order.getCourier().getId().equals(user.getCourier().getId()))
throw new CustomAccessDeniedException();
} else if (user.getRole() == Role.CLIENT) {
if (!order.getClient().getId().equals(user.getClient().getId()))
throw new CustomAccessDeniedException();
}
OrderStatus oldStatus = order.getStatus();
OrderStatus newStatus = dto.getNewStatus();
if (oldStatus == OrderStatus.CANCELLED || oldStatus == OrderStatus.DELIVERED || (oldStatus.ordinal() > newStatus.ordinal()))
throw new OrderStatusChangeException(order.getId());
order.setStatus(newStatus);
orderRepo.save(order);
}
Aggregations