Skip to content

Commit

Permalink
Merge branch 'dev' into common/dev/feat_club_user_add/#1256
Browse files Browse the repository at this point in the history
  • Loading branch information
junyoung2015 authored Jul 20, 2023
2 parents 55e4380 + fe5e55d commit 4e9d350
Show file tree
Hide file tree
Showing 29 changed files with 897 additions and 105 deletions.
40 changes: 20 additions & 20 deletions .github/workflows/back-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ jobs:
run: |
mkdir -p before-deploy
cp backend/build/libs/cabinet-*.jar before-deploy/
cp scripts/*.sh before-deploy/
cp scripts/deploy-dev.sh before-deploy/deploy.sh
cp appspec.yml before-deploy/
cp Dockerfile before-deploy/
cp Dockerfile.dev before-deploy/Dockerfile
cd before-deploy && zip -r before-deploy *
cd ../ && mkdir -p deploy
mv before-deploy/before-deploy.zip deploy/deploy.zip
Expand All @@ -88,22 +88,22 @@ jobs:
--file-exists-behavior OVERWRITE \
--s3-location bucket=${{ secrets.AWS_S3_DEV_BUCKET_NAME }},bundleType=zip,key=deploy.zip
# - name: Main S3에 업로드
# if: ${{ github.ref == 'refs/heads/main' }}
# run: |
# mkdir -p before-deploy
# cp backend/build/libs/cabinet-*.jar before-deploy/
# cp scripts/*.sh before-deploy/
# cp appspec.yml before-deploy/
# cp Dockerfile before-deploy/
# cd before-deploy && zip -r before-deploy *
# cd ../ && mkdir -p deploy
# mv before-deploy/before-deploy.zip deploy/deploy.zip
# aws s3 cp deploy/deploy.zip s3://${{ secrets.AWS_S3_MAIN_BUCKET_NAME }}/deploy.zip
- name: Main S3에 업로드
if: ${{ github.ref == 'refs/heads/main' }}
run: |
mkdir -p before-deploy
cp backend/build/libs/cabinet-*.jar before-deploy/
cp scripts/deploy-main.sh before-deploy/deploy.sh
cp appspec.yml before-deploy/
cp Dockerfile.main before-deploy/Dockerfile
cd before-deploy && zip -r before-deploy *
cd ../ && mkdir -p deploy
mv before-deploy/before-deploy.zip deploy/deploy.zip
aws s3 cp deploy/deploy.zip s3://${{ secrets.AWS_S3_MAIN_BUCKET_NAME }}/deploy.zip
# aws deploy create-deployment \
# --application-name ${{ secrets.AWS_CODEDEPLOY_MAIN_APP_NAME }} \
# --deployment-config-name CodeDeployDefault.AllAtOnce \
# --deployment-group-name ${{ secrets.AWS_CODEDEPLOY_MAIN_GROUP_NAME }} \
# --file-exists-behavior OVERWRITE \
# --s3-location bucket=${{ secrets.AWS_S3_MAIN_BUCKET_NAME }},bundleType=zip,key=deploy.zip
aws deploy create-deployment \
--application-name ${{ secrets.AWS_CODEDEPLOY_MAIN_APP_NAME }} \
--deployment-config-name CodeDeployDefault.AllAtOnce \
--deployment-group-name ${{ secrets.AWS_CODEDEPLOY_MAIN_GROUP_NAME }} \
--file-exists-behavior OVERWRITE \
--s3-location bucket=${{ secrets.AWS_S3_MAIN_BUCKET_NAME }},bundleType=zip,key=deploy.zip
1 change: 0 additions & 1 deletion .idea/misc.xml

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

File renamed without changes.
5 changes: 5 additions & 0 deletions Dockerfile.main
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM amazoncorretto:11

COPY cabinet-0.0.1-SNAPSHOT.jar .

CMD java -jar -Dspring.profiles.active=main cabinet-0.0.1-SNAPSHOT.jar
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public JsonNode getFtUsersInfoByName(String name) {
log.info("요청에 실패했습니다. 최대 3번 재시도합니다. 현재 시도 횟수: {}", tryCount);
this.issueAccessToken();
if (tryCount == MAX_RETRY) {
throw new RuntimeException();
log.error("요청에 실패했습니다. 최대 재시도 횟수를 초과했습니다. {}", e.getMessage());
throw new ServiceException(ExceptionStatus.OAUTH_BAD_GATEWAY);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.ftclub.cabinet.dto;

import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;

/**
* 유저의 식별자, 이름, 이메일, 블랙홀 날짜를 반환하는 DTO입니다.
*/
@AllArgsConstructor
@Getter
@ToString
public class UserBlackholeInfoDto {

private final Long userId;
private final String name;
private final String email;
private final LocalDateTime blackHoledAt;

public static UserBlackholeInfoDto of(Long userId, String name, String email,
LocalDateTime blackHoledAt) {
return new UserBlackholeInfoDto(userId, name, email, blackHoledAt);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import net.bytebuddy.asm.Advice;
import org.ftclub.cabinet.auth.domain.AuthGuard;
import org.ftclub.cabinet.dto.BlockedUserPaginationDto;
import org.ftclub.cabinet.dto.CabinetFloorStatisticsResponseDto;
import org.ftclub.cabinet.dto.LentsStatisticsResponseDto;
import org.ftclub.cabinet.dto.OverdueUserCabinetPaginationDto;
import org.ftclub.cabinet.statistics.service.StatisticsFacadeService;
import org.ftclub.cabinet.user.service.UserFacadeService;
import org.ftclub.cabinet.utils.DateUtil;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.DateTimeFormat.ISO;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -54,7 +52,7 @@ public List<CabinetFloorStatisticsResponseDto> getCabinetsInfoOnAllFloors() {
@AuthGuard(level = ADMIN_ONLY)
public LentsStatisticsResponseDto getCountOnLentAndReturn(
@RequestParam("startDate") @DateTimeFormat(iso = ISO.DATE_TIME) LocalDateTime startDate,
@RequestParam("endDate") @DateTimeFormat(iso = ISO.DATE_TIME)LocalDateTime endDate
@RequestParam("endDate") @DateTimeFormat(iso = ISO.DATE_TIME) LocalDateTime endDate
) {
log.info("Called getCountOnLentAndReturn");
return statisticsFacadeService.getCountOnLentAndReturn(startDate, endDate);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.ftclub.cabinet.statistics.repository;

import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
@Log4j2
public class StatisticsOptionalFetcher {


}
Original file line number Diff line number Diff line change
@@ -1,71 +1,78 @@
package org.ftclub.cabinet.statistics.service;

import static org.ftclub.cabinet.utils.ExceptionUtil.throwIfFalse;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.ftclub.cabinet.cabinet.domain.CabinetStatus;
import org.ftclub.cabinet.cabinet.repository.CabinetRepository;
import org.ftclub.cabinet.cabinet.repository.CabinetOptionalFetcher;
import org.ftclub.cabinet.dto.CabinetFloorStatisticsResponseDto;
import org.ftclub.cabinet.dto.LentsStatisticsResponseDto;
import org.ftclub.cabinet.exception.ExceptionStatus;
import org.ftclub.cabinet.exception.ServiceException;
import org.ftclub.cabinet.lent.repository.LentRepository;
import org.ftclub.cabinet.statistics.repository.StatisticsRepository;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

@Service
@RequiredArgsConstructor
@Log4j2
public class StatisticsFacadeServiceImpl implements StatisticsFacadeService {

private final StatisticsRepository statisticsRepository;
private final CabinetRepository cabinetRepository;
private final LentRepository lentRepository;
private final StatisticsRepository statisticsRepository;
private final CabinetOptionalFetcher cabinetOptionalFetcher;
private final LentRepository lentRepository;

// TODO: 로직 수정 필요
// TODO: 로직 수정 필요

/**
* @return
*/
@Override
public List<CabinetFloorStatisticsResponseDto> getCabinetsCountOnAllFloors() {
log.info("Called getCabinetsCountOnAllFloors");
List<CabinetFloorStatisticsResponseDto> cabinetFloorStatisticsResponseDtos = new ArrayList<>();
List<Integer> floors = cabinetRepository.findAllFloorsByBuilding("새롬관");
for (Integer floor : floors) {
Integer used = statisticsRepository.getCabinetsCountByStatus(floor, CabinetStatus.FULL);
List<Long> availableCabinetsId = statisticsRepository.getAvailableCabinetsId(floor);
Integer unused = 0;
for (Long cabinetId : availableCabinetsId) {
if (lentRepository.countCabinetActiveLent(cabinetId) > 0) {
used++;
} else {
unused++;
}
}
Integer overdue = statisticsRepository.getCabinetsCountByStatus(floor,
CabinetStatus.OVERDUE);
Integer disabled = statisticsRepository.getCabinetsCountByStatus(floor,
CabinetStatus.BROKEN);
Integer total = used + overdue + unused + disabled;
cabinetFloorStatisticsResponseDtos.add(
new CabinetFloorStatisticsResponseDto(floor, total, used, overdue, unused,
disabled));
}
return cabinetFloorStatisticsResponseDtos;
}
/**
* @return
*/
@Override
public List<CabinetFloorStatisticsResponseDto> getCabinetsCountOnAllFloors() {
log.info("Called getCabinetsCountOnAllFloors");
List<CabinetFloorStatisticsResponseDto> cabinetFloorStatisticsResponseDtos = new ArrayList<>();
List<Integer> floors = cabinetOptionalFetcher.findAllFloorsByBuilding("새롬관");
throwIfFalse(floors != null, new ServiceException(ExceptionStatus.INVALID_ARGUMENT));
for (Integer floor : floors) {
Integer used = statisticsRepository.getCabinetsCountByStatus(floor, CabinetStatus.FULL);
List<Long> availableCabinetsId = statisticsRepository.getAvailableCabinetsId(floor);
Integer unused = 0;
for (Long cabinetId : availableCabinetsId) {
if (lentRepository.countCabinetActiveLent(cabinetId) > 0) {
used++;
} else {
unused++;
}
}
Integer overdue = statisticsRepository.getCabinetsCountByStatus(floor,
CabinetStatus.OVERDUE);
Integer disabled = statisticsRepository.getCabinetsCountByStatus(floor,
CabinetStatus.BROKEN);
Integer total = used + overdue + unused + disabled;
cabinetFloorStatisticsResponseDtos.add(
new CabinetFloorStatisticsResponseDto(floor, total, used, overdue, unused,
disabled));
}
return cabinetFloorStatisticsResponseDtos;
}

/**
* @param startDate
* @param endDate
* @return
*/
@Override
public LentsStatisticsResponseDto getCountOnLentAndReturn(LocalDateTime startDate, LocalDateTime endDate) {
log.info("Called getCountOnLentAndReturn");
Integer lentStartCount = lentRepository.countLentByTimeDuration(startDate, endDate);
Integer lentEndCount = lentRepository.countReturnByTimeDuration(startDate, endDate);
return new LentsStatisticsResponseDto(startDate, endDate, lentStartCount, lentEndCount);
}
/**
* @param startDate
* @param endDate
* @return
*/
@Override
public LentsStatisticsResponseDto getCountOnLentAndReturn(LocalDateTime startDate,
LocalDateTime endDate) {
log.info("Called getCountOnLentAndReturn");
throwIfFalse(startDate.isBefore(endDate),
new ServiceException(ExceptionStatus.INVALID_ARGUMENT));
Integer lentStartCount = lentRepository.countLentByTimeDuration(startDate, endDate);
Integer lentEndCount = lentRepository.countReturnByTimeDuration(startDate, endDate);
return new LentsStatisticsResponseDto(startDate, endDate, lentStartCount, lentEndCount);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.ftclub.cabinet.user.repository;

import java.util.List;
import java.util.Optional;
import org.ftclub.cabinet.user.domain.User;
import org.ftclub.cabinet.user.domain.UserRole;
Expand Down Expand Up @@ -54,4 +55,19 @@ public interface UserRepository extends JpaRepository<User, Long> {
*
*/
Page<User> findAllByRoleAndDeletedAtIsNull(@Param("role") UserRole role, Pageable pageable);
* 블랙홀에 빠질 위험이 있는 유저들의 정보를 조회합니다. blackholedAt이 현재 시간보다 과거인 유저들을 블랙홀에 빠질 위험이 있는 유저로 판단합니다.
*
* @return {@link User} 리스트
*/
@Query("SELECT u FROM User u WHERE u.blackholedAt IS NOT NULL OR u.blackholedAt <= CURRENT_TIMESTAMP")
List<User> findByRiskOfFallingIntoBlackholeUsers();

/**
* 블랙홀에 빠질 위험이 없는 유저들의 정보를 조회합니다. blackholedAt이 null이거나 현재 시간보다 미래인 유저들을 블랙홀에 빠질 위험이 없는 유저로
* 판단합니다.
*
* @return {@link User} 리스트
*/
@Query("SELECT u FROM User u WHERE u.blackholedAt IS NULL OR u.blackholedAt > CURRENT_TIMESTAMP")
List<User> findByNoRiskOfFallingIntoBlackholeUsers();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.ftclub.cabinet.user.service;

import java.time.LocalDateTime;
import java.util.List;
import org.ftclub.cabinet.cabinet.domain.LentType;
import org.ftclub.cabinet.dto.UserBlackholeInfoDto;
import org.ftclub.cabinet.user.domain.AdminRole;
import org.ftclub.cabinet.user.domain.UserRole;

Expand Down Expand Up @@ -52,4 +54,17 @@ void banUser(Long userId, LentType lentType, LocalDateTime startedAt, LocalDateT

void updateClubUser(Long clubId, String clubName);

/**
* 블랙홀에 빠질 위험이 있는 유저들의 블랙홀 정보를 가져옵니다.
*
* @return {@link List<UserBlackholeInfoDto>}
*/
List<UserBlackholeInfoDto> getAllRiskOfBlackholeInfo();

/**
* 블랙홀에 빠질 위험이 없는 유저들의 블랙홀 정보를 가져옵니다.
*
* @return {@link List<UserBlackholeInfoDto>}
*/
List<UserBlackholeInfoDto> getAllNoRiskOfBlackholeInfo();
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
Expand All @@ -13,6 +14,7 @@
import org.ftclub.cabinet.exception.ExceptionStatus;
import org.ftclub.cabinet.exception.ServiceException;
import org.ftclub.cabinet.lent.repository.LentOptionalFetcher;
import org.ftclub.cabinet.dto.UserBlackholeInfoDto;
import org.ftclub.cabinet.user.domain.AdminRole;
import org.ftclub.cabinet.user.domain.AdminUser;
import org.ftclub.cabinet.user.domain.BanHistory;
Expand Down Expand Up @@ -189,5 +191,24 @@ public void updateClubUser(Long clubId, String clubName) {
}
User clubUser = userOptionalFetcher.getClubUser(clubId);
clubUser.changeName(clubName);
public List<UserBlackholeInfoDto> getAllRiskOfBlackholeInfo() {
log.info("Called getAllRiskOfBlackholeInfo");
List<User> users = userRepository.findByRiskOfFallingIntoBlackholeUsers();
return users.stream()
.filter(user -> user.getBlackholedAt().isBefore(LocalDateTime.now().plusDays(7)))
.map(user -> UserBlackholeInfoDto.of(user.getUserId(), user.getName(),
user.getEmail(), user.getBlackholedAt()))
.collect(Collectors.toList());
}

@Override
public List<UserBlackholeInfoDto> getAllNoRiskOfBlackholeInfo() {
log.info("Called getAllNoRiskOfBlackholeInfo");
List<User> users = userRepository.findByNoRiskOfFallingIntoBlackholeUsers();
return users.stream()
.filter(user -> user.getBlackholedAt().isBefore(LocalDateTime.now().plusDays(7)))
.map(user -> UserBlackholeInfoDto.of(user.getUserId(), user.getName(),
user.getEmail(), user.getBlackholedAt()))
.collect(Collectors.toList());
}
}
Loading

0 comments on commit 4e9d350

Please sign in to comment.