Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] : 멤버가 만든 이벤트에 처음 접속한 경우 조회가 되지 않는 문제를 해결한다 #111

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading