Search in sources :

Example 51 with User

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);
}
Also used : Role(com.ncedu.fooddelivery.api.v1.entities.Role)

Example 52 with User

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);
}
Also used : RegistrationMapper(com.ncedu.fooddelivery.api.v1.mappers.RegistrationMapper) com.ncedu.fooddelivery.api.v1.dto.isCreatedDTO(com.ncedu.fooddelivery.api.v1.dto.isCreatedDTO)

Example 53 with User

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;
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) AlreadyExistsException(com.ncedu.fooddelivery.api.v1.errors.badrequest.AlreadyExistsException) Client(com.ncedu.fooddelivery.api.v1.entities.Client)

Example 54 with User

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;
}
Also used : FileLinkDTO(com.ncedu.fooddelivery.api.v1.dto.file.FileLinkDTO)

Example 55 with User

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);
}
Also used : Order(com.ncedu.fooddelivery.api.v1.entities.order.Order) ResponseEntity(org.springframework.http.ResponseEntity) NotFoundEx(com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx) CustomAccessDeniedException(com.ncedu.fooddelivery.api.v1.errors.security.CustomAccessDeniedException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

User (com.ncedu.fooddelivery.api.v1.entities.User)58 Test (org.junit.jupiter.api.Test)55 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)55 File (com.ncedu.fooddelivery.api.v1.entities.File)21 Path (java.nio.file.Path)19 MultipartFile (org.springframework.web.multipart.MultipartFile)19 CustomAccessDeniedException (com.ncedu.fooddelivery.api.v1.errors.security.CustomAccessDeniedException)18 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)18 FileLinkDTO (com.ncedu.fooddelivery.api.v1.dto.file.FileLinkDTO)15 Order (com.ncedu.fooddelivery.api.v1.entities.order.Order)14 BufferedImage (java.awt.image.BufferedImage)10 UserInfoDTO (com.ncedu.fooddelivery.api.v1.dto.user.UserInfoDTO)9 Role (com.ncedu.fooddelivery.api.v1.entities.Role)7 NotFoundEx (com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx)7 IOException (java.io.IOException)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 ProductPosition (com.ncedu.fooddelivery.api.v1.entities.productPosition.ProductPosition)6 AlreadyExistsException (com.ncedu.fooddelivery.api.v1.errors.badrequest.AlreadyExistsException)6 PasswordsMismatchException (com.ncedu.fooddelivery.api.v1.errors.badrequest.PasswordsMismatchException)6 CommitAfter (org.apache.tapestry5.jpa.annotations.CommitAfter)6