Skip to content

Commit

Permalink
fix: 더비데이터 테ì�스트 API 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
junseokkim committed Feb 20, 2024
1 parent 8866052 commit 40bc632
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
@RequiredArgsConstructor
public enum BranchInfo {

// 3기
SANGGAMJADEL("생감자들", "생가자들 지부입니다.", Semester.THIRD, List.of(GACHON_UNIV, DONGGUK_UNIV, SOONGSIL_UNIV, CHUNGANG_UNIV)),
EPIC("EPIC", "EPIC지 지부입니다.", Semester.THIRD, List.of(DONGDUK_WOMENS_UNIV, SANGMYUNG_UNIV, SUNGSHIN_WOMENS_UNIV, CATHOLIC_UNIV)),
WUSK("WUSK", "WUSK 지부입니다.", Semester.THIRD, List.of(KWANGWOON_UNIV, DUKSUNG_WOMENS_UNIV, SEOUL_WOMENS_UNIV)),
BOLD("BOLD", "BOLD 지부입니다.", Semester.THIRD, List.of(KYUNGHEE_UNIV, AJOU_UNIV, INHA_UNIV, HANKUK_FOREIGN_STUDIES_UNIV, HANYANG_ERICA_UNIV)),
REFFO("레뽀", "레뽀 지부입니다.", Semester.THIRD, List.of(MYONGJI_UNIV, EWHA_WOMANS_UNIV, SOOKMYUNG_WOMENS_UNIV, HONGIK_UNIV, KOREA_AEROSPACE_UNIV)),
KKIROOK("끼룩끼룩", "끼룩끼룩 지부입니다.", Semester.THIRD, List.of(GYEONGSANG_NATIONAL_UNIV, PUKYONG_UNIV)),

// 4기
NEO("NEO(네오)", "NEO 지부입니다.", Semester.FOURTH, List.of(KWANGWOON_UNIV, DONGDUK_WOMENS_UNIV, SEOUL_WOMENS_UNIV, SOONGSIL_UNIV, HANKUK_FOREIGN_STUDIES_UNIV)),
DEST("DEST(데스트)", "DEST 지부입니다.", Semester.FOURTH, List.of(DUKSUNG_WOMENS_UNIV, DONGGUK_UNIV, SANGMYUNG_UNIV, SUNGSHIN_WOMENS_UNIV)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -52,7 +53,7 @@ public void onApplicationEvent(ContextRefreshedEvent event) {

// 새로운 지부가 있는 경우 대학교 연결(새로운 기수인 경우)
if (!newBranches.isEmpty()) {
updateBranchUniversities(branchUniversityRepository.findAll());
updateBranchUniversities();
connectNewBranchesAndUniversities(newBranches);
}

Expand Down Expand Up @@ -126,9 +127,12 @@ private BranchUniversity buildBranchUniversity(Branch branch, University univers
}

// 새로운 기수가 생길 경우 이전 기수들의 isActive 정보 수정
private void updateBranchUniversities(List<BranchUniversity> branchUniversities) {
@Transactional
public void updateBranchUniversities() {
List<BranchUniversity> branchUniversities = branchUniversityRepository.findAllByIsActive(Boolean.TRUE);
for (BranchUniversity branchUniversity : branchUniversities) {
if (branchUniversity.getBranch().getSemester() != Semester.findActiveSemester()) {
Branch branch = branchUniversity.getBranch();
if (branch.getSemester() != Semester.findActiveSemester()) {
branchUniversity.updateIsActive(Boolean.FALSE);
branchUniversityRepository.save(branchUniversity);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.umc.networkingService.domain.board.repository;

import com.umc.networkingService.domain.board.entity.Board;
import com.umc.networkingService.domain.board.entity.BoardType;
import com.umc.networkingService.domain.board.entity.HostType;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
Expand All @@ -12,4 +14,6 @@ public interface BoardRepository extends JpaRepository<Board, UUID>, BoardReposi
@Query(value = "select b from Board b where b.id = :boardId and b.deletedAt is null")
Optional<Board> findById(@Param("boardId") UUID boardId);

boolean existsByBoardTypeAndHostType(BoardType boardType, HostType hostType);

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ public interface BoardService extends EntityLoader<Board, UUID> {

MyBoardResponse.MyBoardPageInfos showBoardsByMemberHeartForWeb(Member member, HostType hostType, BoardType boardType, String keyword, Pageable pageable);

Boolean existsByBoardTypeAndHostType(BoardType boardType, HostType hostType);

}
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,11 @@ public MyBoardResponse.MyBoardPageInfos showBoardsByMemberHeartForWeb(Member mem
return boardMapper.toMyBoardPageInfos(boardRepository.findBoardsByMemberHeartForWeb(member, hostType, boardType, keyword, pageable));
}

@Override
public Boolean existsByBoardTypeAndHostType(BoardType boardType, HostType hostType) {
return boardRepository.existsByBoardTypeAndHostType(boardType, hostType);
}


@Override
@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.umc.networkingService.domain.university.entity.University;
import com.umc.networkingService.global.common.enums.Semester;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
Expand All @@ -14,8 +15,8 @@
@Repository
public interface BranchUniversityRepository extends JpaRepository<BranchUniversity, UUID> {

Optional<BranchUniversity> findByUniversityAndIsActive(University university, Boolean isActive);

@Query("SELECT bu FROM BranchUniversity bu JOIN FETCH bu.branch WHERE bu.isActive = :isActive")
List<BranchUniversity> findAllByIsActive(Boolean isActive);
List<BranchUniversity> findAllByBranch(Branch branch);

Boolean existsByBranchIdAndUniversityId(UUID branchId, UUID universityId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public Member toMember(final String clientId, SocialType socialType){
.clientId(clientId)
.socialType(socialType)
.role(Role.MEMBER)
.contributionPoint(0L)
.remainPoint(0L)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public interface MemberRepository extends JpaRepository<Member, UUID> {
List<Member> findAllByUniversityOrderByContributionPointDesc(University university);
List<Member> findAllByNicknameAndName(String nickname, String name);
boolean existsByGitNickname(String gitNickname);
boolean existsByUniversityAndNicknameAndName(University university, String nickname, String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ private MemberLoginResponse saveNewMember(String clientId, SocialType socialType
}

@Override
@Transactional
//dummy 데이터 생성용
public MemberIdResponse saveNewDummyMember(String clientId) {
Member member = memberMapper.toMember(clientId, SocialType.KAKAO);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.domain.member.entity.PointType;
import com.umc.networkingService.domain.member.entity.PositionType;
import com.umc.networkingService.domain.university.entity.University;
import com.umc.networkingService.global.common.base.EntityLoader;
import org.springframework.web.multipart.MultipartFile;

Expand All @@ -24,10 +25,8 @@ public interface MemberService extends EntityLoader<Member, UUID> {
void updateMemberActiveTime(UUID memberId);
List<String> getPositionNamesByType(Member member, PositionType type);
Member saveEntity(Member member);

List<Member> findContributionRankings(Member member);

Member usePoint (Member member, PointType pointType);

Member findByMemberId (UUID memberId);
boolean existsByUniversityAndNicknameAndName(University university, String nickname, String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,12 @@ public Member findByMemberId (UUID memberId) {
.orElseThrow(() -> new RestApiException(MemberErrorCode.EMPTY_MEMBER));
}

@Override
public boolean existsByUniversityAndNicknameAndName(University university, String nickname, String name) {
return memberRepository.existsByUniversityAndNicknameAndName(
university, nickname, name);
}

@Override
@Transactional
public Member usePoint(Member member, PointType pointType) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.umc.networkingService.domain.schedule.repository;

import com.umc.networkingService.domain.board.entity.HostType;
import com.umc.networkingService.domain.schedule.entity.Schedule;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -16,4 +17,5 @@ List<Schedule> findSchedulesByYearAndMonth (
@Param("date") LocalDate date
);

boolean existsByHostType(HostType hostType);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.umc.networkingService.domain.schedule.service;

import com.umc.networkingService.domain.board.entity.HostType;
import com.umc.networkingService.domain.member.entity.Member;
import com.umc.networkingService.domain.schedule.dto.request.ScheduleRequest.CreateSchedule;
import com.umc.networkingService.domain.schedule.dto.request.ScheduleRequest.UpdateSchedule;
Expand All @@ -21,4 +22,5 @@ public interface ScheduleService {
ScheduleId deleteSchedule(Member member, UUID scheduleId);
ScheduleInfoSummaryLists getScheduleLists(Member member, LocalDate date);
ScheduleInfo getScheduleDetail(Member member, UUID scheduleId);
boolean existsByHostType(HostType hostType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ public ScheduleInfo getScheduleDetail(Member member, UUID scheduleId) {
return scheduleMapper.toScheduleInfo(schedule);
}

@Override
public boolean existsByHostType(HostType hostType) {
return scheduleRepository.existsByHostType(hostType);
}

@Override
public ScheduleId createSchedule(Member member, CreateSchedule request) {
Schedule schedule = scheduleMapper.createScheduleToSchedule(member, request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,18 @@ public void CheckFlag(Integer flag) {
@Transactional
public String createDummyBoard(Member member) {
List<Member> members = createDummyMember(member);
if (members.isEmpty()) return "이미 존재합니다.";
createBoard(members, BoardType.FREE, HostType.CAMPUS);
createBoard(members, BoardType.FREE, HostType.BRANCH);
createBoard(members, BoardType.FREE, HostType.CENTER);
if (!boardService.existsByBoardTypeAndHostType(BoardType.FREE, HostType.CENTER))
createBoard(members, BoardType.FREE, HostType.CENTER);
createBoard(members, BoardType.QUESTION, HostType.CAMPUS);
createBoard(members, BoardType.QUESTION, HostType.BRANCH);
createBoard(members, BoardType.QUESTION, HostType.CENTER);
if (!boardService.existsByBoardTypeAndHostType(BoardType.QUESTION, HostType.CENTER))
createBoard(members, BoardType.QUESTION, HostType.CENTER);
createOB(members, HostType.CAMPUS);
createOB(members, HostType.CENTER);
if (!boardService.existsByBoardTypeAndHostType(BoardType.OB, HostType.CENTER))
createOB(members, HostType.CENTER);
createNoticeAndWorkbook(members);

members.forEach(this::createSchedules);
Expand All @@ -87,6 +91,10 @@ public List<Member> createDummyMember(Member loginMember) {
//로그인 한 멤버의 지부와 학교 정보 불러오기
Branch branch = branchService.loadEntity(loginMember.getBranch().getId());
University university = universityService.loadEntity(loginMember.getUniversity().getId());

if (memberService.existsByUniversityAndNicknameAndName(university, "시루", "김루시"))
return List.of();

//로그인한 멤버의 지부에 해당하는 university list를 불러오기
List<University> universities = branchUniversityService.findUniversitiesByBranch(branch);

Expand Down Expand Up @@ -141,7 +149,7 @@ public List<SemesterPart> createSemesterPart(Member member, MemberDummyInfo memb
return semesterPartRepository.saveAll(semesterParts);
}

private void createBoard(List<Member> members, BoardType boardType, HostType hostType) {
public void createBoard(List<Member> members, BoardType boardType, HostType hostType) {
Random random = new Random();
List<MultipartFile> files = new ArrayList<>();

Expand Down Expand Up @@ -184,13 +192,6 @@ private void createNoticeAndWorkbook(List<Member> members) {
.content("여러분~~~~ 이제 UMC 5기도 마지막이에요ㅠㅠ." + i)
.build();

BoardCreateRequest request3 = BoardCreateRequest.builder()
.hostType(HostType.CENTER.toString())
.boardType(BoardType.NOTICE.toString())
.title("UMC 서울 해커톤 개최!" + i)
.content("해커톤을 개최합니다 여러분 많은 참여 부탁드려요."+i)
.build();

BoardCreateRequest request4 = BoardCreateRequest.builder()
.hostType(HostType.CAMPUS.toString())
.boardType(BoardType.WORKBOOK.toString())
Expand All @@ -204,8 +205,18 @@ private void createNoticeAndWorkbook(List<Member> members) {
boardFileService.uploadBoardFilesForDummy(board1, getRandomImages());
Board board2 = boardService.loadEntity(boardService.createBoard(branchStaff, request2, files).getBoardId());
boardFileService.uploadBoardFilesForDummy(board2, getRandomImages());
Board board3 = boardService.loadEntity(boardService.createBoard(centerStaff, request3, files).getBoardId());
boardFileService.uploadBoardFilesForDummy(board3, getRandomImages());

if (!boardService.existsByBoardTypeAndHostType(BoardType.NOTICE, HostType.CENTER)) {
BoardCreateRequest request3 = BoardCreateRequest.builder()
.hostType(HostType.CENTER.toString())
.boardType(BoardType.NOTICE.toString())
.title("UMC 서울 해커톤 개최!" + i)
.content("해커톤을 개최합니다 여러분 많은 참여 부탁드려요."+i)
.build();

Board board3 = boardService.loadEntity(boardService.createBoard(centerStaff, request3, files).getBoardId());
boardFileService.uploadBoardFilesForDummy(board3, getRandomImages());
}
Board board4 = boardService.loadEntity(boardService.createBoard(campusStaff, request4, files).getBoardId());
boardFileService.uploadBoardFilesForDummy(board4, getRandomImages());

Expand Down Expand Up @@ -255,9 +266,11 @@ private List<String> getDummyImages(String bucketName) {
private void createSchedules(Member member) {
Optional<HostType> hostType = getHostType(member);
if (hostType.isPresent()) {
createDemoDaySchedule(member, hostType.get());
createHackathonSchedule(member, hostType.get());
createDiningSchedule(member, hostType.get());
if (hostType.get() != HostType.CENTER || !scheduleService.existsByHostType(hostType.get())) {
createDemoDaySchedule(member, hostType.get());
createHackathonSchedule(member, hostType.get());
createDiningSchedule(member, hostType.get());
}
}
}

Expand Down

0 comments on commit 40bc632

Please sign in to comment.