Skip to content

Commit

Permalink
추가: 오픈 예정 티켓 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
rrosiee committed May 18, 2024
1 parent 6f2f72f commit fcb77b7
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,20 @@ public class CulturalEventController {
private final MemberJwtService memberJwtService;

@ApiOperation(value = "문화생활 리스트 조회",
notes = " - ordering : point(인기순)")
notes = " - ordering : ticketOpenDate(마감 다가온 순) | -point(인기순)")
@GetMapping
public ResponseEntity getCulturalEventList(
@RequestParam() CategoryTitle type,
@RequestParam(required = false) CategoryTitle type,
@RequestParam(defaultValue = "0") int page,
@RequestParam(defaultValue = "10") int size,
@RequestParam(required = false) String ordering
@RequestParam(required = false) String ordering,
@RequestParam(required = false) Boolean isOpened
) {
// Member
Member member = memberJwtService.getMember();

// Response
List<CulturalEvent> culturalEventList = culturalEventService.getCulturalEventList(type, page, size, ordering);
List<CulturalEvent> culturalEventList = culturalEventService.getCulturalEventList(page, size, type, ordering, isOpened);
List<CulturalEventListDto> culturalEventResponseDtoList = culturalEventMapper
.culturalEventToCulturalEventListDtos(culturalEventList);
culturalEventResponseDtoList.forEach(dto -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@

import java.util.Optional;

public interface CulturalEventRepository extends JpaRepository<CulturalEvent, Long> {
public interface CulturalEventRepository extends JpaRepository<CulturalEvent, Long>, CulturalEventRepositoryCustom {
Optional<CulturalEvent> findFirstByTitle(String title);
Page<CulturalEvent> findAll(Pageable pageable);

Page<CulturalEvent> findAllByCulturalEventCategory(Pageable pageable, CulturalEventCategory culturalEventCategory);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package project.backend.domain.culturalevent.repository;

import project.backend.domain.culturalevent.entity.CulturalEvent;
import project.backend.domain.culturalevnetcategory.entity.CategoryTitle;
import project.backend.domain.member.dto.MemberStatisticsResponseDto;
import project.backend.domain.member.dto.MemberYearStatisticsResponseDto;
import project.backend.domain.member.entity.Member;
import project.backend.domain.ticket.entity.Ticket;

import java.time.LocalDateTime;
import java.util.List;

public interface CulturalEventRepositoryCustom {
List<CulturalEvent> getCulturalEventList(int page, int size, CategoryTitle category, String ordering, Boolean isOpened);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package project.backend.domain.culturalevent.repository;

import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import project.backend.domain.culturalevent.entity.CulturalEvent;
import project.backend.domain.culturalevnetcategory.entity.CategoryTitle;

import java.time.LocalDateTime;
import java.util.List;


import static project.backend.domain.culturalevent.entity.QCulturalEvent.culturalEvent;

@RequiredArgsConstructor
public class CulturalEventRepositoryImpl implements CulturalEventRepositoryCustom {
private final JPAQueryFactory queryFactory;

@Override
public List<CulturalEvent> getCulturalEventList(int page, int size, CategoryTitle category, String ordering, Boolean isOpened) {
LocalDateTime now = LocalDateTime.now();
JPAQuery<CulturalEvent> culturalEventJPAQuery = queryFactory.selectFrom(culturalEvent);

// ordering 있을 경우
if (ordering != null) {
if (ordering.equals("-point")) {
culturalEventJPAQuery.orderBy(culturalEvent.point.desc());
} if (ordering.equals("ticketOpenDate")) {
culturalEventJPAQuery.orderBy(culturalEvent.ticketOpenDate.asc());
}
}

// isOpened 있을 경우
if (isOpened != null) {
if (isOpened) {
culturalEventJPAQuery.where(culturalEvent.ticketOpenDate.before(now));
} else {
culturalEventJPAQuery.where(culturalEvent.ticketOpenDate.after(now));
}
}

// category 있을 경우
if (!(category == CategoryTitle.ALL || category == null)) {
culturalEventJPAQuery.where(culturalEvent.culturalEventCategory.title.eq(category));
}

// page, size 적용
Pageable pageable = PageRequest.of(page, size);
culturalEventJPAQuery.offset(pageable.getOffset());
culturalEventJPAQuery.limit(pageable.getPageSize());

// Result
return culturalEventJPAQuery.fetch();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,8 @@ public class CulturalEventService {
private final MemberJwtService memberJwtService;
private final CulturalEventVisitRepository culturalEventVisitRepository;

public List<CulturalEvent> getCulturalEventList(CategoryTitle type, int page, int size, String ordering) {
Pageable pageable = PageRequest.of(page, size, createSort(ordering));
if (type == CategoryTitle.ALL || type == null) {
return culturalEventRepository.findAll(pageable).getContent();
} else {
CulturalEventCategory culturalEventCategory = culturalEventCategoryService.verifiedCulturalEventCategoryByTitle(type);
return culturalEventRepository.findAllByCulturalEventCategory(pageable, culturalEventCategory).getContent();
}
public List<CulturalEvent> getCulturalEventList(int page, int size, CategoryTitle category, String ordering, Boolean isOpened) {
return culturalEventRepository.getCulturalEventList(page, size, category, ordering, isOpened);
}

public CulturalEvent getCulturalEvent(Long id) {
Expand Down

0 comments on commit fcb77b7

Please sign in to comment.