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

[feat] : 로그인 유저 대상, 이벤트 조회 시 이벤트 참여 상태도 반환한다 #104

Merged
merged 2 commits into from
Nov 2, 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
5 changes: 4 additions & 1 deletion src/main/java/side/onetime/controller/EventController.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ public ResponseEntity<ApiResponse<CreateEventResponse>> createEvent(
// 이벤트 조회 API
@GetMapping("/{event_id}")
public ResponseEntity<ApiResponse<GetEventResponse>> getEvent(
@RequestHeader(value = "Authorization", required = false) String authorizationHeader,
@PathVariable("event_id") String eventId) {

GetEventResponse getEventResponse = eventService.getEvent(eventId);
GetEventResponse getEventResponse = eventService.getEvent(eventId, authorizationHeader);


return ApiResponse.onSuccess(SuccessStatus._GET_EVENT, getEventResponse);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import side.onetime.domain.Event;
import side.onetime.domain.enums.Category;
import side.onetime.domain.enums.EventStatus;

import java.util.List;

Expand All @@ -15,15 +16,17 @@ public record GetEventResponse(
String startTime,
String endTime,
Category category,
List<String> ranges
List<String> ranges,
EventStatus eventStatus
) {
public static GetEventResponse of(Event event, List<String> ranges) {
public static GetEventResponse of(Event event, List<String> ranges, EventStatus eventStatus) {
return new GetEventResponse(
event.getTitle(),
event.getStartTime(),
event.getEndTime(),
event.getCategory(),
ranges
ranges,
eventStatus
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import side.onetime.domain.Event;
import side.onetime.domain.EventParticipation;
import side.onetime.domain.enums.Category;
import side.onetime.domain.enums.EventStatus;

import java.util.List;
import java.util.UUID;
Expand All @@ -18,7 +19,7 @@ public record GetUserParticipatedEventsResponse(
String title,
String createdDate,
int participantCount,
String eventStatus,
EventStatus eventStatus,
List<GetMostPossibleTime> mostPossibleTimes
) {
public static GetUserParticipatedEventsResponse of(Event event, EventParticipation eventParticipation, int participantCount, List<GetMostPossibleTime> mostPossibleTimes) {
Expand All @@ -28,7 +29,7 @@ public static GetUserParticipatedEventsResponse of(Event event, EventParticipati
event.getTitle(),
String.valueOf(event.getCreatedDate()),
participantCount,
String.valueOf(eventParticipation.getEventStatus()),
eventParticipation.getEventStatus(),
mostPossibleTimes
);
}
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/side/onetime/service/EventService.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected void createAndSaveDaySchedules(Event event, List<String> ranges, Strin

// 이벤트 조회 메서드
@Transactional(readOnly = true)
public GetEventResponse getEvent(String eventId) {
public GetEventResponse getEvent(String eventId, String authorizationHeader) {
Event event = eventRepository.findByEventId(UUID.fromString(eventId))
.orElseThrow(() -> new CustomException(EventErrorStatus._NOT_FOUND_EVENT));

Expand All @@ -126,7 +126,15 @@ public GetEventResponse getEvent(String eventId) {
? DateUtil.getSortedDateRanges(schedules.stream().map(Schedule::getDate).toList(), "yyyy.MM.dd")
: DateUtil.getSortedDayRanges(schedules.stream().map(Schedule::getDay).toList());

return GetEventResponse.of(event, ranges);
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();
}

return GetEventResponse.of(event, ranges, eventStatus);
}

// 참여자 조회 메서드
Expand Down
Loading