Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,23 @@ public ResponseEntity<Void> deleteUser(
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

@Operation(
summary = "Удалить свой профиль",
description = "Метод, чтобы пользователь мог удалить свой профиль."
)
@DeleteMapping("/me")
@ApiResponses(value = {
@ApiResponse(responseCode = "204", description = "Успешно. Пустой ответ", content = @Content),
@ApiResponse(responseCode = "404", description = "Пользователь не найден", content = @Content),
@ApiResponse(responseCode = "422", description = "Ошибка валидации", content = @Content),
@ApiResponse(responseCode = "500", description = "Непредвиденная ошибка со стороны сервера", content = @Content)
})
@SecurityRequirement(name = "JWT")
public ResponseEntity<Void> deleteMe(
Authentication authentication
) {
userService.deleteMe(authentication);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import kattsyn.dev.rentplace.dtos.users.UserCreateEditDTO;
import kattsyn.dev.rentplace.dtos.users.UserDTO;
import kattsyn.dev.rentplace.entities.User;
import org.springframework.security.core.Authentication;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
Expand All @@ -18,8 +19,6 @@ public interface UserService {

Optional<User> getUserOptionalByEmail(String email);

boolean existsByEmail(String email);

UserDTO getUserDTOByEmail(String email);

UserDTO findById(Long id);
Expand All @@ -30,6 +29,8 @@ public interface UserService {

void deleteById(long id);

void deleteMe(Authentication authentication);

ImageDTO uploadImage(MultipartFile file, long id);

UserDTO updateUserById(long id, UserCreateEditDTO userCreateEditDTO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import kattsyn.dev.rentplace.services.UserService;
import kattsyn.dev.rentplace.utils.PathResolver;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

Expand Down Expand Up @@ -52,11 +53,6 @@ public Optional<User> getUserOptionalByEmail(String email) {
return userRepository.findByEmail(email);
}

@Override
public boolean existsByEmail(String email) {
return userRepository.findByEmail(email).isPresent();
}

@Override
public UserDTO getUserDTOByEmail(String email) {
return userMapper.fromUser(userRepository.findByEmail(email)
Expand Down Expand Up @@ -99,6 +95,14 @@ public void deleteById(long id) {
userRepository.delete(user);
}

@Override
@Transactional
public void deleteMe(Authentication authentication) {
User user = getUserByEmail(authentication.getName());

userRepository.delete(user);
}

@Transactional
@Override
public ImageDTO uploadImage(MultipartFile file, long id) {
Expand Down
Loading