use of com.ncedu.fooddelivery.api.v1.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class UserUtils method moderatorLeonardHofstadter.
public static User moderatorLeonardHofstadter(Long id) {
final String fullName = "Leonard Leakey Hofstadter";
final String email = "hofstadter@bigbang.theory";
final Role role = Role.MODERATOR;
return createUser(id, fullName, email, role);
}
use of com.ncedu.fooddelivery.api.v1.entities.User 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.User in project 2021-msk-food-delivery by netcracker-edu.
the class ClientServiceImpl method changeClientInfo.
@Override
public boolean changeClientInfo(Long id, UserChangeInfoDTO newUserInfo) {
Client client = getClientById(id);
String newFullName = newUserInfo.getFullName();
if (newFullName != null) {
User user = client.getUser();
user.setFullName(newFullName);
client.setUser(user);
}
String newPhoneNumber = newUserInfo.getPhoneNumber();
if (newPhoneNumber != null) {
Client clientWithNewNumber = clientRepo.findByPhoneNumber(newPhoneNumber);
if (clientWithNewNumber != null) {
throw new AlreadyExistsException(newPhoneNumber);
}
client.setPhoneNumber(newPhoneNumber);
}
clientRepo.save(client);
return true;
}
use of com.ncedu.fooddelivery.api.v1.entities.User in project 2021-msk-food-delivery by netcracker-edu.
the class FileController method uploadFile.
@PostMapping("/api/v1/file")
public FileLinkDTO uploadFile(@RequestParam("file") MultipartFile file, @AuthenticationPrincipal User authedUser) {
FileLinkDTO fileLinkDTO = fileService.save(file, authedUser);
log.debug("Created file link: " + fileLinkDTO.getLink());
return fileLinkDTO;
}
use of com.ncedu.fooddelivery.api.v1.entities.User 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);
}
Aggregations