Skip to content

Commit 4fb40d8

Browse files
authored
Merge pull request #114 from Recipe-Project/fix/user_withdraw
Fix/user withdraw
2 parents dca8e64 + dd933c5 commit 4fb40d8

17 files changed

Lines changed: 306 additions & 102 deletions

File tree

src/main/java/com/recipe/app/src/common/config/JwtFilter.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ public class JwtFilter extends GenericFilterBean {
2929
@Override
3030
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
3131

32-
System.out.println(jwtUtil.createAccessToken(18L));
33-
3432
String accessToken = jwtUtil.resolveAccessToken((HttpServletRequest) request);
3533
String requestURI = ((HttpServletRequest) request).getRequestURI();
3634

src/main/java/com/recipe/app/src/common/entity/BaseEntity.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,15 @@ public abstract class BaseEntity {
2525
@Column(name = "updatedAt", nullable = false)
2626
private LocalDateTime updatedAt = LocalDateTime.now();
2727

28+
@Column(name = "deletedAt")
29+
private LocalDateTime deletedAt;
30+
31+
public void markAsDeleted() {
32+
this.deletedAt = LocalDateTime.now();
33+
}
34+
35+
public boolean isDeleted() {
36+
return this.deletedAt != null;
37+
}
38+
2839
}

src/main/java/com/recipe/app/src/ingredient/application/IngredientService.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,6 @@ public IngredientCreateResponse create(Long userId, IngredientRequest request) {
5151
return new IngredientCreateResponse(ingredient.getIngredientId());
5252
}
5353

54-
@Transactional
55-
public void deleteAllByUserId(long userId) {
56-
57-
List<Ingredient> ingredients = ingredientRepository.findByUserId(userId);
58-
59-
ingredientRepository.deleteAll(ingredients);
60-
}
61-
6254
@Transactional(readOnly = true)
6355
public Ingredient findByIngredientId(Long ingredientId) {
6456

src/main/java/com/recipe/app/src/recipe/application/RecipeService.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,6 @@ private Recipe findByUserIdAndRecipeId(User user, Long recipeId) {
8585
});
8686
}
8787

88-
@Transactional
89-
public void deleteAllByUserId(long userId) {
90-
91-
List<Recipe> recipes = recipeRepository.findByUserId(userId);
92-
93-
recipeScrapService.deleteAllByUserId(userId);
94-
recipeViewService.deleteAllByUserId(userId);
95-
recipeRepository.deleteAll(recipes);
96-
}
97-
9888
@Transactional(readOnly = true)
9989
public long countRecipeScrapByUserId(long userId) {
10090

src/main/java/com/recipe/app/src/user/api/UserController.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.recipe.app.src.user.application.dto.UserSocialLoginResponse;
1212
import com.recipe.app.src.user.application.dto.UserTokenRefreshRequest;
1313
import com.recipe.app.src.user.application.dto.UserTokenRefreshResponse;
14+
import com.recipe.app.src.user.application.dto.UserWithdrawRequest;
1415
import com.recipe.app.src.user.domain.User;
1516
import io.swagger.v3.oas.annotations.Operation;
1617
import io.swagger.v3.oas.annotations.Parameter;
@@ -106,9 +107,12 @@ public void patchUser(@Parameter(hidden = true) User user,
106107
@Operation(summary = "회원 탈퇴 API")
107108
@DeleteMapping
108109
@LoginCheck
109-
public void deleteUser(HttpServletRequest request, @Parameter(hidden = true) User user) {
110+
public void deleteUser(HttpServletRequest request,
111+
@Parameter(hidden = true) User user,
112+
@Parameter(name = "회원 탈퇴 요청 정보")
113+
@RequestBody(required = false) UserWithdrawRequest withdrawRequest) {
110114

111-
userFacadeService.deleteUser(user, request);
115+
userFacadeService.deleteUser(user, request, withdrawRequest);
112116
}
113117

114118
@Operation(summary = "로그아웃 API")

src/main/java/com/recipe/app/src/user/application/UserFacadeService.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33
import com.recipe.app.src.fridge.application.FridgeService;
44
import com.recipe.app.src.fridgeBasket.application.FridgeBasketService;
55
import com.recipe.app.src.ingredient.application.IngredientService;
6+
import com.recipe.app.src.recipe.application.RecipeScrapService;
67
import com.recipe.app.src.recipe.application.RecipeSearchService;
78
import com.recipe.app.src.recipe.application.RecipeService;
9+
import com.recipe.app.src.recipe.application.RecipeViewService;
810
import com.recipe.app.src.recipe.application.blog.BlogScrapService;
911
import com.recipe.app.src.recipe.application.blog.BlogViewService;
1012
import com.recipe.app.src.recipe.application.youtube.YoutubeScrapService;
1113
import com.recipe.app.src.recipe.application.youtube.YoutubeViewService;
1214
import com.recipe.app.src.recipe.domain.Recipe;
1315
import com.recipe.app.src.user.application.dto.UserProfileResponse;
16+
import com.recipe.app.src.user.application.dto.UserWithdrawRequest;
1417
import com.recipe.app.src.user.domain.User;
1518
import jakarta.servlet.http.HttpServletRequest;
1619
import org.springframework.stereotype.Service;
@@ -24,6 +27,8 @@ public class UserFacadeService {
2427
private final UserService userService;
2528
private final RecipeService recipeService;
2629
private final RecipeSearchService recipeSearchService;
30+
private final RecipeScrapService recipeScrapService;
31+
private final RecipeViewService recipeViewService;
2732
private final YoutubeScrapService youtubeScrapService;
2833
private final YoutubeViewService youtubeViewService;
2934
private final BlogScrapService blogScrapService;
@@ -35,13 +40,16 @@ public class UserFacadeService {
3540
private static final int USER_PROFILE_RECIPE_CNT = 6;
3641

3742
public UserFacadeService(UserService userService, RecipeService recipeService, RecipeSearchService recipeSearchService,
43+
RecipeScrapService recipeScrapService, RecipeViewService recipeViewService,
3844
YoutubeScrapService youtubeScrapService, YoutubeViewService youtubeViewService,
3945
BlogScrapService blogScrapService, BlogViewService blogViewService,
4046
FridgeService fridgeService, FridgeBasketService fridgeBasketService, IngredientService ingredientService) {
4147

4248
this.userService = userService;
4349
this.recipeService = recipeService;
4450
this.recipeSearchService = recipeSearchService;
51+
this.recipeScrapService = recipeScrapService;
52+
this.recipeViewService = recipeViewService;
4553
this.youtubeScrapService = youtubeScrapService;
4654
this.youtubeViewService = youtubeViewService;
4755
this.blogScrapService = blogScrapService;
@@ -64,17 +72,17 @@ public UserProfileResponse findUserProfile(User user) {
6472
}
6573

6674
@Transactional
67-
public void deleteUser(User user, HttpServletRequest request) {
75+
public void deleteUser(User user, HttpServletRequest request, UserWithdrawRequest withdrawRequest) {
6876

6977
fridgeService.deleteAllByUserId(user.getUserId());
7078
fridgeBasketService.deleteAllByUserId(user.getUserId());
71-
recipeService.deleteAllByUserId(user.getUserId());
72-
ingredientService.deleteAllByUserId(user.getUserId());
79+
recipeScrapService.deleteAllByUserId(user.getUserId());
80+
recipeViewService.deleteAllByUserId(user.getUserId());
7381
youtubeScrapService.deleteAllByUserId(user.getUserId());
7482
youtubeViewService.deleteAllByUserId(user.getUserId());
7583
blogScrapService.deleteAllByUserId(user.getUserId());
7684
blogViewService.deleteAllByUserId(user.getUserId());
7785

78-
userService.withdraw(user, request);
86+
userService.withdraw(user, request, withdrawRequest);
7987
}
8088
}

src/main/java/com/recipe/app/src/user/application/UserService.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.recipe.app.src.user.application.dto.UserSocialLoginResponse;
1111
import com.recipe.app.src.user.application.dto.UserTokenRefreshRequest;
1212
import com.recipe.app.src.user.application.dto.UserTokenRefreshResponse;
13+
import com.recipe.app.src.user.application.dto.UserWithdrawRequest;
1314
import com.recipe.app.src.user.domain.User;
1415
import com.recipe.app.src.user.exception.NotFoundUserException;
1516
import com.recipe.app.src.user.exception.UserTokenNotExistException;
@@ -30,12 +31,15 @@ public class UserService {
3031
private final JwtUtil jwtUtil;
3132
private final BadWordFiltering badWordFiltering;
3233
private final UserAuthClientService userAuthClientService;
34+
private final UserWithdrawalService userWithdrawalService;
3335

34-
public UserService(UserRepository userRepository, JwtUtil jwtUtil, BadWordFiltering badWordFiltering, UserAuthClientService userAuthClientService) {
36+
public UserService(UserRepository userRepository, JwtUtil jwtUtil, BadWordFiltering badWordFiltering,
37+
UserAuthClientService userAuthClientService, UserWithdrawalService userWithdrawalService) {
3538
this.userRepository = userRepository;
3639
this.jwtUtil = jwtUtil;
3740
this.badWordFiltering = badWordFiltering;
3841
this.userAuthClientService = userAuthClientService;
42+
this.userWithdrawalService = userWithdrawalService;
3943
}
4044

4145
@Transactional(readOnly = true)
@@ -127,11 +131,17 @@ public void update(User user, UserProfileRequest request) {
127131
}
128132

129133
@Transactional
130-
public void withdraw(User user, HttpServletRequest request) {
134+
public void withdraw(User user, HttpServletRequest request, UserWithdrawRequest withdrawRequest) {
131135

132-
userRepository.delete(user);
136+
user.maskPersonalInfo();
137+
user.markAsDeleted();
138+
userRepository.save(user);
133139

134140
logout(request);
141+
142+
if (withdrawRequest != null && StringUtils.hasText(withdrawRequest.getWithdrawalReason())) {
143+
userWithdrawalService.saveWithdrawalReason(user.getUserId(), withdrawRequest.getWithdrawalReason());
144+
}
135145
}
136146

137147
@Transactional
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.recipe.app.src.user.application;
2+
3+
import com.recipe.app.src.user.domain.UserWithdrawal;
4+
import com.recipe.app.src.user.infra.UserWithdrawalRepository;
5+
import org.springframework.stereotype.Service;
6+
import org.springframework.transaction.annotation.Transactional;
7+
8+
@Service
9+
public class UserWithdrawalService {
10+
11+
private final UserWithdrawalRepository userWithdrawalRepository;
12+
13+
public UserWithdrawalService(UserWithdrawalRepository userWithdrawalRepository) {
14+
this.userWithdrawalRepository = userWithdrawalRepository;
15+
}
16+
17+
@Transactional
18+
public void saveWithdrawalReason(Long userId, String withdrawalReason) {
19+
20+
UserWithdrawal userWithdrawal = UserWithdrawal.builder()
21+
.userId(userId)
22+
.withdrawalReason(withdrawalReason)
23+
.build();
24+
25+
userWithdrawalRepository.save(userWithdrawal);
26+
}
27+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.recipe.app.src.user.application.dto;
2+
3+
import lombok.Getter;
4+
import lombok.NoArgsConstructor;
5+
6+
@Getter
7+
@NoArgsConstructor
8+
public class UserWithdrawRequest {
9+
10+
private String withdrawalReason;
11+
}

src/main/java/com/recipe/app/src/user/domain/User.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,12 @@ public void changeDeviceToken(String deviceToken) {
8787

8888
this.deviceToken = deviceToken;
8989
}
90+
91+
public void maskPersonalInfo() {
92+
this.email = null;
93+
this.phoneNumber = null;
94+
this.nickname = "탈퇴한 사용자";
95+
this.profileImgUrl = ProfileImage.getInitProfileImgUrl();
96+
this.deviceToken = null;
97+
}
9098
}

0 commit comments

Comments
 (0)