Skip to content

Commit

Permalink
Merge pull request #47 from jkuznik/Task-41-Remove-phone-number
Browse files Browse the repository at this point in the history
Task-41-Remove-phone-number
  • Loading branch information
Slawek84PL authored Nov 20, 2024
2 parents 5b7f262 + 00df466 commit f42dbf3
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/pl/ateam/disasteralerts/user/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class User extends EntityAudit {
private String email;

@Pattern(
regexp = "^(\\+48)?\\d{9}$",
regexp = "^(|\\+48\\d{9})$",
message = "Nieprawidłowy format numeru telefonu"
)
private String phoneNumber;
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/pl/ateam/disasteralerts/user/UserFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@ public UserUpdateDTO getUserForUpdate(UUID userId) {
public void updateUser(UserUpdateDTO userUpdateDto, UUID userId) {
userService.updateUserEntity(userUpdateDto, userId);
}

public void removePhoneNumber(String email) {
userService.removePhoneNumber(email);
}
}
6 changes: 6 additions & 0 deletions src/main/java/pl/ateam/disasteralerts/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public void save(UserRegisterDTO userRegisterDTO) {

}

@Transactional
public void removePhoneNumber(String email) {
User user = findUserByEmail(email);
user.setPhoneNumber("");
}

public void saveAll(Collection<User> users) {
userRepository.saveAll(users);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public record UserUpdateDTO(
String email,

@Pattern(
regexp = "^(\\+48)?\\d{9}$",
regexp = "^(|\\+48\\d{9})$",
message = "Nieprawidłowy format numeru telefonu")
String phoneNumber,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ public String updateUser(@AuthenticationPrincipal AppUser appUser,
return "redirect:/disasters/add";
}

@GetMapping("removePhoneNumber")
public String removePhoneNumber(@AuthenticationPrincipal AppUser appUser,
RedirectAttributes redirectAttributes) {

userFacade.removePhoneNumber(appUser.getUsername());
redirectAttributes.addFlashAttribute("message", "Numer telefonu został usunięty");
return "redirect:/users/edit";
}

private void baseModel(Model model, UserUpdateDTO userUpdateDto) {
model.addAttribute("selectedLocation", userUpdateDto.location());
model.addAttribute("cities", CitiesInPoland.getList());
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/templates/fragments.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta charset="UTF-8">
<title th:text="*{pageTitle}">DisasterAlerts</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
</head>
<body>
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/templates/updateUser.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ <h1 class="display-4 fw-bold lh-1 text-body-emphasis mb-3">Aktualizacja danych</
<label for="phoneNumber" class="form-label">Numer Telefonu</label>
<div class="input-group">
<input th:value="*{phoneNumber}" name="phoneNumber" type="text" class="form-control" id="phoneNumber" placeholder="+48.........">
<a th:if="*{phoneNumber() != ''}" role="button" class="btn btn-danger ms-2" href='/users/removePhoneNumber' methods="POST">
<i class="bi bi-trash"></i> Usuń numer telefonu
</a>
</div>
<div class="invalid-feedback">
Nieprawidłowy format numeru telefonu
Expand Down

0 comments on commit f42dbf3

Please sign in to comment.