diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 5f3d9ff..6310385 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -44,6 +44,11 @@ jobs: cd ./src/main/resources touch ./application.properties echo "${{ secrets.PROPERTIES }}" > ./application.properties + touch ./triptogether-e7bac-firebase-adminsdk-peiki-127517aa66.json + echo "${{ secrets.FIREBASE_KEY }}" > ./triptogether-e7bac-firebase-adminsdk-peiki-127517aa66.json + cat ./triptogether-e7bac-firebase-adminsdk-peiki-127517aa66.json + pwd + ls shell: bash - name: Grant execute permission to Gradle wrapper @@ -100,4 +105,4 @@ jobs: author_name: 'SERVER CI/CD' fields: 'Job ID: ${{ github.run_id }} SUCCEEDED' env: - SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} \ No newline at end of file + SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} diff --git a/src/main/java/com/hanaro/triptogether/team/dto/response/DetailTeamResDto.java b/src/main/java/com/hanaro/triptogether/team/dto/response/DetailTeamResDto.java index b192308..025cb53 100644 --- a/src/main/java/com/hanaro/triptogether/team/dto/response/DetailTeamResDto.java +++ b/src/main/java/com/hanaro/triptogether/team/dto/response/DetailTeamResDto.java @@ -15,4 +15,5 @@ public class DetailTeamResDto { private BigDecimal accBalance; private TeamMemberState teamMemberState; private Long preferTripIdx; + private Integer teamMemberCount; } diff --git a/src/main/java/com/hanaro/triptogether/team/service/impl/TeamServiceImpl.java b/src/main/java/com/hanaro/triptogether/team/service/impl/TeamServiceImpl.java index a1ae267..15505ff 100644 --- a/src/main/java/com/hanaro/triptogether/team/service/impl/TeamServiceImpl.java +++ b/src/main/java/com/hanaro/triptogether/team/service/impl/TeamServiceImpl.java @@ -68,6 +68,7 @@ public void addTeam(AddTeamReqDto addTeamReqDto) { public DetailTeamResDto detailTeam(DetailTeamReqDto detailTeamReqDto) { Team team = teamRepository.findById(detailTeamReqDto.getTeamIdx()).orElseThrow(() -> new ApiException(ExceptionEnum.TEAM_NOT_FOUND)); TeamMember teamMember = teamMemberRepository.findById(detailTeamReqDto.getTeamMemberIdx()).orElseThrow(() -> new ApiException(ExceptionEnum.TEAM_MEMBER_NOT_FOUND)); + Integer teamMemberCount = teamMemberRepository.findTeamMembersByTeamAndTeamMemberState(team); Long preferTripIdx = null; if(team.getPreferTrip()!=null) preferTripIdx = team.getPreferTrip().getTripIdx(); @@ -78,6 +79,7 @@ public DetailTeamResDto detailTeam(DetailTeamReqDto detailTeamReqDto) { .accNumber(team.getAccount().getAccNumber()) .accBalance(team.getAccount().getAccBalance()) .teamMemberState(teamMember.getTeamMemberState()) + .teamMemberCount(teamMemberCount) .build(); } diff --git a/src/main/java/com/hanaro/triptogether/teamMember/domain/TeamMemberRepository.java b/src/main/java/com/hanaro/triptogether/teamMember/domain/TeamMemberRepository.java index 51f7a71..e9a3bd2 100644 --- a/src/main/java/com/hanaro/triptogether/teamMember/domain/TeamMemberRepository.java +++ b/src/main/java/com/hanaro/triptogether/teamMember/domain/TeamMemberRepository.java @@ -1,5 +1,6 @@ package com.hanaro.triptogether.teamMember.domain; +import com.hanaro.triptogether.member.domain.Member; import com.hanaro.triptogether.team.domain.Team; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; @@ -18,4 +19,11 @@ public interface TeamMemberRepository extends JpaRepository { List findTeamMemberByMember_MemberIdx(Long memberIdx); Optional findTeamMemberByMember_MemberIdxAndTeam_TeamIdx(Long memberIdx, Long teamIdx); + + + @Query("SELECT count(*) FROM TeamMember tm where tm.team = :team and deletedAt is null and (tm.teamMemberState=\"총무\" or tm.teamMemberState=\"모임원\")") + Integer findTeamMembersByTeamAndTeamMemberState(Team team); + + TeamMember findTeamMemberByMemberAndTeam(Member member, Team team); + } diff --git a/src/main/java/com/hanaro/triptogether/teamMember/service/impl/TeamMemberServiceImpl.java b/src/main/java/com/hanaro/triptogether/teamMember/service/impl/TeamMemberServiceImpl.java index b95f684..7fe3b8a 100644 --- a/src/main/java/com/hanaro/triptogether/teamMember/service/impl/TeamMemberServiceImpl.java +++ b/src/main/java/com/hanaro/triptogether/teamMember/service/impl/TeamMemberServiceImpl.java @@ -200,14 +200,23 @@ public void joinTeamMember(JoinTeamMemberReq joinTeamMemberReq) throws IOExcepti Member member = memberRepository.findById(joinTeamMemberReq.getMemberIdx()).orElseThrow(() -> new ApiException(ExceptionEnum.MEMBER_NOT_FOUND)); Team team = teamRepository.findById(joinTeamMemberReq.getTeamIdx()).orElseThrow(() -> new ApiException(ExceptionEnum.TEAM_NOT_FOUND)); - TeamMember teamMember = TeamMember.builder() - .team(team) - .member(member) - .teamMemberState(TeamMemberState.수락대기) - .createdAt(LocalDateTime.now()).build(); - - teamMemberRepository.save(teamMember); + TeamMember existingTeamMember = teamMemberRepository.findTeamMemberByMemberAndTeam(member, team); + + if (existingTeamMember != null) { + existingTeamMember.updateTeamMemberState(TeamMemberState.수락대기); + existingTeamMember.delete(null, null); + teamMemberRepository.save(existingTeamMember); + } else { + TeamMember teamMember = TeamMember.builder() + .team(team) + .member(member) + .teamMemberState(TeamMemberState.수락대기) + .createdAt(LocalDateTime.now()) + .build(); + teamMemberRepository.save(teamMember); + } firebaseFCMService.sendMessageTo(FcmSendDto.builder().token(member.getFcmToken()).title("모임 참여 요청 알림").body(member.getMemberName()+"님이 "+team.getTeamName()+"모임에 참여하기를 원합니다.").build()); + } @Override diff --git a/src/main/java/com/hanaro/triptogether/trip/domain/Trip.java b/src/main/java/com/hanaro/triptogether/trip/domain/Trip.java index 6a1d141..a2e4707 100644 --- a/src/main/java/com/hanaro/triptogether/trip/domain/Trip.java +++ b/src/main/java/com/hanaro/triptogether/trip/domain/Trip.java @@ -37,6 +37,9 @@ public class Trip { @Column(nullable = false, precision = 20, scale = 2) private BigDecimal tripGoalAmount = BigDecimal.ZERO; + @Column(nullable = false, precision = 20, scale = 2) + private BigDecimal tripExpectedAmount = BigDecimal.ZERO; + @Column(nullable = false) private Integer tripDay = 1; @@ -74,6 +77,7 @@ public TripResDto toTrip() { .tripDay(this.getTripDay()) .tripContent(this.getTripContent()) .tripGoalAmount(this.getTripGoalAmount()) + .tripExpectedAmount(this.getTripExpectedAmount()) .tripName(this.getTripName()) .tripStartDay(this.getTripStartDay()) .build(); diff --git a/src/main/java/com/hanaro/triptogether/trip/domain/TripRepository.java b/src/main/java/com/hanaro/triptogether/trip/domain/TripRepository.java index ea2fb31..6820dec 100644 --- a/src/main/java/com/hanaro/triptogether/trip/domain/TripRepository.java +++ b/src/main/java/com/hanaro/triptogether/trip/domain/TripRepository.java @@ -13,6 +13,6 @@ public interface TripRepository extends JpaRepository { List findAllByTeam_TeamIdx(Long teamIdx); @Modifying - @Query("UPDATE Trip t SET t.tripGoalAmount = :goalAmount WHERE t.tripIdx = :tripIdx") - void updateGoalAmount(@Param("tripIdx") Long tripIdx, @Param("goalAmount") BigDecimal goalAmount); + @Query("UPDATE Trip t SET t.tripExpectedAmount = :tripExpectedAmount WHERE t.tripIdx = :tripIdx") + void updateExpectedAmount(@Param("tripIdx") Long tripIdx, @Param("tripExpectedAmount") BigDecimal expectedAmount); } diff --git a/src/main/java/com/hanaro/triptogether/trip/dto/response/TripResDto.java b/src/main/java/com/hanaro/triptogether/trip/dto/response/TripResDto.java index d4be00d..bd9d44d 100644 --- a/src/main/java/com/hanaro/triptogether/trip/dto/response/TripResDto.java +++ b/src/main/java/com/hanaro/triptogether/trip/dto/response/TripResDto.java @@ -18,6 +18,7 @@ public class TripResDto { private String tripName; private String tripContent; private BigDecimal tripGoalAmount; + private BigDecimal tripExpectedAmount; private Integer tripDay; private Integer tripImg; private LocalDate tripStartDay; diff --git a/src/main/java/com/hanaro/triptogether/trip/service/TripService.java b/src/main/java/com/hanaro/triptogether/trip/service/TripService.java index da1352d..231897a 100644 --- a/src/main/java/com/hanaro/triptogether/trip/service/TripService.java +++ b/src/main/java/com/hanaro/triptogether/trip/service/TripService.java @@ -75,6 +75,7 @@ public void createTrip(TripReqDto tripReqDto) throws NoSuchElementException{ .tripName(tripReqDto.getTripName()) .tripContent(tripReqDto.getTripContent()) .tripGoalAmount(tripReqDto.getTripGoalAmount()) + .tripExpectedAmount(BigDecimal.ZERO) .tripDay(tripReqDto.getTripDay()) .tripImg(tripReqDto.getTripImg()) .tripStartDay(tripReqDto.getTripStartDay()) @@ -141,8 +142,10 @@ private TripResDto toTripResDto(Trip trip) { .teamName(trip.getTeam().getTeamName()) .tripIdx(trip.getTripIdx()) .tripDay(trip.getTripDay()) + .tripImg(trip.getTripImg()) .tripContent(trip.getTripContent()) .tripGoalAmount(trip.getTripGoalAmount()) + .tripExpectedAmount(trip.getTripExpectedAmount()) .tripName(trip.getTripName()) .tripStartDay(trip.getTripStartDay()) .build(); @@ -154,8 +157,10 @@ private TripResDto toTripResDto(Trip trip) { .teamName(trip.getTeam().getTeamName()) .tripIdx(trip.getTripIdx()) .tripDay(trip.getTripDay()) + .tripImg(trip.getTripImg()) .tripContent(trip.getTripContent()) .tripGoalAmount(trip.getTripGoalAmount()) + .tripExpectedAmount(trip.getTripExpectedAmount()) .tripName(trip.getTripName()) .tripStartDay(trip.getTripStartDay()) .countryIdx(country.getCountryIdx()) @@ -166,9 +171,9 @@ private TripResDto toTripResDto(Trip trip) { } @Transactional - public void setGoalAmount(Long tripIdx, BigDecimal goalAmount) { + public void setExpectedAmount(Long tripIdx, BigDecimal expectedAmount) { Trip trip = tripRepository.findById(tripIdx) .orElseThrow(() -> new ApiException(ExceptionEnum.TRIP_NOT_FOUND)); - tripRepository.updateGoalAmount(tripIdx, goalAmount); + tripRepository.updateExpectedAmount(tripIdx, expectedAmount); } } diff --git a/src/main/java/com/hanaro/triptogether/tripPlace/service/TripPlaceService.java b/src/main/java/com/hanaro/triptogether/tripPlace/service/TripPlaceService.java index 1237963..5b97dd2 100644 --- a/src/main/java/com/hanaro/triptogether/tripPlace/service/TripPlaceService.java +++ b/src/main/java/com/hanaro/triptogether/tripPlace/service/TripPlaceService.java @@ -74,7 +74,7 @@ public void updatePlace(Long trip_placeIdx, TripPlaceUpdateInfoReqDto dto) { Long tripIdx = tripPlace.getTrip().getTripIdx(); //goalAmount 계산 및 설정 - tripService.setGoalAmount(tripIdx, tripPlaceRepository.getSumPlaceAmountByTripIdx(tripIdx)); + tripService.setExpectedAmount(tripIdx, tripPlaceRepository.getSumPlaceAmountByTripIdx(tripIdx)); } @Transactional @@ -179,8 +179,11 @@ public void updateTripPlace(Long tripIdx, TripPlaceUpdateReqDto reqDto) { tripPlace.updateOrder(dto.getPlaceOrder(), dto.getTripDate(), member); } + BigDecimal expectedAmount = tripPlaceRepository.getSumPlaceAmountByTripIdx(tripIdx); + if (reqDto.getNewPlaces().isEmpty()) expectedAmount = BigDecimal.ZERO; + //goalAmount 계산 및 설정 - tripService.setGoalAmount(tripIdx, tripPlaceRepository.getSumPlaceAmountByTripIdx(tripIdx)); + tripService.setExpectedAmount(tripIdx, expectedAmount); }