Search in sources :

Example 11 with Moderator

use of com.ncedu.fooddelivery.api.v1.entities.Moderator in project 2021-msk-food-delivery by netcracker-edu.

the class UserController method changeUserInfo.

@PutMapping("/api/v1/user/{id}")
@PreAuthorize("hasAnyAuthority('MODERATOR', 'ADMIN')")
public ResponseEntity<?> changeUserInfo(@PathVariable Long id, @Valid @RequestBody UserChangeInfoDTO newUserInfo) {
    User user = userService.getUserById(id);
    String userRole = user.getRole().name();
    boolean isModified = false;
    if (Role.isCLIENT(userRole)) {
        isModified = clientService.changeClientInfo(id, newUserInfo);
    }
    // for admin and moderator we can change only full name
    String newFullName = newUserInfo.getFullName();
    isModified = userService.changeFullName(id, newFullName);
    log.debug("User with id " + id + " modified " + isModified);
    return createModifyResponse(isModified);
}
Also used : User(com.ncedu.fooddelivery.api.v1.entities.User) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)7 CustomAccessDeniedException (com.ncedu.fooddelivery.api.v1.errors.security.CustomAccessDeniedException)6 User (com.ncedu.fooddelivery.api.v1.entities.User)4 NotFoundEx (com.ncedu.fooddelivery.api.v1.errors.notfound.NotFoundEx)4 ProductPosition (com.ncedu.fooddelivery.api.v1.entities.productPosition.ProductPosition)3 Test (org.junit.jupiter.api.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 ResponseEntity (org.springframework.http.ResponseEntity)3 com.ncedu.fooddelivery.api.v1.dto.isCreatedDTO (com.ncedu.fooddelivery.api.v1.dto.isCreatedDTO)2 Moderator (com.ncedu.fooddelivery.api.v1.entities.Moderator)2 ModeratorInfoDTO (com.ncedu.fooddelivery.api.v1.dto.user.ModeratorInfoDTO)1 Order (com.ncedu.fooddelivery.api.v1.entities.order.Order)1 ProductPositionNotHierarchical (com.ncedu.fooddelivery.api.v1.entities.productPosition.ProductPositionNotHierarchical)1 RegistrationMapper (com.ncedu.fooddelivery.api.v1.mappers.RegistrationMapper)1 ArrayList (java.util.ArrayList)1