Skip to content

Commit

Permalink
Merge pull request #64 from onetime-with-members/fix/#61/no-contain
Browse files Browse the repository at this point in the history
[fix] : 이벤트 생성자도 스케줄 등록 이전에는 참여자로 포함되지 않는다
  • Loading branch information
bbbang105 authored Oct 2, 2024
2 parents 446253f + 9498fe9 commit fc3544d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/main/java/side/onetime/dto/EventDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public void updateEndTime(String endTime) {
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class GetUserParticipatedEventsResponse {
private UUID eventId;
private Category category;
private String title;
private String createdDate;
private int participantCount;
Expand All @@ -168,6 +169,7 @@ public static class GetUserParticipatedEventsResponse {
public static GetUserParticipatedEventsResponse of(Event event, EventParticipation eventParticipation, int participantCount, List<GetMostPossibleTime> mostPossibleTimes) {
return GetUserParticipatedEventsResponse.builder()
.eventId(event.getEventId())
.category(event.getCategory())
.title(event.getTitle())
.createdDate(String.valueOf(event.getCreatedDate()))
.participantCount(participantCount)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public interface SelectionRepository extends JpaRepository<Selection, Long> {
void deleteAllByUserAndScheduleIn(User user, List<Schedule> schedules);
@Query("SELECT s FROM Selection s JOIN FETCH s.schedule sc WHERE sc.event = :event")
List<Selection> findAllSelectionsByEvent(@Param("event") Event event);
@Query("SELECT COUNT(s) > 0 FROM Selection s WHERE s.user = :user AND s.schedule.event = :event")
boolean existsByUserAndEventSchedules(@Param("user") User user, @Param("event") Event event);
}
27 changes: 19 additions & 8 deletions src/main/java/side/onetime/service/EventService.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class EventService {
private static final int MAX_MOST_POSSIBLE_TIMES_SIZE = 6;
private final EventRepository eventRepository;
private final EventParticipationRepository eventParticipationRepository;
private final MemberRepository memberRepository;
private final ScheduleRepository scheduleRepository;
private final SelectionRepository selectionRepository;
private final JwtUtil jwtUtil;
Expand Down Expand Up @@ -135,6 +134,13 @@ public EventDto.GetParticipantsResponse getParticipants(String eventId) {
// 이벤트에 참여하는 모든 유저
List<EventParticipation> eventParticipations = eventParticipationRepository.findAllByEvent(event);
List<User> users = eventParticipations.stream()
.filter(eventParticipation -> {
// CREATOR일 경우, 스케줄 등록을 했는지 확인
if (eventParticipation.getEventStatus() == EventStatus.CREATOR) {
return selectionRepository.existsByUserAndEventSchedules(eventParticipation.getUser(), eventParticipation.getEvent());
}
return true;
})
.map(EventParticipation::getUser)
.toList();

Expand All @@ -155,11 +161,15 @@ public List<EventDto.GetMostPossibleTime> getMostPossibleTime(String eventId) {

// 이벤트에 참여하는 모든 유저
List<EventParticipation> eventParticipations = eventParticipationRepository.findAllByEvent(event);
List<User> users = eventParticipations.stream()

EventDto.GetParticipantsResponse getParticipantsResponse = getParticipants(eventId);
List<String> participantNames = getParticipantsResponse.getNames();

// 유저 필터링: 참여자 목록에 있는 유저만 포함
List<String> allUserNicknames = eventParticipations.stream()
.map(EventParticipation::getUser)
.toList();
List<String> allUserNicknames = users.stream()
.map(User::getNickname)
.filter(participantNames::contains)
.toList();

List<Selection> selections = selectionRepository.findAllSelectionsByEvent(event);
Expand Down Expand Up @@ -264,10 +274,11 @@ public List<EventDto.GetUserParticipatedEventsResponse> getUserParticipatedEvent
.reversed()) // 최신순으로 정렬
.map(eventParticipation -> {
Event event = eventParticipation.getEvent();
int memberCount = memberRepository.countByEvent(event);
int participantCount = eventParticipationRepository.countByEvent(event);
List<EventDto.GetMostPossibleTime> mostPossibleTimes = getMostPossibleTime(String.valueOf(event.getEventId()));
return EventDto.GetUserParticipatedEventsResponse.of(event, eventParticipation, memberCount + participantCount, mostPossibleTimes);
String eventId = String.valueOf(event.getEventId());
EventDto.GetParticipantsResponse getParticipantsResponse = getParticipants(eventId);
List<String> participantNames = getParticipantsResponse.getNames();
List<EventDto.GetMostPossibleTime> mostPossibleTimes = getMostPossibleTime(eventId);
return EventDto.GetUserParticipatedEventsResponse.of(event, eventParticipation, participantNames.size(), mostPossibleTimes);
})
.collect(Collectors.toList());
}
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/side/onetime/service/ScheduleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.stereotype.Service;
import side.onetime.domain.*;
import side.onetime.domain.enums.EventStatus;
import side.onetime.dto.EventDto;
import side.onetime.dto.ScheduleDto;
import side.onetime.exception.*;
import side.onetime.repository.*;
Expand All @@ -22,6 +23,7 @@ public class ScheduleService {
private final ScheduleRepository scheduleRepository;
private final SelectionRepository selectionRepository;
private final JwtUtil jwtUtil;
private final EventService eventService;

// 요일 스케줄 등록 메서드 (비로그인)
@Transactional
Expand Down Expand Up @@ -174,10 +176,16 @@ public List<ScheduleDto.PerDaySchedulesResponse> getAllDaySchedules(String event

// 이벤트에 참여하는 모든 멤버
List<Member> members = memberRepository.findAllWithSelectionsAndSchedulesByEvent(event);

// 이벤트에 참여하는 모든 참여자 목록
EventDto.GetParticipantsResponse getParticipantsResponse = eventService.getParticipants(eventId);
List<String> participantNames = getParticipantsResponse.getNames();

// 이벤트에 참여하는 모든 유저
List<EventParticipation> eventParticipations = eventParticipationRepository.findAllByEvent(event);
List<User> users = eventParticipations.stream()
.map(EventParticipation::getUser)
.filter(user -> participantNames.contains(user.getNickname())) // 유저가 참여자 목록에 있는지 확인
.toList();

List<ScheduleDto.PerDaySchedulesResponse> perDaySchedulesResponses = new ArrayList<>();
Expand Down Expand Up @@ -270,10 +278,16 @@ public List<ScheduleDto.PerDateSchedulesResponse> getAllDateSchedules(String eve

// 이벤트에 참여하는 모든 멤버
List<Member> members = memberRepository.findAllWithSelectionsAndSchedulesByEvent(event);

// 이벤트에 참여하는 모든 참여자 목록
EventDto.GetParticipantsResponse getParticipantsResponse = eventService.getParticipants(eventId);
List<String> participantNames = getParticipantsResponse.getNames();

// 이벤트에 참여하는 모든 유저
List<EventParticipation> eventParticipations = eventParticipationRepository.findAllByEvent(event);
List<User> users = eventParticipations.stream()
.map(EventParticipation::getUser)
.filter(user -> participantNames.contains(user.getNickname())) // 유저가 참여자 목록에 있는지 확인
.toList();

List<ScheduleDto.PerDateSchedulesResponse> perDateSchedulesResponses = new ArrayList<>();
Expand Down

0 comments on commit fc3544d

Please sign in to comment.