Skip to content

Commit

Permalink
Merge pull request #25 from PLACE-4th-UMC/fix/7-uploadStory
Browse files Browse the repository at this point in the history
[fix/7-uploadStory] 스토리 업로드 - 전시회 검색 기능 추가
  • Loading branch information
5jisoo authored Aug 10, 2023
2 parents 654ab1a + 08f92be commit 0ae3d34
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.umc.place.exhibition.dto;

import com.umc.place.exhibition.entity.Exhibition;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.domain.Page;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Data
@NoArgsConstructor
public class SearchExhibitionsByNameResDto {

private List<SearchedExhibitionByName> searchedExhibitions = new ArrayList();

@Builder
public SearchExhibitionsByNameResDto(Page<Exhibition> exhibitions) {
this.searchedExhibitions
= exhibitions.stream()
.map(exhibition -> new SearchedExhibitionByName(exhibition))
.collect(Collectors.toList());
}

@Data
@NoArgsConstructor
public static class SearchedExhibitionByName {
private Long exhibitionIdx;
private String exhibitionName;

@Builder
public SearchedExhibitionByName(Exhibition exhibition) {
this.exhibitionIdx = exhibition.getExhibitionIdx();
this.exhibitionName = exhibition.getExhibitionName();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
@Repository
public interface ExhibitionRepository extends JpaRepository<Exhibition, Long> {
Page<Exhibition> findByCategory(Category category, Pageable pageable); // 카테고리 기반 전체 조회(페이징)

Page<Exhibition> findAll(Pageable pageable); // 전체 조회(페이징)

boolean existsByCategory(Category category);

@Query("select case when count(e) > 0 then true else false end from Exhibition e where Function('replace', e.location, ' ', '') like %:location%")
Expand All @@ -25,4 +27,6 @@ public interface ExhibitionRepository extends JpaRepository<Exhibition, Long> {

@Query("select e from Exhibition e where Function('replace', e.location, ' ', '') like %:location%")
Page<Exhibition> findByLocationLike(@Param("location") String location, Pageable pageable);

Page<Exhibition> findByExhibitionNameContainingOrderByExhibitionName(String searchKeyword, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import com.umc.place.comment.service.CommentService;
import com.umc.place.common.BaseException;
import com.umc.place.common.BaseResponse;
import com.umc.place.exhibition.dto.SearchExhibitionsByNameResDto;
import com.umc.place.story.dto.StoryDetailResponseDto;
import com.umc.place.story.dto.StoryUploadRequestDto;
import com.umc.place.story.dto.StoryUploadResponseDto;
import com.umc.place.story.service.StoryService;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

import static com.umc.place.common.BaseResponseStatus.NULL_STORY;
Expand Down Expand Up @@ -41,6 +44,17 @@ public BaseResponse<StoryDetailResponseDto> getStoryDetail(@PathVariable Long st
}
}

@GetMapping("/search")
public BaseResponse<SearchExhibitionsByNameResDto> getExhibitionWhenUploadStory(
@PageableDefault(size = 5) Pageable pageable,
@RequestParam(required = false) String searchWord) {
try {
return new BaseResponse<>(storyService.searchExhibitionByName(searchWord, pageable));
} catch (BaseException e) {
return new BaseResponse<>(e.getStatus());
}
}

@PostMapping("/{storyIdx}/comment")
public BaseResponse<CommentUploadResDto> uploadStoryComment(@PathVariable Long storyIdx,
@RequestBody CommentUploadReqDto reqDto,
Expand Down
16 changes: 16 additions & 0 deletions place/src/main/java/com/umc/place/story/service/StoryService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.umc.place.comment.dto.CommentResDto;
import com.umc.place.comment.repository.CommentRepository;
import com.umc.place.common.BaseException;
import com.umc.place.exhibition.dto.SearchExhibitionsByNameResDto;
import com.umc.place.exhibition.entity.Exhibition;
import com.umc.place.exhibition.repository.ExhibitionRepository;
import com.umc.place.story.dto.StoryDetailResponseDto;
Expand All @@ -16,6 +17,8 @@
import com.umc.place.user.entity.User;
import com.umc.place.user.repository.UserRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand Down Expand Up @@ -79,6 +82,19 @@ public StoryDetailResponseDto getStoryDetail(Long storyIdx, Long userId) throws
}
}

public SearchExhibitionsByNameResDto searchExhibitionByName(String searchWord, Pageable page) throws BaseException {
try {
searchWord = searchWord.trim();
Page<Exhibition> searchedExhibitions
= exhibitionRepository.findByExhibitionNameContainingOrderByExhibitionName(searchWord, page);
return SearchExhibitionsByNameResDto.builder()
.exhibitions(searchedExhibitions)
.build();
} catch (Exception e) {
throw new BaseException(DATABASE_ERROR);
}
}

@Transactional
public StoryUploadResponseDto uploadStory(StoryUploadRequestDto storyUploadRequestDto, Long userId) throws BaseException {
try {
Expand Down

0 comments on commit 0ae3d34

Please sign in to comment.