Skip to content

Commit

Permalink
Merge pull request #1260 from innovationacademy-kr/common/dev/feat_cl…
Browse files Browse the repository at this point in the history
…ub_user_add/#1256

[COMMON] 동아리 유저 추가 및 동아리 유저 목록 조회 기능 추가 #1256
  • Loading branch information
enaenen authored Jul 21, 2023
2 parents b128d36 + d9dd9bc commit b5f8e4f
Show file tree
Hide file tree
Showing 59 changed files with 1,849 additions and 143 deletions.
8 changes: 8 additions & 0 deletions 42Cabi.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"folders": [
{
"path": "."
}
],
"settings": {}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.ftclub.cabinet;
package org.ftclub.cabinet;

import org.ftclub.cabinet.config.CorsConfig;
import org.springframework.boot.SpringApplication;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package org.ftclub.cabinet.auth.controller;

import java.io.IOException;
import java.time.LocalDateTime;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.ftclub.cabinet.auth.service.AuthFacadeService;
import org.ftclub.cabinet.config.DomainProperties;
import org.ftclub.cabinet.config.GoogleApiProperties;
import org.ftclub.cabinet.dto.MasterLoginDto;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDateTime;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
* 관리자 인증을 수행하는 컨트롤러 클래스입니다.
Expand Down Expand Up @@ -48,8 +52,8 @@ public void login(HttpServletResponse res) throws IOException {
*/
@PostMapping("/login")
public void masterLogin(HttpServletRequest req,
HttpServletResponse res,
@RequestBody MasterLoginDto masterLoginDto) {
HttpServletResponse res,
@RequestBody MasterLoginDto masterLoginDto) {
authFacadeService.masterLogin(masterLoginDto, req, res, LocalDateTime.now());
}

Expand All @@ -69,9 +73,10 @@ public void masterLogin(HttpServletRequest req,
* @param res 요청 시의 서블렛 {@link HttpServletResponse}
* @throws IOException 입출력 예외
*/

@GetMapping("/login/callback")
public void loginCallback(@RequestParam String code, HttpServletRequest req,
HttpServletResponse res) throws IOException {
HttpServletResponse res) throws IOException {
authFacadeService.handleLogin(code, req, res, googleApiProperties, LocalDateTime.now());
res.sendRedirect(DomainProperties.getFeHost() + "/admin/home");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
import org.ftclub.cabinet.cabinet.domain.CabinetStatus;
import org.ftclub.cabinet.cabinet.domain.LentType;
import org.ftclub.cabinet.cabinet.service.CabinetFacadeService;
import org.ftclub.cabinet.dto.CabinetClubStatusRequestDto;
import org.ftclub.cabinet.dto.CabinetInfoResponseDto;
import org.ftclub.cabinet.dto.CabinetPaginationDto;
import org.ftclub.cabinet.dto.CabinetStatusRequestDto;
import org.ftclub.cabinet.dto.LentHistoryPaginationDto;
import org.ftclub.cabinet.exception.ControllerException;
import org.ftclub.cabinet.exception.ExceptionStatus;
import org.ftclub.cabinet.lent.service.LentFacadeService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -34,6 +36,7 @@
public class AdminCabinetController {

private final CabinetFacadeService cabinetFacadeService;
private final LentFacadeService lentFacadeService;

/**
* 사물함의 정보와 그 사물함의 대여 정보들을 가져옵니다.
Expand Down Expand Up @@ -100,6 +103,16 @@ public void updateCabinetBundleStatus(
cabinetFacadeService.updateCabinetBundleStatus(cabinetStatusRequestDto);
}

@PatchMapping("/club")
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
public void updateCabinetClubStatus(
@Valid @RequestBody CabinetClubStatusRequestDto cabinetClubStatusRequestDto) {
log.info("Called updateCabinetClubStatus: {}", cabinetClubStatusRequestDto);
cabinetFacadeService.updateCabinetClubStatus(cabinetClubStatusRequestDto);
lentFacadeService.startLentClubCabinet(cabinetClubStatusRequestDto.getUserId(),
cabinetClubStatusRequestDto.getCabinetId());
}


/**
* 사물함의 행과 열을 업데이트합니다.
Expand Down Expand Up @@ -246,13 +259,14 @@ public CabinetPaginationDto getCabinetsByVisibleNum(
*/
@GetMapping("/{cabinetId}/lent-histories")
@AuthGuard(level = AuthLevel.ADMIN_ONLY)
public LentHistoryPaginationDto getCabinetLentHistories(
@PathVariable("cabinetId") Long cabinetId,
public LentHistoryPaginationDto getCabinetLentHistories(@Valid
@PathVariable("cabinetId") Long cabinetId,
@RequestParam("page") Integer page,
@RequestParam("size") Integer size) {
if (cabinetId == null) {
throw new ControllerException(ExceptionStatus.INCORRECT_ARGUMENT);
}
return cabinetFacadeService.getCabinetLentHistoriesPagination(cabinetId, page, size);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
package org.ftclub.cabinet.cabinet.domain;

import static org.ftclub.cabinet.exception.ExceptionStatus.INVALID_ARGUMENT;
import static org.ftclub.cabinet.exception.ExceptionStatus.INVALID_STATUS;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ Page<Cabinet> findPaginationByStatus(@Param("status") CabinetStatus status,
Page<Cabinet> findPaginationByVisibleNum(@Param("visibleNum") Integer visibleNum,
Pageable pageable);

@Query("SELECT c " +
"FROM Cabinet c " +
"WHERE c.cabinetPlace.location = :location")
List<Cabinet> findAllCabinetsByLocation(@Param("location") Location location);
@Query("SELECT c " +
"FROM Cabinet c " +
"WHERE c.cabinetPlace.location = :location")
List<Cabinet> findAllCabinetsByLocation(@Param("location") Location location);

@EntityGraph(attributePaths = {"cabinetPlace"})
@Query("SELECT DISTINCT c, lh, u " +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
package org.ftclub.cabinet.cabinet.service;

import java.util.List;
import org.ftclub.cabinet.cabinet.domain.CabinetStatus;
import org.ftclub.cabinet.cabinet.domain.LentType;
import org.ftclub.cabinet.dto.BuildingFloorsDto;
import org.ftclub.cabinet.dto.CabinetClubStatusRequestDto;
import org.ftclub.cabinet.dto.CabinetInfoPaginationDto;
import org.ftclub.cabinet.dto.CabinetInfoResponseDto;
import org.ftclub.cabinet.dto.CabinetPaginationDto;
import org.ftclub.cabinet.dto.CabinetSimplePaginationDto;
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;
Expand Down Expand Up @@ -41,7 +51,7 @@ public interface CabinetFacadeService {
* @return 구역에 따른 사물함 정보 리스트
*/
List<CabinetsPerSectionResponseDto> getCabinetsPerSection(String building, Integer floor);

/**
* 사물함의 상태 메모를 업데이트합니다.
*
Expand Down Expand Up @@ -95,39 +105,50 @@ public interface CabinetFacadeService {
* 대여 타입에 따른 사물함 페이지네이션을 가져옵니다.
*
* @param lentType 대여 타입
* @param pageable 페이지네이션(page, size)
* @param page 페이지 번호
* @param size 페이지 당 보여줄 개수
* @return 사물함 페이지네이션
*/
CabinetPaginationDto getCabinetPaginationByLentType(LentType lentType, Integer page,
Integer size);
Integer size);

/**
* 사물함 상태에 따른 사물함 페이지네이션을 가져옵니다.
*
* @param status 사물함 상태
* @param pageable 페이지네이션(page, size)
* @param page 페이지 번호
* @param size 페이지 당 보여줄 개수
* @return 사물함 페이지네이션
*/
CabinetPaginationDto getCabinetPaginationByStatus(CabinetStatus status, Integer page, Integer size);
CabinetPaginationDto getCabinetPaginationByStatus(CabinetStatus status, Integer page,
Integer size);

/**
* 사물함 표시 번호에 따른 사물함 페이지네이션을 가져옵니다.
*
* @param visibleNum 사물함 표시 번호
* @param pageable 페이지네이션(page, size)
* @param page 페이지 번호
* @param size 페이지 당 보여줄 개수
* @return 사물함 페이지네이션
*/
CabinetPaginationDto getCabinetPaginationByVisibleNum(Integer visibleNum, Integer page,
Integer size);
Integer size);

/**
* 사물함 Id에 따른 대여 기록 페이지네이션을 가져옵니다.
*
* @param cabinetId 사물함 Id
* @param pageable 페이지네이션(page, size)
* @param page 페이지네이션(page, size)
* @return 대여 기록 페이지네이션
*/
LentHistoryPaginationDto getCabinetLentHistoriesPagination(Long cabinetId,
Integer page,
Integer size);
Integer page,
Integer size);

/**
* 사물함에 동아
*
* @param clubStatusRequestDto
*/
void updateCabinetClubStatus(CabinetClubStatusRequestDto clubStatusRequestDto);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,26 @@
import org.ftclub.cabinet.cabinet.domain.Grid;
import org.ftclub.cabinet.cabinet.domain.LentType;
import org.ftclub.cabinet.cabinet.repository.CabinetOptionalFetcher;
import org.ftclub.cabinet.dto.BuildingFloorsDto;
import org.ftclub.cabinet.dto.CabinetClubStatusRequestDto;
import org.ftclub.cabinet.dto.CabinetDto;
import org.ftclub.cabinet.dto.CabinetInfoPaginationDto;
import org.ftclub.cabinet.dto.CabinetInfoResponseDto;
import org.ftclub.cabinet.dto.CabinetPaginationDto;
import org.ftclub.cabinet.dto.CabinetPreviewDto;
import org.ftclub.cabinet.dto.CabinetSimpleDto;
import org.ftclub.cabinet.dto.CabinetSimplePaginationDto;
import org.ftclub.cabinet.dto.CabinetStatusRequestDto;
import org.ftclub.cabinet.dto.CabinetsPerSectionResponseDto;
import org.ftclub.cabinet.dto.LentDto;
import org.ftclub.cabinet.dto.LentHistoryDto;
import org.ftclub.cabinet.dto.LentHistoryPaginationDto;
import org.ftclub.cabinet.dto.*;
import org.ftclub.cabinet.lent.domain.LentHistory;
import org.ftclub.cabinet.lent.repository.LentOptionalFetcher;
import org.ftclub.cabinet.mapper.CabinetMapper;
import org.ftclub.cabinet.mapper.LentMapper;
import org.ftclub.cabinet.user.domain.User;
import org.ftclub.cabinet.user.repository.UserOptionalFetcher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
Expand All @@ -31,7 +44,6 @@ public class CabinetFacadeServiceImpl implements CabinetFacadeService {
private final CabinetService cabinetService;
private final CabinetOptionalFetcher cabinetOptionalFetcher;
private final LentOptionalFetcher lentOptionalFetcher;
private final UserOptionalFetcher userOptionalFetcher;
private final CabinetMapper cabinetMapper;
private final LentMapper lentMapper;

Expand Down Expand Up @@ -319,6 +331,20 @@ public void updateCabinetBundleStatus(CabinetStatusRequestDto cabinetStatusReque
}
}


/**
* 사물함에 동아리 유저를 대여 시킵니다.
*
* @param cabinetClubStatusRequestDto
*/
@Override
@Transactional
public void updateCabinetClubStatus(CabinetClubStatusRequestDto cabinetClubStatusRequestDto) {
cabinetService.updateClub(cabinetClubStatusRequestDto.getCabinetId(),
cabinetClubStatusRequestDto.getUserId(),
cabinetClubStatusRequestDto.getStatusNote());
}

// /**
// * {@inheritDoc}
// */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,6 @@ public interface CabinetService {
* @param statusNote 변경할 상태 메모
*/
void updateStatusNote(Long cabinetId, String statusNote);

void updateClub(Long cabinetId, Long userId, String statusNote);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.ftclub.cabinet.cabinet.repository.CabinetOptionalFetcher;
import org.ftclub.cabinet.exception.ExceptionStatus;
import org.ftclub.cabinet.exception.ServiceException;
import org.ftclub.cabinet.lent.repository.LentOptionalFetcher;
import org.ftclub.cabinet.user.repository.UserOptionalFetcher;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

Expand All @@ -20,6 +22,8 @@
public class CabinetServiceImpl implements CabinetService {

private final CabinetOptionalFetcher cabinetOptionalFetcher;
private final UserOptionalFetcher userOptionalFetcher;
private final LentOptionalFetcher lentOptionalFetcher;

/**
* {@inheritDoc}
Expand Down Expand Up @@ -118,7 +122,7 @@ public void updateLentType(Long cabinetId, LentType lentType) {
cabinet.specifyLentType(lentType);
if (lentType == LentType.SHARE) {
cabinet.specifyMaxUser(3); // todo : policy에서 외부에서 설정된 properties 변수로 설정하게끔 수정
} else if (lentType == LentType.PRIVATE) {
} else { // club 도 1명으로 변경
cabinet.specifyMaxUser(1);
}
}
Expand All @@ -142,4 +146,20 @@ public void updateStatusNote(Long cabinetId, String statusNote) {
Cabinet cabinet = cabinetOptionalFetcher.getCabinet(cabinetId);
cabinet.writeStatusNote(statusNote);
}

@Override
public void updateClub(Long cabinetId, Long userId, String statusNote) {
Cabinet cabinet = cabinetOptionalFetcher.getCabinetForUpdate(cabinetId);
String clubName = "";
if (userId != null) {
clubName = userOptionalFetcher.getClubUser(userId).getName();
}
Cabinet lentCabinet = lentOptionalFetcher.findActiveLentCabinetByUserId(userId);
if (lentCabinet != null) {
throw new ServiceException(ExceptionStatus.LENT_ALREADY_EXISTED);
}
cabinet.writeTitle(clubName);
cabinet.writeStatusNote(statusNote);
cabinet.specifyLentType(LentType.CLUB);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.ftclub.cabinet.dto;

import javax.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;

@AllArgsConstructor
@Getter
public class CabinetClubStatusRequestDto {

private final Long userId;
@NotNull
private final Long cabinetId;
@NotNull
private final String statusNote;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
import javax.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.ftclub.cabinet.cabinet.domain.CabinetStatus;
import org.ftclub.cabinet.cabinet.domain.LentType;

@AllArgsConstructor
@Getter
@NoArgsConstructor
public class CabinetStatusRequestDto {

@NotNull
private final List<Long> cabinetIds;
private final LentType lentType;
private final CabinetStatus status;
private List<Long> cabinetIds;
private LentType lentType;
private CabinetStatus status;
}
Loading

0 comments on commit b5f8e4f

Please sign in to comment.