Skip to content

Commit

Permalink
[feat] 회원 탈퇴 API 탈퇴 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ksj000625 committed Dec 17, 2024
1 parent 9ad77ca commit 4891deb
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import site.billbill.apiserver.api.auth.dto.request.LocationRequest;
import site.billbill.apiserver.api.users.dto.request.BlacklistRequest;
import site.billbill.apiserver.api.users.dto.request.PasswordRequest;
import site.billbill.apiserver.api.users.dto.request.WithdrawRequest;
import site.billbill.apiserver.api.users.dto.response.*;
import site.billbill.apiserver.api.users.service.UserService;
import site.billbill.apiserver.common.response.BaseResponse;
Expand Down Expand Up @@ -81,8 +82,8 @@ public BaseResponse<String> blacklist(@RequestBody BlacklistRequest request) {
@Operation(summary = "회원 탈퇴", description = "회원 탈퇴 API")
@ResponseStatus(HttpStatus.OK)
@DeleteMapping("/withdraw")
public BaseResponse<String> withdraw() {
userService.withdraw();
public BaseResponse<String> withdraw(@RequestBody WithdrawRequest request) {
userService.withdraw(request);
return new BaseResponse<>(null);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package site.billbill.apiserver.api.users.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.List;

@Data
public class WithdrawRequest {
@Schema(description = "탈퇴 사유 코드", type = "array",example = "[\"TOO_EXPENSIVE\", \"ETC\"]")
private List<String> code;
@Schema(description = "탈퇴 사유 상세", example = "detail withdraw reason")
private String detail;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import site.billbill.apiserver.api.auth.dto.request.DeviceRequest;
import site.billbill.apiserver.api.auth.dto.request.LocationRequest;
import site.billbill.apiserver.api.users.dto.request.PasswordRequest;
import site.billbill.apiserver.api.users.dto.request.WithdrawRequest;
import site.billbill.apiserver.api.users.dto.response.*;
import site.billbill.apiserver.common.utils.posts.ItemHistoryType;
import site.billbill.apiserver.model.common.CodeDetailJpaEntity;
Expand All @@ -21,7 +22,7 @@ public interface UserService {

void blockCancel(String userId);

void withdraw();
void withdraw(WithdrawRequest request);

List<PostHistoryResponse> getPostHistory(Pageable pageable);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,17 @@
import site.billbill.apiserver.api.auth.dto.request.DeviceRequest;
import site.billbill.apiserver.api.auth.dto.request.LocationRequest;
import site.billbill.apiserver.api.users.dto.request.PasswordRequest;
import site.billbill.apiserver.api.users.dto.request.WithdrawRequest;
import site.billbill.apiserver.api.users.dto.response.*;
import site.billbill.apiserver.common.enums.exception.ErrorCode;
import site.billbill.apiserver.common.utils.jwt.JWTUtil;
import site.billbill.apiserver.common.utils.posts.ItemHistoryType;
import site.billbill.apiserver.exception.CustomException;
import site.billbill.apiserver.model.common.CodeDetailJpaEntity;
import site.billbill.apiserver.model.user.UserBlacklistJpaEntity;
import site.billbill.apiserver.model.user.UserDeviceJpaEntity;
import site.billbill.apiserver.model.user.UserIdentityJpaEntity;
import site.billbill.apiserver.model.user.UserJpaEntity;
import site.billbill.apiserver.model.user.UserLocationJpaEntity;
import site.billbill.apiserver.model.user.*;
import site.billbill.apiserver.repository.borrowPosts.ItemsRepository;
import site.billbill.apiserver.repository.common.CodeDetailRepository;
import site.billbill.apiserver.repository.user.UserBlacklistRepository;
import site.billbill.apiserver.repository.user.UserDeviceRepository;
import site.billbill.apiserver.repository.user.UserIdentityRepository;
import site.billbill.apiserver.repository.user.UserLocationReposity;
import site.billbill.apiserver.repository.user.UserRepository;
import site.billbill.apiserver.repository.user.*;

import java.util.List;
import java.util.Objects;
Expand All @@ -51,6 +44,7 @@ public class UserServiceImpl implements UserService {
private final UserLocationReposity userLocationRepository;
private final UserDeviceRepository userDeviceRepository;
private final CodeDetailRepository codeDetailRepository;
private final WithdrawHistRepository withdrawHistRepository;

private final GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), 4326);

Expand Down Expand Up @@ -122,14 +116,21 @@ public void blockCancel(String userId) {

@Override
@Transactional
public void withdraw() {
public void withdraw(WithdrawRequest request) {
String userId = MDC.get(JWTUtil.MDC_USER_ID);

Optional<UserJpaEntity> user = userRepository.findById(userId);

if (user.isEmpty()) throw new CustomException(ErrorCode.NotFound, "존재하지 않는 회원입니다.", HttpStatus.NOT_FOUND);

userRepository.withdrawUserById(userId);

WithdrawHistJpaEntity withdrawHist = WithdrawHistJpaEntity.builder()
.user(user.get())
.withdrawCode(request.getCode())
.detail(request.getDetail())
.build();

withdrawHistRepository.save(withdrawHist);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package site.billbill.apiserver.model.user;

import jakarta.persistence.*;
import lombok.*;
import site.billbill.apiserver.common.converter.StringListConverter;
import site.billbill.apiserver.model.BaseTime;

import java.util.List;

@Entity
@Table(name = "withdraw_hist")
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WithdrawHistJpaEntity extends BaseTime {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "withdraw_seq", nullable = false)
private Long withdrawSeq;
@ManyToOne
@JoinColumn(name = "user_id")
private UserJpaEntity user;
@Convert(converter = StringListConverter.class)
@Column(name = "withdraw_code", nullable = false)
private List<String> withdrawCode;
@Column(name = "detail")
private String detail;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package site.billbill.apiserver.repository.user;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import site.billbill.apiserver.model.user.WithdrawHistJpaEntity;

@Repository
public interface WithdrawHistRepository extends JpaRepository<WithdrawHistJpaEntity, Long> {
}

0 comments on commit 4891deb

Please sign in to comment.