Skip to content
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
Expand Up @@ -20,37 +20,6 @@
public interface ExhibitRepository extends JpaRepository<Exhibit, Long>,ExhibitRepositoryCustom{


@Query(value = """
SELECT e.*
FROM exhibit e
JOIN exhibit_keyword ek ON e.exhibit_id = ek.exhibit_id
JOIN keyword k ON ek.keyword_id = k.keyword_id
JOIN exhibit_hall h ON e.exhibit_hall_id = h.exhibit_hall_id
WHERE k.type = 'GENRE'
AND k.name = :genre
AND e.end_date >= NOW()
AND (:isDomestic IS NULL OR h.is_domestic = :isDomestic)
ORDER BY RAND()
LIMIT :limit
""", nativeQuery = true)
List<Exhibit> findThemeExhibits(@Param("genre") String genre, @Param("limit") int limit, @Param("isDomestic") Boolean isDomestic);

@Query(value = """
SELECT e.*
FROM exhibit e
JOIN exhibit_keyword ek ON e.exhibit_id = ek.exhibit_id
JOIN keyword k ON ek.keyword_id = k.keyword_id
JOIN exhibit_hall h ON e.exhibit_hall_id = h.exhibit_hall_id
WHERE k.type = 'GENRE'
AND k.name = :genre
AND e.end_date >= NOW()
AND (:isDomestic IS NULL OR h.is_domestic = :isDomestic)
""", nativeQuery = true)
List<Exhibit> findAllByGenreAndDomestic(
@Param("genre") String genre,
@Param("isDomestic") Boolean isDomestic
);

@Query(value = """
SELECT DISTINCT k.name
FROM keyword k
Expand All @@ -60,23 +29,6 @@ List<Exhibit> findAllByGenreAndDomestic(
List<String> findAllGenres();


@Query(value = """
SELECT e.*
FROM exhibit e
JOIN exhibit_keyword ek ON e.exhibit_id = ek.exhibit_id
JOIN keyword k ON ek.keyword_id = k.keyword_id
JOIN exhibit_hall h ON e.exhibit_hall_id = h.exhibit_hall_id
WHERE e.end_date >= NOW()
AND (:isDomestic IS NULL OR h.is_domestic = :isDomestic)
AND ((k.type = 'GENRE' AND k.name IN (:genres))
OR (k.type = 'STYLE' AND k.name IN (:styles)))
""", nativeQuery = true)
List<Exhibit> findAllByKeywords(
@Param("genres") Set<String> genres,
@Param("styles") Set<String> styles,
@Param("isDomestic") Boolean isDomestic
);

@Modifying
@Query(value = """
UPDATE exhibit
Expand All @@ -98,16 +50,6 @@ WHERE status IN ('ONGOING', 'ENDING_SOON')



@Query(value = """
SELECT e.*
FROM exhibit e
JOIN exhibit_hall h ON e.exhibit_hall_id = h.exhibit_hall_id
WHERE :date BETWEEN e.start_date AND e.end_date
AND (:isDomestic IS NULL OR h.is_domestic = :isDomestic)
""", nativeQuery = true)
List<Exhibit> findAllByDate(@Param("isDomestic") Boolean isDomestic,
@Param("date") LocalDate date);

@Query("SELECT DISTINCT e FROM Exhibit e LEFT JOIN FETCH e.keywords WHERE e.exhibitId = :id")
Optional<Exhibit> findByIdWithKeywords(@Param("id") Long id);

Expand All @@ -118,25 +60,5 @@ List<Exhibit> findAllByDate(@Param("isDomestic") Boolean isDomestic,

long countByExhibitHall_ExhibitHallId(Long exhibitHallId);


@Query(value = """
SELECT e.*
FROM exhibit e
JOIN exhibit_hall h ON e.exhibit_hall_id = h.exhibit_hall_id
WHERE h.country = :country
ORDER BY RAND()
LIMIT :limit
""", nativeQuery = true)
List<Exhibit> findRandomByCountry(@Param("country") String country, @Param("limit") int limit);

@Query("""
SELECT e
FROM Exhibit e
JOIN e.exhibitHall h
WHERE h.region = :region
""")
Page<Exhibit> findAllByRegion(@Param("region") String region, Pageable pageable);


Optional<Exhibit> findByTitleAndStartDate(String title, LocalDate startDate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Slice<Exhibit> findExhibitByFilters(ExhibitFilterRequestDto dto, Pageable
.leftJoin(f).on(f.exhibit.eq(e))
.where(
e.status.ne(Status.FINISHED),
typeFilter(dto, h),
isDomesticEq(dto.getIsDomestic()),
dateFilter(dto.getStartDate(), dto.getEndDate(),e),
cursorCondition(cursor, cursorFavoriteCount, dto.getSortType(), e, f),
countryEq(dto.getCountry()),
Expand Down Expand Up @@ -168,16 +168,6 @@ private OrderSpecifier<?>[] sortFilter(ExhibitFilterRequestDto dto, QExhibit e,
}
}

private BooleanExpression typeFilter(ExhibitFilterRequestDto dto, QExhibitHall h) {
if (dto.getType() == null) return null;

if ("DOMESTIC".equalsIgnoreCase(dto.getType())) {
return h.isDomestic.isTrue();
} else if ("OVERSEAS".equalsIgnoreCase(dto.getType())) {
return h.isDomestic.isFalse();
}
return null;
}

private BooleanExpression dateFilter(LocalDate startDate, LocalDate endDate, QExhibit e) {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.atdev.artrip.domain.exhibit.service;

import lombok.RequiredArgsConstructor;
import org.atdev.artrip.domain.exhibit.data.Exhibit;
import org.atdev.artrip.domain.exhibit.reponse.ExhibitDetailResponse;
import org.atdev.artrip.domain.exhibit.repository.ExhibitRepository;
import org.atdev.artrip.domain.home.converter.HomeConverter;
import org.atdev.artrip.global.apipayload.code.status.ExhibitError;
import org.atdev.artrip.global.apipayload.exception.GeneralException;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class ExhibitService {

private final ExhibitRepository exhibitRepository;
private final HomeConverter homeConverter;


public ExhibitDetailResponse getExhibitDetail(Long exhibitId) {

Exhibit exhibit = exhibitRepository.findById(exhibitId)
.orElseThrow(() -> new GeneralException(ExhibitError._EXHIBIT_NOT_FOUND));

return homeConverter.toHomeExhibitResponse(exhibit);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.atdev.artrip.domain.exhibit.reponse.ExhibitDetailResponse;
import org.atdev.artrip.domain.exhibit.service.ExhibitService;
import org.atdev.artrip.domain.exhibit.web.dto.request.ExhibitFilterRequestDto;
import org.atdev.artrip.domain.home.response.FilterResponse;
import org.atdev.artrip.domain.home.response.HomeListResponse;
Expand All @@ -28,6 +29,7 @@
public class ExhibitController {

private final HomeService homeService;
private final ExhibitService exhibitService;


@Operation(summary = "장르 조회", description = "키워드 장르 데이터 전체 조회")
Expand All @@ -41,20 +43,6 @@ public ResponseEntity<CommonResponse<List<String>>> getGenres(){
return ResponseEntity.ok(CommonResponse.onSuccess(genres));
}

@Operation(summary = "장르별 전시 조회", description = "true=국내, false=국외")
@ApiErrorResponses(
common = {CommonError._BAD_REQUEST, CommonError._UNAUTHORIZED},
home = {HomeError._HOME_GENRE_NOT_FOUND}
)
@GetMapping("/genre/all")
public ResponseEntity<CommonResponse<List<HomeListResponse>>> getAllExhibits(
@RequestParam String genre,
@RequestParam Boolean isDomestic){

List<HomeListResponse> exhibits = homeService.getAllgenreExhibits(genre,isDomestic);
return ResponseEntity.ok(CommonResponse.onSuccess(exhibits));
}

@Operation(summary = "전시 상세 조회")
@ApiErrorResponses(
common = {CommonError._BAD_REQUEST, CommonError._UNAUTHORIZED},
Expand All @@ -64,42 +52,11 @@ public ResponseEntity<CommonResponse<List<HomeListResponse>>> getAllExhibits(
public ResponseEntity<CommonResponse<ExhibitDetailResponse>> getExhibit(
@PathVariable Long id){

ExhibitDetailResponse exhibit= homeService.getExhibitDetail(id);
ExhibitDetailResponse exhibit= exhibitService.getExhibitDetail(id);

return ResponseEntity.ok(CommonResponse.onSuccess(exhibit));
}

@Operation(summary = "사용자 맞춤 전시 전체 조회")
@ApiErrorResponses(
common = {CommonError._BAD_REQUEST, CommonError._UNAUTHORIZED},
home = {HomeError._HOME_EXHIBIT_NOT_FOUND}
)
@GetMapping("/personalized/all")
public ResponseEntity<CommonResponse<List<HomeListResponse>>> getAllPersonalized(
@AuthenticationPrincipal UserDetails userDetails,
@RequestParam Boolean isDomestic){

long userId = Long.parseLong(userDetails.getUsername());

List<HomeListResponse> exhibits= homeService.getAllPersonalized(userId,isDomestic);

return ResponseEntity.ok(CommonResponse.onSuccess(exhibits));
}

@Operation(summary = "이번주 전시 일정 전체 조회")
@ApiErrorResponses(
common = {CommonError._BAD_REQUEST, CommonError._UNAUTHORIZED},
home = {HomeError._HOME_EXHIBIT_NOT_FOUND}
)
@GetMapping("/schedule/all")
public ResponseEntity<CommonResponse<List<HomeListResponse>>> getAllSchedule(
@RequestParam(name = "isDomestic", required = false) Boolean isDomestic,
@RequestParam("date") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) LocalDate date){

List<HomeListResponse> exhibits= homeService.getAllSchedule(isDomestic,date);

return ResponseEntity.ok(CommonResponse.onSuccess(exhibits));
}

@Operation(summary = "해외 국가 목록 조회")
@ApiErrorResponses(
Expand All @@ -125,33 +82,8 @@ public ResponseEntity<CommonResponse<List<String>>> getDomestic(){
return ResponseEntity.ok(CommonResponse.onSuccess(domesticList));
}

@Operation(summary = "해외 특정 국가 랜덤 조회",description = "특정 해외 국가 전시데이터 3개 랜덤조회")
@ApiErrorResponses(
common = {CommonError._BAD_REQUEST, CommonError._UNAUTHORIZED},
home = {HomeError._HOME_UNRECOGNIZED_REGION, HomeError._HOME_EXHIBIT_NOT_FOUND}
)
@GetMapping("/overseas/random")
public ResponseEntity<CommonResponse<List<HomeListResponse>>> getRandomOverseas(@RequestParam String country){

List<HomeListResponse> random = homeService.getRandomOverseas(country, 3);

return ResponseEntity.ok(CommonResponse.onSuccess(random));
}

@Operation(summary = "국내 지역 전체 조회",description = "국내 지역 전시 전체 조회 1p 당 20개씩 조회.")
@ApiErrorResponses(
common = {CommonError._BAD_REQUEST, CommonError._UNAUTHORIZED},
home = {HomeError._HOME_UNRECOGNIZED_REGION, HomeError._HOME_EXHIBIT_NOT_FOUND}
)
@GetMapping("/domestic/all")
public ResponseEntity<CommonResponse<List<HomeListResponse>>> getRandomDomestic(@RequestParam String region){

List<HomeListResponse> random = homeService.getRandomDomestic(region, Pageable.ofSize(20));

return ResponseEntity.ok(CommonResponse.onSuccess(random));
}

@Operation(summary = "전시 조건 필터",description = "기간, 지역, 장르, 전시 스타일 필터 조회 - null 시 전체선택")
@Operation(summary = "전시 조건 필터 전체 조회",description = "기간, 지역, 장르, 전시 스타일 필터 조회 - null 시 전체선택")
@ApiErrorResponses(
common = {CommonError._BAD_REQUEST, CommonError._UNAUTHORIZED},
home = {HomeError._HOME_INVALID_DATE_RANGE, HomeError._HOME_UNRECOGNIZED_REGION, HomeError._HOME_EXHIBIT_NOT_FOUND}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class ExhibitFilterRequestDto {
private LocalDate startDate;
private LocalDate endDate;

private String type; // 국내,해외
private Boolean isDomestic;

private String country;
private String region;

Expand Down
Loading
Loading