Skip to content

Commit

Permalink
Merge pull request #27 from MUIT-UMC/feature/search
Browse files Browse the repository at this point in the history
[feat] 뮤지컬, 공연장 검색 기능
  • Loading branch information
sweatbuckets authored Jan 23, 2025
2 parents 9115628 + c912139 commit 160e43b
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.Optional;

@Slf4j
@RestControllerAdvice(annotations = {RestController.class}, basePackageClasses = {CommentService.class})
@RestControllerAdvice(annotations = {RestController.class})
public class ExceptionAdvice extends ResponseEntityExceptionHandler {

//유효성 검사에서 제약 조건이 위반되었을 때 발생하는 예외
Expand Down
25 changes: 19 additions & 6 deletions src/main/java/muit/backend/controller/MusicalController.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package muit.backend.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import lombok.RequiredArgsConstructor;
import muit.backend.apiPayLoad.ApiResponse;
import muit.backend.dto.musicalDTO.MusicalResponseDTO;
import muit.backend.dto.theatreDTO.TheatreResponseDTO;
import muit.backend.service.musicalService.MusicalService;
import org.springframework.web.bind.annotation.*;

Expand Down Expand Up @@ -35,8 +38,9 @@ public ApiResponse<MusicalResponseDTO.MusicalHomeListDTO> getFiveHotMusicals() {

@GetMapping("/hot/all")
@Operation(summary = "뮤지컬 조회 - 리스트 HOT NOW 전체보기", description = "현재 HOT한 뮤지컬 전체 조회하는 API")
public ApiResponse<MusicalResponseDTO.MusicalHomeListDTO> getAllHotMusicals() {
return ApiResponse.onSuccess(musicalService.getAllHotMusicals());
@Parameter( name = "page", description = "페이지를 정수로 입력")
public ApiResponse<MusicalResponseDTO.MusicalHomeListDTO> getAllHotMusicals(@RequestParam(defaultValue = "0", name = "page") Integer page) {
return ApiResponse.onSuccess(musicalService.getAllHotMusicals(page));
}

@GetMapping("/rank")
Expand All @@ -47,8 +51,8 @@ public ApiResponse<MusicalResponseDTO.MusicalHomeListDTO> getFiveRankMusicals()

@GetMapping("/rank/all")
@Operation(summary = "뮤지컬 조회 - 리스트 RANKING 전체보기", description = "RANKING 뮤지컬 전체 조회하는 API")
public ApiResponse<MusicalResponseDTO.MusicalHomeListDTO> getAllRankMusicals() {
return ApiResponse.onSuccess(musicalService.getAllHotMusicals());
public ApiResponse<MusicalResponseDTO.MusicalHomeListDTO> getAllRankMusicals(@RequestParam(defaultValue = "0", name = "page") Integer page) {
return ApiResponse.onSuccess(musicalService.getAllHotMusicals(page));
}

@GetMapping("/open")
Expand All @@ -59,7 +63,16 @@ public ApiResponse<MusicalResponseDTO.MusicalOpenListDTO> getFiveOpenMusicals()

@GetMapping("/open/all")
@Operation(summary = "뮤지컬 조회 - 리스트 TICKET OPEN 전체보기", description = "오늘 이후 티켓 오픈하는 뮤지컬 전체 조회하는 API")
public ApiResponse<MusicalResponseDTO.MusicalOpenListDTO> getAllOpenMusicals() {
return ApiResponse.onSuccess(musicalService.getAllOpenMusicals());
public ApiResponse<MusicalResponseDTO.MusicalOpenListDTO> getAllOpenMusicals(@RequestParam(defaultValue = "0", name = "page") Integer page) {
return ApiResponse.onSuccess(musicalService.getAllOpenMusicals(page));
}

@GetMapping("")
@Operation(summary = "뮤지컬 검색", description = "상단바에서 뮤지컬을 검색하는 API 입니다.")
@Parameters({
@Parameter(name = "musicalName", description = "뮤지컬 이름을 검색어로 입력")
})
public ApiResponse<MusicalResponseDTO.MusicalHomeListDTO> searchMusicals(@RequestParam("musicalName") String musicalName) {
return ApiResponse.onSuccess(musicalService.findMusicalsByName(musicalName));
}
}
6 changes: 3 additions & 3 deletions src/main/java/muit/backend/controller/TheatreController.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public class TheatreController {
private final TheatreService theatreService;

@GetMapping ("/")
@Operation(summary = "공연장 조회", description = "시야확인에서 공연장을 검색하는 API 입니다.")
@Operation(summary = "공연장 검색", description = "시야확인에서 공연장을 검색하는 API 입니다.")
@Parameters({
@Parameter(name = "theatreName", description = "공연장 이름을 검색어로 입력")
})
public ApiResponse<TheatreResponseDTO.TheatreResultDTO> getTheatre(@RequestParam("theatreName") String theatreName) {
return ApiResponse.onSuccess(theatreService.getTheatre(theatreName));
public ApiResponse<TheatreResponseDTO.TheatreResultListDTO> getTheatre(@RequestParam("theatreName") String theatreName) {
return ApiResponse.onSuccess(theatreService.findTheatreByName(theatreName));
}

@GetMapping ("/{theatreId}")
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/muit/backend/converter/TheatreConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

public class TheatreConverter {
//DTO -> Entity
Expand All @@ -34,6 +36,16 @@ public static TheatreResponseDTO.TheatreResultDTO toTheatreResultDTO(Theatre the
.build();
}

public static TheatreResponseDTO.TheatreResultListDTO toTheatreResultListDTO(List<Theatre> theatres) {

List<TheatreResponseDTO.TheatreResultDTO> theatreResultsDTO = theatres.stream()
.map(TheatreConverter::toTheatreResultDTO).toList();

return TheatreResponseDTO.TheatreResultListDTO.builder()
.theatreResults(theatreResultsDTO)
.build();
}

public static TheatreRequestDTO.TheatreCreateDTO convertKopisDTOToTheatreCreateDTO(KopisTheatreResponseDTO.KopisTheatreDTO kopisTheatreDTO) {
return TheatreRequestDTO.TheatreCreateDTO.builder()
.name(kopisTheatreDTO.getFcltynm())
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/muit/backend/dto/theatreDTO/TheatreResponseDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import muit.backend.domain.enums.PostType;
import muit.backend.domain.enums.SectionType;

import java.util.List;

public class TheatreResponseDTO {
@Builder
@Getter
Expand All @@ -19,4 +21,12 @@ public static class TheatreResultDTO{
private String address;
private String theatrePic;
}

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public static class TheatreResultListDTO{
private List<TheatreResultDTO> theatreResults;
}
}
6 changes: 4 additions & 2 deletions src/main/java/muit/backend/repository/MusicalRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
@Repository
public interface MusicalRepository extends JpaRepository<Musical, Long> {
List<Musical> findTop5ByOrderByIdAsc();
List<Musical> findAllByOrderByIdAsc();
List<Musical> findAllByOrderByIdAsc(Pageable pageable);

@Query(value = "SELECT * FROM musical m WHERE m.open_date BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 7 DAY) ORDER BY m.open_date ASC", nativeQuery = true)
List<Musical> getFiveOpenWithin7Days(Pageable pageable);

@Query("SELECT m FROM Musical m WHERE m.openDate > CURRENT_TIMESTAMP ORDER BY m.openDate ASC")
List<Musical> getAllOpenAfterToday();
List<Musical> getAllOpenAfterToday(Pageable pageable);

List<Musical> findByNameContaining(String name);
}
3 changes: 2 additions & 1 deletion src/main/java/muit/backend/repository/TheatreRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import muit.backend.domain.entity.musical.Theatre;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
import java.util.Optional;

public interface TheatreRepository extends JpaRepository<Theatre, Long> {
Optional<Theatre> findByName(String name);
List<Theatre> findByNameContaining(String name);

Optional<Theatre> findAllById(Long theatreId);
}
3 changes: 3 additions & 0 deletions src/main/java/muit/backend/service/EventServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import muit.backend.dto.eventDTO.EventResponseDTO;
import muit.backend.repository.EventRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -40,6 +41,8 @@ public EventResponseDTO.EventGroupListDTO getEventListOrderByEvFrom(LocalDate to
.filter(group -> group.stream() // List<Event>로 변환된 스트림을 다시 스트림으로 변환
.anyMatch(event -> !event.getEvFrom().isBefore(today))) //evFrom이 today보다 앞선다면의 부정
.collect(Collectors.toList()); // 최종적으로 List<List<Event>>로 변환


return EventConverter.toEventGroupListDTO(eventListGroupedByMusicalId);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ public interface MusicalService {

public MusicalResponseDTO.MusicalHomeListDTO getFiveMusicals();

public MusicalResponseDTO.MusicalHomeListDTO getAllHotMusicals();
public MusicalResponseDTO.MusicalHomeListDTO getAllHotMusicals(Integer page);

public MusicalResponseDTO.MusicalOpenListDTO getFiveOpenMusicals();

public MusicalResponseDTO.MusicalOpenListDTO getAllOpenMusicals();
public MusicalResponseDTO.MusicalOpenListDTO getAllOpenMusicals(Integer page);

public MusicalResponseDTO.MusicalHomeListDTO findMusicalsByName(String musicalName);
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ public MusicalResponseDTO.MusicalHomeListDTO getFiveMusicals(){
}

@Override
public MusicalResponseDTO.MusicalHomeListDTO getAllHotMusicals(){
List<Musical> musicals = musicalRepository.findAllByOrderByIdAsc();

public MusicalResponseDTO.MusicalHomeListDTO getAllHotMusicals(Integer page){
Pageable pageable = PageRequest.of(page,20);
List<Musical> musicals = musicalRepository.findAllByOrderByIdAsc(pageable);
return MusicalConverter.toMusicalHomeListDTO(musicals);
}

Expand All @@ -104,9 +104,17 @@ public MusicalResponseDTO.MusicalOpenListDTO getFiveOpenMusicals(){
}

@Override
public MusicalResponseDTO.MusicalOpenListDTO getAllOpenMusicals(){
List<Musical> musicals = musicalRepository.getAllOpenAfterToday();
public MusicalResponseDTO.MusicalOpenListDTO getAllOpenMusicals(Integer page){
Pageable pageable = PageRequest.of(page,20);
List<Musical> musicals = musicalRepository.getAllOpenAfterToday(pageable);

return MusicalConverter.toMusicalOpenListDTO(musicals);
}

@Override
public MusicalResponseDTO.MusicalHomeListDTO findMusicalsByName(String musicalName){
List<Musical> musicals = musicalRepository.findByNameContaining(musicalName);

return MusicalConverter.toMusicalHomeListDTO(musicals);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

@Service
public interface TheatreService {
public TheatreResponseDTO.TheatreResultDTO getTheatre(String theatreName);
public TheatreResponseDTO.TheatreResultListDTO findTheatreByName(String theatreName);

public SectionResponseDTO.SectionResultDTO getSection(Long theatreId, SectionType sectionType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.springframework.transaction.annotation.Transactional;

import java.io.InputStream;
import java.util.List;
import java.util.Optional;

@Service
Expand All @@ -33,11 +34,10 @@ public class TheatreServiceImpl implements TheatreService {
private final KopisConfig kopisConfig;

@Override
public TheatreResponseDTO.TheatreResultDTO getTheatre(String theatreName){
Theatre theatre = theatreRepository.findByName(theatreName)
.orElseThrow(() -> new RuntimeException("Theatre not found"));
public TheatreResponseDTO.TheatreResultListDTO findTheatreByName(String theatreName){
List<Theatre> theatre = theatreRepository.findByNameContaining(theatreName);

return TheatreConverter.toTheatreResultDTO(theatre);
return TheatreConverter.toTheatreResultListDTO(theatre);
}

@Override
Expand Down

0 comments on commit 160e43b

Please sign in to comment.