diff --git a/src/main/java/site/billbill/apiserver/api/users/controller/UserController.java b/src/main/java/site/billbill/apiserver/api/users/controller/UserController.java index 2515b9e..eb8aa15 100644 --- a/src/main/java/site/billbill/apiserver/api/users/controller/UserController.java +++ b/src/main/java/site/billbill/apiserver/api/users/controller/UserController.java @@ -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; @@ -81,8 +82,8 @@ public BaseResponse blacklist(@RequestBody BlacklistRequest request) { @Operation(summary = "회원 탈퇴", description = "회원 탈퇴 API") @ResponseStatus(HttpStatus.OK) @DeleteMapping("/withdraw") - public BaseResponse withdraw() { - userService.withdraw(); + public BaseResponse withdraw(@RequestBody WithdrawRequest request) { + userService.withdraw(request); return new BaseResponse<>(null); } diff --git a/src/main/java/site/billbill/apiserver/api/users/dto/request/WithdrawRequest.java b/src/main/java/site/billbill/apiserver/api/users/dto/request/WithdrawRequest.java new file mode 100644 index 0000000..83940ec --- /dev/null +++ b/src/main/java/site/billbill/apiserver/api/users/dto/request/WithdrawRequest.java @@ -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 code; + @Schema(description = "탈퇴 사유 상세", example = "detail withdraw reason") + private String detail; +} diff --git a/src/main/java/site/billbill/apiserver/api/users/service/UserService.java b/src/main/java/site/billbill/apiserver/api/users/service/UserService.java index 19b2986..66f9cea 100644 --- a/src/main/java/site/billbill/apiserver/api/users/service/UserService.java +++ b/src/main/java/site/billbill/apiserver/api/users/service/UserService.java @@ -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; @@ -21,7 +22,7 @@ public interface UserService { void blockCancel(String userId); - void withdraw(); + void withdraw(WithdrawRequest request); List getPostHistory(Pageable pageable); diff --git a/src/main/java/site/billbill/apiserver/api/users/service/UserServiceImpl.java b/src/main/java/site/billbill/apiserver/api/users/service/UserServiceImpl.java index 2fbfba5..6686a5a 100644 --- a/src/main/java/site/billbill/apiserver/api/users/service/UserServiceImpl.java +++ b/src/main/java/site/billbill/apiserver/api/users/service/UserServiceImpl.java @@ -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; @@ -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); @@ -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 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 diff --git a/src/main/java/site/billbill/apiserver/model/user/WithdrawHistJpaEntity.java b/src/main/java/site/billbill/apiserver/model/user/WithdrawHistJpaEntity.java new file mode 100644 index 0000000..12d4c44 --- /dev/null +++ b/src/main/java/site/billbill/apiserver/model/user/WithdrawHistJpaEntity.java @@ -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 withdrawCode; + @Column(name = "detail") + private String detail; +} diff --git a/src/main/java/site/billbill/apiserver/repository/user/WithdrawHistRepository.java b/src/main/java/site/billbill/apiserver/repository/user/WithdrawHistRepository.java new file mode 100644 index 0000000..75de90b --- /dev/null +++ b/src/main/java/site/billbill/apiserver/repository/user/WithdrawHistRepository.java @@ -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 { +}