Skip to content

Commit

Permalink
Merge pull request #111 from onetime-with-members/fix/#110/member-event
Browse files Browse the repository at this point in the history
[fix] : 멤버가 만든 이벤트에 처음 접속한 경우 조회가 되지 않는 문제를 해결한다
  • Loading branch information
bbbang105 authored Nov 3, 2024
2 parents 04f1f6a + 6433d4d commit d6e0b89
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
package side.onetime.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import side.onetime.domain.Event;
import side.onetime.domain.EventParticipation;
import side.onetime.domain.User;

import java.util.List;
import java.util.Optional;

public interface EventParticipationRepository extends JpaRepository<EventParticipation,Long> {
List<EventParticipation> findAllByEvent(Event event);
List<EventParticipation> findAllByUser(User user);
@Query("SELECT COUNT(ep) FROM EventParticipation ep WHERE ep.event = :event")
int countByEvent(@Param("event") Event event);
Optional<EventParticipation> findByUserAndEvent(User user, Event event);
EventParticipation findByUserAndEvent(User user, Event event);
}
13 changes: 8 additions & 5 deletions src/main/java/side/onetime/service/EventService.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,10 @@ public GetEventResponse getEvent(String eventId, String authorizationHeader) {
EventStatus eventStatus = null;
if (authorizationHeader != null) {
User user = jwtUtil.getUserFromHeader(authorizationHeader);
EventParticipation eventParticipation = eventParticipationRepository.findByUserAndEvent(user, event)
.orElseThrow(() -> new CustomException(EventParticipationErrorStatus._NOT_FOUND_EVENT_PARTICIPATION));
eventStatus = eventParticipation.getEventStatus();
EventParticipation eventParticipation = eventParticipationRepository.findByUserAndEvent(user, event);
if (eventParticipation != null) {
eventStatus = eventParticipation.getEventStatus();
}
}

return GetEventResponse.of(event, ranges, eventStatus);
Expand Down Expand Up @@ -308,8 +309,10 @@ public void removeUserCreatedEvent(String authorizationHeader, String eventId) {
Event event = eventRepository.findByEventId(UUID.fromString(eventId))
.orElseThrow(() -> new CustomException(EventErrorStatus._NOT_FOUND_EVENT));

EventParticipation eventParticipation = eventParticipationRepository.findByUserAndEvent(user, event)
.orElseThrow(() -> new CustomException(EventParticipationErrorStatus._NOT_FOUND_EVENT_PARTICIPATION));
EventParticipation eventParticipation = eventParticipationRepository.findByUserAndEvent(user, event);
if (eventParticipation == null) {
throw new CustomException(EventParticipationErrorStatus._NOT_FOUND_EVENT_PARTICIPATION);
}
if (!EventStatus.CREATOR.equals(eventParticipation.getEventStatus())) {
// 해당 이벤트의 생성자가 아닌 경우
throw new CustomException(EventParticipationErrorStatus._IS_NOT_USERS_CREATED_EVENT_PARTICIPATION);
Expand Down
36 changes: 20 additions & 16 deletions src/main/java/side/onetime/service/ScheduleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ public void createDaySchedulesForAuthenticatedUser(CreateDayScheduleRequest crea
.orElseThrow(() -> new CustomException(EventErrorStatus._NOT_FOUND_EVENT));
User user = jwtUtil.getUserFromHeader(authorizationHeader);
// 참여 정보가 없는 경우 참여자로 저장
eventParticipationRepository.findByUserAndEvent(user, event)
.orElseGet(() -> eventParticipationRepository.save(
EventParticipation.builder()
.user(user)
.event(event)
.eventStatus(EventStatus.PARTICIPANT)
.build()
));
EventParticipation eventParticipation = eventParticipationRepository.findByUserAndEvent(user, event);
if (eventParticipation == null) {
eventParticipationRepository.save(
EventParticipation.builder()
.user(user)
.event(event)
.eventStatus(EventStatus.PARTICIPANT)
.build()
);
}

List<DaySchedule> daySchedules = createDayScheduleRequest.daySchedules();
List<Selection> newSelections = new ArrayList<>();
Expand Down Expand Up @@ -141,14 +143,16 @@ public void createDateSchedulesForAuthenticatedUser(CreateDateScheduleRequest cr
.orElseThrow(() -> new CustomException(EventErrorStatus._NOT_FOUND_EVENT));
User user = jwtUtil.getUserFromHeader(authorizationHeader);
// 참여 정보가 없는 경우 참여자로 저장
eventParticipationRepository.findByUserAndEvent(user, event)
.orElseGet(() -> eventParticipationRepository.save(
EventParticipation.builder()
.user(user)
.event(event)
.eventStatus(EventStatus.PARTICIPANT)
.build()
));
EventParticipation eventParticipation = eventParticipationRepository.findByUserAndEvent(user, event);
if (eventParticipation == null) {
eventParticipationRepository.save(
EventParticipation.builder()
.user(user)
.event(event)
.eventStatus(EventStatus.PARTICIPANT)
.build()
);
}

List<DateSchedule> dateSchedules = createDateScheduleRequest.dateSchedules();
List<Selection> newSelections = new ArrayList<>();
Expand Down

0 comments on commit d6e0b89

Please sign in to comment.