-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #188 from UnivApp/feature/festival
feat: 축제 정보 구현
- Loading branch information
Showing
74 changed files
with
1,203 additions
and
637 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 57 additions & 28 deletions
85
src/main/java/yerong/wedle/calendar/service/CalendarEventService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,83 @@ | ||
package yerong.wedle.calendar.service; | ||
|
||
import java.time.LocalDate; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.context.SecurityContextHolder; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import yerong.wedle.calendar.domain.CalendarEvent; | ||
import yerong.wedle.calendar.dto.CalendarEventResponse; | ||
import yerong.wedle.calendar.exception.CalendarEventNotFoundException; | ||
import yerong.wedle.calendar.repository.CalendarEventRepository; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
import yerong.wedle.member.domain.Member; | ||
import yerong.wedle.member.exception.MemberNotFoundException; | ||
import yerong.wedle.member.repository.MemberRepository; | ||
import yerong.wedle.notification.domain.Notification; | ||
import yerong.wedle.notification.repository.NotificationRepository; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class CalendarEventService { | ||
|
||
private final CalendarEventRepository calendarEventRepository; | ||
private final NotificationRepository notificationRepository; | ||
private final MemberRepository memberRepository; | ||
|
||
public List<CalendarEventResponse> getAll() { | ||
List<CalendarEvent> calendarEvents = calendarEventRepository.findAll(); | ||
|
||
return calendarEvents.stream() | ||
.flatMap(event -> convertToDto(event).stream()) | ||
.collect(Collectors.toList()); | ||
return convertToDto(calendarEvents); | ||
} | ||
|
||
public List<CalendarEventResponse> convertToDto(CalendarEvent calendarEvent) { | ||
LocalDate startDate = calendarEvent.getStartDate(); | ||
LocalDate endDate = calendarEvent.getEndDate(); | ||
|
||
if (endDate == null) { | ||
return List.of(new CalendarEventResponse( | ||
calendarEvent.getId(), | ||
calendarEvent.getTitle(), | ||
startDate, | ||
calendarEvent.getCalendarEventType().getDisplayName() | ||
)); | ||
} | ||
public List<CalendarEventResponse> convertToDto(List<CalendarEvent> calendarEvents) { | ||
List<CalendarEventResponse> calendarEventResponses = new ArrayList<>(); | ||
String socialId = getCurrentUserId(); | ||
Member member = memberRepository.findBySocialId(socialId) | ||
.orElseThrow(MemberNotFoundException::new); | ||
for (CalendarEvent calendarEvent : calendarEvents) { | ||
LocalDate startDate = calendarEvent.getStartDate(); | ||
LocalDate endDate = calendarEvent.getEndDate(); | ||
|
||
return startDate.datesUntil(endDate.plusDays(1)) | ||
.map(date -> new CalendarEventResponse( | ||
if (endDate == null) { | ||
Notification notification = notificationRepository.findByMemberAndEventAndNotificationDate(member, | ||
calendarEvent, startDate).orElse(null); | ||
Long notificationId = notification != null ? notification.getNotificationId() : null; | ||
calendarEventResponses.add(new CalendarEventResponse( | ||
calendarEvent.getId(), | ||
calendarEvent.getTitle(), | ||
date, | ||
calendarEvent.getCalendarEventType().getDisplayName() | ||
)) | ||
.collect(Collectors.toList()); | ||
startDate, | ||
calendarEvent.getCalendarEventType().getDisplayName(), | ||
notification != null && notification.isActive() && notification.getNotificationDate() | ||
.equals(startDate), | ||
notificationId | ||
)); | ||
} else { | ||
startDate.datesUntil(endDate.plusDays(1)) | ||
.forEach(date -> { | ||
Notification notification = notificationRepository.findByMemberAndEventAndNotificationDate( | ||
member, calendarEvent, date).orElse(null); | ||
Long notificationId = notification != null ? notification.getNotificationId() : null; | ||
boolean isActive = notification != null && notification.isActive() | ||
&& notification.getNotificationDate().equals(date); | ||
|
||
calendarEventResponses.add(new CalendarEventResponse( | ||
calendarEvent.getId(), | ||
calendarEvent.getTitle(), | ||
date, | ||
calendarEvent.getCalendarEventType().getDisplayName(), | ||
isActive, | ||
notificationId | ||
)); | ||
}); | ||
} | ||
} | ||
return calendarEventResponses; | ||
} | ||
|
||
private String getCurrentUserId() { | ||
String socialId = SecurityContextHolder.getContext().getAuthentication().getName(); | ||
|
||
return socialId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/yerong/wedle/category/event/controller/ArtistController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package yerong.wedle.category.event.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import yerong.wedle.category.event.dto.ArtistTop10Response; | ||
import yerong.wedle.category.event.service.ArtistService; | ||
|
||
@Tag(name = "Artist API", description = "아티스트 정보 API") | ||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/api/artists") | ||
public class ArtistController { | ||
|
||
private final ArtistService artistService; | ||
|
||
@Operation( | ||
summary = "가장 많이 방문한 아티스트 조회", | ||
description = "대학교에서 가장 많이 방문한 아티스트 TOP 10을 조회합니다." | ||
) | ||
@GetMapping("/top") | ||
public ResponseEntity<List<ArtistTop10Response>> getTopArtists() { | ||
List<ArtistTop10Response> topArtists = artistService.getTopArtists(); | ||
return ResponseEntity.ok(topArtists); | ||
} | ||
} |
32 changes: 0 additions & 32 deletions
32
src/main/java/yerong/wedle/category/event/controller/EventApiController.java
This file was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
src/main/java/yerong/wedle/category/event/controller/FestivalApiController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package yerong.wedle.category.event.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import yerong.wedle.category.event.dto.UniversityFestivalResponse; | ||
import yerong.wedle.category.event.service.FestivalService; | ||
|
||
@Tag(name = "Festival API", description = "대학교 관련 축제 정보 API") | ||
@RequiredArgsConstructor | ||
@RestController | ||
@RequestMapping("/api/festivals") | ||
public class FestivalApiController { | ||
private final FestivalService eventService; | ||
|
||
@Operation( | ||
summary = "대학교 이벤트 조회", | ||
description = "대학교 ID를 이용해 해당 대학교에서 진행된 이벤트 목록을 조회합니다.", | ||
responses = { | ||
@ApiResponse(responseCode = "200", description = "성공적으로 축제 목록 조회"), | ||
@ApiResponse(responseCode = "404", description = "해당 대학교를 찾을 수 없음") | ||
} | ||
) | ||
@GetMapping | ||
public ResponseEntity<UniversityFestivalResponse> getEventsByUniversityId(@RequestParam Long universityId) { | ||
UniversityFestivalResponse eventsByUniversityId = eventService.getFestivalsByUniversityId(universityId); | ||
return ResponseEntity.ok(eventsByUniversityId); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/yerong/wedle/category/event/domain/Artist.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package yerong.wedle.category.event.domain; | ||
|
||
import static lombok.AccessLevel.PROTECTED; | ||
|
||
import jakarta.persistence.CascadeType; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.OneToMany; | ||
import java.util.Set; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = PROTECTED) | ||
@Entity | ||
public class Artist { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "artist_id") | ||
private Long artistId; | ||
|
||
@Column(nullable = false) | ||
private String name; | ||
@Column(nullable = false) | ||
private String subname; | ||
|
||
private final String image = ""; | ||
|
||
@OneToMany(mappedBy = "artist", cascade = CascadeType.ALL, orphanRemoval = true) | ||
private Set<FestivalArtist> eventArtists; | ||
} |
47 changes: 0 additions & 47 deletions
47
src/main/java/yerong/wedle/category/event/domain/Event.java
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
src/main/java/yerong/wedle/category/event/domain/EventDetails.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.