Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
[Feat] 여행 스페이스 알람 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
NoJaeHyuk committed Jan 27, 2024
1 parent a06f0b2 commit ba976d5
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

public record SpaceEventInfo(
Long spaceId,
String spaceTitle
String spaceTitle,
String oldTitle,
String oldDates,
String changDate
) {
}
44 changes: 44 additions & 0 deletions app/src/main/java/fc/be/app/domain/space/service/SpaceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import fc.be.app.domain.member.entity.Member;
import fc.be.app.domain.member.exception.MemberException;
import fc.be.app.domain.member.repository.MemberRepository;
import fc.be.app.domain.notification.domain.event.space.SpaceEvent;
import fc.be.app.domain.notification.domain.event.vo.MemberEventInfo;
import fc.be.app.domain.notification.domain.event.vo.SpaceEventInfo;
import fc.be.app.domain.notification.entity.NotificationType;
import fc.be.app.domain.place.Place;
import fc.be.app.domain.place.exception.PlaceException;
import fc.be.app.domain.place.repository.PlaceRepository;
Expand All @@ -21,12 +25,14 @@
import fc.be.app.domain.space.vo.SpaceType;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Period;
import java.util.ArrayList;
import java.util.List;
Expand All @@ -48,6 +54,7 @@ public class SpaceService {
private final JourneyRepository journeyRepository;
private final PlaceRepository placeRepository;
private final SelectedPlaceRepository selectedPlaceRepository;
private final ApplicationEventPublisher eventPublisher;

@Transactional
public SpaceResponse createSpace(Long memberId) {
Expand Down Expand Up @@ -90,6 +97,8 @@ public SpaceResponse updateSpaceByTitle(Long spaceId, Long memberId, TitleUpdate

validateSpace(space, requestMember, currentDate);

publishSpaceEvent(space, requestMember, NotificationType.SPACE_LOCATION_CHANGED, String.join(",", updateRequest.cities()) + " 여행", "");

space.updateByCity(updateRequest.cities());
return SpaceResponse.of(space);
}
Expand All @@ -103,6 +112,8 @@ public SpaceResponse updateSpaceByDates(Long spaceId, Long memberId, DateUpdateR
.orElseThrow(() -> new SpaceException(SPACE_NOT_FOUND));

validateSpace(space, requestMember, currentDate);
String changeDates = updateRequest.startDate().toString() + " - " + updateRequest.endDate().toString();
publishSpaceEvent(space, requestMember, NotificationType.SPACE_SCHEDULE_CHANGED, null, changeDates);

if (space.getJourneys().isEmpty()) {
List<Journey> journeys = Journey.createJourneys(updateRequest.startDate(),
Expand Down Expand Up @@ -152,6 +163,8 @@ public void exitSpace(Long spaceId, Long memberId) {
JoinedMember joinedMember = joinedMemberRepository.findBySpaceAndMemberAndLeftSpace(space,
requestMember, false).orElseThrow(() -> new SpaceException(NOT_JOINED_MEMBER));

publishSpaceEvent(space, requestMember, NotificationType.MEMBER_EXIT);

joinedMember.updateLeftSpace(true);
}

Expand Down Expand Up @@ -232,6 +245,9 @@ public void joinMember(Long spaceId, Long memberId) {
Member member = memberRepository.findById(memberId).orElseThrow(() -> new MemberException(MEMBER_NOT_FOUND));
return JoinedMember.create(space, member);
});

publishSpaceEvent(space, joinedMember.getMember(), NotificationType.MEMBER_INVITED);

joinedMember.updateLeftSpace(false);
}

Expand Down Expand Up @@ -311,4 +327,32 @@ private static void validateJoinedMember(Space space, Member requestMember) {
throw new SpaceException(NOT_JOINED_MEMBER);
}
}

private void publishSpaceEvent(Space space, Member requestMember, NotificationType type, String changeTitle, String changeDates) {
String title = (space.getCityToString() != null) ? space.getCityToString() + " 여행" : null;
String oldDates = (space.getStartDate() != null) ? space.getStartDate().toString() + " - " + space.getEndDate().toString() : null;

if (changeTitle == null) {
changeTitle = title;
}
eventPublisher.publishEvent(
new SpaceEvent(
space.getId(),
new MemberEventInfo(requestMember.getId(), requestMember.getNickname(), requestMember.getProfile()),
new SpaceEventInfo(space.getId(), changeTitle, title, oldDates, changeDates),
type,
LocalDateTime.now())
);
}

private void publishSpaceEvent(Space space, Member requestMember, NotificationType type) {
String title = (space.getCityToString() != null) ? space.getCityToString() + " 여행" : null;

eventPublisher.publishEvent(new SpaceEvent(space.getId(),
new MemberEventInfo(requestMember.getId(), requestMember.getNickname(), requestMember.getProfile()),
new SpaceEventInfo(space.getId(), title, null, null, null),
type,
LocalDateTime.now())
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,11 @@ public VoteUpdateApiResponse updateVoteTitle(Long voteId, Long memberId, VoteUpd
}

private void publishVoteEvent(Space space, Member requestMember, Vote vote, NotificationType type) {
String title = (space.getCityToString() != null) ? space.getCityToString() + " 여행" : null;

eventPublisher.publishEvent(new VoteEvent(space.getId(),
new MemberEventInfo(requestMember.getId(), requestMember.getNickname(), requestMember.getProfile()),
new SpaceEventInfo(space.getId(), space.getTitle()),
new SpaceEventInfo(space.getId(), title, null, null, null),
new VoteEventInfo(vote.getId(), vote.getTitle()),
type,
LocalDateTime.now())
Expand Down

0 comments on commit ba976d5

Please sign in to comment.