-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ce5053
commit 1b278c5
Showing
6 changed files
with
149 additions
and
1 deletion.
There are no files selected for viewing
12 changes: 11 additions & 1 deletion
12
...notinote/src/main/java/com/answer/notinote/Notice/domain/repository/NoticeRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
package com.answer.notinote.Notice.domain.repository; | ||
|
||
import com.answer.notinote.Notice.domain.entity.Notice; | ||
import com.answer.notinote.Search.domain.repository.SearchDateInf; | ||
import com.answer.notinote.User.domain.entity.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
|
||
@Repository | ||
public interface NoticeRepository extends JpaRepository<Notice, Integer> { | ||
public interface NoticeRepository extends JpaRepository<Notice, Long> { | ||
Notice findByNid(Long nid); | ||
|
||
@Query("SELECT distinct n.ndate as ndate FROM Notice n, User u WHERE n.user.uid = u.uid") | ||
List<SearchDateInf> findUniqueNdate(User user); | ||
|
||
List<Notice> findByUser(User user); | ||
} |
33 changes: 33 additions & 0 deletions
33
spring/notinote/src/main/java/com/answer/notinote/Search/controller/SearchController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.answer.notinote.Search.controller; | ||
|
||
import com.answer.notinote.Search.dto.SearchListDto; | ||
import com.answer.notinote.Search.service.SearchService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import java.util.List; | ||
|
||
@RestController | ||
public class SearchController { | ||
|
||
@Autowired | ||
SearchService searchService; | ||
|
||
public SearchController(SearchService searchService){ | ||
this.searchService = searchService; | ||
} | ||
|
||
@RequestMapping(value="/search", method = RequestMethod.GET) | ||
public List<SearchListDto> searchList(HttpServletRequest request){ | ||
return searchService.searchList(request); | ||
} | ||
|
||
@RequestMapping(value="/search/{nid}", method = RequestMethod.GET) | ||
public String searchDetail(){ | ||
return "SearchDetail"; | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
...ng/notinote/src/main/java/com/answer/notinote/Search/domain/repository/SearchDateInf.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.answer.notinote.Search.domain.repository; | ||
|
||
import java.time.LocalDate; | ||
|
||
public interface SearchDateInf { | ||
LocalDate getNdate(); | ||
} |
7 changes: 7 additions & 0 deletions
7
spring/notinote/src/main/java/com/answer/notinote/Search/dto/SearchDetailDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.answer.notinote.Search.dto; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class SearchDetailDto { | ||
} |
26 changes: 26 additions & 0 deletions
26
spring/notinote/src/main/java/com/answer/notinote/Search/dto/SearchListDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.answer.notinote.Search.dto; | ||
|
||
import com.answer.notinote.Notice.domain.entity.Notice; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class SearchListDto { | ||
private LocalDate date; | ||
private List<String> save_titles; | ||
|
||
@Builder | ||
public SearchListDto(LocalDate date, List<String> save_titles){ | ||
this.date = date; | ||
this.save_titles = save_titles; | ||
} | ||
|
||
|
||
|
||
|
||
} |
65 changes: 65 additions & 0 deletions
65
spring/notinote/src/main/java/com/answer/notinote/Search/service/SearchService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.answer.notinote.Search.service; | ||
|
||
import com.answer.notinote.Auth.token.provider.JwtTokenProvider; | ||
import com.answer.notinote.Notice.domain.entity.Notice; | ||
import com.answer.notinote.Notice.domain.repository.NoticeRepository; | ||
import com.answer.notinote.Search.dto.SearchListDto; | ||
import com.answer.notinote.User.domain.entity.User; | ||
import com.answer.notinote.User.domain.repository.UserRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import java.time.LocalDate; | ||
import java.util.ArrayList; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
|
||
@Service | ||
public class SearchService { | ||
|
||
@Autowired | ||
NoticeRepository noticeRepository; | ||
@Autowired | ||
UserRepository userRepository; | ||
@Autowired | ||
JwtTokenProvider jwtTokenProvider; | ||
|
||
public List<SearchListDto> searchList(HttpServletRequest request){ | ||
|
||
String token = jwtTokenProvider.resolveToken(request); | ||
String useremail = jwtTokenProvider.getUserEmail(token); | ||
User user = userRepository.findByUemail(useremail).orElseThrow(IllegalArgumentException::new); | ||
|
||
List<Notice> notices = noticeRepository.findByUser(user); | ||
|
||
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))) { | ||
titleList.add(notices.get(j).getTitle()); | ||
} | ||
} | ||
titleLists.add(titleList); | ||
SearchListDto searchListDto = SearchListDto.builder() | ||
.date(dateList.get(i)) | ||
.save_titles(titleLists.get(i)) | ||
.build(); | ||
searchListDtos.add(searchListDto); | ||
} | ||
return searchListDtos; | ||
} | ||
|
||
} |