Skip to content

Commit

Permalink
[#52] feat: search filter with child
Browse files Browse the repository at this point in the history
  • Loading branch information
hellouz818 committed May 26, 2022
1 parent 273c6db commit fbeddc7
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
Expand All @@ -11,6 +12,7 @@

@Configuration
@EnableSwagger2
@EnableWebMvc
public class SwaggerConfig {
@Bean
public Docket restAPI() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.answer.notinote.Notice.domain.repository;

import com.answer.notinote.Child.domain.Child;
import com.answer.notinote.Notice.domain.entity.Notice;
import com.answer.notinote.Search.domain.repository.SearchDateInf;
import com.answer.notinote.User.domain.entity.User;
Expand All @@ -10,7 +11,6 @@

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;


@Repository
Expand All @@ -24,4 +24,7 @@ public interface NoticeRepository extends JpaRepository<Notice, Long> {
List<Notice> findByUser(User user);

List<Notice> findByNdate(LocalDate date);
}

List<Notice> findByUserAndChild(User user, Child child);

}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,10 @@ public SearchDetailDto searchDetail(@RequestParam("date") String date, HttpServl
return searchService.searchDetailList(date, request);
}

@RequestMapping(value="/search/child", method = RequestMethod.GET)
public List<SearchListDto> searchChildList(@RequestParam("cid") Long cid, HttpServletRequest request){
return searchService.searchChildList(cid, request);
}


}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.answer.notinote.Search.service;

import com.answer.notinote.Auth.token.provider.JwtTokenProvider;
import com.answer.notinote.Child.domain.Child;
import com.answer.notinote.Child.domain.repository.ChildRepository;
import com.answer.notinote.Event.domain.Event;
import com.answer.notinote.Event.service.EventService;
import com.answer.notinote.Notice.domain.entity.Notice;
Expand Down Expand Up @@ -34,6 +36,8 @@ public class SearchService {
@Autowired
UserRepository userRepository;
@Autowired
ChildRepository childRepository;
@Autowired
JwtTokenProvider jwtTokenProvider;

public List<SearchListDto> searchList(HttpServletRequest request){
Expand Down Expand Up @@ -107,4 +111,44 @@ public SearchDetailDto searchDetailList(String date, HttpServletRequest request)
.build();

}

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

String token = jwtTokenProvider.resolveToken(request);
String useremail = jwtTokenProvider.getUserEmail(token);
User user = userRepository.findByUemail(useremail).orElseThrow(IllegalArgumentException::new);
Child child = childRepository.findById(cid).orElseThrow(IllegalArgumentException::new);
List<Notice> notices = noticeRepository.findByUserAndChild(user,child);

List<LocalDate> dateList = new ArrayList<>();
List<List<String>> titleLists = new ArrayList<>();
List<SearchListDto> searchListDtos = new ArrayList<>();

//유니크한 날짜값만 리스트에 저장하는 jpa 쿼리 메소드
for(int i = 0; i < noticeRepository.findUniqueNdate(user).size(); i++){
dateList.add(noticeRepository.findUniqueNdate(user).get(i).getNdate());
}

dateList.sort(Comparator.reverseOrder()); //최신순 정렬

for(int i = 0; i < dateList.size(); i++){
List<String> titleList = new ArrayList<>();
for(int j = 0; j < notices.size(); j++){
if((notices.get(j).getNdate()).equals(dateList.get(i))) {
if (notices.get(j).getTitle() != null) {
titleList.add(notices.get(j).getTitle());
}
}
}

if (!titleLists.get(i).isEmpty()) {
SearchListDto searchListDto = SearchListDto.builder()
.date(dateList.get(i))
.saved_titles(titleLists.get(i))
.build();
searchListDtos.add(searchListDto);
}
}
return searchListDtos;
}
}

0 comments on commit fbeddc7

Please sign in to comment.