-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 회원 탈퇴 사유 저장 로직 추가 및 cors 관련 재설정 #123
Changes from all commits
e88a298
31d8f2d
31504b3
13f821e
1e3027c
ca9a9df
818dba5
9cf36da
d469ae2
9c1c00e
4b5f29c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package net.teumteum.user.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import net.teumteum.core.entity.TimeBaseEntity; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
@Entity(name = "withdraw_reasons") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class WithdrawReason extends TimeBaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(name = "withdraw_reason", nullable = false) | ||
private String reason; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package net.teumteum.user.domain; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface WithdrawReasonRepository extends JpaRepository<WithdrawReason, Long> { | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package net.teumteum.user.domain.request; | ||
|
||
|
||
import com.fasterxml.jackson.annotation.JsonAutoDetect; | ||
import jakarta.validation.constraints.Size; | ||
import java.util.List; | ||
import net.teumteum.user.domain.WithdrawReason; | ||
|
||
@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY) | ||
public record UserWithdrawRequest( | ||
@Size(min = 1, max = 3, message = "탈퇴 사유는 최소 1개, 최대 3개의 입력값입니다.") | ||
List<String> withdrawReasons | ||
) { | ||
|
||
private static final Long IGNORE_ID = null; | ||
|
||
public List<WithdrawReason> toEntity() { | ||
return withdrawReasons.stream() | ||
.map(withdrawReason -> new WithdrawReason(IGNORE_ID, withdrawReason)) | ||
.toList(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,10 @@ | |
import net.teumteum.user.domain.InterestQuestion; | ||
import net.teumteum.user.domain.User; | ||
import net.teumteum.user.domain.UserRepository; | ||
import net.teumteum.user.domain.WithdrawReasonRepository; | ||
import net.teumteum.user.domain.request.UserRegisterRequest; | ||
import net.teumteum.user.domain.request.UserUpdateRequest; | ||
import net.teumteum.user.domain.request.UserWithdrawRequest; | ||
import net.teumteum.user.domain.response.FriendsResponse; | ||
import net.teumteum.user.domain.response.InterestQuestionResponse; | ||
import net.teumteum.user.domain.response.UserGetResponse; | ||
|
@@ -28,6 +30,7 @@ | |
public class UserService { | ||
|
||
private final UserRepository userRepository; | ||
private final WithdrawReasonRepository withdrawReasonRepository; | ||
private final InterestQuestion interestQuestion; | ||
private final RedisService redisService; | ||
private final JwtService jwtService; | ||
|
@@ -71,11 +74,13 @@ public void addFriends(Long myId, Long friendId) { | |
} | ||
|
||
@Transactional | ||
public void withdraw(Long userId) { | ||
public void withdraw(UserWithdrawRequest request, Long userId) { | ||
var existUser = getUser(userId); | ||
|
||
userRepository.delete(existUser); | ||
redisService.deleteData(String.valueOf(userId)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 트랜잭션안에서 I/O작업과 같이 스레드가 노는 작업 하는건 피해야 합니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 오호 그런 부분까지 생각이 부족했네요 |
||
|
||
withdrawReasonRepository.saveAll(request.toEntity()); | ||
} | ||
|
||
@Transactional | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
create table if not exists withdraw_reason | ||
( | ||
id bigint not null auto_increment, | ||
withdraw_reason varchar(30) not null, | ||
created_at timestamp(6) not null, | ||
updated_at timestamp(6) not null, | ||
primary key (id) | ||
Comment on lines
+3
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UserEntity 참조는 어디서 진행되고 있나요?? 제가 잘못이해한거면 그냥 넘겨주세요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이거 탈퇴사유가 서비스의 탈퇴 사유 데이터 수집을 순수하게 수집하는 목적으로 이해해서 유저의 id 을 포하시키지 않았습니다 |
||
); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
drop table withdraw_reason; | ||
|
||
create table if not exists withdraw_reasons | ||
( | ||
id bigint not null auto_increment, | ||
withdraw_reason varchar(30) not null, | ||
created_at timestamp(6) not null, | ||
updated_at timestamp(6) not null, | ||
primary key (id) | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
withdraw에서 id참조로 유저를 바라보게 되면, 소프트 삭제를 진행해야 할거 같아요.
다만, 이렇게하면 모든 조회에 소프트 삭제된 유저는 조회하지 않는 조건이 들어가게됩니다. 이게 번거롭다면, withdraw필드에 유저 정보를 반정규화 해서 저장해도 됩니다. (id 참조가 아닌 유저 정보를 모두 풀어서 withdraw 테이블에 카피해서 저장)