Skip to content

Commit

Permalink
[BE] FIX: dev 변경사항 머지
Browse files Browse the repository at this point in the history
  • Loading branch information
enaenen committed Oct 26, 2023
1 parent 2c76240 commit a738ae0
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 232 deletions.
1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.ftclub.cabinet.cabinet.repository;

import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.ftclub.cabinet.cabinet.domain.Cabinet;
Expand All @@ -18,9 +20,6 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

/**
* CabinetService를 위한 ExceptionService
*/
Expand Down Expand Up @@ -62,22 +61,23 @@ public List<ActiveCabinetInfoEntities> findCabinetsActiveLentHistoriesByBuilding
public List<Cabinet> findCabinetsByBuildingAndFloor2(String building, Integer floor) {
return cabinetRepository.findAllCabinetsByBuildingAndFloor(building, floor);
}
/**
* 유저 ID로 사물함을 찾습니다.
*
* @param userId 유저ID
* @return 사물함 엔티티
* @throws ServiceException 사물함을 찾을 수 없는 경우
*/
public Cabinet findLentCabinetByUserId(Long userId) {
log.debug("Called findLentCabinetByUserId: {}", userId);
return cabinetRepository.findLentCabinetByUserId(userId).orElse(null);
}

public List<String> findAllBuildings() {
log.debug("Called findAllBuildings");
return cabinetRepository.findAllBuildings();
}

/**
* 유저 ID로 사물함을 찾습니다.
*
* @param userId 유저ID
* @return 사물함 엔티티
* @throws ServiceException 사물함을 찾을 수 없는 경우
*/
public Cabinet findLentCabinetByUserId(Long userId) {
log.debug("Called findLentCabinetByUserId: {}", userId);
return cabinetRepository.findLentCabinetByUserId(userId).orElse(null);
}

public List<String> findAllBuildings() {
log.debug("Called findAllBuildings");
return cabinetRepository.findAllBuildings();
}

public List<Integer> findAllFloorsByBuilding(String building) {
log.debug("Called findAllFloorsByBuilding: {}", building);
Expand All @@ -90,10 +90,11 @@ public List<String> findAllSectionsByBuildingAndFloor(String building, Integer f
return cabinetRepository.findAllSectionsByBuildingAndFloor(building, floor);
}

public List<Cabinet> findAllPendingCabinetsByCabinetStatusAndBeforeEndedAt(CabinetStatus cabinetStatus, LocalDateTime currentDate) {
log.debug("Called findAllCabinetsByCabinetStatusAndBeforeEndedAt: {}", cabinetStatus);
return cabinetRepository.findAllCabinetsByCabinetStatusAndBeforeEndedAt(cabinetStatus, currentDate);
}
public List<Cabinet> findAllPendingCabinetsByCabinetStatusAndBeforeEndedAt(CabinetStatus cabinetStatus,
LocalDateTime currentDate) {
log.debug("Called findAllCabinetsByCabinetStatusAndBeforeEndedAt: {}", cabinetStatus);
return cabinetRepository.findAllCabinetsByCabinetStatusAndBeforeEndedAt(cabinetStatus, currentDate);
}

public Page<Cabinet> findPaginationByLentType(LentType lentType, PageRequest pageable) {
log.debug("Called findPaginationByLentType: {}", lentType);
Expand All @@ -120,17 +121,6 @@ public List<Cabinet> findAllCabinetsByBuildingAndFloor(String building, Integer
}
/*-------------------------------------------GET--------------------------------------------*/

/**
* 유저 ID로 사물함을 찾습니다.
*
* @param userId 유저ID
* @return 사물함 엔티티
* @throws ServiceException 사물함을 찾을 수 없는 경우
*/
public Cabinet findLentCabinetByUserId(Long userId) {
log.debug("Called findLentCabinetByUserId: {}", userId);
return cabinetRepository.findLentCabinetByUserId(userId).orElse(null);
}

/**
* 사물함 ID로 변경 사항이 예정된 사물함을 찾습니다.
Expand Down Expand Up @@ -189,16 +179,16 @@ public Cabinet getClubCabinet(Long cabinetId) {
return cabinet;
}

/**
* 사물함 ID로 위치(빌딩, 층, 섹션) 정보를 찾습니다.
*
* @param cabinetId 사물함 ID
* @return 위치 엔티티
* @throws ServiceException 사물함을 찾을 수 없는 경우
*/
public Location getLocation(Long cabinetId) {
log.debug("Called getLocation: {}", cabinetId);
return cabinetRepository.findLocationById(cabinetId)
.orElseThrow(() -> new ServiceException(ExceptionStatus.NOT_FOUND_CABINET));
}
/**
* 사물함 ID로 위치(빌딩, 층, 섹션) 정보를 찾습니다.
*
* @param cabinetId 사물함 ID
* @return 위치 엔티티
* @throws ServiceException 사물함을 찾을 수 없는 경우
*/
public Location getLocation(Long cabinetId) {
log.debug("Called getLocation: {}", cabinetId);
return cabinetRepository.findLocationById(cabinetId)
.orElseThrow(() -> new ServiceException(ExceptionStatus.NOT_FOUND_CABINET));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class CabinetProperties {
@Value("${spring.cabinet.lent.term.share}")
private Integer lentTermShare;
@Value("${spring.cabinet.lent.term.extend}")
private Integer lentTermExtend;
private Integer lentExtendTerm;
@Value("${spring.cabinet.penalty.day.share}")
private Integer penaltyDayShare;
@Value("${spring.cabinet.penalty.day.padding}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public void startLentCabinet(
log.info("Called startLentCabinet user: {}, cabinetId: {}", user, cabinetId);
lentFacadeService.startLentCabinet(user.getUserId(), cabinetId);
}

@PostMapping("/cabinets/share/{cabinetId}")
public void startLentShareCabinet(
@UserSession UserSessionDto user,
Expand All @@ -50,13 +49,6 @@ public void startLentShareCabinet(
shareCodeDto.getShareCode());
}

@PatchMapping("/cabinets/extend")
public void extendLentCabinet(
@UserSession UserSessionDto user) {
log.info("Called extendLentCabinet user: {}, cabinetId: {}", user);
lentFacadeService.extendLent(user.getUserId());
}

@PatchMapping("/cabinets/share/cancel/{cabinetId}")
public void cancelLentShareCabinet(
@UserSession UserSessionDto user,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ LentPolicyStatus verifyUserForLentShare(User user, Cabinet cabinet, int userActi
*/
Integer getDaysForLentTermShare(Integer totalUserCount);

/**
* @return 사물함 대여 기간 연장 가능한 날
*/
int getDaysForTermExtend();

/**
* @return 만료가 임박하여 공유 사물함을 빌릴 수 없는 날
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,6 @@ public Integer getDaysForLentTermShare(Integer totalUserCount) {
return cabinetProperties.getLentTermShare() * totalUserCount;
}

@Override
public int getDaysForTermExtend() {
log.debug("Called getDaysForTermExtend");
return cabinetProperties.getLentTermExtend();
}

@Override
public Integer getDaysForNearExpiration() {
log.debug("Called getDaysForNearExpiration");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,4 @@ void updateCabinetInfo(UserSessionDto userSessionDto,
*/
void assignLent(Long userId, Long cabinetId);

/**
* 대여기간을 연장합니다.
*
* @param userId
*/
void extendLent(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,5 @@ public interface LentService {
*
* @param userId
*/
void extendLentCabinet(Long userId);


}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
import org.ftclub.cabinet.cabinet.repository.CabinetOptionalFetcher;
import org.ftclub.cabinet.config.CabinetProperties;
import org.ftclub.cabinet.dto.ActiveLentHistoryDto;
import org.ftclub.cabinet.exception.ExceptionStatus;
import org.ftclub.cabinet.exception.ServiceException;
import org.ftclub.cabinet.lent.domain.LentHistory;
import org.ftclub.cabinet.lent.domain.LentPolicy;
import org.ftclub.cabinet.lent.repository.LentOptionalFetcher;
Expand All @@ -26,7 +24,6 @@
import org.ftclub.cabinet.user.repository.BanHistoryRepository;
import org.ftclub.cabinet.user.repository.UserOptionalFetcher;
import org.ftclub.cabinet.user.service.UserService;
import org.ftclub.cabinet.utils.slackbot.SlackbotManager;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -46,7 +43,6 @@ public class LentServiceImpl implements LentService {
private final LentMapper lentMapper;
private final LentRedis lentRedis;
private final CabinetProperties cabinetProperties;
private final SlackbotManager slackbotManager;


@Override
Expand All @@ -71,7 +67,6 @@ public void startLentCabinet(Long userId, Long cabinetId) {
LentHistory lentHistory = LentHistory.of(now, expiredAt, userId, cabinetId);
lentPolicy.applyExpirationDate(lentHistory, expiredAt);
lentRepository.save(lentHistory);
slackbotManager.sendSlackMessage(user.getName(), cabinet.getVisibleNum(), expiredAt);
}

@Override
Expand Down Expand Up @@ -268,39 +263,6 @@ public List<ActiveLentHistoryDto> getAllActiveLentHistories() {
.collect(Collectors.toList());
}

@Override
public void extendLentCabinet(Long userId) {
log.debug("Called extendLentCabinet: {}, {}", userId);

User user = userOptionalFetcher.getUser(userId);
if (!user.isExtensible()) {
throw new ServiceException(ExceptionStatus.EXTENSION_TICKET_NOT_FOUND);
}

Cabinet lentCabinet = cabinetOptionalFetcher.findLentCabinetByUserId(userId);
if (lentCabinet == null) {
throw new ServiceException(ExceptionStatus.NO_LENT_CABINET);
}

Long cabinetId = lentCabinet.getCabinetId();
List<LentHistory> allActiveLentByCabinetId = lentOptionalFetcher.findAllActiveLentByCabinetId(
cabinetId);
int lentHistorySize = allActiveLentByCabinetId.size();

// 공유사물함에서 1명일 때 연장권 사용 방지
LentType lentType = lentCabinet.getLentType();
if (lentType.equals(LentType.SHARE) && lentHistorySize == 1) {
throw new ServiceException(ExceptionStatus.EXTENSION_SOLO_IN_SHARE_NOT_ALLOWED);
}

LocalDateTime oldExpiredAt = allActiveLentByCabinetId.get(0).getExpiredAt();
allActiveLentByCabinetId.forEach(lentHistory -> {
lentHistory.setExpiredAt(
lentPolicy.generateExtendedExpirationDate(oldExpiredAt));
});
user.setExtensible(false);
}

public void saveLentHistories(LocalDateTime now, Long cabinetId) {
ArrayList<String> userIdList = lentRedis.getUserIdsByCabinetIdInRedis(
cabinetId.toString());
Expand All @@ -315,3 +277,4 @@ public void saveLentHistories(LocalDateTime now, Long cabinetId) {
});
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public interface UserMapper {
@Mapping(target = "userId", source = "user.userId")
@Mapping(target = "cabinetId", source = "cabinet.cabinetId")
MyProfileResponseDto toMyProfileResponseDto(UserSessionDto user, Cabinet cabinet,
BanHistory banHistory, boolean isExtensible);
BanHistory banHistory);

BlockedUserPaginationDto toBlockedUserPaginationDto(List<UserBlockedInfoDto> result,
Long totalLength);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public void issueLentExtension() {
});
}


@Override
public void assignLentExtension(String username) {
log.debug("Called assignLentExtension {}", username);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ public interface UserService {

void updateUserBlackholedAt(Long userId, LocalDateTime newBlackholedAt);

void updateUserExtensible(List<UserMonthDataDto> extensibleUsers);

void banUser(Long userId, LentType lentType, LocalDateTime startedAt, LocalDateTime endedAt,
LocalDateTime expiredAt);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.ftclub.cabinet.dto.UserBlackholeInfoDto;
import org.ftclub.cabinet.lent.service.LentService;
import org.ftclub.cabinet.occupiedtime.OccupiedTimeManager;
import org.ftclub.cabinet.occupiedtime.UserMonthDataDto;
import org.ftclub.cabinet.user.service.UserService;
import org.ftclub.cabinet.utils.blackhole.manager.BlackholeManager;
import org.ftclub.cabinet.utils.leave.absence.LeaveAbsenceManager;
Expand Down Expand Up @@ -99,10 +98,10 @@ public void releasePendingCabinet() {
releaseManager.releasingCabinets();
}

@Scheduled(cron = "${spring.schedule.cron.extensible-user-check}")
public void checkUserQualifyForExtensible(){
log.info("called checkUserQualifyForExtensible");
List<UserMonthDataDto> userMonthDataDtos = occupiedTimeManager.metLimitTimeUser(occupiedTimeManager.getUserLastMonthOccupiedTime());
userService.updateUserExtensible(userMonthDataDtos);
}
// @Scheduled(cron = "${spring.schedule.cron.extensible-user-check}")
// public void checkUserQualifyForExtensible(){
// log.info("called checkUserQualifyForExtensible");
// List<UserMonthDataDto> userMonthDataDtos = occupiedTimeManager.metLimitTimeUser(occupiedTimeManager.getUserLastMonthOccupiedTime());
// userService.updateUserExtensible(userMonthDataDtos);
// }
}
Loading

0 comments on commit a738ae0

Please sign in to comment.