Skip to content

Commit

Permalink
Merge pull request #1311 from innovationacademy-kr/fe/dev/hotfix_bloc…
Browse files Browse the repository at this point in the history
…k_lent_if_exists/#1310

[FE] HOTFIX: 사물함 대여 존재 시 타 사물함 대여 불가
  • Loading branch information
YESHYUNGSEOK authored Aug 18, 2023
2 parents fcb5acc + 41be6c7 commit 2b18373
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 28 deletions.
10 changes: 5 additions & 5 deletions backend/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ services:
build: ./
restart: always
environment:
MARIADB_DATABASE_HOST: ${HOST}
MARIADB_DATABASE: ${DATABASE}
MARIADB_USER: ${DB_USER}
MARIADB_PASSWORD: ${DB_PASSWORD}
MARIADB_ROOT_PASSWORD: ${ROOT_PASSWORD}
MARIADB_DATABASE_HOST: localhost
MARIADB_DATABASE: cabi_local
MARIADB_USER: root
MARIADB_PASSWORD: YourPassword
MARIADB_ROOT_PASSWORD: YourPassword
ports:
- '3307:3306'
tty: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public List<BuildingFloorsDto> getBuildingFloorsResponse() {
public List<CabinetsPerSectionResponseDto> getCabinetsPerSection(
@PathVariable("building") String building,
@PathVariable("floor") Integer floor) {
log.info("Called getCabinetsPerSection building : {} floor : {}", building, floor);
return cabinetFacadeService.getCabinetsPerSection(building, floor);
log.info("Called getCabinetsPerSection");
return cabinetFacadeService.getCabinetsPerSectionRefactor(building, floor);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.ftclub.cabinet.cabinet.repository;

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 @@ -17,9 +19,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
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package org.ftclub.cabinet.cabinet.repository;

import java.util.List;
import java.util.Optional;
import javax.persistence.LockModeType;
import org.ftclub.cabinet.cabinet.domain.Cabinet;
import org.ftclub.cabinet.cabinet.domain.CabinetStatus;
import org.ftclub.cabinet.cabinet.domain.LentType;
Expand All @@ -13,10 +16,6 @@
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.persistence.LockModeType;
import java.util.List;
import java.util.Optional;

@Repository
public interface CabinetRepository extends JpaRepository<Cabinet, Long> {

Expand Down Expand Up @@ -98,6 +97,7 @@ Page<Cabinet> findPaginationByVisibleNum(@Param("visibleNum") Integer visibleNum
List<Object[]> findCabinetActiveLentHistoryUserListByBuildingAndFloor(
@Param("building") String building, @Param("floor") Integer floor);


@EntityGraph(attributePaths = {"cabinetPlace"})
@Query("SELECT c " +
"FROM Cabinet c " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
import org.ftclub.cabinet.dto.CabinetStatusRequestDto;
import org.ftclub.cabinet.dto.CabinetsPerSectionResponseDto;
import org.ftclub.cabinet.dto.LentHistoryPaginationDto;
import org.ftclub.cabinet.dto.*;

import java.util.List;

public interface CabinetFacadeService {

Expand Down Expand Up @@ -52,6 +49,8 @@ public interface CabinetFacadeService {
*/
List<CabinetsPerSectionResponseDto> getCabinetsPerSection(String building, Integer floor);

List<CabinetsPerSectionResponseDto> getCabinetsPerSectionRefactor(String building, Integer floor);

/**
* 사물함의 상태 메모를 업데이트합니다.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,33 @@ public List<CabinetsPerSectionResponseDto> getCabinetsPerSection(String building
.collect(Collectors.toList());
}

@Override
public List<CabinetsPerSectionResponseDto> getCabinetsPerSectionRefactor(String building,
Integer floor) {
List<Cabinet> cabinets = cabinetOptionalFetcher.findAllCabinetsByBuildingAndFloor(building, floor);
Map<String, List<CabinetPreviewDto>> map = new HashMap<>();
cabinets.forEach(cabinet -> {
List<LentHistory> lentHistories = lentOptionalFetcher
.findActiveLentByCabinetIdWithUser(cabinet.getCabinetId());
String section = cabinet.getCabinetPlace().getLocation().getSection();
if (map.containsKey(section)) {
map.get(section).add(cabinetMapper.toCabinetPreviewDto(cabinet, lentHistories.size(),
lentHistories.isEmpty() ? null : lentHistories.get(0).getUser().getName()));
}
else {
List<CabinetPreviewDto> cabinetPreviewDtoList = new ArrayList<>();
cabinetPreviewDtoList.add(cabinetMapper.toCabinetPreviewDto(cabinet, lentHistories.size(),
lentHistories.isEmpty() ? null : lentHistories.get(0).getUser().getName()));
map.put(section, cabinetPreviewDtoList);
}
});
map.forEach((key, value) -> value.sort(Comparator.comparing(CabinetPreviewDto::getVisibleNum)));
return map.entrySet().stream()
.sorted(Comparator.comparing(entry -> entry.getValue().get(0).getVisibleNum()))
.map(entry -> cabinetMapper.toCabinetsPerSectionResponseDto(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());
}

private CabinetPreviewDto createCabinetPreviewDto(Cabinet cabinet, List<LentHistory> lentHistories) {
String lentUserName = null;
if (!lentHistories.isEmpty() && lentHistories.get(0).getUser() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public List<LentHistory> findAllActiveLentByCabinetId(Long cabinetId) {
return lentRepository.findAllActiveLentByCabinetId(cabinetId);
}

public List<LentHistory> findActiveLentByCabinetIdWithUser(Long cabinetId) {
log.info("Called findActiveLentByCabinetIdWithUser: {}", cabinetId);
return lentRepository.findActiveLentHistoriesByCabinetIdWithUser(cabinetId);
}

public Page<LentHistory> findPaginationByCabinetId(Long cabinetId, PageRequest pageable) {
log.debug("Called findPaginationByCabinetId: {}", cabinetId);
return lentRepository.findPaginationByCabinetId(cabinetId, pageable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ List<LentHistory> findByUserIdAndEndedAtNotNull(@Param("userId") Long userId,
"WHERE lh.cabinetId = :cabinetId and lh.endedAt is null")
List<LentHistory> findAllActiveLentByCabinetId(@Param("cabinetId") Long cabinetId);

@Query("SELECT lh " +
"FROM LentHistory lh " +
"LEFT JOIN FETCH lh.user " +
"WHERE lh.cabinetId = :cabinetId and lh.endedAt is null")
List<LentHistory> findActiveLentHistoriesByCabinetIdWithUser(@Param("cabinetId") Long cabinetId);

@Query("SELECT lh " +
"FROM LentHistory lh " +
"WHERE lh.cabinetId = :cabinetId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
@Disabled
class CabinetApplicationTests {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const CabinetInfoArea: React.FC<{
theme="fill"
disabled={!isAvailable || selectedCabinetInfo.lentType === "CLUB"}
/>
<ButtonContainer onClick={closeCabinet} text="취소" theme="line" />
<ButtonContainer onClick={closeCabinet} text="닫기" theme="line" />
</>
)}
</CabinetInfoButtonsContainerStyled>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import React from "react";
import Modal from "@/components/Modals/Modal";
import { IModalContents } from "@/components/Modals/Modal";
import ModalPortal from "@/components/Modals/ModalPortal";
import { additionalModalType, modalPropsMap } from "@/assets/data/maps";
import errorIcon from "@/assets/images/errorIcon.svg";
import CabinetStatus from "@/types/enum/cabinet.status.enum";
import { additionalModalType, modalPropsMap } from "@/assets/data/maps";

const UnavailableModal: React.FC<{
status: CabinetStatus | additionalModalType;
Expand All @@ -13,7 +13,7 @@ const UnavailableModal: React.FC<{
const modalContents: IModalContents = {
type: "noBtn",
icon: errorIcon,
title: modalPropsMap[additionalModalType.MODAL_OVERDUE_PENALTY].title,
title: modalPropsMap[props.status].title,
closeModal: props.closeModal,
};

Expand Down
14 changes: 7 additions & 7 deletions frontend/src/pages/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ const Layout = (): JSX.Element => {
<CabinetInfoAreaContainer />
</DetailInfoContainerStyled>
<MapInfoContainer />
{isModalOpen && myInfoData && myInfoData.unbannedAt !== undefined && (
<OverduePenaltyModal
status={additionalModalType.MODAL_OVERDUE_PENALTY}
closeModal={closeModal}
unbannedAt={myInfoData.unbannedAt}
/>
)}
</WrapperStyled>
)}
{isModalOpen && myInfoData && myInfoData.unbannedAt !== undefined && (
<OverduePenaltyModal
status={additionalModalType.MODAL_OVERDUE_PENALTY}
closeModal={closeModal}
unbannedAt={myInfoData.unbannedAt}
/>
)}
</React.Fragment>
);
};
Expand Down

0 comments on commit 2b18373

Please sign in to comment.