Skip to content

Commit

Permalink
[PDS-213] fix: 기획변경으로 인한 회원탈퇴 로직 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
chaerlo127 committed Nov 30, 2023
1 parent 0d9a7a3 commit 8c6d22e
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ public interface CarBookingCustom {
List<String> getBookedTime(Car car, LocalDate date);

List<ProductBookingRes> findCarBookingByDate(Car car, LocalDate date);
void updateBookingStatusForResigning(User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;

import javax.persistence.EntityManager;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
Expand All @@ -28,6 +29,7 @@
@RequiredArgsConstructor
public class CarBookingRepositoryImpl implements CarBookingCustom {
private final JPAQueryFactory jpaQueryFactory;
private final EntityManager entityManager;

@Override
public boolean existsDateTime(Car car, LocalDateTime startDateTime, LocalDateTime endDateTime) {
Expand Down Expand Up @@ -210,4 +212,17 @@ public List<ProductBookingRes> findCarBookingByDate(Car car, LocalDate standardD

return bookings.stream().map(ProductBookingRes::toDto).collect(Collectors.toList());
}

// 회원 탈퇴를 위한 예약 상태 변경
@Override
public void updateBookingStatusForResigning(User user) {
jpaQueryFactory.update(carBooking)
.set(carBooking.status, BookingStatus.CANCELED)
.where(carBooking.user.eq(user)
.and(carBooking.status.in(BookingStatus.WAITING, BookingStatus.BOOKED, BookingStatus.USING)))
.execute();

// 영속성 컨텍스트를 DB 에 즉시 반영
entityManager.flush();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.pladialmserver.global.entityListener;

import com.example.pladialmserver.booking.repository.carBooking.CarBookingRepository;
import com.example.pladialmserver.booking.repository.officeBooking.OfficeBookingRepository;
import com.example.pladialmserver.booking.repository.resourceBooking.ResourceBookingRepository;
import com.example.pladialmserver.global.utils.BeanUtil;
Expand All @@ -16,5 +17,8 @@ public void onUpdate(User user){
// 자원 예약 확인 및 예약 취소
ResourceBookingRepository resourceBookingRepository = BeanUtil.getBean(ResourceBookingRepository.class);
resourceBookingRepository.updateBookingStatusForResigning(user);
// 차량 예약 확인 및 예약 취소
CarBookingRepository carBookingRepository = BeanUtil.getBean(CarBookingRepository.class);
carBookingRepository.updateBookingStatusForResigning(user);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public enum BaseResponseCode {
EXISTS_PHONE("U0019", HttpStatus.CONFLICT, "존재하는 휴대폰번호입니다."),
NOT_EMPTY_AFFILIATION("U0020", HttpStatus.BAD_REQUEST, "소속을 입력해주세요."),
AFFILIATION_NOT_FOUND("U0021", HttpStatus.NOT_FOUND, "소속을 찾을 수 없습니다."),
EXISTS_CAR_AMDIN_USER("U0022", HttpStatus.BAD_REQUEST, "차량을 관리하는 직원입니다. 관리자를 변경해주세요."),
EXISTS_RESOURCE_AMDIN_USER("U0023", HttpStatus.BAD_REQUEST, "장비을 관리하는 직원입니다. 관리자를 변경해주세요."),

// Booking
DATE_OR_TIME_IS_NULL("B0001", HttpStatus.BAD_REQUEST, "날짜와 시간을 모두 입력해주세요."),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.pladialmserver.product.car.repository;

import com.example.pladialmserver.product.car.entity.Car;
import com.example.pladialmserver.user.entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -26,4 +27,5 @@ public interface CarRepository extends JpaRepository<Car, Long>,CarCustom {
Page<Car> findAllByIsEnableTrueAndIsActiveTrue(Pageable pageable);

Optional<Car> findByCarIdAndIsEnable(Long carId, boolean isEnable);
Boolean existsByUserAndIsEnable(User user, Boolean isEnable);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.pladialmserver.product.resource.repository;

import com.example.pladialmserver.product.resource.entity.Resource;
import com.example.pladialmserver.user.entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
Expand Down Expand Up @@ -32,4 +33,6 @@ public interface ResourceRepository extends JpaRepository<Resource, Long>, Resou
"WHERE r.isEnable = true AND r.isActive = true")
Page<Resource> findAllByIsEnableTrueAndIsActiveTrue(Pageable pageable);

Boolean existsByUserAndIsEnable(User user, Boolean isEnable);

}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public ResponseCustom<UserRes> getUserInfo(@Account User user,
@Operation(summary = "직원 탈퇴 (장채은)", description = "직원을 탈퇴 시킨다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "(S0001)직원 탈퇴 성공"),
@ApiResponse(responseCode = "400", description = "(U0022)차량을 관리하는 직원입니다. 관리자를 변경해주세요.\n (U0023)장비을 관리하는 직원입니다. 관리자를 변경해주세요."),
@ApiResponse(responseCode = "403", description = "(G0002)접근 권한이 없습니다.", content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
@ApiResponse(responseCode = "404", description = "(U0001)사용자를 찾을 수 없습니다.[관리자 및 직원 모두]", content = @Content(schema = @Schema(implementation = ResponseCustom.class)))
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public ResponseCustom<ResponsibilityListRes> getResponsibilityList(
@Operation(summary = "직원 탈퇴 (장채은)", description = "직원을 탈퇴한다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "(S0001)직원 탈퇴 성공"),
@ApiResponse(responseCode = "400", description = "(U0022)차량을 관리하는 직원입니다. 관리자를 변경해주세요.\n (U0023)장비을 관리하는 직원입니다. 관리자를 변경해주세요."),
@ApiResponse(responseCode = "404", description = "(U0001)사용자를 찾을 수 없습니다.", content = @Content(schema = @Schema(implementation = ResponseCustom.class)))
})
@DeleteMapping("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.example.pladialmserver.global.utils.JwtUtil;
import com.example.pladialmserver.notification.entity.PushNotification;
import com.example.pladialmserver.notification.repository.PushNotificationRepository;
import com.example.pladialmserver.product.car.repository.CarRepository;
import com.example.pladialmserver.product.resource.repository.ResourceRepository;
import com.example.pladialmserver.user.dto.TokenDto;
import com.example.pladialmserver.user.dto.request.*;
import com.example.pladialmserver.user.dto.response.DepartmentListDto;
Expand Down Expand Up @@ -42,6 +44,8 @@ public class UserService {
private final UserRepository userRepository;
private final DepartmentRepository departmentRepository;
private final PushNotificationRepository notificationRepository;
private final CarRepository carRepository;
private final ResourceRepository resourceRepository;
private final AffiliationRepository affiliationRepository;
private final PasswordEncoder passwordEncoder;
private final JwtUtil jwtUtil;
Expand Down Expand Up @@ -116,6 +120,9 @@ public ResponsibilityListRes getResponsibilityList(String name) {
}
// 직원 접근 탈퇴
public void resignUser(User user) {
// 탈회하려는 회원이 장비, 차량 관리자인 경우 애러처리
if (resourceRepository.existsByUserAndIsEnable(user, true)) throw new BaseException(EXISTS_RESOURCE_AMDIN_USER);
if (carRepository.existsByUserAndIsEnable(user, true)) throw new BaseException(EXISTS_CAR_AMDIN_USER);
jwtUtil.deleteRefreshToken(user.getUserId());
userRepository.delete(user);
}
Expand Down

0 comments on commit 8c6d22e

Please sign in to comment.