Skip to content

Commit

Permalink
[#52] fix: search Detail API
Browse files Browse the repository at this point in the history
  • Loading branch information
hellouz818 committed Jun 2, 2022
1 parent 9af22a5 commit d49688c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.answer.notinote.Search.controller;

import com.answer.notinote.Search.dto.SearchDetailDto;
import com.answer.notinote.Search.dto.SearchListDto;
import com.answer.notinote.Search.dto.SearchResultDetailDto;
import com.answer.notinote.Search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -10,7 +10,6 @@
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;
import java.util.List;

@RestController
Expand All @@ -29,8 +28,8 @@ public List<SearchListDto> searchList(HttpServletRequest request){
}

@RequestMapping(value="/search/detail", method = RequestMethod.GET)
public SearchDetailDto searchDetail(@RequestParam("date") String date, HttpServletRequest request){
return searchService.searchDetailList(date, request);
public SearchResultDetailDto searchDetail(@RequestParam("nid") Long nid, HttpServletRequest request){
return searchService.searchDetailList(nid, request);
}

@RequestMapping(value="/search/child", method = RequestMethod.GET)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.answer.notinote.Search.dto;

import com.answer.notinote.Notice.domain.entity.Notice;
import com.answer.notinote.Notice.dto.NoticeSentenceDto;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -11,14 +10,12 @@
@Getter
@NoArgsConstructor
public class SearchResultDetailDto {
private Long id;
private String imageUri;
private List<NoticeSentenceDto> fullText;
private String korean;

@Builder
public SearchResultDetailDto(Long id, String imageUri, List<NoticeSentenceDto> fullText, String korean){
this.id = id;
public SearchResultDetailDto(String imageUri, List<NoticeSentenceDto> fullText, String korean){
this.imageUri = imageUri;
this.fullText = fullText;
this.korean = korean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.answer.notinote.Notice.dto.NoticeSentenceDto;
import com.answer.notinote.Notice.service.NoticeService;
import com.answer.notinote.Search.dto.SearchSavedListDto;
import com.answer.notinote.Search.dto.SearchDetailDto;
import com.answer.notinote.Search.dto.SearchListDto;
import com.answer.notinote.Search.dto.SearchResultDetailDto;
import com.answer.notinote.User.domain.entity.User;
Expand Down Expand Up @@ -85,40 +84,23 @@ public List<SearchListDto> searchList(HttpServletRequest request) {
return saved;
}

public SearchDetailDto searchDetailList(String date, HttpServletRequest request) {
public SearchResultDetailDto searchDetailList(Long nid, HttpServletRequest request) {

String token = jwtTokenProvider.resolveToken(request);
String useremail = jwtTokenProvider.getUserEmail(token);
User user = userRepository.findByUemail(useremail).orElseThrow(IllegalArgumentException::new);
LocalDate trans_date = LocalDate.parse(date, DateTimeFormatter.ISO_DATE);
List<Notice> notices = noticeRepository.findByNdate(trans_date);

System.out.println(notices);
List<List<Object>> resultLists = new ArrayList<>();
List<Object> test = new ArrayList<>();

for (int i = 0; i < notices.size(); i++) {
Notice notice = notices.get(i);

List<Event> events = eventService.findAllByNotice(notice);
List<NoticeSentenceDto> fullText = noticeService.extractSentenceFromEvent(notice.getTrans_full(), events);

SearchResultDetailDto searchResultDetailDto = SearchResultDetailDto.builder()
.imageUri(notice.getNimageurl() + "/" + notice.getNimagename())
.id(notice.getNid())
.korean(notice.getOrigin_full())
.fullText(fullText)
.build();

test.add(searchResultDetailDto);
}
System.out.println(test);
Notice notice = noticeRepository.findByNid(nid);
List<Event> events = eventService.findAllByNotice(notice);
List<NoticeSentenceDto> fullText = noticeService.extractSentenceFromEvent(notice.getTrans_full(), events);

return SearchDetailDto.builder()
.date(trans_date)
.results(test)
SearchResultDetailDto searchResultDetailDto = SearchResultDetailDto.builder()
.imageUri(notice.getNimageurl()+ "/" + notice.getNimagename())
.fullText(fullText)
.korean(notice.getOrigin_full())
.build();

return searchResultDetailDto;

}

public List<SearchListDto> searchChildList(Long cid, HttpServletRequest request) {
Expand Down

0 comments on commit d49688c

Please sign in to comment.